This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Can I force gcc not to optimize calling to leaf functions with `-O2' option?


The optimization you described is called a "function tail merge". You
can disable that optimization without disabling the rest of -O2. I
forget the exact switch, but I expect a search for "tail merge" would
find it.

PRC wrote:
> Hi All,
> I wonder if I can inform gcc not to optimize calling to leaf functions.
>
> For example
> -------------------
> void say_hello()
> {
> 	printf("Hello\n");
> }
> void func()
> {
> 	say_hello();
> }
>
>
> with -O2 option, gcc will optimize 
> 	jal say_hello
> 	...
> 	jr ra
> 	...
> to
> 	j  say_hello
> 	
> This is not what I want in some case. The start of the function can be located
> by searching `addiu sp, XXXX' instruction, and the end of the function by
> searching `jr ra', beginning with EPC when expctions arise, if all function calls
> have their own exits. By this way, I can trace down the calling frames. But this
> optimization breaks the rule and will confused the tracer. And the `-O2' option
> is neccessary since some bugs are only exposed on `-O2'.
>
> Is there an approach for this purpose?
>
> Best Regards
> PRC
> Mar 29, 2008
>
>
>   


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]