Ryan Taylor via llvm-dev
2016-Sep-04 01:18 UTC
[llvm-dev] How to insert instructions before each function calls?
So one way might look like this: IRBuilder<> Builder(&*BB); // BB = Function::iterator OR IRBuilder<> Builder(CallInst->getParent()); Builder.SetInsertPoint(CallInst); InstructionClass *YourNewInstruction builder.CreateInstructionClass(.....); // InstructionClass = type of instruction you are inserting -Ryan On Sat, Sep 3, 2016 at 6:04 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:> Take a look at IRBuilder and SetInsertPoint(). > > On Sep 3, 2016 18:02, "SHUCAI YAO via llvm-dev" <llvm-dev at lists.llvm.org> > wrote: > >> I'm trying to insert some instructions before each function calls (before >> arguments push): >> lea %EAX, label ----- new instructions >> mov [ESP+stacksize], %EAX ----- new instructions >> push arg1 >> push arg2 >> ... >> push argn >> call callee_name >> >> I am a newbie to LLVM. I tried to use buildMI() to insert the >> instructions in the lowercall() function. But I couldn't put these >> instructions in the right positions. Is there a way to locate the position >> by using MachineBasicBlock iterator? >> >> Any suggestions are appreciated. >> >> Thanks! >> Shucai >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160903/e20cef85/attachment.html>
Mehdi Amini via llvm-dev
2016-Sep-04 05:45 UTC
[llvm-dev] How to insert instructions before each function calls?
> On Sep 3, 2016, at 6:18 PM, Ryan Taylor via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > So one way might look like this: > > IRBuilder<> Builder(&*BB); // BB = Function::iterator OR IRBuilder<> Builder(CallInst->getParent()); > Builder.SetInsertPoint(CallInst); > InstructionClass *YourNewInstruction = builder.CreateInstructionClass(.....); // InstructionClass = type of instruction you are inserting >I’m not sure how the IRBuilder would work at the MI level, as Shucai was asking.> > > > On Sat, Sep 3, 2016 at 6:04 PM, Ryan Taylor <ryta1203 at gmail.com <mailto:ryta1203 at gmail.com>> wrote: > Take a look at IRBuilder and SetInsertPoint(). > > > On Sep 3, 2016 18:02, "SHUCAI YAO via llvm-dev" <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: > I'm trying to insert some instructions before each function calls (before arguments push): > lea %EAX, label ----- new instructions > mov [ESP+stacksize], %EAX ----- new instructions > push arg1 > push arg2 > ... > push argn > call callee_name > > I am a newbie to LLVM. I tried to use buildMI() to insert the instructions in the lowercall() function. But I couldn't put these instructions in the right positions. Is there a way to locate the position by using MachineBasicBlock iterator?Can you describe more precisely what are you trying to achieve? I.e. what are these instructions? Why do you want to do that? It may lead to a different answer. — Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160903/bfebafaf/attachment-0001.html>
Ryan Taylor via llvm-dev
2016-Sep-04 11:44 UTC
[llvm-dev] How to insert instructions before each function calls?
Mehdi, Sorry, I misread his original post. So something like: XXXInsrtInfo *XII; // target instruction info MachineBasicBlock::iterator MI = MachineBasicBlock(YourCallInst); MachineBasicBlock *MBB = YourCallInst->getParent(); // basic block location of your call inst BuildMI(*MBB, MI, DebugLoc(), XII->get(XXX:::INSTRUCTION)......); The BuildMI params are going to depend on what you want to do with the instruction being inserted. http://llvm.org/docs/doxygen/html/MachineInstrBuilder_8h.html -Ryan On Sun, Sep 4, 2016 at 1:45 AM, Mehdi Amini <mehdi.amini at apple.com> wrote:> > On Sep 3, 2016, at 6:18 PM, Ryan Taylor via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > So one way might look like this: > > IRBuilder<> Builder(&*BB); // BB = Function::iterator OR IRBuilder<> > Builder(CallInst->getParent()); > Builder.SetInsertPoint(CallInst); > InstructionClass *YourNewInstruction = builder.CreateInstructionClass(.....); > // InstructionClass = type of instruction you are inserting > > > I’m not sure how the IRBuilder would work at the MI level, as Shucai was > asking. > > > > > On Sat, Sep 3, 2016 at 6:04 PM, Ryan Taylor <ryta1203 at gmail.com> wrote: > >> Take a look at IRBuilder and SetInsertPoint(). >> >> On Sep 3, 2016 18:02, "SHUCAI YAO via llvm-dev" <llvm-dev at lists.llvm.org> >> wrote: >> >>> I'm trying to insert some instructions before each function calls >>> (before arguments push): >>> lea %EAX, label ----- new instructions >>> mov [ESP+stacksize], %EAX ----- new instructions >>> push arg1 >>> push arg2 >>> ... >>> push argn >>> call callee_name >>> >>> I am a newbie to LLVM. I tried to use buildMI() to insert the >>> instructions in the lowercall() function. But I couldn't put these >>> instructions in the right positions. Is there a way to locate the position >>> by using MachineBasicBlock iterator? >>> >> > Can you describe more precisely what are you trying to achieve? > I.e. what are these instructions? Why do you want to do that? It may lead > to a different answer. > > — > Mehdi >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160904/94599254/attachment.html>