Reputation: 403
I'm writing a function pass in LLVM and need to call the method Module::getOrInsertFunction. I need to access the module of the current function. How do I get it?
Upvotes: 5
Views: 5151
Reputation: 31
Please refer to: http://llvm.org/docs/WritingAnLLVMPass.html According to the documentation here, To be explicit, FunctionPass subclasses are not allowed to: 1. Inspect or modify a Function other than the one currently being processed. 2. Add or remove Functions from the current Module. 3. Add or remove global variables from the current Module. 4. Maintain state across invocations of runOnFunction (including global data).
So, you cannot call getOrInsertFunction from inside a FunctionPass. You will need a ModulePass
Upvotes: 3
Reputation: 581
You can use getParent() function: http://llvm.org/docs/doxygen/html/classllvm_1_1GlobalValue.html#a9e1fc23a17e97d2d1732e753ae9251ac
Upvotes: 10