[cfe-dev] A question on register allocation

Viswesh Narayanan via cfe-dev cfe-dev at lists.llvm.org
Sun Oct 4 05:42:49 PDT 2015


OK. I am also willing to change the source code (clang and/or LLVM) to
get the desired behavior.
So if some expert can point me to right areas in source code, it would
be great!

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



More information about the cfe-dev mailing list