<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><br></div><div>-seth</div></div><div class="gmail_extra"><br clear="all"><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 href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><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 style="white-space:pre-wrap">       </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 style="white-space:pre-wrap">                          </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 href="tel:(412)%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 class="m_-2559148107378462058moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>
<a 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"><font color="#888888">
    <br>
    <p><br>
    </p>
    <pre class="m_-2559148107378462058moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a 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>
  </font></span></div>

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