<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 12/11/17 11:10 AM, Seth Goldstein
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAKSia9_=TM+GXGiMjVScvVeJkt5_Ltp95rgSzq5-UHi9q2A0xQ@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">The issue is that I need to insert this code as
        part of a transformation.  Is there a way to insert assembly
        code in a pass?</div>
    </blockquote>
    <br>
    Yes.<br>
    <br>
    You can create an inline assembly code "value" by creating an
    InlineAsm object.  You then make that "value" an argument to an LLVM
    CallInst object.<br>
    <br>
    For more information, look at the InlineAsm and CallInst classes in
    the LLVM Doxygen documentation.<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CAKSia9_=TM+GXGiMjVScvVeJkt5_Ltp95rgSzq5-UHi9q2A0xQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>-seth</div>
      </div>
      <div class="gmail_extra"><br>
        <div>
          <div class="gmail_signature" data-smartmail="gmail_signature">
            <div dir="ltr">
              <div>
                <div dir="ltr">
                  <div><br>
                  </div>
                  <div>--------------</div>
                  <div>Seth Copen Goldstein</div>
                  <div>Carnegie Mellon University</div>
                  <div>Computer Science Dept</div>
                  <div>7111 GHC</div>
                  <div>412-268-3828</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <br>
        <div class="gmail_quote">On Mon, Dec 11, 2017 at 10:51 AM, John
          Criswell <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote">
            <div><span class="">
                <div class="m_-2559148107378462058moz-cite-prefix">On
                  12/10/17 9:58 PM, Seth Goldstein via cfe-dev wrote:<br>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">
                    <div>I need to use the stack pointer, e.g., RSP on
                      X86, to get some</div>
                    <div>information off the stack.  I am not sure what
                      the best way to do this is.</div>
                  </div>
                </blockquote>
                <br>
              </span> Is there a reason that you cannot insert some
              inline assembly code to read the stack pointer?  The only
              downside to it (as far as I can tell) is that you would
              need to have different assembly code for each platform on
              which you want to do this.<br>
              <br>
              Regards,<br>
              <br>
              John Criswell<br>
              <blockquote type="cite">
                <div>
                  <div class="h5">
                    <div dir="ltr">
                      <div><br>
                      </div>
                      <div>My plan was to create an intrinsic, e.g., </div>
                      <div><br>
                      </div>
                      <div>  let TargetPrefix = "x86" in {</div>
                      <div>     def int_x86_read_sp :
                        GCCBuiltin<"__builtin_read_sp"<wbr>>, </div>
                      <div>  <span> </span>   
                        Intrinsic<[llvm_i64_ty], [], [IntrNoMem]>;</div>
                      <div>  }</div>
                      <div>  </div>
                      <div>I thought I would define a PseudoI, e.g., </div>
                      <div><br>
                      </div>
                      <div>  let Uses = [RSP] in</div>
                      <div>      def READSP64 : PseudoI<(outs
                        GR64:$dst), (ins),</div>
                      <div>            [(set GR64:$dst, RSP)]>,</div>
                      <div>               
                        Requires<[In64BitMode]>;</div>
                      <div><span> </span></div>
                      <div>But, actually I am not sure how this would
                        come into play.  (Do I need this?  If so, how do
                        I use it?)</div>
                      <div><br>
                      </div>
                      <div>To test it out I added a Builtin to
                        BuiltinsX86.def, e.g.,</div>
                      <div><br>
                      </div>
                      <div>  BUILTIN(__builtin_read_sp, "ULLi", "")</div>
                      <div>  </div>
                      <div>When I try and compile, I get a proper .ll
                        file from clang with the instruction</div>
                      <div><br>
                      </div>
                      <div>    %0 = call i64 @llvm.x86.read.sp()</div>
                      <div><br>
                      </div>
                      <div>However, it fails, with </div>
                      <div><br>
                      </div>
                      <div>llc: ./llvm/lib/CodeGen/<wbr>SelectionDAG/InstrEmitter.cpp:<wbr>303:
                        unsigned int llvm::InstrEmitter::getVR(<wbr>llvm::SDValue,
                        llvm::DenseMap<llvm::SDValue, unsigned
                        int>&): Assertion `I != VRBaseMap.end()
                        && "Node emitted out of order - late"'
                        failed.</div>
                      <div><br>
                      </div>
                      <div>I am not sure how to introduce the IR to read
                        the RSP so I can create</div>
                      <div>code to do a calculation on the RSP to
                        retrieve a value buried in the</div>
                      <div>stack.  I figure I need to lower the `call
                        i64 @llvm.x86.read.sp` in</div>
                      <div>X86TargetLowering::<wbr>LowerOperation.  I am
                        not sure if this would be</div>
                      <div>ISD::INTRINSIC_WO_CHAIN or
                        ISD::INTRINSIC_W_CHAIN (and I don't</div>
                      <div>actually understand what would go in the
                        intrinsic definition to make</div>
                      <div>it one or the other.  Any pointers would be
                        appreciated.  Thanks,</div>
                      <div><br>
                      </div>
                      <div>seth</div>
                      <div><br>
                      </div>
                      <div>
                        <div
                          class="m_-2559148107378462058gmail_signature">
                          <div dir="ltr">
                            <div>
                              <div dir="ltr">
                                <div><br>
                                </div>
                                <div>--------------</div>
                                <div>Seth Copen Goldstein</div>
                                <div>Carnegie Mellon University</div>
                                <div>Computer Science Dept</div>
                                <div>7111 GHC</div>
                                <div><a moz-do-not-send="true"
                                    href="tel:%28412%29%20268-3828"
                                    value="+14122683828" target="_blank">412-268-3828</a></div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <br>
                    <fieldset
                      class="m_-2559148107378462058mimeAttachmentHeader"></fieldset>
                    <br>
                  </div>
                </div>
                <span class="">
                  <pre>______________________________<wbr>_________________
cfe-dev mailing list
<a moz-do-not-send="true" class="m_-2559148107378462058moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>
<a moz-do-not-send="true" class="m_-2559148107378462058moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a>
</pre>
    </span></blockquote><span class="HOEnZb">
    

    <p>

    </p>
    <pre class="m_-2559148107378462058moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a moz-do-not-send="true" class="m_-2559148107378462058moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/<wbr>criswell</a></pre>
  </span></div>

</blockquote></div>
</div>



</blockquote>
<p>
</p><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>