我想在llvm IR中找到对llvm.pow.f64函数的所有函数调用。请给我一个方法来执行此操作。
答案 0 :(得分:3)
嗯,这是一个基本的FunctionPass
,可以找到对函数的所有调用:
class MyPass : public FunctionPass {
public:
static char ID;
MyPass()
: FunctionPass(ID)
{}
virtual bool runOnFunction(Function &F) {
for (Function::iterator bb = F.begin(), bb_e = F.end(); bb != bb_e; ++bb) {
for (BasicBlock::iterator ii = bb->begin(), ii_e = bb->end(); ii != ii_e; ++ii) {
if (CallInst *callInst = dyn_cast<CallInst>(&*ii)) {
Function *calledFunc = callInst->getCalledFunction();
errs() << "Calling function " << calledFunc->getName() << "\n";
}
}
}
}
};
它打印由其正在处理的函数调用的所有函数的名称。 getName
会为您提供StringRef
,因此请随意将其与您想要的任何值进行比较。