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?

4

1 回答 1

1
  1. 遍历函数中的所有指令。每一个人,

  2. 检查它是否是AllocaInst. 如果是,

  3. 创建一个新的CallInst调用您的函数*,并将AllocaInst实例作为第一个参数传递。

*如果您的功能已经在模块中,您可以通过Module::getFunction; 如果它在另一个模块中,则必须为它创建一个声明。

于 2014-07-01T12:32:28.633 回答