From abe612e94f4536ef0931b96a82caedbad5ec4aca Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 30 Dec 2013 14:25:59 -0500
Subject: [PATCH 013/159] FIXME: scaffolding: BB_HEAD etc

---
 gcc/basic-block.h |  21 ++++++++--
 gcc/bb-reorder.c  |   4 +-
 gcc/caller-save.c |   6 +--
 gcc/cfgbuild.c    |   4 +-
 gcc/cfgcleanup.c  |  14 +++----
 gcc/cfgexpand.c   |  23 ++++++-----
 gcc/cfgrtl.c      | 114 ++++++++++++++++++++++++++++++++++++------------------
 gcc/combine.c     |   2 +-
 gcc/emit-rtl.c    |  12 +++---
 gcc/ifcvt.c       |   4 +-
 gcc/ira.c         |   6 +--
 11 files changed, 133 insertions(+), 77 deletions(-)

diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index c538ae6..31fad71 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -206,6 +206,15 @@ struct GTY((chain_next ("%h.next_bb"), chain_prev ("%h.prev_bb"))) basic_block_d
      among several basic blocks that share a common locus, allowing for
      more accurate sample-based profiling.  */
   int discriminator;
+
+public:
+
+  /* TODO: these should accept rtx_base_insn rather than rtx.  */
+  void set_bb_head (rtx insn) { il.x.head_ = insn; }
+  void set_bb_header (rtx insn) { il.x.rtl->header_ = insn; }
+  void set_bb_footer (rtx insn) { il.x.rtl->footer_ = insn; }
+  void set_bb_end (rtx insn) { il.x.rtl->end_ = insn; }
+
 };
 
 /* This ensures that struct gimple_bb_info is smaller than
@@ -388,10 +397,14 @@ struct GTY(()) control_flow_graph {
 
 /* Stuff for recording basic block info.  */
 
-#define BB_HEAD(B)      (B)->il.x.head_
-#define BB_END(B)       (B)->il.x.rtl->end_
-#define BB_HEADER(B)    (B)->il.x.rtl->header_
-#define BB_FOOTER(B)    (B)->il.x.rtl->footer_
+/* For now, these will be functions (so that they can include checked casts
+   to rtx_base_insn.   Once the underlying fields are converted from rtx
+   to rtx_base_insn, these can be converted back to macros.  */
+
+extern rtx_base_insn BB_HEAD (const_basic_block bb);
+extern rtx_base_insn BB_END (const_basic_block bb);
+extern rtx_base_insn BB_HEADER (const_basic_block bb);
+extern rtx_base_insn BB_FOOTER (const_basic_block bb);
 
 /* Special block numbers [markers] for entry and exit.
    Neither of them is supposed to hold actual statements.  */
diff --git a/gcc/bb-reorder.c b/gcc/bb-reorder.c
index 096d940..8cc08ad 100644
--- a/gcc/bb-reorder.c
+++ b/gcc/bb-reorder.c
@@ -1761,7 +1761,7 @@ add_labels_and_missing_jumps (vec<edge> crossing_edges)
       gcc_assert (single_succ_p (src));
 
       new_jump = emit_jump_insn_after (gen_jump (label), BB_END (src));
-      BB_END (src) = new_jump;
+      src->set_bb_end (new_jump);
       JUMP_LABEL (new_jump) = label;
       LABEL_NUSES (label) += 1;
 
@@ -2190,7 +2190,7 @@ fix_crossing_unconditional_branches (void)
 	      /* Make BB_END for cur_bb be the jump instruction (NOT the
 		 barrier instruction at the end of the sequence...).  */
 
-	      BB_END (cur_bb) = jump_insn;
+	      cur_bb->set_bb_end (jump_insn);
 	    }
 	}
     }
diff --git a/gcc/caller-save.c b/gcc/caller-save.c
index 6450e5a..0d01ad8 100644
--- a/gcc/caller-save.c
+++ b/gcc/caller-save.c
@@ -918,7 +918,7 @@ save_call_clobbered_regs (void)
 		      if (NEXT_INSN (ins))
 			NEXT_INSN (ins)->set_prev_insn (ins);
                       if (BB_END (bb) == insn)
-			BB_END (bb) = ins;
+			bb->set_bb_end (ins);
 		    }
 		  else
 		    gcc_assert (DEBUG_INSN_P (ins));
