0

I am trying to do some instrumentation over an ll file. One of the task I want to achieve is the following.

Whenever I meet an AllocaInstr like:

%1 = alloca i32

I want to instrument a function call __save_addr() after it as follows:

%1 = alloca i32

call __save_addr(i32* %1)

Is there a way to achieve this?

StrawHara
  • 1,301
  • 19
  • 33
ZLW
  • 151
  • 9

1 Answers1

1
  1. Iterate over all the instructions in the function. For each one,

  2. check whether it's an AllocaInst. If it is,

  3. Create a new CallInst calling your function*, and pass the AllocaInst instance as the first argument.

*If your function is already in the module, you can find it via Module::getFunction; if it's in another module, you'll have to create a declaration for it.

Oak
  • 26,231
  • 8
  • 93
  • 152