This is the mail archive of the gcc-patches@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: [Patch][AVR]: Support tail calls


On 03/11/2011 05:43 AM, Georg-Johann Lay wrote:
> 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.

You need a new symbol in libgcc for this.  It should be easy enough to have
the sibcall epilogue load up Z+EIND before jumping to the new symbol
(perhaps called __sibcall_restores__).  This new symbol would be just like
the existing __epilogue_restores__ except that it would finish with an
eijmp/ijmp instruction (depending on multilib) instead of a ret instruction.

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

Look at how the s390 port handles this exact problem.

  /* Register 6 on s390 is available as an argument register but unfortunately
     "caller saved". This makes functions needing this register for arguments
     not suitable for sibcalls.  */
  return !s390_call_saved_register_used (exp);

I'll admit that it would be helpful if the cumulative_args pointer was passed
into the ok_for_sibcall hook, but it's not *that* hard to recreate that value
by hand.  This is what the s390_call_saved_register_used function does.

> +      || (avr_OS_task_function_p (decl_callee) ^ avr_OS_task_function_p (current_function_decl))

Please just use != instead of ^ here.  Also, needs line wrapping.


I do like very much how you've cleaned up the call patterns.  IMO this should
be committed as a separate patch; I'll let the AVR maintainers approve it though.


r~

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


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