[Patch][AVR]: Support tail calls

Georg-Johann Lay avr@gjlay.de
Fri Mar 11 13:44:00 GMT 2011


This is a patch to test/review/comment on. It adds tail call
optimization to avr backend.

The implementation uses struct machine_function to pass information
around, i.e. from avr_function_arg_advance to avr_function_ok_for_sibcall.

Tail call support is more general than avr-ld's replacement of
call/ret sequences with --relax which are sometimes wrong, see
http://sourceware.org/PR12494

gcc can, e.g. tail-call bar1 in

void bar0 (void);
void bar1 (int);

int foo (int x)
{
  bar0();
  return bar1 (x);
}

I did not find a way to make this work together with -mcall-prologues.
Please let me know if you have suggestion on how call prologues can be
combine with tail calls.

Regards, Johann


2011-03-10  Georg-Johann Lay  <avr@gjlay.de>

	* config/avr/avr-protos.h (expand_epilogue): Change prototype
	* config/avr/avr.h (struct machine_function): Add field
	sibcall_fails.
	* config/avr/avr.c (init_cumulative_args,
	avr_function_arg_advance): Use it.
	* config/avr/avr.c (expand_epilogue): Add bool parameter. Handle
	sibcall	epilogues.
	(TARGET_FUNCTION_OK_FOR_SIBCALL): Define to...
	(avr_function_ok_for_sibcall): ...this new function.
	(avr_lookup_function_attribute1): New static Function.
	(avr_naked_function_p, interrupt_function_p,
	signal_function_p, avr_OS_task_function_p,
	avr_OS_main_function_p): Use it.
	* config/avr/avr.md ("sibcall", "sibcall_value",
	"sibcall_epilogue"): New expander.
	("*call_insn", "*call_value_insn"): New insn.
	("call_insn", "call_value_insn"): Remove
	("call", "call_value", "epilogue"): Change expander to handle
	sibling calls.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sibcall-v2.diff
Type: text/x-patch
Size: 14277 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20110311/18e7f51c/attachment.bin>


More information about the Gcc-patches mailing list