@@ -1415,7 +1415,7 @@ insert_one_insn (struct insn_chain *chain, int before_p, int code, rtx pat)
 
       CLEAR_REG_SET (&new_chain->dead_or_set);
       if (chain->insn == BB_HEAD (BASIC_BLOCK (chain->block)))
-	BB_HEAD (BASIC_BLOCK (chain->block)) = new_chain->insn;
+	BASIC_BLOCK (chain->block)->set_bb_head (new_chain->insn);
     }
   else
     {
@@ -1435,7 +1435,7 @@ insert_one_insn (struct insn_chain *chain, int before_p, int code, rtx pat)
 		   &new_chain->live_throughout);
       CLEAR_REG_SET (&new_chain->dead_or_set);
       if (chain->insn == BB_END (BASIC_BLOCK (chain->block)))
-	BB_END (BASIC_BLOCK (chain->block)) = new_chain->insn;
+	BASIC_BLOCK (chain->block)->set_bb_end (new_chain->insn);
     }
   new_chain->block = chain->block;
   new_chain->is_caller_save_insn = 1;
diff --git a/gcc/cfgbuild.c b/gcc/cfgbuild.c
index 08534d4..755047b 100644
--- a/gcc/cfgbuild.c
+++ b/gcc/cfgbuild.c
@@ -467,7 +467,7 @@ find_bb_boundaries (basic_block bb)
 	  fallthru = split_block (bb, PREV_INSN (insn));
 	  if (flow_transfer_insn)
 	    {
-	      BB_END (bb) = flow_transfer_insn;
+	      bb->set_bb_end (flow_transfer_insn);
 
 	      /* Clean up the bb field for the insns between the blocks.  */
 	      for (x = NEXT_INSN (flow_transfer_insn);
@@ -504,7 +504,7 @@ find_bb_boundaries (basic_block bb)
      ordinary jump, we need to take care and move basic block boundary.  */
   if (flow_transfer_insn)
     {
-      BB_END (bb) = flow_transfer_insn;
+      bb->set_bb_end (flow_transfer_insn);
 
       /* Clean up the bb field for the insns that do not belong to BB.  */
       x = flow_transfer_insn;
diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c
index 234e5b6..9cd8117 100644
--- a/gcc/cfgcleanup.c
+++ b/gcc/cfgcleanup.c
@@ -724,7 +724,7 @@ merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
   if (tablejump_p (BB_END (b), &label, &table)
       && prev_active_insn (label) == BB_END (b))
     {
-      BB_END (b) = table;
+      b->set_bb_end (table);
     }
 
   /* There had better have been a barrier there.  Delete it.  */
@@ -737,7 +737,7 @@ merge_blocks_move_successor_nojumps (basic_block a, basic_block b)
   reorder_insns_nobb (BB_HEAD (b), BB_END (b), BB_END (a));
 
   /* Restore the real end of b.  */
-  BB_END (b) = real_b_end;
+  b->set_bb_end (real_b_end);
 
   if (dump_file)
     fprintf (dump_file, "Moved block %d after %d and merged.\n",
@@ -1720,7 +1720,7 @@ 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 (&BB_END (bb1), replace_label, &rr);
+		  for_each_rtx (&bb1->il.x.rtl->end_, replace_label, &rr);
 
 		  match = (old_insns_match_p (mode, BB_END (bb1), BB_END (bb2))
 			   == dir_both);
@@ -1734,7 +1734,7 @@ 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 (&BB_END (bb1), replace_label, &rr);
+		  for_each_rtx (&bb1->il.x.rtl->end_, replace_label, &rr);
 
 		  return match;
 		}
@@ -2670,13 +2670,13 @@ try_optimize_cfg (int mode)
 				{
 				  if (BB_FOOTER (b))
 				    {
-				      BB_FOOTER (e->src) = BB_FOOTER (b);
-				      BB_FOOTER (b) = NULL;
+				      e->src->set_bb_footer (BB_FOOTER (b));
+				      b->set_bb_footer (NULL);
 				    }
 				  else
 				    {
 				      start_sequence ();
-				      BB_FOOTER (e->src) = emit_barrier ();
+				      e->src->set_bb_footer (emit_barrier ());
 				      end_sequence ();
 				    }
 				}
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index ee9754e..cdc84de 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -2107,9 +2107,9 @@ expand_gimple_cond (basic_block bb, gimple stmt)
     set_curr_insn_location (false_edge->goto_locus);
   emit_jump (label_rtx_for_bb (false_edge->dest));
 
-  BB_END (bb) = last;
+  bb->set_bb_end (last);
   if (BARRIER_P (BB_END (bb)))
-    BB_END (bb) = PREV_INSN (BB_END (bb));
+    bb->set_bb_end (PREV_INSN (BB_END (bb)));
   update_bb_for_insn (bb);
 
   new_bb = create_basic_block (NEXT_INSN (last), get_last_insn (), bb);
@@ -2124,7 +2124,7 @@ expand_gimple_cond (basic_block bb, gimple stmt)
   new_edge->probability = REG_BR_PROB_BASE;
   new_edge->count = new_bb->count;
   if (BARRIER_P (BB_END (new_bb)))
-    BB_END (new_bb) = PREV_INSN (BB_END (new_bb));
+    new_bb->set_bb_end (PREV_INSN (BB_END (new_bb)));
   update_bb_for_insn (new_bb);
 
   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
@@ -3420,7 +3420,7 @@ expand_gimple_tailcall (basic_block bb, gimple stmt, bool *can_fallthru)
 		 | EDGE_SIBCALL);
   e->probability += probability;
   e->count += count;
-  BB_END (bb) = last;
+  bb->set_bb_end (last);
   update_bb_for_insn (bb);
 
   if (NEXT_INSN (last))
@@ -3429,7 +3429,7 @@ expand_gimple_tailcall (basic_block bb, gimple stmt, bool *can_fallthru)
 
       last = BB_END (bb);
       if (BARRIER_P (last))
-	BB_END (bb) = PREV_INSN (last);
+	bb->set_bb_end (PREV_INSN (last));
     }
 
   maybe_dump_rtl_for_gimple_stmt (stmt, last2);
@@ -4894,15 +4894,18 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
 
       /* Java emits line number notes in the top of labels.
 	 ??? Make this go away once line number notes are obsoleted.  */
-      BB_HEAD (bb) = NEXT_INSN (last);
+      bb->set_bb_head (NEXT_INSN (last));
       if (NOTE_P (BB_HEAD (bb)))
-	BB_HEAD (bb) = NEXT_INSN (BB_HEAD (bb));
+	bb->set_bb_head (NEXT_INSN (BB_HEAD (bb)));
       note = emit_note_after (NOTE_INSN_BASIC_BLOCK, BB_HEAD (bb));
 
       maybe_dump_rtl_for_gimple_stmt (stmt, last);
     }
   else
