<div dir="ltr">I have reimplemented __builtin_stack_pointer() on a new llvm::stackpointer intrinsic. I wasn't sure if it was appropriate to post the code to this email list, and all other recipients but I wanted to know if this was an acceptable approach, so I am posting links to the patches below:<div>
<br></div><div>LLVM patch:</div><div><br></div><div><a href="http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=toolchain/clang/patches/llvm/builtin_stack_pointer-new.patch;h=1b8a5d707975704d31485db4cc94fe0315884619;hb=HEAD">http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=toolchain/clang/patches/llvm/builtin_stack_pointer-new.patch;h=1b8a5d707975704d31485db4cc94fe0315884619;hb=HEAD</a></div>
<div><br></div><div>Clang patch:</div><div><a href="http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=toolchain/clang/patches/clang/builtin_stack_pointer-new.patch;h=c0dbeea1564a3f4521dc79c083f456bf444a07f8;hb=HEAD">http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=toolchain/clang/patches/clang/builtin_stack_pointer-new.patch;h=c0dbeea1564a3f4521dc79c083f456bf444a07f8;hb=HEAD</a><br>
<div><br></div><div>Please let me know the appropriate place to submit the patches or if they need to be further enhanced. I have a bad feeling the changes I added to LegalizeDAG.cpp are not needed, but I was basing my changes on ISD::RETURNADDR;</div>
<div><br></div><div>I have implemented llvm:stackpointer for ARM, AArch64 and X86. <br><br>I included tests for ARM and AArch64 but I have no idea how to write the test for X86.</div><div><br></div><div>Getting the stack pointer in an efficient way is not possible with clang today, but can be done with GCC. I hope this approach can facilitate getting the stack pointer efficiently via both compilers.</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Mark</div><div> </div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 8, 2013 at 1:13 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">On Nov 6, 2013, at 5:46 PM, Behan Webster <<a href="mailto:behanw@converseincode.com" target="_blank">behanw@converseincode.com</a>> wrote:<br>
<div><blockquote type="cite"><div style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
Another way would be to introduce a new builtin in parallel to others<br>like __builtin_return_address(). Essentially adding a<br>__builtin_stack_pointer() which does what the above code does. The idea<br>would be to get something like this added to both clang and gcc in order<br>
to make this work across compilers, and across arches.<br><br>It ends up being a trivial patch for clang (see below). We're still<br>looking for someone to help us on the gcc side.<br></div></blockquote><div dir="auto">
<br></div><div dir="auto">From my perspective, adding __builtin_stack_pointer() makes perfect sense.  Mapping it to Intrinsic::stacksave does not though, it should map down to a new llvm.stackpointer() intrinsic, and the code generator should turn it into the stack pointer register at isel time.</div>
<span class="HOEnZb"><font color="#888888"><div dir="auto"><br></div><div dir="auto">-Chris</div></font></span></div></div></blockquote></div><br></div>