public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Can I force gcc not to optimize calling to leaf functions with `-O2' option?
@ 2008-03-29  8:12 PRC
  2008-03-29 14:24 ` John Fine
  2008-03-29 22:57 ` Ian Lance Taylor
  0 siblings, 2 replies; 3+ messages in thread
From: PRC @ 2008-03-29  8:12 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Can I force gcc not to optimize calling to leaf functions with  `-O2' option?
  2008-03-29  8:12 Can I force gcc not to optimize calling to leaf functions with `-O2' option? PRC
@ 2008-03-29 14:24 ` John Fine
  2008-03-29 22:57 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: John Fine @ 2008-03-29 14:24 UTC (permalink / raw)
  To: PRC; +Cc: gcc-help

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
>
>
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Can I force gcc not to optimize calling to leaf functions with `-O2' option?
  2008-03-29  8:12 Can I force gcc not to optimize calling to leaf functions with `-O2' option? PRC
  2008-03-29 14:24 ` John Fine
@ 2008-03-29 22:57 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2008-03-29 22:57 UTC (permalink / raw)
  To: PRC; +Cc: gcc-help

"PRC" <panruochen@gmail.com> writes:

> I wonder if I can inform gcc not to optimize calling to leaf functions.

What you describe is not an optimization of calling leaf functions,
it's an optimization when the last action a function takes is to call
another function.  There are a couple of names for this optimization.
gcc calls it a sibling call.  The option to turn it off is
-fno-optimize-sibling-calls.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-29 22:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-29  8:12 Can I force gcc not to optimize calling to leaf functions with `-O2' option? PRC
2008-03-29 14:24 ` John Fine
2008-03-29 22:57 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).