[RFC] make arm-use-movt and arm-reserve-r9 options available for all arm

Jeroen Hofstee llvm at myspectrum.nl
Mon Aug 12 10:31:59 PDT 2013


Hello Renato,

On 08/11/2013 10:58 PM, Renato Golin wrote:
> On 10 August 2013 12:37, Jeroen Hofstee <llvm at myspectrum.nl 
> <mailto:llvm at myspectrum.nl>> wrote:
>
>     + The first issue is U-boot's use of global registers. As this is
>     not supported by
>     clang / llvm, it looks like a show stopper.
>
>
> Not sure what you mean by that. Is it just the use of the "register" 
> modifier on variables, I'm not sure how the R9 reservation will help 
> here... Otherwise, if U-boot uses R9 the same way the AAPCS states 
> (static base or thread register), than turning it on ARM-wide seems 
> the right fix.
>

U-boot uses 'register volatile gd_t *gd asm ("r8")' to access data which 
needs
to be available before and after relocation. This is a global definition 
and gcc
is compiled with -ffixed-r8 in order to prevent using r8.

 From the looks of [2] "clang does not support global register 
variables; this is
unlikely to be implemented soon because it requires additional LLVM backend
support.", you might be led to believe U-boot cannot be compiled with 
llvm/clang,

However changing it to:

static __inline __maybe_unused volatile gd_t *get_gd(void)
{
     gd_t *gd_ptr;

     __asm__ volatile("mov %0, r9\n" : "=r" (gd_ptr));

     return gd_ptr;
}

#define gd  get_gd()

works fine (albeit slightly less efficient), when clang / llvm does not 
change r9.
That is the reason I need the ReserveR9 also outside of IOS.

> If I got it right, you want to disable movt/movh for your specific 
> case, so leaving it ARM-wide makes sense.
>

yes, It hardcodes addresses in code, which is not intended behaviour for 
U-boot.
>
>     IOS does this conditionally IsR9Reserved = ReserveR9 | !HasV6Ops;
>     but I
>     don't understand why, therefore I just left it untouched.
>
>
> I could be wrong but the AAPCS document hints that R9 usage is v6+, so 
> I'm guessing HasV6Ops is important for all platforms, not just Darwin. 
> But I don't have the old APCS document to show me that R9 can be used 
> as GPR in pre-v6.
>

I am not sure what you are referring to. In general v6 in 5.1.1 refers 
to the use of r9 as a
general-purpose register. As in variable 6, not version 6. Changing r9 
in llvm will definitely
crash u-boot and likely every other application with explicitly asked 
llvm _not_ to touch r9
by setting ReserveR9.

> I think both flags can be set together, and leave the isTargetIOS() 
> just for the SupportsTailCall, like:
>
>   UseMovt = hasV6T2Ops() && ArmUseMOVT;
>   IsR9Reserved = ReserveR9 | !HasV6Ops;
>   if (isTargetIOS())
>     SupportsTailCall = !getTargetTriple().isOSVersionLT(5, 0);
>

See above, and the initial commit. I want r9 to always be left alone. 
IOS doesn't
for some reasons I do not know, but it is not for AAPCS. (and if I have 
to guess,
it is related to their r9 usage depending on the target).

>
>     patch attached (hopefully unified, it at least applies with patch
>     -u -p0).
>
>
> Have you ran all tests? Test-suite? I suppose you'd have to test on 
> both Linux and Darwin systems, but if you don't have access to them, 
> I'll be happy to test on Linux, and other folks could test on Darwin.
>

No, not manually at least, just build it on Linux and verified u-boot works.
I grepped for the usage of these flags inside llvm / clang, but there is
nothing interesting there. I do not have a darwin / ios build env.

Regards,
Jeroen

[1] 
http://git.denx.de/?p=u-boot.git;a=blob;f=arch/arm/include/asm/global_data.h;h=79a959741945968eca7a21018187b97eb65d70f3;hb=refs/heads/master
[2] 
http://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130812/2e92ac5b/attachment.html>


More information about the llvm-commits mailing list