[cfe-dev] A question on register allocation

Jacques Pienaar via cfe-dev cfe-dev at lists.llvm.org
Sun Oct 4 11:30:46 PDT 2015


You can make the register reserved (requires changing the LLVM backend) and
then you can use the named global register support added in
http://reviews.llvm.org/D3261.

Jacques

On Sun, Oct 4, 2015 at 11:06 AM, mats petersson via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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").
>
> --
> Mats
>
> On 4 October 2015 at 13:42, Viswesh Narayanan via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> 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
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151004/d5df93b7/attachment.html>


More information about the cfe-dev mailing list