<p dir="ltr"><br>
On 27 Mar 2014 16:30, "Rafael Espíndola" <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
><br>
> > That's my idea, yes. I'm not sure how Clang would transform the named<br>
> > registers into the intrinsic, but something along the lines of:<br>
> ><br>
> > i8* @SP = "SP";<br>
> ><br>
> > define void @step() nounwind {<br>
> > entry:<br>
> >   %0 = call i32 @llvm.read_register(i8* @SP)<br>
> >   %1 = add i32 %0, i32 4<br>
> >   call void @llvm.write_register(i8* @SP, %1)<br>
> > }<br>
> ><br>
> > declare void @llvm.write_register(i8*, i32) nounwind readnone<br>
> > declare i32 @llvm.read_register(i8*) nounwind readnone<br>
><br>
> I would not produce any llvm global for it. So some insanity like<br>
><br>
> register long a asm("rsp");<br>
> long f(long x) {<br>
>   long ret = a;<br>
>   a = x;<br>
>   return ret;<br>
> }<br>
><br>
> would compile to<br>
><br>
> define i64 @f(i64 %x) {<br>
>   %ret = call i64 @llvm.read_register("rsp");<br>
>   call void @llvm.write_register("rsp", i64 %x)<br>
>   ret %ret<br>
> }<br>
> declare void @llvm.write_register(i8*, i64)<br>
> declare i64 @llvm.read_register(i8*)</p>
<p dir="ltr">That was actually my first idea, but I got confused on the implementation. :-) </p>
<p dir="ltr">I'll try it again. </p>
<p dir="ltr">Cheers, <br>
Renato <br></p>
<p dir="ltr">> >> This is not exactly the semantics gcc uses since the register would<br>
> >> still be allocatable, but should cover 99% of the uses, including<br>
> >> reading the stack pointer in the kernel.<br>
> ><br>
> > <a href="http://gcc.gnu.org/onlinedocs/gcc/Global-Reg-Vars.html">http://gcc.gnu.org/onlinedocs/gcc/Global-Reg-Vars.html</a><br>
> ><br>
> > It seems that the semantics is to avoid PCS registers, or they will be<br>
> > clobbered...<br>
><br>
> Yes, it is really odd. It says "Global register variables reserve<br>
> registers throughout the program.", which is obviously not the case<br>
> since not all compile units might see it.<br>
><br>
> ><br>
> >> For example, is it legal to move the read of rsp out of  a<br>
> >> loop?<br>
> ><br>
> > No. It should be a volatile read/write.<br>
><br>
> Agreed. With the intrinsic the semantics are easy to represent.<br>
><br>
> Cheers,<br>
> Rafael<br>
</p>