[cfe-dev] Specifying registers for local variables

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Dec 19 13:19:45 PST 2014


On 19 December 2014 at 16:17, Daniel Sanders <Daniel.Sanders at imgtec.com> wrote:
>> -----Original Message-----
>> From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] On
>> Behalf Of Rafael EspĂ­ndola
>> Sent: 19 December 2014 15:29
>> To: Simon Atanasyan
>> Cc: Clang Developers List
>> Subject: Re: [cfe-dev] Specifying registers for local variables
>>
>> 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.
>
> I'm told that GCC makes a few undocumented promises too (I'm also told that clang/llvm is unlikely to support all of them). The one that affects this example is the promise that a read of the uninitialized variable is lowered to a read of the specified register. I've just spoken to Behan Webster and he tells me that Renato added support for this kind of declaration but that it only works for the stack pointer.
>
> Just to provide the context: The mips portion of the linux kernel uses code similar to Simon's example to read the thread context pointer ($28). Clang currently handles this as unreachable code and removes large sections of the kernel boot sequence.

I think it will work with any register as long as you use a global variable.

Cheers,
Rafael




More information about the cfe-dev mailing list