From 1d3519c8a0bfce26cde7e83390e5d0a52f4127c2 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 9 Jan 2014 13:41:57 -0500
Subject: [PATCH 120/159] FIXME: rtl_bb_info.end_, set_bb_end, BB_END; also
 BB_NOTE_LIST and friends

---
 gcc/basic-block.h  |  4 ++--
 gcc/cfgbuild.c     |  4 ++--
 gcc/cfgcleanup.c   |  8 +++++---
 gcc/cfgrtl.c       | 13 +++++--------
 gcc/emit-rtl.c     |  6 ++++--
 gcc/haifa-sched.c  | 20 +++++++++++---------
 gcc/rtl.h          |  1 +
 gcc/rtlanal.c      |  9 +++++++++
 gcc/sched-int.h    |  4 ++--
 gcc/sel-sched-ir.c |  7 ++++---
 gcc/sel-sched-ir.h |  2 +-
 gcc/sel-sched.c    |  5 +++--
 12 files changed, 49 insertions(+), 34 deletions(-)

diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index 412b817..87487dc 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -122,7 +122,7 @@ struct loop;
 struct GTY(()) rtl_bb_info {
   /* The first insn of the block is embedded into bb->il.x.  */
   /* The last insn of the block.  */
-  rtx end_;
+  rtx_base_insn end_;
 
   /* In CFGlayout mode points to insn notes/jumptables to be placed just before
      and after the block.   */
@@ -213,7 +213,7 @@ public:
   void set_bb_head (rtx_base_insn insn) { il.x.head_ = insn; }
   void set_bb_header (rtx_base_insn insn) { il.x.rtl->header_ = insn; }
   void set_bb_footer (rtx_base_insn insn) { il.x.rtl->footer_ = insn; }
-  void set_bb_end (rtx insn) { il.x.rtl->end_ = insn; }
+  void set_bb_end (rtx_base_insn insn) { il.x.rtl->end_ = insn; }
 
 };
 
diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index a22c666..fefffc0 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -449,7 +449,7 @@ find_bb_boundaries (basic_block bb)
   rtx_base_insn insn = BB_HEAD (bb);
   rtx end = BB_END (bb), x;
   rtx_jump_table_data table;
-  rtx flow_transfer_insn = NULL_RTX;
+  rtx_base_insn flow_transfer_insn = NULL_RTX_BASE_INSN;
   edge fallthru = NULL;
 
   if (insn == BB_END (bb))
@@ -483,7 +483,7 @@ find_bb_boundaries (basic_block bb)
 
 	  bb = fallthru->dest;
 	  remove_edge (fallthru);
-	  flow_transfer_insn = NULL_RTX;
+	  flow_transfer_insn = NULL_RTX_BASE_INSN;
 	  if (code == CODE_LABEL && LABEL_ALT_ENTRY_P (insn))
 	    make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, 0);
 	}
diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 7f7590c..1ea4c3d 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -702,7 +702,7 @@ merge_blocks_move_predecessor_nojumps (basic_block a, basic_block b)
 static void
 merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
 {
-  rtx barrier, real_b_end;
+  rtx_base_insn barrier, real_b_end;
   rtx_code_label label;
   rtx_jump_table_data table;
 
@@ -1724,7 +1724,8 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
 		  rr.r1 = label1;
 		  rr.r2 = label2;
 		  rr.update_label_nuses = false;
-		  for_each_rtx (&bb1->il.x.rtl->end_, replace_label, &rr);
+		  for_each_rtx_in_insn (&bb1->il.x.rtl->end_, replace_label,
+					&rr);
 
 		  match = (old_insns_match_p (mode, BB_END (bb1), BB_END (bb2))
 			   == dir_both);
@@ -1738,7 +1739,8 @@ outgoing_edges_match (int mode, basic_block bb1, basic_block bb2)
 		     from the instruction is deleted too.  */
 		  rr.r1 = label2;
 		  rr.r2 = label1;
-		  for_each_rtx (&bb1->il.x.rtl->end_, replace_label, &rr);
+		  for_each_rtx_in_insn (&bb1->il.x.rtl->end_, replace_label,
+					&rr);
 
 		  return match;
 		}
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 3588196..ebaca1f 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -154,7 +154,8 @@ delete_insn (rtx insn)
 	      reorder_insns_nobb (insn, insn, bb_note);
 	      bb->set_bb_head (bb_note);
 	      if (BB_END (bb) == bb_note)
-		bb->set_bb_end (insn);
+		bb->set_bb_end (insn->as_an_rtx_base_insn ());
+	      /* TODO: remove the cast from the above line.  */
 	    }
 	}
 
