how to avoid default inlining of static functions at O3 ?
Mihai Donțu
mihai.dontu@gmail.com
Fri Sep 26 19:17:00 GMT 2008
On Friday 26 September 2008, john wrote:
> Hi,
> I am using gcc 3.4.6 (gcc version 3.4.6 20060404 (Red Hat 3.4.6-3))
> and trying a simple C program which was given at the end of this mail along
> with its assembly code.
>
> I am compiling the program using -O3
From gcc info page (function attributes):
`noinline': This function attribute prevents a function from being
considered for inlining.
__attribute__((noinline)) static void test2();
> /usr/bin/gcc -c -pipe -m32 -D_REENTRANT -fPIC -W -Wall -Wextra -O -O3
> -DSERVER -DMONITORS -DHA_KEY='"NONE"' test.c -S -o test.s
>
> I see that at optimization level O3, the compiler is defaultly inlining my
> static functions. Is there a way to avoid inlining static functions for C
> programs ?
>
>
> -fno-inline may avoid inlining all functions. There is -fno-default-inline,
> but that is for C++.
>
> Thanks for any help in advance,
> Regards
> --John
>
>
>
> #include<stdio.h>
> void test(int a, int b, int c)
> {
> int d;
> d=a*b*c;
> printf("%d * %d * %d is %d\n",a,b,c,d);
> }
>
>
>
> static void test2(int a, int b, int c)
> {
> int d;
> d=a+b+c;
> printf("%d + %d + %d is %d\n",a,b,c,d);
> }
>
> int main(int argc, char *argv[])
> {
> test(1,2,3);
> test2(4,5,6);
> }
>
>
>
> .file "test.c"
> .section .rodata.str1.1,"aMS",@
> progbits,1
> ..LC0:
> .string "%d * %d * %d is %d\n"
> .text
> .p2align 2,,3
> ..globl test
> .type test, @function
> test:
> pushl %ebp
> movl %esp, %ebp
> pushl %esi
> movl 8(%ebp), %esi
> movl 12(%ebp), %ecx
> movl %esi, %eax
> pushl %ebx
> movl 16(%ebp), %edx
> imull %ecx, %eax
> subl $12, %esp
> imull %edx, %eax
> pushl %eax
> pushl %edx
> pushl %ecx
> call .L2
> ..L2:
> popl %ebx
> addl $_GLOBAL_OFFSET_TABLE_+[.-.L2] , %ebx
> pushl %esi
> leal .LC0@GOTOFF(%ebx), %eax
> pushl %eax
> call printf@PLT
> leal -8(%ebp), %esp
> popl %ebx
> popl %esi
> leave
> ret
> .size test, .-test
> .section .rodata.str1.1
> ..LC1:
> .string "%d + %d + %d is %d\n"
> .text
> .p2align 2,,3
> ..globl main
> .type main, @function
> main:
> pushl %ebp
> movl %esp, %ebp
> pushl %ebx
> pushl %eax
> andl $-16, %esp
> subl $20, %esp
> pushl $3
> pushl $2
> pushl $1
> call .L5
> ..L5:
> popl %ebx
> addl $_GLOBAL_OFFSET_TABLE_+[.-.L5] , %ebx
> call test@PLT
> movl $15, (%esp)
> pushl $6
> pushl $5
> pushl $4
> leal .LC1@GOTOFF(%ebx), %eax
> pushl %eax
> call printf@PLT
> addl $32, %esp
> movl -4(%ebp), %ebx
> leave
> ret
> .size main, .-main
> .section .note.GNU-stack,"",@progbits
> .ident "GCC: (GNU) 3.4.6 20060404 (Red Hat 3.4.6-3)"
--
Mihai Donțu
More information about the Gcc-help
mailing list