[cfe-dev] Specifying registers for local variables
Rafael EspĂndola
rafael.espindola at gmail.com
Fri Dec 19 07:29:00 PST 2014
On 18 December 2014 at 10:12, Simon Atanasyan <simon at atanasyan.com> wrote:
> Hi,
>
> Does LLVM/Clang support specifying registers for local variables?
In some way, yes. We implement what is documented by gcc:
Local register variables in specific registers do not reserve the
registers, except at the point where they are used as input or
output operands in an 'asm' statement and the 'asm' statement
itself is not deleted.
That is, it is just a way of writing a asm constraint.
> The following code is accepted by the Clang. It parses the `asm`
> attribute in the `Parser::ParseAsmAttributesAfterDeclarator()` routine
> and checks the declaration in the `Sema::ActOnVariableDeclarator()`.
> But it looks like the asm label expression is not used anywhere
> further. Is this language extension is unsupported by the Clang?
>
> % cat check.c
> int foo() {
> register int v asm ("edx") = 3;
> v = v + 1;
> return v;
> }
>
> The assembler output demonstrates the problem:
>
> % gcc -S check.c && cat check.s
> ...
> movl $3, %edx ; use register
> movl %edx, %eax
> addl $1, %eax
> movl %eax, %edx
> movl %edx, %eax
> ...
>
> % clang -S check.c && cat check.s
> ...
> movl $3, -4(%rbp) ; use stack
> movl -4(%rbp), %eax
> addl $1, %eax
> movl %eax, -4(%rbp)
> movl -4(%rbp), %eax
> ...
>
> --
> Simon
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list