<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/10/17 9:58 PM, Seth Goldstein via
cfe-dev wrote:<br>
</div>
<blockquote
cite="mid:CAKSia995L+xS7rF6+8dWomC3ZxMz5XRLW1VkMBDmETvnMJXTyQ@mail.gmail.com"
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>
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
cite="mid:CAKSia995L+xS7rF6+8dWomC3ZxMz5XRLW1VkMBDmETvnMJXTyQ@mail.gmail.com"
type="cite">
<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">, </div>
<div> <span style="white-space:pre"> </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"> </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/SelectionDAG/InstrEmitter.cpp:303:
unsigned int llvm::InstrEmitter::getVR(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::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="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>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br>
<p><br>
</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>