Commit b06775f9 by Richard Henderson Committed by Richard Henderson

calls.c (expand_call): Pass parms not original exp to optimize_tail_recursion.

        * calls.c (expand_call): Pass parms not original exp to
        optimize_tail_recursion.  Mind return value instead of looking
        for a barrier.
        * stmt.c (optimize_tail_recursion): Take parameter list, not entire
        call_expr.  Move checks for call_expr and current_function_decl ...
        (expand_return): ... here.

From-SVN: r32758
parent a843e0ce
2000-03-26 Richard Henderson <rth@cygnus.com>
* calls.c (expand_call): Pass parms not original exp to
optimize_tail_recursion. Mind return value instead of looking
for a barrier.
* stmt.c (optimize_tail_recursion): Take parameter list, not entire
call_expr. Move checks for call_expr and current_function_decl ...
(expand_return): ... here.
2000-03-26 Tom Tromey <tromey@cygnus.com> 2000-03-26 Tom Tromey <tromey@cygnus.com>
* gcc.c (handle_braces): Recognize `%{<S}' construct. * gcc.c (handle_braces): Recognize `%{<S}' construct.
......
...@@ -2099,28 +2099,20 @@ expand_call (exp, target, ignore) ...@@ -2099,28 +2099,20 @@ expand_call (exp, target, ignore)
recursion call can be ignored if we indeed use the tail recursion recursion call can be ignored if we indeed use the tail recursion
call expansion. */ call expansion. */
int save_pending_stack_adjust = pending_stack_adjust; int save_pending_stack_adjust = pending_stack_adjust;
rtx last;
/* Use a new sequence to hold any RTL we generate. We do not even /* Use a new sequence to hold any RTL we generate. We do not even
know if we will use this RTL yet. The final decision can not be know if we will use this RTL yet. The final decision can not be
made until after RTL generation for the entire function is made until after RTL generation for the entire function is
complete. */ complete. */
push_to_sequence (0); start_sequence ();
/* Emit the pending stack adjustments before we expand any arguments. */ /* Emit the pending stack adjustments before we expand any arguments. */
do_pending_stack_adjust (); do_pending_stack_adjust ();
optimize_tail_recursion (exp, get_last_insn ()); if (optimize_tail_recursion (actparms, get_last_insn ()))
tail_recursion_insns = get_insns ();
last = get_last_insn ();
tail_recursion_insns = get_insns ();
end_sequence (); end_sequence ();
/* If the last insn on the tail recursion sequence is not a
BARRIER, then tail recursion optimization failed. */
if (last == NULL_RTX || GET_CODE (last) != BARRIER)
tail_recursion_insns = NULL_RTX;
/* Restore the original pending stack adjustment for the sibling and /* Restore the original pending stack adjustment for the sibling and
normal call cases below. */ normal call cases below. */
pending_stack_adjust = save_pending_stack_adjust; pending_stack_adjust = save_pending_stack_adjust;
......
...@@ -2872,7 +2872,14 @@ expand_return (retval) ...@@ -2872,7 +2872,14 @@ expand_return (retval)
} }
/* Attempt to optimize the call if it is tail recursive. */ /* Attempt to optimize the call if it is tail recursive. */
if (optimize_tail_recursion (retval_rhs, last_insn)) if (optimize
&& retval_rhs != NULL_TREE
&& frame_offset == 0
&& TREE_CODE (retval_rhs) == CALL_EXPR
&& TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR
&& (TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0)
== current_function_decl)
&& optimize_tail_recursion (TREE_OPERAND (retval_rhs, 1), last_insn))
return; return;
#ifdef HAVE_return #ifdef HAVE_return
...@@ -3084,33 +3091,20 @@ drop_through_at_end_p () ...@@ -3084,33 +3091,20 @@ drop_through_at_end_p ()
return insn && GET_CODE (insn) != BARRIER; return insn && GET_CODE (insn) != BARRIER;
} }
/* Test CALL_EXPR to determine if it is a potential tail recursion call /* Attempt to optimize a potential tail recursion call into a goto.
and emit code to optimize the tail recursion. LAST_INSN indicates where ARGUMENTS are the arguments to a CALL_EXPR; LAST_INSN indicates
to place the jump to the tail recursion label. Return TRUE if the where to place the jump to the tail recursion label.
call was optimized into a goto.
Return TRUE if the call was optimized into a goto. */
This is only used by expand_return, but expand_call is expected to
use it soon. */
int int
optimize_tail_recursion (call_expr, last_insn) optimize_tail_recursion (arguments, last_insn)
tree call_expr; tree arguments;
rtx last_insn; rtx last_insn;
{ {
/* For tail-recursive call to current function, /* Finish checking validity, and if valid emit code to set the
just jump back to the beginning. argument variables for the new call. */
It's unsafe if any auto variable in this function if (tail_recursion_args (arguments, DECL_ARGUMENTS (current_function_decl)))
has its address taken; for simplicity,
require stack frame to be empty. */
if (optimize && call_expr != 0
&& frame_offset == 0
&& TREE_CODE (call_expr) == CALL_EXPR
&& TREE_CODE (TREE_OPERAND (call_expr, 0)) == ADDR_EXPR
&& TREE_OPERAND (TREE_OPERAND (call_expr, 0), 0) == current_function_decl
/* Finish checking validity, and if valid emit code
to set the argument variables for the new call. */
&& tail_recursion_args (TREE_OPERAND (call_expr, 1),
DECL_ARGUMENTS (current_function_decl)))
{ {
if (tail_recursion_label == 0) if (tail_recursion_label == 0)
{ {
...@@ -3123,7 +3117,6 @@ optimize_tail_recursion (call_expr, last_insn) ...@@ -3123,7 +3117,6 @@ optimize_tail_recursion (call_expr, last_insn)
emit_barrier (); emit_barrier ();
return 1; return 1;
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment