常用LLVM PASS 记载:

常用类:

const Function, const PHINode, const Argument, (省略const), Value, CallInst, BasicBlock, Instruction, ReturnInst

常用api:

判断是否为某一个类:

举例: if(const Argument * arg = dyn_cast<Argument>(xxxx) )

CallInst获取参数:

CallInst->getArgOperand(arg_index)

获取返回值:

ReturnInst->getReturnValue()

获取函数的调用点:

for(const User user: Function->users()){

// 这里的Function代表Function的一个对象

}

遍历整个Module

for (const Function &f : Module m) {

​ for (const BasicBlock &b : f) {

​ for (const Instruction &i : b) {

获取名字

xxx->getName().data()

参数获取父亲函数(即参数在哪一个函数中)

arg->getParent()

参数获取在父亲函数的第几个参数

arg->getArgNo()

获取Call指令的内容

CallInst->getCalledOperand()

获取Call指令具体调用的函数

CallInst->getCalledFunction()

获取Call指令有多少参数

CallInst->getNumArgOperands()

函数获取第几个参数

Function->getArg(index)

遍历PHI节点的目的可能情况

for (const Value *income :phi->incoming_values())