Commit 589ca5cb by Mark Mitchell

Put phi nodes after NOTE_INSN_BASIC_BLOCK.

	* rtl.h (NOTE_INSN_BASIC_BLOCK_P): New macro.
	* bb-reorder.c (get_next_bb_note): Use NOTE_INSN_BASIC_BLOCK_P.
	(get_prev_bb_note): Likewise.
	(remove_scope_notes): Likewise.
	* flow.c (commit_one_edge_insertion): Likewise.
	(merge_blocks_nomove): Likewise.
	(verify_flow_info): Likewise.
	* gcse.c (insert_insn_end_bb): Likewise.
	* reg-stack.c (emit_swap_insn): Likewise.
	* ssa.c (first_insn_after_basic_block_note): New function.
	(insert_phi_node): Use it.
	(rename_block): Likewise.
	(eliminate_phi): Likewise.
	(make_regs_equivalent_over_bad_edges): Likewise.
	(make_equivalent_phi_alternatives_equivalent): Likewise.
	(for_each_successor_phi): Likewise.
	(convert_from_ssa): Modify phi-node deletion algorithm.

From-SVN: r35296
parent 2d97a719
...@@ -777,8 +777,7 @@ get_next_bb_note (x) ...@@ -777,8 +777,7 @@ get_next_bb_note (x)
{ {
while (x) while (x)
{ {
if (GET_CODE (x) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (x))
&& NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
return x; return x;
x = NEXT_INSN (x); x = NEXT_INSN (x);
} }
...@@ -792,8 +791,7 @@ get_prev_bb_note (x) ...@@ -792,8 +791,7 @@ get_prev_bb_note (x)
{ {
while (x) while (x)
{ {
if (GET_CODE (x) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (x))
&& NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
return x; return x;
x = PREV_INSN (x); x = PREV_INSN (x);
} }
...@@ -1050,8 +1048,7 @@ remove_scope_notes () ...@@ -1050,8 +1048,7 @@ remove_scope_notes ()
for (x = get_insns (); x; x = next) for (x = get_insns (); x; x = next)
{ {
next = NEXT_INSN (x); next = NEXT_INSN (x);
if (GET_CODE (x) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (x))
&& NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
currbb = NOTE_BASIC_BLOCK (x); currbb = NOTE_BASIC_BLOCK (x);
if (GET_CODE (x) == NOTE if (GET_CODE (x) == NOTE
......
...@@ -1673,8 +1673,7 @@ commit_one_edge_insertion (e) ...@@ -1673,8 +1673,7 @@ commit_one_edge_insertion (e)
tmp = bb->head; tmp = bb->head;
if (GET_CODE (tmp) == CODE_LABEL) if (GET_CODE (tmp) == CODE_LABEL)
tmp = NEXT_INSN (tmp); tmp = NEXT_INSN (tmp);
if (GET_CODE (tmp) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (tmp))
&& NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BASIC_BLOCK)
tmp = NEXT_INSN (tmp); tmp = NEXT_INSN (tmp);
if (tmp == bb->head) if (tmp == bb->head)
before = tmp; before = tmp;
...@@ -2164,8 +2163,7 @@ merge_blocks_nomove (a, b) ...@@ -2164,8 +2163,7 @@ merge_blocks_nomove (a, b)
} }
/* Delete the basic block note. */ /* Delete the basic block note. */
if (GET_CODE (b_head) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (b_head))
&& NOTE_LINE_NUMBER (b_head) == NOTE_INSN_BASIC_BLOCK)
{ {
if (b_head == b_end) if (b_head == b_end)
b_empty = 1; b_empty = 1;
...@@ -6471,9 +6469,7 @@ verify_flow_info () ...@@ -6471,9 +6469,7 @@ verify_flow_info ()
} }
x = NEXT_INSN (x); x = NEXT_INSN (x);
} }
if (GET_CODE (x) != NOTE if (!NOTE_INSN_BASIC_BLOCK_P (x) || NOTE_BASIC_BLOCK (x) != bb)
|| NOTE_LINE_NUMBER (x) != NOTE_INSN_BASIC_BLOCK
|| NOTE_BASIC_BLOCK (x) != bb)
{ {
error ("NOTE_INSN_BASIC_BLOCK is missing for block %d\n", error ("NOTE_INSN_BASIC_BLOCK is missing for block %d\n",
bb->index); bb->index);
...@@ -6489,8 +6485,7 @@ verify_flow_info () ...@@ -6489,8 +6485,7 @@ verify_flow_info ()
x = NEXT_INSN (x); x = NEXT_INSN (x);
while (x) while (x)
{ {
if (GET_CODE (x) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (x))
&& NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
{ {
error ("NOTE_INSN_BASIC_BLOCK %d in the middle of basic block %d", error ("NOTE_INSN_BASIC_BLOCK %d in the middle of basic block %d",
INSN_UID (x), bb->index); INSN_UID (x), bb->index);
...@@ -6518,8 +6513,7 @@ verify_flow_info () ...@@ -6518,8 +6513,7 @@ verify_flow_info ()
x = rtx_first; x = rtx_first;
while (x) while (x)
{ {
if (GET_CODE (x) == NOTE if (NOTE_INSN_BASIC_BLOCK_P (x))
&& NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
{ {
basic_block bb = NOTE_BASIC_BLOCK (x); basic_block bb = NOTE_BASIC_BLOCK (x);
num_bb_notes++; num_bb_notes++;
......
...@@ -4331,8 +4331,7 @@ insert_insn_end_bb (expr, bb, pre) ...@@ -4331,8 +4331,7 @@ insert_insn_end_bb (expr, bb, pre)
the insn in the wrong basic block. In that case, put the insn the insn in the wrong basic block. In that case, put the insn
after the CODE_LABEL. Also, respect NOTE_INSN_BASIC_BLOCK. */ after the CODE_LABEL. Also, respect NOTE_INSN_BASIC_BLOCK. */
while (GET_CODE (insn) == CODE_LABEL while (GET_CODE (insn) == CODE_LABEL
|| (GET_CODE (insn) == NOTE || NOTE_INSN_BASIC_BLOCK_P (insn))
&& NOTE_LINE_NUMBER (insn) == NOTE_INSN_BASIC_BLOCK))
insn = NEXT_INSN (insn); insn = NEXT_INSN (insn);
new_insn = emit_block_insn_before (pat, insn, BASIC_BLOCK (bb)); new_insn = emit_block_insn_before (pat, insn, BASIC_BLOCK (bb));
......
...@@ -978,8 +978,7 @@ emit_swap_insn (insn, regstack, reg) ...@@ -978,8 +978,7 @@ emit_swap_insn (insn, regstack, reg)
while (tmp != limit) while (tmp != limit)
{ {
if (GET_CODE (tmp) == CODE_LABEL if (GET_CODE (tmp) == CODE_LABEL
|| (GET_CODE (tmp) == NOTE || NOTE_INSN_BASIC_BLOCK_P (tmp)
&& NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BASIC_BLOCK)
|| (GET_CODE (tmp) == INSN || (GET_CODE (tmp) == INSN
&& stack_regs_mentioned (tmp))) && stack_regs_mentioned (tmp)))
{ {
......
...@@ -565,6 +565,11 @@ extern const char * const reg_note_name[]; ...@@ -565,6 +565,11 @@ extern const char * const reg_note_name[];
Other kinds of NOTEs are identified by negative numbers here. */ Other kinds of NOTEs are identified by negative numbers here. */
#define NOTE_LINE_NUMBER(INSN) XCINT(INSN, 4, NOTE) #define NOTE_LINE_NUMBER(INSN) XCINT(INSN, 4, NOTE)
/* Nonzero if INSN is a note marking the beginning of a basic block. */
#define NOTE_INSN_BASIC_BLOCK_P(INSN) \
(GET_CODE (INSN) == NOTE \
&& NOTE_LINE_NUMBER (INSN) == NOTE_INSN_BASIC_BLOCK)
/* Codes that appear in the NOTE_LINE_NUMBER field /* Codes that appear in the NOTE_LINE_NUMBER field
for kinds of notes that are not line numbers. for kinds of notes that are not line numbers.
......
...@@ -98,6 +98,8 @@ struct rename_context; ...@@ -98,6 +98,8 @@ struct rename_context;
static inline rtx * phi_alternative static inline rtx * phi_alternative
PARAMS ((rtx, int)); PARAMS ((rtx, int));
static rtx first_insn_after_basic_block_note PARAMS ((basic_block));
static int remove_phi_alternative static int remove_phi_alternative
PARAMS ((rtx, int)); PARAMS ((rtx, int));
static void simplify_to_immediate_dominators static void simplify_to_immediate_dominators
...@@ -449,6 +451,28 @@ compute_iterated_dominance_frontiers (idfs, frontiers, evals, nregs) ...@@ -449,6 +451,28 @@ compute_iterated_dominance_frontiers (idfs, frontiers, evals, nregs)
} }
} }
/* Return the INSN immediately following the NOTE_INSN_BASIC_BLOCK
note associated with the BLOCK. */
static rtx
first_insn_after_basic_block_note (block)
basic_block block;
{
rtx insn;
/* Get the first instruction in the block. */
insn = block->head;
if (insn == NULL_RTX)
return NULL_RTX;
if (GET_CODE (insn) == CODE_LABEL)
insn = NEXT_INSN (insn);
if (!NOTE_INSN_BASIC_BLOCK_P (insn))
abort ();
return NEXT_INSN (insn);
}
/* Insert the phi nodes. */ /* Insert the phi nodes. */
...@@ -461,6 +485,8 @@ insert_phi_node (regno, bb) ...@@ -461,6 +485,8 @@ insert_phi_node (regno, bb)
int npred, i; int npred, i;
rtvec vec; rtvec vec;
rtx phi, reg; rtx phi, reg;
rtx insn;
int end_p;
/* Find out how many predecessors there are. */ /* Find out how many predecessors there are. */
for (e = b->pred, npred = 0; e; e = e->pred_next) for (e = b->pred, npred = 0; e; e = e->pred_next)
...@@ -488,10 +514,11 @@ insert_phi_node (regno, bb) ...@@ -488,10 +514,11 @@ insert_phi_node (regno, bb)
phi = gen_rtx_PHI (VOIDmode, vec); phi = gen_rtx_PHI (VOIDmode, vec);
phi = gen_rtx_SET (VOIDmode, reg, phi); phi = gen_rtx_SET (VOIDmode, reg, phi);
if (GET_CODE (b->head) == CODE_LABEL) insn = first_insn_after_basic_block_note (b);
emit_insn_after (phi, b->head); end_p = PREV_INSN (insn) == b->end;
else emit_insn_before (phi, insn);
b->head = emit_insn_before (phi, b->head); if (end_p)
b->end = PREV_INSN (insn);
} }
...@@ -811,9 +838,7 @@ rename_block (bb, idom) ...@@ -811,9 +838,7 @@ rename_block (bb, idom)
if (e->dest == EXIT_BLOCK_PTR) if (e->dest == EXIT_BLOCK_PTR)
continue; continue;
insn = e->dest->head; insn = first_insn_after_basic_block_note (e->dest);
if (GET_CODE (insn) == CODE_LABEL)
insn = NEXT_INSN (insn);
while (PHI_NODE_P (insn)) while (PHI_NODE_P (insn))
{ {
...@@ -1145,9 +1170,7 @@ eliminate_phi (e, reg_partition) ...@@ -1145,9 +1170,7 @@ eliminate_phi (e, reg_partition)
/* Collect an upper bound on the number of registers needing processing. */ /* Collect an upper bound on the number of registers needing processing. */
insn = e->dest->head; insn = first_insn_after_basic_block_note (e->dest);
if (GET_CODE (insn) == CODE_LABEL)
insn = next_nonnote_insn (insn);
n_nodes = 0; n_nodes = 0;
while (PHI_NODE_P (insn)) while (PHI_NODE_P (insn))
...@@ -1171,9 +1194,7 @@ eliminate_phi (e, reg_partition) ...@@ -1171,9 +1194,7 @@ eliminate_phi (e, reg_partition)
sbitmap_vector_zero (pred, n_nodes); sbitmap_vector_zero (pred, n_nodes);
sbitmap_vector_zero (succ, n_nodes); sbitmap_vector_zero (succ, n_nodes);
insn = e->dest->head; insn = first_insn_after_basic_block_note (e->dest);
if (GET_CODE (insn) == CODE_LABEL)
insn = next_nonnote_insn (insn);
n_nodes = 0; n_nodes = 0;
for (; PHI_NODE_P (insn); insn = next_nonnote_insn (insn)) for (; PHI_NODE_P (insn); insn = next_nonnote_insn (insn))
...@@ -1271,11 +1292,10 @@ make_regs_equivalent_over_bad_edges (bb, reg_partition) ...@@ -1271,11 +1292,10 @@ make_regs_equivalent_over_bad_edges (bb, reg_partition)
{ {
int changed = 0; int changed = 0;
basic_block b = BASIC_BLOCK (bb); basic_block b = BASIC_BLOCK (bb);
rtx phi = b->head; rtx phi;
/* Advance to the first phi node. */ /* Advance to the first phi node. */
if (GET_CODE (phi) == CODE_LABEL) phi = first_insn_after_basic_block_note (b);
phi = next_nonnote_insn (phi);
/* Scan all the phi nodes. */ /* Scan all the phi nodes. */
for (; for (;
...@@ -1341,12 +1361,11 @@ make_equivalent_phi_alternatives_equivalent (bb, reg_partition) ...@@ -1341,12 +1361,11 @@ make_equivalent_phi_alternatives_equivalent (bb, reg_partition)
partition reg_partition; partition reg_partition;
{ {
int changed = 0; int changed = 0;
rtx phi = BLOCK_HEAD (bb);
basic_block b = BASIC_BLOCK (bb); basic_block b = BASIC_BLOCK (bb);
rtx phi;
/* Advance to the first phi node. */ /* Advance to the first phi node. */
if (GET_CODE (phi) == CODE_LABEL) phi = first_insn_after_basic_block_note (b);
phi = next_nonnote_insn (phi);
/* Scan all the phi nodes. */ /* Scan all the phi nodes. */
for (; for (;
...@@ -1889,23 +1908,27 @@ convert_from_ssa() ...@@ -1889,23 +1908,27 @@ convert_from_ssa()
for (bb = n_basic_blocks; --bb >= 0; ) for (bb = n_basic_blocks; --bb >= 0; )
{ {
rtx insn = BLOCK_HEAD (bb); rtx insn = BLOCK_HEAD (bb);
int start = (GET_CODE (insn) != CODE_LABEL);
if (! start) while (1)
insn = next_nonnote_insn (insn);
while (PHI_NODE_P (insn))
{ {
/* If a phi node is the last insn in the block, there must /* If this is a PHI node delete it. */
have been nothing else. Set the block end to the block if (PHI_NODE_P (insn))
head. */ {
if (insn == BLOCK_END (bb)) if (insn == BLOCK_END (bb))
BLOCK_END (bb) = BLOCK_HEAD (bb); BLOCK_END (bb) = PREV_INSN (insn);
insn = delete_insn (insn); insn = delete_insn (insn);
if (GET_CODE (insn) == NOTE) }
insn = next_nonnote_insn (insn); /* Since all the phi nodes come at the beginning of the
block, if we find an ordinary insn, we can stop looking
for more phi nodes. */
else if (INSN_P (insn))
break;
/* If we've reached the end of the block, stop. */
else if (insn == BLOCK_END (bb))
break;
else
insn = NEXT_INSN (insn);
} }
if (start)
BLOCK_HEAD (bb) = insn;
} }
/* Commit all the copy nodes needed to convert out of SSA form. */ /* Commit all the copy nodes needed to convert out of SSA form. */
...@@ -1947,11 +1970,7 @@ for_each_successor_phi (bb, fn, data) ...@@ -1947,11 +1970,7 @@ for_each_successor_phi (bb, fn, data)
continue; continue;
/* Advance to the first non-label insn of the successor block. */ /* Advance to the first non-label insn of the successor block. */
insn = successor->head; insn = first_insn_after_basic_block_note (successor);
while (insn != NULL
&& (GET_CODE (insn) == CODE_LABEL
|| GET_CODE (insn) == NOTE))
insn = NEXT_INSN (insn);
if (insn == NULL) if (insn == NULL)
continue; continue;
......
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