<div dir="ltr">Clang doesn't support global register variables like GCC afaik so it needs to be emulated if really needed by forcing the register to the intended value. <div><br></div><div>In general it can be clobbered by whatever else but such is the way without backend support.</div><div><br></div><div>But someone more knowledgeable about Clang's backend may provide a better insight.<br><div><br></div><div><br><div><br></div><div><div><br></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 4 October 2015 at 12:31, Viswesh Narayanan <span dir="ltr"><<a href="mailto:visweshn92@gmail.com" target="_blank">visweshn92@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think you have got my question wrong (Or perhaps my writing was bad).<br>
<br>
I want that register (say xmm15) to hold value 100 throughout the<br>
execution of program.<br>
And LLVM should lock down xmm15 for me and should always allocate some<br>
other register for other functions.<br>
<br>
The solution provided applies only to context of main() and is not<br>
generic if my source code grows bigger.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Sun, Oct 4, 2015 at 7:24 PM, Goncalo Carvalho <<a href="mailto:glslang@gmail.com">glslang@gmail.com</a>> wrote:<br>
> I don't think clang supports global register variables in general although<br>
> 'sp' appears to work from clang-3.7 onwards. However it doesn't appear to<br>
> understand 'r13' on arm which is equivalent.<br>
><br>
> You can always do something like<br>
><br>
> asm ("movq %0, %%xmm15"::"x"(100):"xmm15");<br>
><br>
> although it's not strictly equivalent.<br>
><br>
> int main() {<br>
><br>
>     asm ("movq %0, %%xmm15"::"x"(100):"xmm15");<br>
><br>
>     return 0;<br>
><br>
> }<br>
><br>
> will generate<br>
><br>
>        movl    $0, -4(%rbp)<br>
><br>
>         movss   .LCPI0_0(%rip), %xmm0<br>
><br>
>         #APP<br>
><br>
>         movq    %xmm0, %xmm15<br>
><br>
>         #NO_APP<br>
><br>
>         xorl    %eax, %eax<br>
><br>
>         popq    %rbp<br>
><br>
>         retq<br>
><br>
><br>
> So you could just have that as a replacement everytime 'A' is written but is<br>
> not the same I appreciate that. The above also lacks context of the actual<br>
> application of what is that you're trying to do so it's possible better (and<br>
> faster) solutions exist!<br>
><br>
><br>
> On 4 October 2015 at 07:44, Viswesh Narayanan via cfe-dev<br>
> <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
>><br>
>> My use case is to store a global value permanently in a register (say<br>
>> xmm15) using LLVM<br>
>><br>
>> The following piece of code works as expected in GCC while it is not<br>
>> supported in LLVM. It complains with "fatal error: error in backend:<br>
>> Invalid register name global variable".<br>
>><br>
>> Can any expert here provide me a solution to this in Clang/LLVM?<br>
>><br>
>> Code:<br>
>> #include <stdio.h><br>
>> volatile register int A asm ("xmm15");<br>
>> int main() {<br>
>>     A = 100;<br>
>>     return A;<br>
>> }<br>
>> _______________________________________________<br>
>> cfe-dev mailing list<br>
>> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
><br>
><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><a href="http://www.cryogenicgraphics.com" target="_blank">http://www.cryogenicgraphics.com</a><br><a href="http://www.flickr.com/photos/hdrflow" target="_blank">http://www.flickr.com/photos/hdrflow</a></div>
</div>