[llvm-dev] Thumb frame pointer register

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Thumb frame pointer register

Rajesh S R via llvm-dev
Hello all,

I noticed that for ARM Thumb target, llc uses r7 as frame pointer (gcc does not do this AFAIK), and this register should therefore not be used as a general-purpose register.

However, when compiling mbedTLS, which contains some code that is highly optimized for ARM platform and uses r7 to efficiently perform an operation. This raises an exception since r7 is now the frame pointer.

I tried passing -fomit-frame-pointer but this is just a hacky workaround and does not work in this case, since the function here does indeed need frame pointer.
```
The -fomit-frame-pointer option instructs the compiler to not store stack frame pointers if the function does not need it. You can use this option to reduce the code image size.
```

My question is, how can I instruct the register allocator to use another register as frame pointer, or at least turn off the use of frame pointer? I tried changing the ABI with -mabi and -meabi but nothing works so far.

Thanks a lot for your help,

Cheers,

Son Tuan Vu

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Thumb frame pointer register

Rajesh S R via llvm-dev
Hi Son Tuan,

On Wed, 21 Aug 2019 at 06:05, Son Tuan VU via llvm-dev
<[hidden email]> wrote:
> I noticed that for ARM Thumb target, llc uses r7 as frame pointer (gcc does not do this AFAIK), and this register should therefore not be used as a general-purpose register.

This is generally considered an ABI matter. On EABI and GNUEABI
platforms, I believe both GCC and Clang use r7 in Thumb mode, but r11
in ARM mode. This isn't configurable.

So I'd suggest making sure llc is producing ARM code for that
particular file: for example by using -mtriple=armv7-linux-gnueabihf
rather than -mtriple=thumbv7-linux-gnueabihf.

Cheers.

Tim.
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Thumb frame pointer register

Rajesh S R via llvm-dev
In reply to this post by Rajesh S R via llvm-dev
On Wed, 21 Aug 2019 at 06:05, Son Tuan VU via llvm-dev
<[hidden email]> wrote:

>
> Hello all,
>
> I noticed that for ARM Thumb target, llc uses r7 as frame pointer (gcc does not do this AFAIK), and this register should therefore not be used as a general-purpose register.
>
> However, when compiling mbedTLS, which contains some code that is highly optimized for ARM platform and uses r7 to efficiently perform an operation. This raises an exception since r7 is now the frame pointer.
>
> I tried passing -fomit-frame-pointer but this is just a hacky workaround and does not work in this case, since the function here does indeed need frame pointer.
> ```
> The -fomit-frame-pointer option instructs the compiler to not store stack frame pointers if the function does not need it. You can use this option to reduce the code image size.
> ```

Can you let us know which function in mbedTLS you are referring to. I
found https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
on the mbedTLS website which implies that you should use
-fomit-frame-pointer. I would be very surprised for code in mbedTLS to
simultaneously require a frame pointer and reserve r7 in Thumb state.
There may be some confusion about what GCC does as arm-none-eabi-gcc
uses -fomit-frame-pointer by default. As Tim points out, I think
you'll find that gcc will use r7 as the frame pointer if
-fno-omit-frame-pointer is used.

Peter

>
> My question is, how can I instruct the register allocator to use another register as frame pointer, or at least turn off the use of frame pointer? I tried changing the ABI with -mabi and -meabi but nothing works so far.
>
> Thanks a lot for your help,
>
> Cheers,
>
> Son Tuan Vu
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Thumb frame pointer register

Rajesh S R via llvm-dev
Thanks Tim & Peter,

I am referring to mpi_montmul function from library/bignum.c, and this problem only occurs at clang -O3, so for the moment I am compiling the library with clang -02.

As for GCC, if -fno-omit-frame-pointer is NOT used, it doesn't use r7 as frame register, while clang uses r7 by default (even without -fno-omit-frame-pointer).

So my question is how to turn the use of frame pointer off for clang/llc?

Son Tuan Vu


On Wed, Aug 21, 2019 at 11:18 AM Peter Smith <[hidden email]> wrote:
On Wed, 21 Aug 2019 at 06:05, Son Tuan VU via llvm-dev
<[hidden email]> wrote:
>
> Hello all,
>
> I noticed that for ARM Thumb target, llc uses r7 as frame pointer (gcc does not do this AFAIK), and this register should therefore not be used as a general-purpose register.
>
> However, when compiling mbedTLS, which contains some code that is highly optimized for ARM platform and uses r7 to efficiently perform an operation. This raises an exception since r7 is now the frame pointer.
>
> I tried passing -fomit-frame-pointer but this is just a hacky workaround and does not work in this case, since the function here does indeed need frame pointer.
> ```
> The -fomit-frame-pointer option instructs the compiler to not store stack frame pointers if the function does not need it. You can use this option to reduce the code image size.
> ```

