[LLVMdev] Named Register Implementation

Evan Cheng evan.cheng at apple.com
Mon Mar 31 12:16:55 PDT 2014


On Mar 30, 2014, at 11:34 AM, Renato Golin <renato.golin at linaro.org> wrote:

> On 29 March 2014 22:25, Evan Cheng <evan.cheng at apple.com> wrote:
>>> 1. Implement named registers for non-allocatable registers
>> 
>> I'm not sure if this would work even for non-allocatable registers. I fear this may codegen to a copy from the register and subsequent reads are all of the gpr.
> 
> Hi Evan,
> 
> I'm not sure I follow what GPRs.
> 
> The plan is to transform all reads from a variable marked "register
> long foo asm("reg")" into an intrinsic "@llvm.read_register("reg")".
> If we also want the builtin, that's as easy as mapping
> "__builtin_stack_pointer()" to "@llvm.read_register("SP")", so the
> underlying implementation is the same.
> 
> So:
> 
> register unsigned long foo asm("SP"); // does nothing
> long a = foo; // %a = call i32 @llvm.read_register("SP") ->
> DAG.CopyFromReg("SP")
> long b = a;   // %0 = load %a, store %0, %b (in GPRs, since both a and
> b are C variables)
> long c = foo; // %c = call i32 @llvm.read_register("SP") ->
> DAG.CopyFromReg("SP")
> 
> In any case, "foo" doesn't exist as a variable in the C level
> representation (no alloca, etc), and since we can't take the address
> of it (due to C restrictions), that's fine. If you transfer the values
> to other variables, in GPRs or in the stack/memory, than all bets are
> off, and I believe that this is the same in GCC, but *all*
> reads/writes to named register variables should be represented by
> read/write intrinsics.

If you are changing all reads / writes to intrinsics, then yes this should work.

Evan

> 
> cheers,
> --renato




More information about the llvm-dev mailing list