-    BB_HEAD (bb) = note = emit_note (NOTE_INSN_BASIC_BLOCK);
+    {
+      note = emit_note (NOTE_INSN_BASIC_BLOCK);
+      bb->set_bb_head (note);
+    }
 
   NOTE_BASIC_BLOCK (note) = bb;
 
@@ -5185,7 +5188,7 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
     last = PREV_INSN (last);
   if (JUMP_TABLE_DATA_P (last))
     last = PREV_INSN (PREV_INSN (last));
-  BB_END (bb) = last;
+  bb->set_bb_end (last);
 
   update_bb_for_insn (bb);
 
@@ -5287,7 +5290,7 @@ construct_exit_block (void)
     return;
   /* While emitting the function end we could move end of the last basic block.
    */
-  BB_END (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb) = orig_end;
+  EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->set_bb_end (orig_end);
   while (NEXT_INSN (head) && NOTE_P (NEXT_INSN (head)))
     head = NEXT_INSN (head);
   exit_block = create_basic_block (NEXT_INSN (head), end,
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index e1ba391..7e89773 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -152,9 +152,9 @@ delete_insn (rtx insn)
 	      && bb == BLOCK_FOR_INSN (bb_note))
 	    {
 	      reorder_insns_nobb (insn, insn, bb_note);
-	      BB_HEAD (bb) = bb_note;
+	      bb->set_bb_head (bb_note);
 	      if (BB_END (bb) == bb_note)
-		BB_END (bb) = insn;
+		bb->set_bb_end (insn);
 	    }
 	}
 
