[cfe-dev] [LLVMdev] Named register variables GNU-style

Renato Golin renato.golin at linaro.org
Thu Mar 27 09:17:20 PDT 2014


On 27 March 2014 15:30, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> For global ones, it should also codegen every non inline asm to use an
> llvm intrinsic (llvm.read_register/llvm.write_register for example).

That's my idea, yes. I'm not sure how Clang would transform the named
registers into the intrinsic, but something along the lines of:

i8* @SP = "SP";

define void @step() nounwind {
entry:
  %0 = call i32 @llvm.read_register(i8* @SP)
  %1 = add i32 %0, i32 4
  call void @llvm.write_register(i8* @SP, %1)
}

declare void @llvm.write_register(i8*, i32) nounwind readnone
declare i32 @llvm.read_register(i8*) nounwind readnone


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

http://gcc.gnu.org/onlinedocs/gcc/Global-Reg-Vars.html

It seems that the semantics is to avoid PCS registers, or they will be
clobbered...

Nevertheless, we can reserve the register on demand, as we already do
with R9, for instance.


> For example, is it legal to move the read of rsp out of  a
> loop?

No. It should be a volatile read/write.


> By using an intrinsic at the llvm level we trivially represent
> and preserve all the reads and writes from the source program.

Exactly!

cheers,
--renato




More information about the cfe-dev mailing list