<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 3/18/16 6:42 AM, Zhiyu Xie via
      llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CA+9aj23JVcrCu4e=HGumEbcwoZEWA4f_p9y-_5rjXy7X+NeFNw@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div><span>Hi all,</span></div>
        <div><span>      I am trying to instrument a program to insert a
            function call</span> after SP-Update instructions. SP-Update
          instructions are those modify the esp register such as mov
          esp, eax ; xchg eax, esp ; add esp, [eax+0x20] and so on. It
          seems that I should dig into the back end. But which
          representation of instructions should I focus on? MachineInstr
          or MCInst or other class?</div>
      </div>
    </blockquote>
    <br>
    You should write a MachineFunctionPass and operate and the
    MachineInstr level.  Your pass will need to be integrated into the
    LLVM code generator for your target.<br>
    <br>
    <br>
    <blockquote
cite="mid:CA+9aj23JVcrCu4e=HGumEbcwoZEWA4f_p9y-_5rjXy7X+NeFNw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div> <span>Where is the definitions of all opcodes and
            registers? <br>
          </span></div>
      </div>
    </blockquote>
    <br>
    For MachineInstr's, registers are just numbers, and there are
    constants (e.g., Reg::RAX, IIRC) that represent the various
    registers.<br>
    <br>
    You can look at the control-flow integrity pass for a dated (but I
    think still useful) example of how to write a MachineFunctionPass. 
    It is at
<a class="moz-txt-link-freetext" href="https://github.com/jtcriswell/SVA/blob/master/llvm/lib/Target/X86/X86CFIOptPass.cpp">https://github.com/jtcriswell/SVA/blob/master/llvm/lib/Target/X86/X86CFIOptPass.cpp</a>.<br>
    <br>
    <blockquote
cite="mid:CA+9aj23JVcrCu4e=HGumEbcwoZEWA4f_p9y-_5rjXy7X+NeFNw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>In which part of the back end should I inspect the
          instructions?  And How to insert a function call? May I use
          MachineInstrBuilder::BuildMI ?</div>
      </div>
    </blockquote>
    <br>
    BuildMI is what you want.<br>
    <br>
    <blockquote
cite="mid:CA+9aj23JVcrCu4e=HGumEbcwoZEWA4f_p9y-_5rjXy7X+NeFNw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div> I am so sorry to ask so many questions because I am a
          newbie to LLVM. I would appreciate it if any one coulld help
          me.</div>
      </div>
    </blockquote>
    <br>
    If you have not done so already, you should read the document on
    "How to Write an LLVM Pass" and the document on the code generator
    (the one that briefly explains MachineInstr's).  You should also
    make use of the doxygen documentation.<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CA+9aj23JVcrCu4e=HGumEbcwoZEWA4f_p9y-_5rjXy7X+NeFNw@mail.gmail.com"
      type="cite">
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>