2

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?

mikasa
  • 783
  • 1
  • 11
  • 29

1 Answers1

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