@@ -326,8 +326,8 @@ create_basic_block_structure (rtx head, rtx end, rtx_note bb_note, basic_block a
   if (NEXT_INSN (end) == bb_note)
     end = bb_note;
 
-  BB_HEAD (bb) = head;
-  BB_END (bb) = end;
+  bb->set_bb_head (head);
+  bb->set_bb_end (end);
   bb->index = last_basic_block++;
   bb->flags = BB_NEW | BB_RTL;
   link_block (bb, after);
@@ -397,7 +397,7 @@ rtl_delete_block (basic_block b)
   end = get_last_bb_insn (b);
 
   /* Selectively delete the entire chain.  */
-  BB_HEAD (b) = NULL;
+  b->set_bb_head (NULL);
   delete_insn_chain (insn, end, true);
 
 
@@ -742,7 +742,7 @@ rtl_split_block (basic_block bb, void *insnp)
   /* Create the new basic block.  */
   new_bb = create_basic_block (NEXT_INSN (insn), BB_END (bb), bb);
   BB_COPY_PARTITION (new_bb, bb);
-  BB_END (bb) = insn;
+  bb->set_bb_end (insn);
 
   /* Redirect the outgoing edges.  */
   new_bb->succs = bb->succs;
@@ -801,7 +801,7 @@ emit_nop_for_unique_locus_between (basic_block a, basic_block b)
   if (!unique_locus_on_edge_between_p (a, b))
     return;
 
-  BB_END (a) = emit_insn_after_noloc (gen_nop (), BB_END (a), a);
+  a->set_bb_end (emit_insn_after_noloc (gen_nop (), BB_END (a), a));
   INSN_LOCATION (BB_END (a)) = EDGE_SUCC (a, 0)->goto_locus;
 }
 
@@ -883,8 +883,8 @@ rtl_merge_blocks (basic_block a, basic_block b)
 
   /* Delete everything marked above as well as crap that might be
      hanging out between the two blocks.  */
