<div dir="ltr"><div><div><div><div><div>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 -mcpu=cortex-m4 -mfloat-abi=soft -mthumb -nostdinc -ffreestanding -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fomit-frame-pointer -momit-leaf-frame-pointer -nostdinc -v -Os -S -o 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" -cc1 -triple thumbv7em-none--eabi -S -disable-free -main-file-name a.c -mrelocation-model static -fmath-errno -mconstructor-aliases -target-abi aapcs -target-cpu cortex-m4 -msoft-float -mfloat-abi soft -target-feature +soft-float -target-feature +soft-float-abi -target-feature -neon -target-linker-version 2.22 -momit-leaf-frame-pointer -v -ffunction-sections -fdata-sections -coverage-file /tmp/a.s -nostdsysteminc -nobuiltininc -resource-dir /usr/local/vendor-20130805-b8d59d2/toolchains/llvm/3.3/armv7m/bin/../lib/clang/3.3 -Os -fno-dwarf-directory-asm -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length 207 -ffreestanding -mstackrealign -fno-rtti -fno-signed-char -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fdiagnostics-show-option -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></div>What's the clang/llvm module responsible for generating the prologue and epilogue for this function?<br></div>I looked into CodeGen/PrologEpilogInserter, ARMFrameLowering.cpp Thumb1FrameLowering.cpp but it's not 100% clear how the code gen decides what the stack frame look like.<br>
<br></div>Here's the -emit-llvm output<br><br>target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:32-n32-S64"<br>target triple = "thumbv7em-none--eabi"<br>
<br>; Function Attrs: nounwind optsize<br>define void @out_char(char)(i8 zeroext %ch) #0 {<br>entry:<br> tail call void @llvm.dbg.value(metadata !{i8 %ch}, i64 0, metadata !10), !dbg !11<br> tail call void @platform_putchar(int, char)(i32 0, i8 zeroext %ch) #3, !dbg !12<br>
ret void, !dbg !13<br>}<br><br>; Function Attrs: optsize<br>declare void @platform_putchar(int, char)(i32, i8 zeroext) #1<br><br>; Function Attrs: nounwind readnone<br>declare void @llvm.dbg.value(metadata, i64, metadata) #2<br>
<br>attributes #0 = { nounwind optsize "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="true" }<br>
attributes #1 = { optsize "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="true" }<br>
attributes #2 = { nounwind readnone }<br>attributes #3 = { nobuiltin nounwind optsize }<br><br>!<a href="http://llvm.dbg.cu">llvm.dbg.cu</a> = !{!0}<br><br>!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"nestlabs-clang version 3.3 (tags/RELEASE_33/final) (based on LLVM 3.3)", i1 true, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !""} ; [ DW_TAG_compile_unit ] [/tmp/a.c] [DW_LANG_C_plus_plus]<br>
!1 = metadata !{metadata !"a.c", metadata !"/tmp"}<br>!2 = metadata !{i32 0}<br>!3 = metadata !{metadata !4}<br>!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"out_char", metadata !"out_char", metadata !"out_char(char)", i32 6, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, void (i8)* @out_char(char), null, null, metadata !9, i32 7} ; [ DW_TAG_subprogram ] [line 6] [def] [scope 7] [out_char]<br>
!5 = metadata !{i32 786473, metadata !1} ; [ DW_TAG_file_type ] [/tmp/a.c]<br>!6 = metadata !{i32 786453, i32 0, i32 0, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, i32 0} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]<br>
!7 = metadata !{null, metadata !8}<br>!8 = metadata !{i32 786468, null, null, metadata !"char", i32 0, i64 8, i64 8, i64 0, i32 0, i32 8} ; [ DW_TAG_base_type ] [char] [line 0, size 8, align 8, offset 0, enc DW_ATE_unsigned_char]<br>
!9 = metadata !{metadata !10}<br>!10 = metadata !{i32 786689, metadata !4, metadata !"ch", metadata !5, i32 16777222, metadata !8, i32 0, i32 0} ; [ DW_TAG_arg_variable ] [ch] [line 6]<br>!11 = metadata !{i32 6, i32 0, metadata !4, null}<br>
!12 = metadata !{i32 8, i32 0, metadata !4, null}<br>!13 = metadata !{i32 9, i32 0, metadata !4, null}<br><br><br></div>Thanks<br></div>Andrea.<br><div><div><div><br></div></div></div></div>