<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 4, 2016 at 7:44 AM, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Mehdi,</div><div><br></div><div> Sorry, I misread his original post. </div><div><br></div><div> So something like:</div><div><br></div><div> XXXInsrtInfo   *XII;    // target instruction info</div><div>  MachineBasicBlock::iterator MI = MachineBasicBlock(<wbr>YourCallInst);</div><div> MachineBasicBlock *MBB = YourCallInst->getParent(); // basic block location of your call inst</div><div> BuildMI(*MBB, MI, DebugLoc(), XII->get(XXX:::INSTRUCTION)...<wbr>...);</div><div><br></div><div>The BuildMI params are going to depend on what you want to do with the instruction being inserted. </div><div> <a href="http://llvm.org/docs/doxygen/html/MachineInstrBuilder_8h.html" target="_blank">http://llvm.org/docs/doxygen/<wbr>html/MachineInstrBuilder_8h.<wbr>html</a></div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>-Ryan</div><div><br></div></font></span></div></blockquote><div>Hi Ryan,</div><div>    I need to add two instructions for each function call. Do you mean I should add this snippet in the Lowercall function? Or I should add a new pass?</div><div><br></div><div>Thanks!</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span class="gmail-HOEnZb"><font color="#888888"><div></div><div>  </div></font></span></div><div class="gmail-HOEnZb"><div class="gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 4, 2016 at 1:45 AM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br><div><span><blockquote type="cite"><div>On Sep 3, 2016, at 6:18 PM, Ryan Taylor via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr"><div>So one way might look like this:</div><div><br></div><div>IRBuilder<> Builder(&*BB); // BB = Function::iterator OR IRBuilder<> Builder(CallInst->getParent())<wbr>;</div><div>Builder.SetInsertPoint(CallIns<wbr>t);</div><div>InstructionClass *YourNewInstruction = builder.CreateInstructionClass<wbr>(.....); // InstructionClass = type of instruction you are inserting</div><div></div><div><br></div></div></div></blockquote><div><br></div></span>I’m not sure how the IRBuilder would work at the MI level, as Shucai was asking.<span><div><br></div><blockquote type="cite"><div><div dir="ltr"><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 3, 2016 at 6:04 PM, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left:1px solid rgb(204,204,204)"><p dir="ltr">Take a look at IRBuilder and SetInsertPoint().</p>
<div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Sep 3, 2016 18:02, "SHUCAI YAO via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left:1px solid rgb(204,204,204)"><div><div><div dir="ltr"><span style="font-family:arial,helvetica,sans-serif;font-size:13px">I'm trying to insert some instructions before each function calls (before arguments push):</span><br><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   lea %EAX, label                      ----- new instructions</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   mov [ESP+stacksize], %EAX  ----- new instructions</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   push arg1</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   push arg2</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   ...</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   push argn</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">   call callee_name</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">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?</span></div></div></div></div></blockquote></div></div></blockquote></div></div></div></blockquote><div><br></div></span><div>Can you describe more precisely what are you trying to achieve?</div><div>I.e. what are these instructions? Why do you want to do that? It may lead to a different answer.</div><div><br></div></div></div></blockquote></div></div></div></div></blockquote><div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">I'm trying to implement something similar to segmented stack mechanism by using LLVM. Instead of inserting comparison code in the prologue of the function, I would like do the probe before arguments pushed. The segmentd stacks append a guarded page. This guard page will call the addmorestack function if the probe instructions touch this guarded page. Otherwise, it only stroe the return address in the bottom of the callee stack frame. </span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">In order to achieve this, for each function call, two instructions are needed to be inserted:</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     LEA  %EAX, callee_return_label</span><br></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     MOV [ESP- callee_stack_frame_size - arguments_size], %EAX</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     PUSH argn</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     ...</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     PUSH arg1</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     JMP callee_name</span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">callee_return_label:</span><span style="font-family:arial,helvetica,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,helvetica,sans-serif;font-size:13px">     ...</span></div></div><div><br></div><div>So I need to insert two instructions (LEA and MOV) before each function call. I don't know when how to insert these two instructions. </div><div><br></div><div>Thanks!</div><div>Shucai  </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div></div><div>— </div><span><font color="#888888"><div>Mehdi</div></font></span></div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>