-  BB_END (a) = a_end;
-  BB_HEAD (b) = b_empty ? NULL_RTX : b_head;
+  a->set_bb_end (a_end);
+  b->set_bb_head (b_empty ? NULL_RTX : b_head);
   delete_insn_chain (del_first, del_last, true);
 
   /* When not optimizing CFG and the edge is the only place in RTL which holds
@@ -900,8 +900,8 @@ rtl_merge_blocks (basic_block a, basic_block b)
     {
       update_bb_for_insn_chain (a_end, b_debug_end, a);
 
-      BB_END (a) = b_debug_end;
-      BB_HEAD (b) = NULL_RTX;
+      a->set_bb_end (b_debug_end);
+      b->set_bb_head (NULL_RTX);
     }
   else if (b_end != b_debug_end)
     {
@@ -913,7 +913,7 @@ rtl_merge_blocks (basic_block a, basic_block b)
 	reorder_insns_nobb (NEXT_INSN (a_end), PREV_INSN (b_debug_start),
 			    b_debug_end);
       update_bb_for_insn_chain (b_debug_start, b_debug_end, a);
-      BB_END (a) = b_debug_end;
+      a->set_bb_end (b_debug_end);
     }
 
   df_bb_delete (b->index);
@@ -978,7 +978,7 @@ block_label (basic_block block)
 
   if (!LABEL_P (BB_HEAD (block)))
     {
-      BB_HEAD (block) = emit_label_before (gen_label_rtx (), BB_HEAD (block));
+      block->set_bb_head (emit_label_before (gen_label_rtx (), BB_HEAD (block)));
     }
 
   return BB_HEAD (block)->as_an_rtx_code_label ();
@@ -1061,7 +1061,7 @@ try_redirect_by_replacing_jump (edge e, basic_block target, bool in_cfglayout)
 		  if (PREV_INSN (insn))
 		    PREV_INSN (insn)->set_next_insn (NEXT_INSN (insn));
 		  else
-		    BB_FOOTER (src) = NEXT_INSN (insn);
+		    src->set_bb_footer (NEXT_INSN (insn));
 		  if (NEXT_INSN (insn))
 		    NEXT_INSN (insn)->set_prev_insn (PREV_INSN (insn));
 		}
@@ -1451,7 +1451,7 @@ emit_barrier_after_bb (basic_block bb)
   gcc_assert (current_ir_type () == IR_RTL_CFGRTL
               || current_ir_type () == IR_RTL_CFGLAYOUT);
   if (current_ir_type () == IR_RTL_CFGLAYOUT)
-    BB_FOOTER (bb) = unlink_insn_chain (barrier, barrier);
+    bb->set_bb_footer (unlink_insn_chain (barrier, barrier));
 }
 
 /* Like force_nonfallthru below, but additionally performs redirection
@@ -3262,7 +3262,7 @@ fixup_abnormal_edges (void)
 	      e = find_fallthru_edge (bb->succs);
 
 	      stop = NEXT_INSN (BB_END (bb));
-	      BB_END (bb) = insn;
+	      bb->set_bb_end (insn);
 
 	      for (insn = NEXT_INSN (insn); insn != stop; insn = next)
 		{
@@ -3458,11 +3458,11 @@ record_effective_endpoints (void)
       rtx end;
 
       if (PREV_INSN (BB_HEAD (bb)) && next_insn != BB_HEAD (bb))
-	BB_HEADER (bb) = unlink_insn_chain (next_insn,
-					      PREV_INSN (BB_HEAD (bb)));
+	bb->set_bb_header (unlink_insn_chain (next_insn,
+					      PREV_INSN (BB_HEAD (bb))));
       end = skip_insns_after_block (bb);
       if (NEXT_INSN (BB_END (bb)) && BB_END (bb) != end)
-	BB_FOOTER (bb) = unlink_insn_chain (NEXT_INSN (BB_END (bb)), end);
+	bb->set_bb_footer (unlink_insn_chain (NEXT_INSN (BB_END (bb)), end));
       next_insn = NEXT_INSN (BB_END (bb));
     }
 
@@ -3627,7 +3627,10 @@ relink_block_chain (bool stay_in_cfglayout_mode)
     {
       bb->aux = NULL;
       if (!stay_in_cfglayout_mode)
-	BB_HEADER (bb) = BB_FOOTER (bb) = NULL;
+	{
+	  bb->set_bb_header (NULL);
+	  bb->set_bb_footer (NULL);
+	}
     }
 
   /* Maybe reset the original copy tables, they are not valid anymore
@@ -3919,8 +3922,8 @@ fixup_reorder_chain (void)
 		}
 	      nb = split_edge (e);
 	      if (!INSN_P (BB_END (nb)))
-		BB_END (nb) = emit_insn_after_noloc (gen_nop (), BB_END (nb),
-						     nb);
+		nb->set_bb_end (emit_insn_after_noloc (gen_nop (), BB_END (nb),
+						       nb));
 	      INSN_LOCATION (BB_END (nb)) = e->goto_locus;
 
 	      /* If there are other incoming edges to the destination block
@@ -3994,8 +3997,8 @@ fixup_fallthru_exit_predecessor (void)
 	  bb = split_block (bb, NULL)->dest;
 	  bb->aux = c->aux;
 	  c->aux = bb;
-	  BB_FOOTER (bb) = BB_FOOTER (c);
-	  BB_FOOTER (c) = NULL;
+	  bb->set_bb_footer (BB_FOOTER (c));
+	  c->set_bb_footer (NULL);
 	}
 
       while (c->aux != bb)
@@ -4199,7 +4202,7 @@ cfg_layout_duplicate_bb (basic_block bb)
 	insn = NEXT_INSN (insn);
       insn = duplicate_insn_chain (BB_HEADER (bb), insn);
       if (insn)
-	BB_HEADER (new_bb) = unlink_insn_chain (insn, get_last_insn ());
+	new_bb->set_bb_header (unlink_insn_chain (insn, get_last_insn ()));
     }
 
   if (BB_FOOTER (bb))
@@ -4209,7 +4212,7 @@ cfg_layout_duplicate_bb (basic_block bb)
 	insn = NEXT_INSN (insn);
       insn = duplicate_insn_chain (BB_FOOTER (bb), insn);
       if (insn)
-	BB_FOOTER (new_bb) = unlink_insn_chain (insn, get_last_insn ());
+	new_bb->set_bb_footer (unlink_insn_chain (insn, get_last_insn ()));
     }
 
   return new_bb;
@@ -4317,8 +4320,8 @@ cfg_layout_split_block (basic_block bb, void *insnp)
   rtx insn = (rtx) insnp;
   basic_block new_bb = rtl_split_block (bb, insn);
 
-  BB_FOOTER (new_bb) = BB_FOOTER (bb);
-  BB_FOOTER (bb) = NULL;
+  new_bb->set_bb_footer (BB_FOOTER (bb));
+  bb->set_bb_footer (NULL);
 
   return new_bb;
 }
@@ -4448,7 +4451,7 @@ cfg_layout_delete_block (basic_block bb)
 	      if (PREV_INSN (insn))
 		PREV_INSN (insn)->set_next_insn (NEXT_INSN (insn));
 	      else
-		BB_FOOTER (bb) = NEXT_INSN (insn);
+		bb->set_bb_footer (NEXT_INSN (insn));
 	      if (NEXT_INSN (insn))
 		NEXT_INSN (insn)->set_prev_insn (PREV_INSN (insn));
 	    }
@@ -4471,7 +4474,7 @@ cfg_layout_delete_block (basic_block bb)
 	}
     }
   if (bb->next_bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
-    to = &BB_HEADER (bb->next_bb);
+    to = &bb->next_bb->il.x.rtl->header_;
   else
     to = &cfg_layout_function_footer;
 
@@ -4583,7 +4586,7 @@ cfg_layout_merge_blocks (basic_block a, basic_block b)
   if (BB_FOOTER (b))
     {
       if (!BB_FOOTER (a))
-	BB_FOOTER (a) = BB_FOOTER (b);
+	a->set_bb_footer (BB_FOOTER (b));
       else
 	{
 	  rtx last = BB_FOOTER (a);
@@ -4593,7 +4596,7 @@ cfg_layout_merge_blocks (basic_block a, basic_block b)
 	  last->set_next_insn (BB_FOOTER (b));
 	  BB_FOOTER (b)->set_prev_insn (last);
 	}
-      BB_FOOTER (b) = NULL;
+      b->set_bb_footer (NULL);
     }
 
   /* Move things from b->header before a->footer.
@@ -4602,7 +4605,7 @@ cfg_layout_merge_blocks (basic_block a, basic_block b)
    if (BB_HEADER (b))
      {
       if (! BB_FOOTER (a))
-	BB_FOOTER (a) = BB_HEADER (b);
+	a->set_bb_footer (BB_HEADER (b));
       else
 	{
 	  rtx last = BB_HEADER (b);
@@ -4611,9 +4614,9 @@ cfg_layout_merge_blocks (basic_block a, basic_block b)
 	    last = NEXT_INSN (last);
 	  last->set_next_insn (BB_FOOTER (a));
 	  BB_FOOTER (a)->set_prev_insn (last);
-	  BB_FOOTER (a) = BB_HEADER (b);
+	  a->set_bb_footer (BB_HEADER (b));
 	}
-      BB_HEADER (b) = NULL;
+      b->set_bb_header (NULL);
     }
 
   /* In the case basic blocks are not adjacent, move them around.  */