@@ -704,7 +705,7 @@ static basic_block
 rtl_split_block (basic_block bb, void *insnp)
 {
   basic_block new_bb;
-  rtx insn = (rtx) insnp;
+  rtx_base_insn insn = ((rtx) insnp)->as_an_rtx_base_insn ();
   edge e;
   edge_iterator ei;
 
@@ -714,7 +715,7 @@ rtl_split_block (basic_block bb, void *insnp)
 
       if (insn)
 	{
-	  rtx next = insn;
+	  rtx_base_insn next = insn;
 
 	  insn = PREV_INSN (insn);
 
@@ -5135,11 +5136,7 @@ rtx_base_insn BB_HEAD (const_basic_block bb)
 
 rtx_base_insn BB_END (const_basic_block bb)
 {
-  rtx tmp = bb->il.x.rtl->end_;
-  if (tmp)
-    return tmp->as_an_rtx_base_insn ();
-  else
-    return NULL;
+  return bb->il.x.rtl->end_;
 }
 
 rtx_base_insn BB_HEADER (const_basic_block bb)
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 0fa4d3d..a035051 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3939,7 +3939,8 @@ add_insn_after (rtx insn, rtx after, basic_block bb)
 	  /* Avoid clobbering of structure when creating new BB.  */
 	  && !BARRIER_P (insn)
 	  && !NOTE_INSN_BASIC_BLOCK_P (insn))
-	bb->set_bb_end (insn);
+	bb->set_bb_end (insn->as_an_rtx_base_insn ());
+      /* TODO: remove the cast in the line above.  */
     }
 }
 
@@ -4177,7 +4178,8 @@ reorder_insns (rtx from, rtx to, rtx after)
 	}
 
       if (BB_END (bb) == after)
-	bb->set_bb_end (to);
+	bb->set_bb_end (to->as_an_rtx_base_insn ());
+      /* TODO: remove the cast from the above line.  */
 
       for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x))
 	if (!BARRIER_P (x))
diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index c8ea82d..4f27a67 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -241,7 +241,7 @@ struct common_sched_info_def *common_sched_info;
 
 /* List of important notes we must keep around.  This is a pointer to the
    last element in the list.  */
-rtx note_list;
+rtx_base_insn note_list;
 
 static struct spec_info_def spec_info_var;
 /* Description of the speculative part of the scheduling.
@@ -3951,9 +3951,9 @@ schedule_insn (rtx insn)
 
 /* Add note list that ends on FROM_END to the end of TO_ENDP.  */
 void
