[cfe-dev] A question on register allocation

Goncalo Carvalho via cfe-dev cfe-dev at lists.llvm.org
Sun Oct 4 04:24:52 PDT 2015


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151004/40962347/attachment.html>


More information about the cfe-dev mailing list