This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Clear bb field for insns outside of basic blocks
Hello,
here is the updated version, bootstrapped & regtested on i686 and ia64.
Zdenek
* haifa-sched.c (restore_bb_notes): Clear bb field of the notes
emited outside of basic block.
* cfgbuild.c (find_bb_boundaries): Clear bb field for insns between
the created blocks.
* rtl.h (delete_insn_chain): Declaration changed.
* cfgrtl.c (delete_insn_chain): Add option to clear bb field for
non-removed insns.
(rtl_delete_block, rtl_merge_blocks): Pass true to delete_insn_chain.
(delete_insn_chain_and_edges, try_redirect_by_replacing_jump,
rtl_tidy_fallthru_edge, cfg_layout_merge_blocks): Pass false
to delete_insn_chain.
(rtl_verify_flow_info_1): Verify that the insns in header and footer
do not have bb field set.
(rtl_verify_flow_info): Verify that insns between basic blocks do not
have bb field set.
* recog.c (peephole2_optimize): Add argument to delete_insn_chain call.
* cfgcleanup.c (try_optimize_cfg): Ditto.
Index: haifa-sched.c
===================================================================
*** haifa-sched.c (revision 125330)
--- haifa-sched.c (working copy)
*************** extend_bb (void)
*** 4080,4087 ****
/* Don't emit a NOTE if it would end up before a BARRIER. */
&& !BARRIER_P (NEXT_INSN (insn))))
{
! emit_note_after (NOTE_INSN_DELETED, insn);
! /* Make insn to appear outside BB. */
BB_END (EXIT_BLOCK_PTR->prev_bb) = insn;
}
}
--- 4080,4088 ----
/* Don't emit a NOTE if it would end up before a BARRIER. */
&& !BARRIER_P (NEXT_INSN (insn))))
{
! rtx note = emit_note_after (NOTE_INSN_DELETED, insn);
! /* Make insn appear outside BB. */
! set_block_for_insn (note, NULL);
BB_END (EXIT_BLOCK_PTR->prev_bb) = insn;
}
}
Index: cfgbuild.c
===================================================================
*** cfgbuild.c (revision 125330)
--- cfgbuild.c (working copy)
*************** find_bb_boundaries (basic_block bb)
*** 630,636 ****
{
basic_block orig_bb = bb;
rtx insn = BB_HEAD (bb);
! rtx end = BB_END (bb);
rtx table;
rtx flow_transfer_insn = NULL_RTX;
edge fallthru = NULL;
--- 630,636 ----
{
basic_block orig_bb = bb;
rtx insn = BB_HEAD (bb);
! rtx end = BB_END (bb), x;
rtx table;
rtx flow_transfer_insn = NULL_RTX;
edge fallthru = NULL;
*************** find_bb_boundaries (basic_block bb)
*** 651,657 ****
{
fallthru = split_block (bb, PREV_INSN (insn));
if (flow_transfer_insn)
! BB_END (bb) = flow_transfer_insn;
bb = fallthru->dest;
remove_edge (fallthru);
--- 651,666 ----
{
fallthru = split_block (bb, PREV_INSN (insn));
if (flow_transfer_insn)
! {
! BB_END (bb) = flow_transfer_insn;
!
! /* Clean up the bb field for the insns between the blocks. */
! for (x = NEXT_INSN (flow_transfer_insn);
! x != BB_HEAD (fallthru->dest);
! x = NEXT_INSN (x))
! if (!BARRIER_P (x))
! set_block_for_insn (x, NULL);
! }
bb = fallthru->dest;
remove_edge (fallthru);
*************** find_bb_boundaries (basic_block bb)
*** 666,671 ****
--- 675,688 ----
{
fallthru = split_block (bb, PREV_INSN (insn));
BB_END (bb) = flow_transfer_insn;
+
+ /* Clean up the bb field for the insns between the blocks. */
+ for (x = NEXT_INSN (flow_transfer_insn);
+ x != BB_HEAD (fallthru->dest);
+ x = NEXT_INSN (x))
+ if (!BARRIER_P (x))
+ set_block_for_insn (x, NULL);
+
bb = fallthru->dest;
remove_edge (fallthru);
flow_transfer_insn = NULL_RTX;
*************** find_bb_boundaries (basic_block bb)
*** 682,688 ****
return and barrier, or possibly other sequence not behaving like
ordinary jump, we need to take care and move basic block boundary. */
if (flow_transfer_insn)
! BB_END (bb) = flow_transfer_insn;
/* We've possibly replaced the conditional jump by conditional jump
followed by cleanup at fallthru edge, so the outgoing edges may
--- 699,716 ----
return and barrier, or possibly other sequence not behaving like
ordinary jump, we need to take care and move basic block boundary. */
if (flow_transfer_insn)
! {
! BB_END (bb) = flow_transfer_insn;
!
! /* Clean up the bb field for the insns that do not belong to BB. */
! x = flow_transfer_insn;
! while (x != end)
! {
! x = NEXT_INSN (x);
! if (!BARRIER_P (x))
! set_block_for_insn (x, NULL);
! }
! }
/* We've possibly replaced the conditional jump by conditional jump
followed by cleanup at fallthru edge, so the outgoing edges may
Index: recog.c
===================================================================
*** recog.c (revision 125330)
--- recog.c (working copy)
*************** peephole2_optimize (void)
*** 3214,3220 ****
try = emit_insn_after_setloc (try, peep2_insn_data[i].insn,
INSN_LOCATOR (peep2_insn_data[i].insn));
before_try = PREV_INSN (insn);
! delete_insn_chain (insn, peep2_insn_data[i].insn);
/* Re-insert the EH_REGION notes. */
if (note || (was_call && nonlocal_goto_handler_labels))
--- 3214,3220 ----
try = emit_insn_after_setloc (try, peep2_insn_data[i].insn,
INSN_LOCATOR (peep2_insn_data[i].insn));
before_try = PREV_INSN (insn);
! delete_insn_chain (insn, peep2_insn_data[i].insn, false);
/* Re-insert the EH_REGION notes. */
if (note || (was_call && nonlocal_goto_handler_labels))
Index: cfgcleanup.c
===================================================================
*** cfgcleanup.c (revision 125330)
--- cfgcleanup.c (working copy)
*************** try_optimize_cfg (int mode)
*** 1999,2005 ****
{
rtx label = BB_HEAD (b);
! delete_insn_chain (label, label);
/* In the case label is undeletable, move it after the
BASIC_BLOCK note. */
if (NOTE_KIND (BB_HEAD (b)) == NOTE_INSN_DELETED_LABEL)
--- 1999,2005 ----
{
rtx label = BB_HEAD (b);
! delete_insn_chain (label, label, false);
/* In the case label is undeletable, move it after the
BASIC_BLOCK note. */
if (NOTE_KIND (BB_HEAD (b)) == NOTE_INSN_DELETED_LABEL)
Index: rtl.h
===================================================================
*** rtl.h (revision 125330)
--- rtl.h (working copy)
*************** extern rtx emit (rtx);
*** 2062,2068 ****
extern rtx delete_insn (rtx);
extern rtx entry_of_function (void);
extern void emit_insn_at_entry (rtx);
! extern void delete_insn_chain (rtx, rtx);
extern rtx unlink_insn_chain (rtx, rtx);
extern rtx delete_insn_and_edges (rtx);
extern void delete_insn_chain_and_edges (rtx, rtx);
--- 2062,2068 ----
extern rtx delete_insn (rtx);
extern rtx entry_of_function (void);
extern void emit_insn_at_entry (rtx);
! extern void delete_insn_chain (rtx, rtx, bool);
extern rtx unlink_insn_chain (rtx, rtx);
extern rtx delete_insn_and_edges (rtx);
extern void delete_insn_chain_and_edges (rtx, rtx);
Index: cfgrtl.c
===================================================================
*** cfgrtl.c (revision 125330)
--- cfgrtl.c (working copy)
*************** delete_insn_and_edges (rtx insn)
*** 195,204 ****
}
/* Unlink a chain of insns between START and FINISH, leaving notes
! that must be paired. */
void
! delete_insn_chain (rtx start, rtx finish)
{
rtx next;
--- 195,205 ----
}
/* Unlink a chain of insns between START and FINISH, leaving notes
! that must be paired. If CLEAR_BB is true, we set bb field for
! insns that cannot be removed to NULL. */
void
! delete_insn_chain (rtx start, rtx finish, bool clear_bb)
{
rtx next;
*************** delete_insn_chain (rtx start, rtx finish
*** 213,218 ****
--- 214,222 ----
else
next = delete_insn (start);
+ if (clear_bb && !INSN_DELETED_P (start))
+ set_block_for_insn (start, NULL);
+
if (start == finish)
break;
start = next;
*************** delete_insn_chain_and_edges (rtx first,
*** 229,235 ****
&& BLOCK_FOR_INSN (last)
&& BB_END (BLOCK_FOR_INSN (last)) == last)
purge = true;
! delete_insn_chain (first, last);
if (purge)
purge_dead_edges (BLOCK_FOR_INSN (last));
}
--- 233,239 ----
&& BLOCK_FOR_INSN (last)
&& BB_END (BLOCK_FOR_INSN (last)) == last)
purge = true;
! delete_insn_chain (first, last, false);
if (purge)
purge_dead_edges (BLOCK_FOR_INSN (last));
}
*************** rtl_delete_block (basic_block b)
*** 370,376 ****
/* Selectively delete the entire chain. */
BB_HEAD (b) = NULL;
! delete_insn_chain (insn, end);
if (b->il.rtl->global_live_at_start)
{
FREE_REG_SET (b->il.rtl->global_live_at_start);
--- 374,381 ----
/* Selectively delete the entire chain. */
BB_HEAD (b) = NULL;
! delete_insn_chain (insn, end, true);
!
if (b->il.rtl->global_live_at_start)
{
FREE_REG_SET (b->il.rtl->global_live_at_start);
*************** rtl_merge_blocks (basic_block a, basic_b
*** 608,614 ****
/* Delete everything marked above as well as crap that might be
hanging out between the two blocks. */
BB_HEAD (b) = NULL;
! delete_insn_chain (del_first, del_last);
/* Reassociate the insns of B with A. */
if (!b_empty)
--- 613,619 ----
/* Delete everything marked above as well as crap that might be
hanging out between the two blocks. */
BB_HEAD (b) = NULL;
! delete_insn_chain (del_first, del_last, true);
/* Reassociate the insns of B with A. */
if (!b_empty)
*************** try_redirect_by_replacing_jump (edge e,
*** 745,751 ****
{
rtx insn = src->il.rtl->footer;
! delete_insn_chain (kill_from, BB_END (src));
/* Remove barriers but keep jumptables. */
while (insn)
--- 750,756 ----
{
rtx insn = src->il.rtl->footer;
! delete_insn_chain (kill_from, BB_END (src), false);
/* Remove barriers but keep jumptables. */
while (insn)
*************** try_redirect_by_replacing_jump (edge e,
*** 765,771 ****
}
}
else
! delete_insn_chain (kill_from, PREV_INSN (BB_HEAD (target)));
}
/* If this already is simplejump, redirect it. */
--- 770,777 ----
}
}
else
! delete_insn_chain (kill_from, PREV_INSN (BB_HEAD (target)),
! false);
}
/* If this already is simplejump, redirect it. */
*************** try_redirect_by_replacing_jump (edge e,
*** 801,813 ****
INSN_UID (insn), INSN_UID (BB_END (src)));
! delete_insn_chain (kill_from, insn);
/* Recognize a tablejump that we are converting to a
simple jump and remove its associated CODE_LABEL
and ADDR_VEC or ADDR_DIFF_VEC. */
if (tablejump_p (insn, &label, &table))
! delete_insn_chain (label, table);
barrier = next_nonnote_insn (BB_END (src));
if (!barrier || !BARRIER_P (barrier))
--- 807,819 ----
INSN_UID (insn), INSN_UID (BB_END (src)));
! delete_insn_chain (kill_from, insn, false);
/* Recognize a tablejump that we are converting to a
simple jump and remove its associated CODE_LABEL
and ADDR_VEC or ADDR_DIFF_VEC. */
if (tablejump_p (insn, &label, &table))
! delete_insn_chain (label, table, false);
barrier = next_nonnote_insn (BB_END (src));
if (!barrier || !BARRIER_P (barrier))
*************** rtl_tidy_fallthru_edge (edge e)
*** 1217,1223 ****
/* Selectively unlink the sequence. */
if (q != PREV_INSN (BB_HEAD (c)))
! delete_insn_chain (NEXT_INSN (q), PREV_INSN (BB_HEAD (c)));
e->flags |= EDGE_FALLTHRU;
}
--- 1223,1229 ----
/* Selectively unlink the sequence. */
if (q != PREV_INSN (BB_HEAD (c)))
! delete_insn_chain (NEXT_INSN (q), PREV_INSN (BB_HEAD (c)), false);
e->flags |= EDGE_FALLTHRU;
}
*************** rtl_verify_flow_info_1 (void)
*** 1715,1720 ****
--- 1721,1743 ----
bb->index);
err = 1;
}
+
+ for (insn = bb->il.rtl->header; insn; insn = NEXT_INSN (insn))
+ if (!BARRIER_P (insn)
+ && BLOCK_FOR_INSN (insn) != NULL)
+ {
+ error ("insn %d in header of bb %d has non-NULL basic block",
+ INSN_UID (insn), bb->index);
+ err = 1;
+ }
+ for (insn = bb->il.rtl->footer; insn; insn = NEXT_INSN (insn))
+ if (!BARRIER_P (insn)
+ && BLOCK_FOR_INSN (insn) != NULL)
+ {
+ error ("insn %d in footer of bb %d has non-NULL basic block",
+ INSN_UID (insn), bb->index);
+ err = 1;
+ }
}
/* Now check the basic blocks (boundaries etc.) */
*************** rtl_verify_flow_info (void)
*** 1918,1927 ****
rtx head = BB_HEAD (bb);
rtx end = BB_END (bb);
- /* Verify the end of the basic block is in the INSN chain. */
for (x = last_head; x != NULL_RTX; x = PREV_INSN (x))
! if (x == end)
! break;
if (!x)
{
--- 1941,1961 ----
rtx head = BB_HEAD (bb);
rtx end = BB_END (bb);
for (x = last_head; x != NULL_RTX; x = PREV_INSN (x))
! {
! /* Verify the end of the basic block is in the INSN chain. */
! if (x == end)
! break;
!
! /* And that the code outside of basic blocks has NULL bb field. */
! if (!BARRIER_P (x)
! && BLOCK_FOR_INSN (x) != NULL)
! {
! error ("insn %d outside of basic blocks has non-NULL bb field",
! INSN_UID (x));
! err = 1;
! }
! }
if (!x)
{
*************** rtl_verify_flow_info (void)
*** 1955,1961 ****
err = 1;
}
! last_head = x;
FOR_EACH_EDGE (e, ei, bb->succs)
if (e->flags & EDGE_FALLTHRU)
--- 1989,1995 ----
err = 1;
}
! last_head = PREV_INSN (x);
FOR_EACH_EDGE (e, ei, bb->succs)
if (e->flags & EDGE_FALLTHRU)
*************** rtl_verify_flow_info (void)
*** 2000,2005 ****
--- 2034,2051 ----
}
}
+ for (x = last_head; x != NULL_RTX; x = PREV_INSN (x))
+ {
+ /* Check that the code before the first basic block has NULL
+ bb field. */
+ if (!BARRIER_P (x)
+ && BLOCK_FOR_INSN (x) != NULL)
+ {
+ error ("insn %d outside of basic blocks has non-NULL bb field",
+ INSN_UID (x));
+ err = 1;
+ }
+ }
free (bb_info);
num_bb_notes = 0;
*************** cfg_layout_merge_blocks (basic_block a,
*** 2550,2556 ****
rtx first = BB_END (a), last;
last = emit_insn_after_noloc (b->il.rtl->header, BB_END (a));
! delete_insn_chain (NEXT_INSN (first), last);
b->il.rtl->header = NULL;
}
--- 2596,2602 ----
rtx first = BB_END (a), last;
last = emit_insn_after_noloc (b->il.rtl->header, BB_END (a));
! delete_insn_chain (NEXT_INSN (first), last, false);
b->il.rtl->header = NULL;
}