@@ -4627,7 +4630,7 @@ cfg_layout_merge_blocks (basic_block a, basic_block b)
   else
     {
       insn = BB_HEAD (b);
-      BB_END (a) = BB_END (b);
+      a->set_bb_end (BB_END (b));
     }
 
   /* emit_insn_after_noloc doesn't call df_insn_change_bb.
@@ -4638,7 +4641,8 @@ cfg_layout_merge_blocks (basic_block a, basic_block b)
   if (!NOTE_INSN_BASIC_BLOCK_P (insn))
     insn = NEXT_INSN (insn);
   gcc_assert (NOTE_INSN_BASIC_BLOCK_P (insn));
-  BB_HEAD (b) = BB_END (b) = NULL;
+  b->set_bb_head (NULL);
+  b->set_bb_end (NULL);
   delete_insn (insn);
 
   df_bb_delete (b->index);
@@ -5109,4 +5113,40 @@ struct cfg_hooks cfg_layout_rtl_cfg_hooks = {
   rtl_account_profile_record,
 };
 
+rtx_base_insn BB_HEAD (const_basic_block bb)
+{
+  rtx tmp = bb->il.x.head_;
+  if (tmp)
+    return tmp->as_an_rtx_base_insn ();
+  else
+    return NULL;
+}
+
+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;
+}
+
+rtx_base_insn BB_HEADER (const_basic_block bb)
+{
+  rtx tmp = bb->il.x.rtl->header_;
+  if (tmp)
+    return tmp->as_an_rtx_base_insn ();
+  else
+    return NULL;
+}
+
+rtx_base_insn BB_FOOTER (const_basic_block bb)
+{
+   rtx tmp = bb->il.x.rtl->footer_;
+   if (tmp)
+     return tmp->as_an_rtx_base_insn ();
+   else
+     return NULL;
+}
+
 #include "gt-cfgrtl.h"
diff --git a/gcc/combine.c b/gcc/combine.c
index ddad93c..48ffa2b 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -2393,7 +2393,7 @@ update_cfg_for_uncondjump (rtx insn)
 	    if (PREV_INSN (insn))
 	      PREV_INSN (insn)->set_next_insn (NEXT_INSN (insn));
 	    else
-	      BB_FOOTER (bb) = NEXT_INSN (insn);
+	      bb->set_bb_footer (NEXT_INSN (insn));
 	    if (NEXT_INSN (insn))
 	      NEXT_INSN (insn)->set_prev_insn (PREV_INSN (insn));
 	  }
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 9819905..0015d60 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3884,7 +3884,7 @@ 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_END (bb) = insn;
+	bb->set_bb_end (insn);
     }
 }
 
@@ -4014,10 +4014,10 @@ remove_insn (rtx insn)
 	  /* Never ever delete the basic block note without deleting whole
 	     basic block.  */
 	  gcc_assert (!NOTE_P (insn));
