Hi all, I want to run a function pass on a certain .bc file. In the process, the pass will insert a check function into the .bc file. I know the .bc file is regarded as a module in LLVM. So, there are two basic steps needed to be done, 1, Use the "getOrInsertFunction"API to add a declaration of the extern "check function". 2, Use the "insertBefore"API to insert the CallInst into the right position. My problem is about the step 1. How can I get the handle of the .bc file (Probably is a Module*)? so I can declare the extern function like // insert the " i32 @fib(i32 )" to the module M Function *FibF cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context), Type::getInt32Ty(Context), (Type *)0)); How can I get the "M" of the .bc file?????? Any help~ -- 祝好! 甄凯 ------------------------------------------------------------------------------------------------------ 2012-04-10 ------------------------------------------------------------------------------------------------------ Name: 甄凯(ZhenKai) Homepage:http://www.renren.com/262729393 Email: zhenkaixd at 126.com or 846227103 at qq.com TEL: 15810729006(Beijing) Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120410/64a6839e/attachment.html>
Alexander Potapenko
2012-Apr-10 07:29 UTC
[LLVMdev] How to get the module handle of a .bc file??
Objects that form the IR (functions, basic blocks, instructions) have the getParent() method that returns their paren (module for a function, basic block for a single instruction etc.) BTW, LLVM Doxygen is really helpful. It's usually the first result when you search for "LLVM <classname> class reference" On Tue, Apr 10, 2012 at 11:17 AM, 15102925731 <zhenkaixd at 126.com> wrote:> > Hi all, > I want to run a function pass on a certain .bc file. In the process, the > pass will insert a check function into the .bc file. > > I know the .bc file is regarded as a module in LLVM. So, there are two basic > steps needed to be done, > 1, Use the "getOrInsertFunction"API to add a declaration of the extern > "check function". > 2, Use the "insertBefore"API to insert the CallInst into the right position. > > My problem is about the step 1. How can I get the handle of the .bc file > (Probably is a Module*)? so I can > declare the extern function like > // insert the " i32 @fib(i32 )" to the module M > Function *FibF > cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context), > Type::getInt32Ty(Context), > (Type *)0)); > How can I get the "M" of the .bc file?????? > > Any help~ > > -- > 祝好! > > 甄凯 > ------------------------------------------------------------------------------------------------------ > 2012-04-10 > ------------------------------------------------------------------------------------------------------ > Name: 甄凯(ZhenKai) > Homepage:http://www.renren.com/262729393 > Email: zhenkaixd at 126.com or 846227103 at qq.com > TEL: 15810729006(Beijing) > Address: Room I-406, Central Building, Tsinghua University, Beijing, China. > 100084. > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Alexander Potapenko Software Engineer Google Moscow
Oh, I see. Also, I also tried a module pass(the short source code is as follow). I intended to run the module pass on the .bc file declaring the check function to the module's symbol table. Then I go for the function pass to insert the CallInst instruction. Does that make sense? Thank you!! #include "llvm/Pass.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Module.h" #include "llvm/Function.h" #include "llvm/LLVMContext.h" #include "llvm/DerivedTypes.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" #include "llvm/Analysis/Verifier.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/Support/TargetSelect.h" using namespace llvm; namespace { struct Hello2 : public ModulePass { static char ID; Hello2() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { errs() << "Hello: " << '\n' << '\n'; //errs().write_escaped(F.getName()) << '\n'; Function *check cast<Function>(M.getOrInsertFunction("check", Type::getInt32Ty(M.getContext()), (Type *)0)); if(NULL!=M.getFunction("check")) errs()<<"declare succeeded!"<<'\n'; return true; } }; } -- 祝好! 甄凯 ------------------------------------------------------------------------------------------------------ 2012-04-10 ------------------------------------------------------------------------------------------------------ Name: 甄凯(ZhenKai) Homepage:http://www.renren.com/262729393 Email: zhenkaixd at 126.com or 846227103 at qq.com TEL: 15810729006(Beijing) Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084. At 2012-04-10 15:29:15,"Alexander Potapenko" <glider at google.com> wrote:>Objects that form the IR (functions, basic blocks, instructions) have >the getParent() method that returns their paren (module for a >function, basic block for a single instruction etc.) >BTW, LLVM Doxygen is really helpful. It's usually the first result >when you search for "LLVM <classname> class reference" > >On Tue, Apr 10, 2012 at 11:17 AM, 15102925731 <zhenkaixd at 126.com> wrote: >> >> Hi all, >> I want to run a function pass on a certain .bc file. In the process, the >> pass will insert a check function into the .bc file. >> >> I know the .bc file is regarded as a module in LLVM. So, there are two basic >> steps needed to be done, >> 1, Use the "getOrInsertFunction"API to add a declaration of the extern >> "check function". >> 2, Use the "insertBefore"API to insert the CallInst into the right position. >> >> My problem is about the step 1. How can I get the handle of the .bc file >> (Probably is a Module*)? so I can >> declare the extern function like >> // insert the " i32 @fib(i32 )" to the module M >> Function *FibF >> cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context), >> Type::getInt32Ty(Context), >> (Type *)0)); >> How can I get the "M" of the .bc file?????? >> >> Any help~ >> >> -- >> 祝好! >> >> 甄凯 >> ------------------------------------------------------------------------------------------------------ >> 2012-04-10 >> ------------------------------------------------------------------------------------------------------ >> Name: 甄凯(ZhenKai) >> Homepage:http://www.renren.com/262729393 >> Email: zhenkaixd at 126.com or 846227103 at qq.com >> TEL: 15810729006(Beijing) >> Address: Room I-406, Central Building, Tsinghua University, Beijing, China. >> 100084. >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > > > >-- >Alexander Potapenko >Software Engineer >Google Moscow-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120410/9a307aef/attachment.html>
Maybe Matching Threads
- [LLVMdev] How to get the module handle of a .bc file??
- [LLVMdev] How to instrument a this function using insertBefore instruction???
- [LLVMdev] How to instrument a this function using insertBefore instruction???
- [LLVMdev] How to explain this weird phenomenon????????
- [LLVMdev] How to instrument a this function using insertBefore instruction???