I want to write an LLVM pass that will extract function call arguments. If the argument is constant, my goal is to restore what this constant is.
IR looks like
%2 = call noalias i8* @malloc(i64 512)
An LLVM pass looks like
bool runOnFunction(Function &F) override {
for (auto& B : F) {
for (auto& I : B) {
if(CallInst* call_inst = dyn_cast<CallInst>(&I)) {
Function* fn = call_inst->getCalledFunction();
StringRef fn_name = fn->getName();
errs() << fn_name << " : " << call_inst->getArgOperand(0) << "\n";
for(auto arg = fn->arg_begin(); arg != fn->arg_end(); ++arg) {
errs() << *arg << "\n";
}
}
}
}
return false;
}
If I run a pass through opt, it produces the following
malloc : 0x3df3f40
i64 %0
What does it mean 0x3df3f40? Instead i64and 512why does he create i64and %0?
source
share