[LLVMdev] A new builtin: __builtin_stack_pointer()

Konstantin Tokarev annulen at yandex.ru
Tue Nov 5 09:26:42 PST 2013



11.10.2013, 01:39, "Jakob Stoklund Olesen" <stoklund at 2pi.dk>:
> On Oct 10, 2013, at 12:32 PM, Behan Webster <behanw at converseincode.com> wrote:
>
>>  One of the issues the LLVMLinux project is having is with the use of
>>  named registers in the Linux kernel code. The kernel uses something like
>>  this in order to assign a C variable name to a register (one for each
>>  kernel arch).
>>
>>     register unsigned long current_stack_pointer asm("esp");
>>
>>  clang doesn't allow this kind of thing which required a patch which less
>>  efficient:
>>
>>  #define current_stack_pointer ({ \
>>        unsigned long esp; \
>>        asm("mov %%esp, %0" : "=r"(esp)); \
>>        esp; \
>>  })
>>
>>  This works for both gcc and clang, but often adds in 3 extra
>>  instructions since you need to copy the stack pointer to another
>>  register, but first that register needs to be saved to the stack and
>>  then restored after the stackpointer has been used; inefficient.
>
> #define current_stack_pointer ({ \
>         register unsigned long esp asm("esp"); \
>         asm("" : "=r"(esp)); \
>         esp; \
>     })

And #ifdef it for each arch? Builtin would be much more handy.

-- 
Regards,
Konstantin



More information about the llvm-dev mailing list