<div dir="ltr">You can make the register reserved (requires changing the LLVM backend) and then you can use the named global register support added in <a href="http://reviews.llvm.org/D3261">http://reviews.llvm.org/D3261</a>.<div><br></div><div>Jacques</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 4, 2015 at 11:06 AM, mats petersson via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Your problem here is that you also need to "remove" your chosen register from the list of registers the compiler may use for other purposes. As far as I understand, there's no infrastructure to "remove this register ALWAYS", so you'll most likely need to do a fair bit of changes - I'm not familiar with this particular bit of code, but it<!--
-->'s obviously an ugly/difficult enough solution that for the "make Linux compile with Clang" was solved by "remove use of global registers", except for "stack pointer" (Stack pointer is OK, since compiler will not use that register for anything other than "as stack pointer"). <div><br></div><div>--</div><div>Mats</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 4 October 2015 at 13:42, Viswesh Narayanan via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">OK. I am also willing to change the source code (clang and/or LLVM) to<br>
get the desired behavior.<br>
So if some expert can point me to right areas in source code, it would<br>
be great!<br>
<div><div><br>
On Sun, Oct 4, 2015 at 8:00 PM, Goncalo Carvalho <<a href="mailto:glslang@gmail.com" target="_blank">glslang@gmail.com</a>> wrote:<br>
> Clang doesn't support global register variables like GCC afaik so it needs<br>
> to be emulated if really needed by forcing the register to the intended<br>
> value.<br>
><br>
> In general it can be clobbered by whatever else but such is the way without<br>
> backend support.<br>
><br>
> But someone more knowledgeable about Clang's backend may provide a better<br>
> insight.<br>
><br>
><br>
><br>
><br>
><br>
> On 4 October 2015 at 12:31, Viswesh Narayanan <<a href="mailto:visweshn92@gmail.com" target="_blank">visweshn92@gmail.com</a>> wrote:<br>
>><br>
>> 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>
>><br>
>><br>
>><br>
>> On Sun, Oct 4, 2015 at 7:24 PM, Goncalo Carvalho <<a href="mailto:glslang@gmail.com" target="_blank">glslang@gmail.com</a>><br>
>> wrote:<br>
>> > I don't think clang supports global register variables in general<br>
>> > although<br>
>> > 'sp' appears to work from clang-3.7 onwards. However it doesn't appear<br>
>> > 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<br>
>> > but is<br>
>> > not the same I appreciate that. The above also lacks context of the<br>
>> > actual<br>
>> > application of what is that you're trying to do so it's possible better<br>
>> > (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" target="_blank">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" target="_blank">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>
><br>
><br>
><br>
><br>
> --<br>
> <a href="http://www.cryogenicgraphics.com" rel="noreferrer" target="_blank">http://www.cryogenicgraphics.com</a><br>
> <a href="http://www.flickr.com/photos/hdrflow" rel="noreferrer" target="_blank">http://www.flickr.com/photos/hdrflow</a><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">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>
</div></div></blockquote></div><br></div>
</div></div><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></blockquote></div><br></div>