-	  BB_HEAD (bb) = next;
+	  bb->set_bb_head (next);
 	}
       if (BB_END (bb) == insn)
-	BB_END (bb) = prev;
+	bb->set_bb_end (prev);
     }
 }
 
@@ -4117,12 +4117,12 @@ reorder_insns (rtx from, rtx to, rtx after)
 	  && (bb2 = BLOCK_FOR_INSN (from)))
 	{
 	  if (BB_END (bb2) == to)
-	    BB_END (bb2) = prev;
+	    bb2->set_bb_end (prev);
 	  df_set_bb_dirty (bb2);
 	}
 
       if (BB_END (bb) == after)
-	BB_END (bb) = to;
+	bb->set_bb_end (to);
 
       for (x = from; x != NEXT_INSN (to); x = NEXT_INSN (x))
 	if (!BARRIER_P (x))
@@ -4293,7 +4293,7 @@ emit_insn_after_1 (rtx first, rtx after, basic_block bb)
 	  df_insn_rescan (last);
 	}
       if (BB_END (bb) == after)
-	BB_END (bb) = last;
+	bb->set_bb_end (last);
     }
   else
     for (last = first->as_an_rtx_base_insn ();
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index ecec98c..fdbf58b 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -2586,7 +2586,7 @@ noce_process_if_block (struct noce_if_info *if_info)
 	  rtx note;
 
 	  if (else_bb && insn_b == BB_END (else_bb))
-	    BB_END (else_bb) = PREV_INSN (insn_b);
+	    else_bb->set_bb_end (PREV_INSN (insn_b));
 	  reorder_insns (insn_b, insn_b, PREV_INSN (jump));
 
 	  /* If there was a REG_EQUAL note, delete it since it may have been
@@ -4306,7 +4306,7 @@ dead_or_predicable (basic_block test_bb, basic_block merge_bb,
       rtx insn;
 
       if (end == BB_END (merge_bb))
-	BB_END (merge_bb) = PREV_INSN (head);
+	merge_bb->set_bb_end (PREV_INSN (head));
 
       /* PR 21767: when moving insns above a conditional branch, the REG_EQUAL
 	 notes being moved might become invalid.  */
diff --git a/gcc/ira.c b/gcc/ira.c
index f24de51..5680599 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -3893,7 +3893,7 @@ update_equiv_regs (void)
 		      REG_LIVE_LENGTH (regno) = 2;
 
 		      if (insn == BB_HEAD (bb))
-			BB_HEAD (bb) = PREV_INSN (insn);
+			bb->set_bb_head (PREV_INSN (insn));
 
 		      ira_reg_equiv[regno].init_insns
 			= gen_rtx_INSN_LIST (VOIDmode, new_insn, NULL_RTX);
@@ -4329,12 +4329,12 @@ build_insn_chain (void)
       /* FIXME!! The following code is a disaster.  Reload needs to see the
 	 labels and jump tables that are just hanging out in between
 	 the basic blocks.  See pr33676.  */
-      insn = BB_HEAD (bb)->as_an_rtx_base_insn ();
+      insn = BB_HEAD (bb);
 
       /* Skip over the barriers and cruft.  */
       while (insn && (BARRIER_P (insn) || NOTE_P (insn)
 		      || BLOCK_FOR_INSN (insn) == bb))
-	insn = PREV_INSN (insn)->as_an_rtx_base_insn ();
+	insn = PREV_INSN (insn);
 
       /* While we add anything except barriers and notes, the focus is
 	 to get the labels and jump tables into the
-- 
1.7.11.7