Can you let us know which function in mbedTLS you are referring to. I
found https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
on the mbedTLS website which implies that you should use
-fomit-frame-pointer. I would be very surprised for code in mbedTLS to
simultaneously require a frame pointer and reserve r7 in Thumb state.
There may be some confusion about what GCC does as arm-none-eabi-gcc
uses -fomit-frame-pointer by default. As Tim points out, I think
you'll find that gcc will use r7 as the frame pointer if
-fno-omit-frame-pointer is used.

Peter

>
> My question is, how can I instruct the register allocator to use another register as frame pointer, or at least turn off the use of frame pointer? I tried changing the ABI with -mabi and -meabi but nothing works so far.
>
> Thanks a lot for your help,
>
> Cheers,
>
> Son Tuan Vu
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Thumb frame pointer register

Rajesh S R via llvm-dev
On Wed, 21 Aug 2019 at 11:29, Son Tuan VU <[hidden email]> wrote:
>
> Thanks Tim & Peter,
>
> I am referring to mpi_montmul function from library/bignum.c, and this problem only occurs at clang -O3, so for the moment I am compiling the library with clang -02.
>
> As for GCC, if -fno-omit-frame-pointer is NOT used, it doesn't use r7 as frame register, while clang uses r7 by default (even without -fno-omit-frame-pointer).
>
> So my question is how to turn the use of frame pointer off for clang/llc?
>

I think you may be referring to
https://bugs.llvm.org/show_bug.cgi?id=34165 this is when compiling for
Thumb with a frame-pointer is enabled (default and with
-fno-omit-frame-pointer) and there is an inline assembly block with r7
in the clobber list.
The option -fomit-frame-pointer will disable the frame pointer in
clang and should work around this problem.

I'm a bit confused by "I tried passing -fomit-frame-pointer but this
is just a hacky workaround and does not work in this case, since the
function here does indeed need frame pointer."
Unless you are planning on unwinding the stack at run time through the
function it shouldn't need a frame-pointer. If you do require a frame
pointer then I think you are out of luck until pr34165 is fixed. If
you can alter the code locally, one possibility is to remove the
inline assembly to use a C implementation.

> Son Tuan Vu
>
>
> On Wed, Aug 21, 2019 at 11:18 AM Peter Smith <[hidden email]> wrote:
>>
>> On Wed, 21 Aug 2019 at 06:05, Son Tuan VU via llvm-dev
>> <[hidden email]> wrote:
>> >
>> > Hello all,
>> >
>> > I noticed that for ARM Thumb target, llc uses r7 as frame pointer (gcc does not do this AFAIK), and this register should therefore not be used as a general-purpose register.
>> >
>> > However, when compiling mbedTLS, which contains some code that is highly optimized for ARM platform and uses r7 to efficiently perform an operation. This raises an exception since r7 is now the frame pointer.
>> >
>> > I tried passing -fomit-frame-pointer but this is just a hacky workaround and does not work in this case, since the function here does indeed need frame pointer.
>> > ```
>> > The -fomit-frame-pointer option instructs the compiler to not store stack frame pointers if the function does not need it. You can use this option to reduce the code image size.
>> > ```
>>
>> Can you let us know which function in mbedTLS you are referring to. I
>> found https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
>> on the mbedTLS website which implies that you should use
>> -fomit-frame-pointer. I would be very surprised for code in mbedTLS to
>> simultaneously require a frame pointer and reserve r7 in Thumb state.
>> There may be some confusion about what GCC does as arm-none-eabi-gcc
>> uses -fomit-frame-pointer by default. As Tim points out, I think
>> you'll find that gcc will use r7 as the frame pointer if
>> -fno-omit-frame-pointer is used.
>>
>> Peter
>>
>> >
>> > My question is, how can I instruct the register allocator to use another register as frame pointer, or at least turn off the use of frame pointer? I tried changing the ABI with -mabi and -meabi but nothing works so far.
>> >
>> > Thanks a lot for your help,
>> >
>> > Cheers,
>> >
>> > Son Tuan Vu
>> > _______________________________________________
>> > LLVM Developers mailing list
>> > [hidden email]
>> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev