<div dir="ltr"><div class="gmail_extra">What about making a new LValue type that doesn't have an address?  At the source level, current_stack_pointer is an lvalue that can be stored to.  If we ever want to add support for the 'register' class specifier as it was originally designed, we will need a new 'Register' LValue type that can be read from and stored to.  We probably don't want to do that, but it feels like the right model to me.</div>
<div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 14, 2014 at 4:27 AM, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Reid,<br>
<br>
So, following up my example...<br>
<div class=""><br>
  register unsigned long current_stack_pointer asm("sp");<br>
</div>  unsigned long get_stack_pointer_addr() {<br>
    return current_stack_pointer;<br>
  }<br>
<br>
In this case, EmitReturnStmt() will call CreateStore(EmitScalarExpr())<br>
which we don't need at this stage, but it doesn't matter because this<br>
will be removed later by the backend.<br>
<br>
The IR I want to generate is:<br>
<br>
  %sp = call i32 @llvm.read_register.i32(metadata !0)<br>
  ret i32 %sp<br>
<br>
Though, this would also work:<br>
<br>
  %ret = alloca i32*<br>
  %0 = call i32 @llvm.read_register.i32(metadata !0)<br>
  store i32 %0, i32* %ret<br>
  ret i32 %ret<br>
<br>
which is what I believe Clang is trying to do.<br>
<br>
What I did was to go all the way down to:<br>
<br>
  LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E);<br>
<br>
adding an "if named register, emit a call to the intrinsic". However,<br>
the result of the call is an RValue, not an LValue. But the return<br>
statement is asking for the RValue, so it passes through a cast<br>
(CK_LValueToRValue) because it's expecting the variable to have an<br>
address, but ours doesn't.<br>
<br>
This is the ast:<br>
<br>
`-FunctionDecl 0x7e9f50 <line:3:1, line:5:1> line:3:15<br>
get_stack_pointer_addr 'unsigned long ()'<br>
  `-CompoundStmt 0x7ea050 <col:40, line:5:1><br>
    `-ReturnStmt 0x7ea030 <line:4:3, col:10><br>
      `-ImplicitCastExpr 0x7ea018 <col:10> 'unsigned long' <LValueToRValue><br>
        `-DeclRefExpr 0x7e9ff0 <col:10> 'unsigned long' lvalue Var<br>
0x7e9e50 'current_stack_pointer' 'unsigned long'<br>
<br>
I want the Var current_stack_pointer NOT to be an lvalue from the<br>
beginning, so that the return gets directly the value itself, not a<br>
cast to RValue.<br>
<br>
Also, would be good to mark it volatile, but<br>
NewVD->getType().addVolatile() doesn't seem to have effect.<br>
<br>
cheers,<br>
--renato<br>
</blockquote></div><br></div></div>