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

Hal Finkel hfinkel at anl.gov
Thu Mar 27 09:58:19 PDT 2014


----- Original Message -----
> From: "Rafael EspĂ­ndola" <rafael.espindola at gmail.com>
> To: "Renato Golin" <renato.golin at linaro.org>
> Cc: "Clang Dev" <cfe-dev at cs.uiuc.edu>, "LLVM Dev" <llvmdev at cs.uiuc.edu>
> Sent: Thursday, March 27, 2014 11:30:46 AM
> Subject: Re: [cfe-dev] [LLVMdev] Named register variables GNU-style
> 
> > 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
> 
> I would not produce any llvm global for it. So some insanity like
> 
> register long a asm("rsp");
> long f(long x) {
>   long ret = a;
>   a = x;
>   return ret;
> }
> 
> would compile to
> 
> define i64 @f(i64 %x) {
>   %ret = call i64 @llvm.read_register("rsp");
>   call void @llvm.write_register("rsp", i64 %x)
>   ret %ret
> }
> declare void @llvm.write_register(i8*, i64)
> declare i64 @llvm.read_register(i8*)

+1

 -Hal

> 
> >> 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...
> 
> Yes, it is really odd. It says "Global register variables reserve
> registers throughout the program.", which is obviously not the case
> since not all compile units might see it.
> 
> >
> >> For example, is it legal to move the read of rsp out of  a
> >> loop?
> >
> > No. It should be a volatile read/write.
> 
> Agreed. With the intrinsic the semantics are easy to represent.
> 
> Cheers,
> Rafael
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory




More information about the cfe-dev mailing list