-concat_note_lists (rtx from_end, rtx *to_endp)
+concat_note_lists (rtx_base_insn from_end, rtx_base_insn *to_endp)
 {
-  rtx from_start;
+  rtx_base_insn from_start;
 
   /* It's easy when have nothing to concat.  */
   if (from_end == NULL)
@@ -3980,14 +3980,15 @@ concat_note_lists (rtx from_end, rtx *to_endp)
 void
 remove_notes (rtx head, rtx tail)
 {
-  rtx next_tail, insn, next;
+  rtx_base_insn next_tail, insn, next;
 
   note_list = 0;
   if (head == tail && !INSN_P (head))
     return;
 
   next_tail = NEXT_INSN (tail);
-  for (insn = head; insn != next_tail; insn = next)
+  /* TODO: remove the cast from the next line.  */
+  for (insn = head->as_an_rtx_base_insn (); insn != next_tail; insn = next)
     {
       next = NEXT_INSN (insn);
       if (!NOTE_P (insn))
@@ -4737,7 +4738,7 @@ get_ebb_head_tail (basic_block beg, basic_block end, rtx *headp, rtx *tailp)
       end_tail = PREV_INSN (end_tail);
     else if (DEBUG_INSN_P (end_tail))
       {
-	rtx note, prev;
+	rtx_base_insn note, prev;
 
 	for (note = PREV_INSN (end_tail);
 	     note != end_head;
@@ -4790,7 +4791,7 @@ restore_other_notes (rtx head, basic_block head_bb)
 {
   if (note_list != 0)
     {
-      rtx note_head = note_list;
+      rtx_base_insn note_head = note_list;
 
       if (head)
 	head_bb = BLOCK_FOR_INSN (head);
@@ -5152,7 +5153,7 @@ reemit_notes (rtx insn)
 
 /* Move INSN.  Reemit notes if needed.  Update CFG, if needed.  */
 static void
-move_insn (rtx insn, rtx last, rtx nt)
+move_insn (rtx_base_insn insn, rtx last, rtx nt)
 {
   if (PREV_INSN (insn) != last)
     {
@@ -5675,7 +5676,8 @@ commit_schedule (rtx prev_head, rtx tail, basic_block *target_bb)
 
       if (current_sched_info->begin_move_insn)
 	(*current_sched_info->begin_move_insn) (insn, last_scheduled_insn);
-      move_insn (insn, last_scheduled_insn,
+      /* TODO: remove the cast from the next line.  */
+      move_insn (insn->as_an_rtx_base_insn (), last_scheduled_insn,
 		 current_sched_info->next_tail);
       if (!DEBUG_INSN_P (insn))
 	reemit_notes (insn);
diff --git a/gcc/rtl.h b/gcc/rtl.h
index a8add45..223266a 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2544,6 +2544,7 @@ extern int computed_jump_p (const_rtx);
 
 typedef int (*rtx_function) (rtx *, void *);
 extern int for_each_rtx (rtx *, rtx_function, void *);
+extern int for_each_rtx_in_insn (rtx_base_insn *, rtx_function, void *);
 
 /* Callback for for_each_inc_dec, to process the autoinc operation OP
    within MEM that sets DEST to SRC + SRCOFF, or SRC if SRCOFF is
diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c
index c69633a..10f3d93 100644
--- a/gcc/rtlanal.c
+++ b/gcc/rtlanal.c
@@ -2988,6 +2988,15 @@ for_each_rtx (rtx *x, rtx_function f, void *data)
   return for_each_rtx_1 (*x, i, f, data);
 }
 
+int
+for_each_rtx_in_insn (rtx_base_insn *insn, rtx_function f, void *data)
+{
+  rtx tmp = *insn;
+  int result = for_each_rtx (&tmp, f, data);
+  *insn = tmp->as_an_rtx_base_insn ();
+  return result;
+}
+
 
 
 /* Data structure that holds the internal state communicated between
diff --git a/gcc/sched-int.h b/gcc/sched-int.h
index 5b28633..83138ca 100644
--- a/gcc/sched-int.h
+++ b/gcc/sched-int.h
@@ -125,7 +125,7 @@ extern int insn_luid (rtx);
 /* This list holds ripped off notes from the current block.  These notes will
    be attached to the beginning of the block when its scheduling is
    finished.  */
-extern rtx note_list;
+extern rtx_base_insn note_list;
 
 extern void remove_notes (rtx, rtx);
 extern rtx restore_other_notes (rtx, basic_block);
@@ -1365,7 +1365,7 @@ extern int sched_speculate_insn (rtx, ds_t, rtx *);
 extern void unlink_bb_notes (basic_block, basic_block);
 extern void add_block (basic_block, basic_block);
 extern rtx_note bb_note (basic_block);
-extern void concat_note_lists (rtx, rtx *);
+extern void concat_note_lists (rtx_base_insn, rtx_base_insn *);
 extern rtx sched_emit_insn (rtx);
 extern rtx get_ready_element (int);
 extern int number_in_ready (void);
diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 7b3f1e7..31a1d90 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -1427,7 +1427,8 @@ sel_move_insn (expr_t expr, int seqno, insn_t after)
   /* Update links from insn to bb and vice versa.  */
   df_insn_change_bb (insn, bb);
   if (BB_END (bb) == after)
-    bb->set_bb_end (insn);
+    bb->set_bb_end (insn->as_an_rtx_base_insn ());
+  /* TODO: remove the cast from the above line.  */
 
   prepare_insn_expr (insn, seqno);
   return insn;
@@ -4644,7 +4645,7 @@ sel_restore_notes (void)
 	{
 	  note_list = BB_NOTE_LIST (first);
 	  restore_other_notes (NULL, first);
-	  BB_NOTE_LIST (first) = NULL_RTX;
+	  BB_NOTE_LIST (first) = NULL_RTX_BASE_INSN;
 
 	  FOR_BB_INSNS (first, insn)
 	    if (NONDEBUG_INSN_P (insn))
@@ -5252,7 +5253,7 @@ move_bb_info (basic_block merge_bb, basic_block empty_bb)
   if (in_current_region_p (merge_bb))
     concat_note_lists (BB_NOTE_LIST (empty_bb),
 		       &BB_NOTE_LIST (merge_bb));
-  BB_NOTE_LIST (empty_bb) = NULL_RTX;
+  BB_NOTE_LIST (empty_bb) = NULL_RTX_BASE_INSN;
 
 }
 
diff --git a/gcc/sel-sched-ir.h b/gcc/sel-sched-ir.h
index ff99e51..86cf469 100644
--- a/gcc/sel-sched-ir.h
+++ b/gcc/sel-sched-ir.h
@@ -897,7 +897,7 @@ typedef struct
 {
   /* This insn stream is constructed in such a way that it should be
      traversed by PREV_INSN field - (*not* NEXT_INSN).  */
-  rtx note_list;
+  rtx_base_insn note_list;
 
   /* Cached availability set at the beginning of a block.
      See also AV_LEVEL () for conditions when this av_set can be used.  */
diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c
index cbc0d2b..f68c9d5 100644
--- a/gcc/sel-sched.c
+++ b/gcc/sel-sched.c
@@ -4612,7 +4612,7 @@ create_block_for_bookkeeping (edge e1, edge e2)
   /* Move note_list from the upper bb.  */
   gcc_assert (BB_NOTE_LIST (new_bb) == NULL_RTX);
   BB_NOTE_LIST (new_bb) = BB_NOTE_LIST (bb);
-  BB_NOTE_LIST (bb) = NULL_RTX;
+  BB_NOTE_LIST (bb) = NULL_RTX_BASE_INSN;
 
   gcc_assert (e2->dest == bb);
 
@@ -5227,7 +5227,8 @@ move_nop_to_previous_block (insn_t nop, basic_block prev_bb)
   nop->set_next_insn (note);
   next_insn->set_prev_insn (note);
 
-  prev_bb->set_bb_end (nop);
+  prev_bb->set_bb_end (nop->as_an_rtx_base_insn ());
+  /* TODO: remove the cast from the above line.  */
   BLOCK_FOR_INSN (nop) = prev_bb;
 }
 
-- 
1.7.11.7

