<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><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>