[LLVMdev] Named register variables GNU-style

Rafael Espíndola
2014-03-27T15:30:20Z

On 27 March 2014 09:55, Renato Golin <renato.golin at linaro.org>
wrote:
> Folks,
>
> I just had a discussion about __builtin_stack_pointer in the GCC list,
> and there were a number of arguments against it, and it got me
> thinking I didn't have strong arguments against GNU's named
register
> extension. Does anyone remember the arguments for not implementing
> that extension?

In clang or llvm? I think we can implement it in clang by lowering
them with a similar trick that we do for local ones.

For local register variables, clang just keeps a note that it has to
add a constraint when it creates an inline assembly.

For global ones, it should also codegen every non inline asm to use an
llvm intrinsic (llvm.read_register/llvm.write_register for example).

This is not exactly the semantics gcc uses since the register would
still be allocatable, but should cover 99% of the uses, including
reading the stack pointer in the kernel.

I don't think we should implement this directly in LLVM, since it
introduces the really odd notion that reading of an value is
observable. For example, is it legal to move the read of rsp out of  a
loop? By using an intrinsic at the llvm level we trivially represent
and preserve all the reads and writes from the source program.

Cheers,
Rafael