Commit 224e770b by Richard Henderson Committed by Richard Henderson

cfgexpand.c (expand_gimple_tailcall): Fix case where we need to create a new basic block.

        * cfgexpand.c (expand_gimple_tailcall): Fix case where we need
        to create a new basic block.

From-SVN: r85029
parent 7761cda3
2004-07-21 Richard Henderson <rth@redhat.com>
* cfgexpand.c (expand_gimple_tailcall): Fix case where we need
to create a new basic block.
2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk> 2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/15052 PR c/15052
......
...@@ -111,26 +111,41 @@ expand_gimple_cond_expr (basic_block bb, tree stmt) ...@@ -111,26 +111,41 @@ expand_gimple_cond_expr (basic_block bb, tree stmt)
} }
/* A subroutine of expand_gimple_basic_block. Expand one CALL_EXPR /* A subroutine of expand_gimple_basic_block. Expand one CALL_EXPR
that has CALL_EXPR_TAILCALL set. Returns a new basic block if we've that has CALL_EXPR_TAILCALL set. Returns non-null if we actually
terminated the current basic block and created a new one. */ generated a tail call (something that might be denied by the ABI
rules governing the call; see calls.c). */
static basic_block static basic_block
expand_gimple_tailcall (basic_block bb, tree stmt) expand_gimple_tailcall (basic_block bb, tree stmt)
{ {
rtx last = get_last_insn (); rtx last = get_last_insn ();
edge e;
int probability;
gcov_type count;
expand_expr_stmt (stmt); expand_expr_stmt (stmt);
for (last = NEXT_INSN (last); last; last = NEXT_INSN (last)) for (last = NEXT_INSN (last); last; last = NEXT_INSN (last))
{
if (CALL_P (last) && SIBLING_CALL_P (last)) if (CALL_P (last) && SIBLING_CALL_P (last))
{ goto found;
edge e;
int probability = 0;
gcov_type count = 0;
return NULL;
found:
/* ??? Wouldn't it be better to just reset any pending stack adjust?
Any instructions emitted here are about to be deleted. */
do_pending_stack_adjust (); do_pending_stack_adjust ();
/* Remove any non-eh, non-abnormal edges that don't go to exit. */
/* ??? I.e. the fallthrough edge. HOWEVER! If there were to be
EH or abnormal edges, we shouldn't have created a tail call in
the first place. So it seems to me we should just be removing
all edges here, or redirecting the existing fallthru edge to
the exit block. */
e = bb->succ; e = bb->succ;
probability = 0;
count = 0;
while (e) while (e)
{ {
edge next = e->succ_next; edge next = e->succ_next;
...@@ -154,10 +169,9 @@ expand_gimple_tailcall (basic_block bb, tree stmt) ...@@ -154,10 +169,9 @@ expand_gimple_tailcall (basic_block bb, tree stmt)
e = next; e = next;
} }
/* This is somewhat ugly: the call_expr expander often emits /* This is somewhat ugly: the call_expr expander often emits instructions
instructions after the sibcall (to perform the function after the sibcall (to perform the function return). These confuse the
return). These confuse the find_sub_basic_blocks code, find_sub_basic_blocks code, so we need to get rid of these. */
so we need to get rid of these. */
last = NEXT_INSN (last); last = NEXT_INSN (last);
if (!BARRIER_P (last)) if (!BARRIER_P (last))
abort (); abort ();
...@@ -169,19 +183,23 @@ expand_gimple_tailcall (basic_block bb, tree stmt) ...@@ -169,19 +183,23 @@ expand_gimple_tailcall (basic_block bb, tree stmt)
break; break;
delete_insn (NEXT_INSN (last)); delete_insn (NEXT_INSN (last));
} }
e = make_edge (bb, EXIT_BLOCK_PTR, EDGE_ABNORMAL | EDGE_SIBCALL); e = make_edge (bb, EXIT_BLOCK_PTR, EDGE_ABNORMAL | EDGE_SIBCALL);
e->probability += probability; e->probability += probability;
e->count += count; e->count += count;
BB_END (bb) = last; BB_END (bb) = last;
update_bb_for_insn (bb); update_bb_for_insn (bb);
if (NEXT_INSN (last)) if (NEXT_INSN (last))
{
bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb); bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
else
return bb; last = BB_END (bb);
} if (BARRIER_P (last))
BB_END (bb) = PREV_INSN (last);
} }
return NULL; return bb;
} }
/* Expand basic block BB from GIMPLE trees to RTL. */ /* Expand basic block BB from GIMPLE trees to RTL. */
......
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