Reputation: 900
I need to check if function A in my file is calling function B. My current approach is to go through all the instructions in function A and see if any of the call/invoke instructions are calling B. Can anyone suggest a better approach?
Upvotes: 3
Views: 1643
Reputation: 1161
LLVM Provides easy to use method to traverse in-memory IR's use-def/def-use chain using Users/Uses.
You can traverse B's Uses and then check if its parent function is A or not.
for(Value::Use_iterator ui = B.Use_Begin(); ui != B.Use_end(); ++ui) {
if(instruction* call = dyn_cast<Instruction>(ui->getUser())) {
Function* caller = call->getParent()->getParent();
// check if caller is A or not
}
}
above code snippet may work with few modifications. See: LLVM Use Ref for more info.
Upvotes: 5