<div dir="ltr"><div><div><div>Umesh,<br><br></div>From Target/ARM/ARMRegisterInfo.td, it looks like FP for Thumb should be r7 instead of r11.<br><br>// Register classes.<br>//<br>// pc == Program Counter<br>// lr == Link Register<br>
// sp == Stack Pointer<br>// r12 == ip (scratch)<br>// r7 == Frame Pointer (thumb-style backtraces)<br>// r9 == May be reserved as Thread Register<br>// r11 == Frame Pointer (arm-style backtraces)<br>// r10 == Stack Limit<br>
<br></div>Regardless, I'm compiling with -fomit-frame-pointer, so it should not really matter, right?<br><br>Andrea<br></div><div> </div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Oct 15, 2013 at 8:33 AM, Umesh Kalappa <span dir="ltr"><<a href="mailto:umesh.kalappa0@gmail.com" target="_blank">umesh.kalappa0@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi andrea,<br>R11 treated as frame pointer at arm backend , which is fixed again .<br><br>Thanks<span class="HOEnZb"><font color="#888888"><br>
Umesh</font></span><div class="HOEnZb"><div class="h5"><br><br>On Tuesday, October 15, 2013, Andrea Mucignat <<a href="mailto:andrea@nestlabs.com" target="_blank">andrea@nestlabs.com</a>> wrote:<br>
> Umesh,<br>> Makes some sort of sense to me, OTOH:<br>> If instead of choosing r11 as a "dummy" to align the stack we had chosen some other register in the range r0-r7 then we could have emitted the PUSH encoding T1 (2 bytes opcode) as opposed to the encoding T2 (which is a 4 bytes opcode).<br>
> A<br>><br>> On Tue, Oct 15, 2013 at 2:59 AM, Umesh Kalappa <<a href="mailto:umesh.kalappa0@gmail.com" target="_blank">umesh.kalappa0@gmail.com</a>> wrote:<br>><br>> Hi Andrea,<br>><br>> That is because the LR is the fixed register as per the<br>
> <a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf" target="_blank">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf</a><br>> and out_char() function is not the leaf function ,Hence compiler<br>
> tends to save and restore the LR and the save and restore of<br>> register r11 is to align stack for 8 bytes as per ARM EABI.<br>><br>><br>><br>> Thanks<br>><br>> ~Umesh<br>><br>><br>> On Tuesday, October 15, 2013, Umesh Kalappa <<a href="mailto:umesh.kalappa0@gmail.com" target="_blank">umesh.kalappa0@gmail.com</a>> wrote:<br>
>> ---------- Forwarded message ----------<br>>> From: Andrea Mucignat <<a href="mailto:andrea@nestlabs.com" target="_blank">andrea@nestlabs.com</a>><br>>> Date: Tue, Oct 15, 2013 at 7:05 AM<br>>> Subject: [LLVMdev] Unwanted push/pop on Cortex-M.<br>
>> To: <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>>><br>>><br>>> Hi,<br>>><br>>> I have this code:<br>>><br>>> void platform_putchar(int, char);<br>
>> void out_char( char ch );<br>
>><br>>> void out_char( char ch )<br>>> {<br>>> platform_putchar (0, ch);<br>>> }<br>>><br>>> I'm compiling with the following clang invocation:<br>>><br>>> $ /usr/local/vendor/toolchains/llvm/3.3/armv7m/bin/armv7m-none-eabi-clang<br>
>> -mcpu=cortex-m4 -mfloat-abi=soft -mthumb -nostdinc -ffreestanding<br>>> -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti<br>>> -fomit-frame-pointer -momit-leaf-frame-pointer -nostdinc -v -Os -S -o<br>
>> a.s a.c<br>>> vendor-clang version 3.3 (tags/RELEASE_33/final) (based on LLVM 3.3)<br>>> Target: armv7m-none--eabi<br>>> Thread model: posix<br>>> "/usr/local/vendor-20130805-b8d59d2/toolchains/llvm/3.3/armv7m/bin/armv7m-none-eabi-clang"<br>
>> -cc1 -triple thumbv7em-none--eabi -S -disable-free -main-file-name a.c<br>>> -mrelocation-model static -fmath-errno -mconstructor-aliases<br>>> -target-abi aapcs -target-cpu cortex-m4 -msoft-float -mfloat-abi soft<br>
>> -target-feature +soft-float -target-feature +soft-float-abi<br>>> -target-feature -neon -target-linker-version 2.22<br>>> -momit-leaf-frame-pointer -v -ffunction-sections -fdata-sections<br>>> -coverage-file /tmp/a.s -nostdsysteminc -nobuiltininc -resource-dir<br>
>> /usr/local/vendor-20130805-b8d59d2/toolchains/llvm/3.3/armv7m/bin/../lib/clang/3.3<br>>> -Os -fno-dwarf-directory-asm -fdebug-compilation-dir /tmp<br>>> -ferror-limit 19 -fmessage-length 207 -ffreestanding -mstackrealign<br>
>> -fno-rtti -fno-signed-char -fobjc-runtime=gcc<br>>> -fobjc-default-synthesize-properties -fdiagnostics-show-option<br>>> -fcolor-diagnostics -backend-option -vectorize-loops -o a.s -x c a.c<br>>> clang -cc1 version 3.3 based upon LLVM 3.3 default target armv7m-none-eabi<br>
>> #include "..." search starts here:<br>>> End of search list.<br>>><br>>> $ cat a.s<br>>> .syntax unified<br>>> .eabi_attribute 6, 10<br>>> .eabi_attribute 9, 2<br>
>> .eabi_attribute 10, 5<br>>> .fpu vfpv4<br>>> .eabi_attribute 20, 1<br>>> .eabi_attribute 21, 1<br>>> .eabi_attribute 23, 3<br>>> .eabi_attribute 24, 1<br>>> .eabi_attribute 25, 1<br>
>> .eabi_attribute 44, 1<br>>> .file "a.c"<br>>> .section .text.out_char,"ax",%progbits<br>>> .globl out_char<br>>> .align 2<br>>> .type out_char,%function<br>
>> .code 16<br>>> .thumb_func<br>>> out_char:<br>>> push.w {r11, lr}<br>>> mov r1, r0<br>>> movs r0, #0<br>>> bl platform_putchar<br>>> pop.w {r11, pc}<br>
>> .Ltmp0:<br>>> .size out_char, .Ltmp0-out_char<br>>><br>>> The one question I have is:<br>>> why can't this out_char function be compiled into:<br>>><br>>> out_char:<br>
>> mov r1, r0<br>>> mov r0, #0<br>>> bl platform_putchar<br>>> bx lr<br>>><br>>> What's the clang/llvm module responsible for generating the prologue<br>>> and epilogue for this function?<br>
>> I looked into CodeGen/PrologEpilogInserter, ARMFrameLowering.cpp<br>>> Thumb1FrameLowering.cpp but it's not 100% clear how the code gen<br>>> decides what the stack frame look like.<br>>><br>
>> Here's the -emit-llvm output
</div></div></blockquote></div><br></div>