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?
Asked
Active
Viewed 1,343 times
1 Answers
4
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.

Community
- 1
- 1

Chirag Patel
- 1,141
- 1
- 11
- 23