[cfe-dev] A new builtin: __builtin_stack_pointer()

Mark Charlebois charlebm at gmail.com
Wed Nov 20 09:41:03 PST 2013


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:

LLVM patch:

http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=toolchain/clang/patches/llvm/builtin_stack_pointer-new.patch;h=1b8a5d707975704d31485db4cc94fe0315884619;hb=HEAD

Clang patch:
http://git.linuxfoundation.org/?p=llvmlinux.git;a=blob;f=toolchain/clang/patches/clang/builtin_stack_pointer-new.patch;h=c0dbeea1564a3f4521dc79c083f456bf444a07f8;hb=HEAD

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;

I have implemented llvm:stackpointer for ARM, AArch64 and X86.

I included tests for ARM and AArch64 but I have no idea how to write the
test for X86.

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.

Thanks,

Mark



On Fri, Nov 8, 2013 at 1:13 PM, Chris Lattner <clattner at apple.com> wrote:

> On Nov 6, 2013, at 5:46 PM, Behan Webster <behanw at converseincode.com>
> wrote:
>
> Another way would be to introduce a new builtin in parallel to others
> like __builtin_return_address(). Essentially adding a
> __builtin_stack_pointer() which does what the above code does. The idea
> would be to get something like this added to both clang and gcc in order
> to make this work across compilers, and across arches.
>
> It ends up being a trivial patch for clang (see below). We're still
> looking for someone to help us on the gcc side.
>
>
> 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.
>
> -Chris
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131120/6fecea42/attachment.html>


More information about the cfe-dev mailing list