Patchwork [06/13] Eliminate BASIC_BLOCK macro.

login
register
mail settings
Submitter David Malcolm
Date Dec. 6, 2013, 2:51 p.m.
Message ID <1386341499-19603-7-git-send-email-dmalcolm@redhat.com>
Download mbox | patch
Permalink /patch/298058/
State New
Headers show

Comments

David Malcolm - Dec. 6, 2013, 2:51 p.m.
gcc/
	* basic-block.h (BASIC_BLOCK): Eliminate macro.

	* alias.c (init_alias_analysis): Eliminate BASIC_BLOCK macro in
	favor of uses of BASIC_BLOCK_FOR_FN, making uses of cfun explicit.
	* bt-load.c (compute_defs_uses_and_gen, compute_out, link_btr_uses,
	block_at_edge_of_live_range_p, migrate_btr_defs): Likewise.
	* caller-save.c (insert_one_insn): Likewise.
	* cfg.c (debug_bb, get_bb_original, get_bb_copy): Likewise.
	* cfgexpand.c (add_scope_conflicts): Likewise.
	* cfghooks.c (verify_flow_info): Likewise.
	* cfgloop.c (flow_loops_find): Likewise.
	* cfgrtl.c (rtl_flow_call_edges_add): Likewise.
	* config/mips/mips.c (r10k_insert_cache_barriers): Likewise.
	* config/s390/s390.c (s390_optimize_nonescaping_tx): Likewise.
	* config/spu/spu.c (spu_machine_dependent_reorg): Likewise.
	* cse.c (cse_main): Likewise.
	* dce.c (fast_dce): Likewise.
	* df-core.c (df_set_blocks, df_worklist_propagate_forward,
	df_worklist_propagate_backward, df_worklist_dataflow_doublequeue,
	df_bb_replace, df_dump_region): Likewise.
	* df-problems.c (df_rd_bb_local_compute, df_lr_bb_local_compute,
	df_live_bb_local_compute, df_chain_remove_problem)
	df_chain_create_bb, df_word_lr_bb_local_compute, df_note_bb_compute,
	df_md_bb_local_compute, df_md_local_compute,
	df_md_transfer_function): Likewise.
	* df-scan.c (df_scan_blocks, df_reorganize_refs_by_reg_by_insn,
	df_reorganize_refs_by_insn, df_bb_refs_collect,
	df_record_entry_block_defs, df_update_entry_block_defs,
	df_record_exit_block_uses): Likewise.
	* dominance.c (nearest_common_dominator_for_set): Likewise.
	* gcse.c (hoist_code): Likewise.
	* graph.c (draw_cfg_nodes_no_loops): Likewise.
	* ipa-inline-analysis.c (param_change_prob,
	estimate_function_body_sizes): Likewise.
	* ipa-split.c (dominated_by_forbidden): Likewise.
	* loop-unroll.c (apply_opt_in_copies): Likewise.
	* lower-subreg.c (decompose_multiword_subregs): Likewise.
	* lra-lives.c (lra_create_live_ranges): Likewise.
	* predict.c (propagate_freq): Likewise.
	* regrename.c (regrename_analyze): Likewise.
	* regstat.c (regstat_bb_compute_ri,
	regstat_bb_compute_calls_crossed): Likewise.
	* resource.c (mark_target_live_regs): Likewise.
	* sched-ebb.c (ebb_fix_recovery_cfg): Likewise.
	* sched-int.h (EBB_FIRST_BB, EBB_LAST_BB): Likewise.
	* sched-rgn.c (debug_region, dump_region_dot, too_large,
	haifa_find_rgns, extend_rgns, compute_dom_prob_ps, update_live,
	propagate_deps, sched_is_disabled_for_current_region_p): Likewise.
	* sched-vis.c (debug_bb_n_slim): Likewise.
	* sel-sched-ir.c (sel_finish_global_and_expr, verify_backedges,
	purge_empty_blocks, sel_remove_loop_preheader): Likewise.
	* sel-sched.c (remove_insns_that_need_bookkeeping)
	(current_region_empty_p, sel_region_init,
	simplify_changed_insns): Likewise.
	* trans-mem.c (execute_tm_mark, execute_tm_edges,
	tm_memopt_compute_antic, ipa_tm_scan_irr_function): Likewise.
	* tree-cfg.c (make_edges, end_recording_case_labels,
	label_to_block_fn, gimple_debug_bb, gimple_flow_call_edges_add,
	remove_edge_and_dominated_blocks, remove_edge_and_dominated_blocks,
	gimple_purge_all_dead_eh_edges,
	gimple_purge_all_dead_abnormal_call_edges): Likewise.
	* tree-cfgcleanup.c (fixup_noreturn_call,
	split_bbs_on_noreturn_calls, cleanup_tree_cfg_1): Likewise.
	* tree-inline.c (copy_cfg_body, fold_marked_statements): Likewise.
	* tree-into-ssa.c (set_livein_block, prune_unused_phi_nodes,
	insert_phi_nodes_for, insert_updated_phi_nodes_for): Likewise.
	* tree-ssa-dom.c (tree_ssa_dominator_optimize): Likewise.
	* tree-ssa-live.c (live_worklist): Likewise.
	* tree-ssa-loop-manip.c (compute_live_loop_exits,
	add_exit_phis_var, find_uses_to_rename, copy_phi_node_args): Likewise.
	* tree-ssa-pre.c (compute_antic): Likewise.
	* tree-ssa-reassoc.c (update_range_test, optimize_range_tests): Likewise.
	* tree-ssa-sink.c (nearest_common_dominator_of_uses): Likewise.
	* tree-ssa-tail-merge.c (same_succ_hash, same_succ_def::equal,
	same_succ_flush_bbs, update_worklist, set_cluster,
	same_phi_alternatives, find_clusters_1, apply_clusters,
	update_debug_stmts): Likewise.
	* tree-ssa-threadupdate.c (mark_threaded_blocks,
	thread_through_all_blocks): Likewise.
	* tree-ssa-uncprop.c (associate_equivalences_with_edges): Likewise.
	* tree-vrp.c (find_assert_locations): Likewise.
---
 gcc/alias.c                 |  2 +-
 gcc/basic-block.h           |  2 --
 gcc/bt-load.c               | 15 ++++++++-------
 gcc/caller-save.c           |  8 ++++----
 gcc/cfg.c                   |  6 +++---
 gcc/cfgexpand.c             |  2 +-
 gcc/cfghooks.c              |  2 +-
 gcc/cfgloop.c               |  2 +-
 gcc/cfgrtl.c                |  2 +-
 gcc/config/mips/mips.c      |  2 +-
 gcc/config/s390/s390.c      |  2 +-
 gcc/config/spu/spu.c        |  2 +-
 gcc/cse.c                   |  2 +-
 gcc/dce.c                   |  2 +-
 gcc/df-core.c               | 18 +++++++++---------
 gcc/df-problems.c           | 20 ++++++++++----------
 gcc/df-scan.c               | 26 ++++++++++++++++----------
 gcc/dominance.c             |  6 +++---
 gcc/gcse.c                  |  4 ++--
 gcc/graph.c                 |  2 +-
 gcc/ipa-inline-analysis.c   |  4 ++--
 gcc/ipa-split.c             |  3 ++-
 gcc/loop-unroll.c           |  4 ++--
 gcc/lower-subreg.c          |  2 +-
 gcc/lra-lives.c             |  2 +-
 gcc/predict.c               |  2 +-
 gcc/regrename.c             |  2 +-
 gcc/regstat.c               |  4 ++--
 gcc/resource.c              |  7 ++++---
 gcc/sched-ebb.c             |  2 +-
 gcc/sched-int.h             |  5 +++--
 gcc/sched-rgn.c             | 32 ++++++++++++++++++++------------
 gcc/sched-vis.c             |  2 +-
 gcc/sel-sched-ir.c          |  8 ++++----
 gcc/sel-sched.c             | 18 ++++++++++--------
 gcc/trans-mem.c             |  9 +++++----
 gcc/tree-cfg.c              | 22 ++++++++++++----------
 gcc/tree-cfgcleanup.c       |  8 ++++----
 gcc/tree-inline.c           | 19 +++++++++++--------
 gcc/tree-into-ssa.c         | 18 ++++++++++--------
 gcc/tree-ssa-dom.c          |  2 +-
 gcc/tree-ssa-live.c         |  2 +-
 gcc/tree-ssa-loop-manip.c   | 12 ++++++------
 gcc/tree-ssa-pre.c          |  4 ++--
 gcc/tree-ssa-reassoc.c      |  6 ++++--
 gcc/tree-ssa-sink.c         |  4 ++--
 gcc/tree-ssa-tail-merge.c   | 26 +++++++++++++-------------
 gcc/tree-ssa-threadupdate.c |  8 ++++----
 gcc/tree-ssa-uncprop.c      |  3 ++-
 gcc/tree-vrp.c              |  2 +-
 50 files changed, 199 insertions(+), 170 deletions(-)

Patch

diff --git a/gcc/alias.c b/gcc/alias.c
index 6a73b09..6290c83 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -2989,7 +2989,7 @@  init_alias_analysis (void)
       /* Walk the insns adding values to the new_reg_base_value array.  */
       for (i = 0; i < rpo_cnt; i++)
 	{
-	  basic_block bb = BASIC_BLOCK (rpo[i]);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
 	  FOR_BB_INSNS (bb, insn)
 	    {
 	      if (NONDEBUG_INSN_P (insn))
diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index f759e27..3bd011e 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -332,8 +332,6 @@  struct GTY(()) control_flow_graph {
 #define label_to_block_map	(cfun->cfg->x_label_to_block_map)
 #define profile_status		(cfun->cfg->x_profile_status)
 
-#define BASIC_BLOCK(N)		((*basic_block_info)[(N)])
-
 /* For iterating over basic blocks.  */
 #define FOR_BB_BETWEEN(BB, FROM, TO, DIR) \
   for (BB = FROM; BB != TO; BB = BB->DIR)
diff --git a/gcc/bt-load.c b/gcc/bt-load.c
index 09eea06..bbd0dd8 100644
--- a/gcc/bt-load.c
+++ b/gcc/bt-load.c
@@ -460,7 +460,7 @@  compute_defs_uses_and_gen (fibheap_t all_btr_defs, btr_def *def_array,
   bitmap_vector_clear (bb_gen, last_basic_block);
   for (i = NUM_FIXED_BLOCKS; i < last_basic_block; i++)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
       int reg;
       btr_def defs_this_bb = NULL;
       rtx insn;
@@ -651,7 +651,7 @@  compute_out (sbitmap *bb_out, sbitmap *bb_gen, sbitmap *bb_kill, int max_uid)
       changed = 0;
       for (i = NUM_FIXED_BLOCKS; i < last_basic_block; i++)
 	{
-	  bitmap_union_of_preds (bb_in, bb_out, BASIC_BLOCK (i));
+	  bitmap_union_of_preds (bb_in, bb_out, BASIC_BLOCK_FOR_FN (cfun, i));
 	  changed |= bitmap_ior_and_compl (bb_out[i], bb_gen[i],
 					       bb_in, bb_kill[i]);
 	}
@@ -670,11 +670,11 @@  link_btr_uses (btr_def *def_array, btr_user *use_array, sbitmap *bb_out,
      Count up the number of reaching defs of each use.  */
   for (i = NUM_FIXED_BLOCKS; i < last_basic_block; i++)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
       rtx insn;
       rtx last;
 
-      bitmap_union_of_preds (reaching_defs, bb_out, BASIC_BLOCK (i));
+      bitmap_union_of_preds (reaching_defs, bb_out, BASIC_BLOCK_FOR_FN (cfun, i));
       for (insn = BB_HEAD (bb), last = NEXT_INSN (BB_END (bb));
 	   insn != last;
 	   insn = NEXT_INSN (insn))
@@ -814,13 +814,14 @@  build_btr_def_use_webs (fibheap_t all_btr_defs)
 static int
 block_at_edge_of_live_range_p (int bb, btr_def def)
 {
-  if (def->other_btr_uses_before_def && BASIC_BLOCK (bb) == def->bb)
+  if (def->other_btr_uses_before_def
+      && BASIC_BLOCK_FOR_FN (cfun, bb) == def->bb)
     return 1;
   else if (def->other_btr_uses_after_use)
     {
       btr_user user;
       for (user = def->uses; user != NULL; user = user->next)
-	if (BASIC_BLOCK (bb) == user->bb)
+	if (BASIC_BLOCK_FOR_FN (cfun, bb) == user->bb)
 	  return 1;
     }
   return 0;
@@ -1406,7 +1407,7 @@  migrate_btr_defs (enum reg_class btr_class, int allow_callee_save)
 
       for (i = NUM_FIXED_BLOCKS; i < last_basic_block; i++)
 	{
-	  basic_block bb = BASIC_BLOCK (i);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
 	  fprintf (dump_file,
 		   "Basic block %d: count = " HOST_WIDEST_INT_PRINT_DEC
 		   " loop-depth = %d idom = %d\n",
diff --git a/gcc/caller-save.c b/gcc/caller-save.c
index b134cde..628fc0b 100644
--- a/gcc/caller-save.c
+++ b/gcc/caller-save.c
@@ -1414,8 +1414,8 @@  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_HEAD (BASIC_BLOCK (chain->block)))
-	BB_HEAD (BASIC_BLOCK (chain->block)) = new_chain->insn;
+      if (chain->insn == BB_HEAD (BASIC_BLOCK_FOR_FN (cfun, chain->block)))
+	BB_HEAD (BASIC_BLOCK_FOR_FN (cfun, chain->block)) = new_chain->insn;
     }
   else
     {
@@ -1434,8 +1434,8 @@  insert_one_insn (struct insn_chain *chain, int before_p, int code, rtx pat)
       note_stores (PATTERN (chain->insn), add_stored_regs,
 		   &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;
+      if (chain->insn == BB_END (BASIC_BLOCK_FOR_FN (cfun, chain->block)))
+	BB_END (BASIC_BLOCK_FOR_FN (cfun, chain->block)) = new_chain->insn;
     }
   new_chain->block = chain->block;
   new_chain->is_caller_save_insn = 1;
diff --git a/gcc/cfg.c b/gcc/cfg.c
index f386168..3337372 100644
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -690,7 +690,7 @@  debug_bb (basic_block bb)
 DEBUG_FUNCTION basic_block
 debug_bb_n (int n)
 {
-  basic_block bb = BASIC_BLOCK (n);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
   debug_bb (bb);
   return bb;
 }
@@ -1139,7 +1139,7 @@  get_bb_original (basic_block bb)
   key.index1 = bb->index;
   entry = bb_original.find (&key);
   if (entry)
-    return BASIC_BLOCK (entry->index2);
+    return BASIC_BLOCK_FOR_FN (cfun, entry->index2);
   else
     return NULL;
 }
@@ -1164,7 +1164,7 @@  get_bb_copy (basic_block bb)
   key.index1 = bb->index;
   entry = bb_copy.find (&key);
   if (entry)
-    return BASIC_BLOCK (entry->index2);
+    return BASIC_BLOCK_FOR_FN (cfun, entry->index2);
   else
     return NULL;
 }
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 853ace2..d98ac5b 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -512,7 +512,7 @@  add_scope_conflicts (void)
       for (i = 0; i < n_bbs; i++)
 	{
 	  bitmap active;
-	  bb = BASIC_BLOCK (rpo[i]);
+	  bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
 	  active = (bitmap)bb->aux;
 	  add_scope_conflicts_1 (bb, work, false);
 	  if (bitmap_ior_into (active, work))
diff --git a/gcc/cfghooks.c b/gcc/cfghooks.c
index 2535c90..0cd6af0 100644
--- a/gcc/cfghooks.c
+++ b/gcc/cfghooks.c
@@ -106,7 +106,7 @@  verify_flow_info (void)
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb, NULL, next_bb)
     {
       if (bb != EXIT_BLOCK_PTR_FOR_FN (cfun)
-	  && bb != BASIC_BLOCK (bb->index))
+	  && bb != BASIC_BLOCK_FOR_FN (cfun, bb->index))
 	{
 	  error ("bb %d on wrong place", bb->index);
 	  err = 1;
diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c
index 0b12e73..6245605 100644
--- a/gcc/cfgloop.c
+++ b/gcc/cfgloop.c
@@ -439,7 +439,7 @@  flow_loops_find (struct loops *loops)
   auto_vec<loop_p> larray (loops->larray->length ());
   for (b = 0; b < n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; b++)
     {
-      basic_block header = BASIC_BLOCK (rc_order[b]);
+      basic_block header = BASIC_BLOCK_FOR_FN (cfun, rc_order[b]);
       if (bb_loop_header_p (header))
 	{
 	  struct loop *loop;
diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 045d78b..de110f4 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -4831,7 +4831,7 @@  rtl_flow_call_edges_add (sbitmap blocks)
 
   for (i = NUM_FIXED_BLOCKS; i < last_bb; i++)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
       rtx insn;
       rtx prev_insn;
 
diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
index 36ba6df..7903443 100644
--- a/gcc/config/mips/mips.c
+++ b/gcc/config/mips/mips.c
@@ -15079,7 +15079,7 @@  r10k_insert_cache_barriers (void)
   n = pre_and_rev_post_order_compute (NULL, rev_post_order, false);
   for (i = 0; i < n; i++)
     {
-      bb = BASIC_BLOCK (rev_post_order[i]);
+      bb = BASIC_BLOCK_FOR_FN (cfun, rev_post_order[i]);
 
       /* If this block is only reached by unconditional edges, and if the
 	 source of every edge is protected, the beginning of the block is
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index a435b2d..fcd7532 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -7982,7 +7982,7 @@  s390_optimize_nonescaping_tx (void)
 
   for (bb_index = 0; bb_index < n_basic_blocks_for_fn (cfun); bb_index++)
     {
-      bb = BASIC_BLOCK (bb_index);
+      bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
 
       if (!bb)
 	continue;
diff --git a/gcc/config/spu/spu.c b/gcc/config/spu/spu.c
index 5b8aef1..a658ee6 100644
--- a/gcc/config/spu/spu.c
+++ b/gcc/config/spu/spu.c
@@ -2490,7 +2490,7 @@  spu_machine_dependent_reorg (void)
 
   for (i = n_basic_blocks_for_fn (cfun) - 1; i >= 0; i--)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       branch = 0;
       if (spu_bb_info[i].prop_jump)
 	{
diff --git a/gcc/cse.c b/gcc/cse.c
index d5357f0..215beb0 100644
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -6564,7 +6564,7 @@  cse_main (rtx f ATTRIBUTE_UNUSED, int nregs)
 	 processed before.  */
       do
 	{
-	  bb = BASIC_BLOCK (rc_order[i++]);
+	  bb = BASIC_BLOCK_FOR_FN (cfun, rc_order[i++]);
 	}
       while (bitmap_bit_p (cse_visited_basic_blocks, bb->index)
 	     && i < n_blocks);
diff --git a/gcc/dce.c b/gcc/dce.c
index 5c11cbe..07d31f7 100644
--- a/gcc/dce.c
+++ b/gcc/dce.c
@@ -1065,7 +1065,7 @@  fast_dce (bool word_level)
       for (i = 0; i < n_blocks; i++)
 	{
 	  int index = postorder[i];
-	  basic_block bb = BASIC_BLOCK (index);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, index);
 	  bool local_changed;
 
 	  if (index < NUM_FIXED_BLOCKS)
diff --git a/gcc/df-core.c b/gcc/df-core.c
index 4fb92a9..87419c2 100644
--- a/gcc/df-core.c
+++ b/gcc/df-core.c
@@ -520,7 +520,7 @@  df_set_blocks (bitmap blocks)
 
 		  EXECUTE_IF_SET_IN_BITMAP (&diff, 0, bb_index, bi)
 		    {
-		      basic_block bb = BASIC_BLOCK (bb_index);
+		      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
 		      if (bb)
 			{
 			  void *bb_info = df_get_bb_info (dflow, bb_index);
@@ -933,7 +933,7 @@  df_worklist_propagate_forward (struct dataflow *dataflow,
 {
   edge e;
   edge_iterator ei;
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   bool changed = !age;
 
   /*  Calculate <conf_op> of incoming edges.  */
@@ -978,7 +978,7 @@  df_worklist_propagate_backward (struct dataflow *dataflow,
 {
   edge e;
   edge_iterator ei;
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   bool changed = !age;
 
   /*  Calculate <conf_op> of incoming edges.  */
@@ -1067,7 +1067,7 @@  df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
 
 	  bitmap_clear_bit (pending, index);
 	  bb_index = blocks_in_postorder[index];
-	  bb = BASIC_BLOCK (bb_index);
+	  bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
 	  prev_age = last_visit_age[index];
 	  if (dir == DF_FORWARD)
 	    changed = df_worklist_propagate_forward (dataflow, bb_index,
@@ -1086,7 +1086,7 @@  df_worklist_dataflow_doublequeue (struct dataflow *dataflow,
       bitmap_clear (worklist);
     }
   for (i = 0; i < n_blocks; i++)
-    BASIC_BLOCK (blocks_in_postorder[i])->aux = NULL;
+    BASIC_BLOCK_FOR_FN (cfun, blocks_in_postorder[i])->aux = NULL;
 
   BITMAP_FREE (worklist);
   BITMAP_FREE (pending);
@@ -1631,7 +1631,7 @@  df_bb_replace (int old_index, basic_block new_block)
     fprintf (dump_file, "shoving block %d into %d\n", new_block_index, old_index);
 
   gcc_assert (df);
-  gcc_assert (BASIC_BLOCK (old_index) == NULL);
+  gcc_assert (BASIC_BLOCK_FOR_FN (cfun, old_index) == NULL);
 
   for (p = 0; p < df->num_problems_defined; p++)
     {
@@ -1647,7 +1647,7 @@  df_bb_replace (int old_index, basic_block new_block)
   df_clear_bb_dirty (new_block);
   SET_BASIC_BLOCK_FOR_FN (cfun, old_index, new_block);
   new_block->index = old_index;
-  df_set_bb_dirty (BASIC_BLOCK (old_index));
+  df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, old_index));
   SET_BASIC_BLOCK_FOR_FN (cfun, new_block_index, NULL);
 }
 
@@ -1659,7 +1659,7 @@  df_bb_replace (int old_index, basic_block new_block)
 void
 df_bb_delete (int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   int i;
 
   if (!df)
@@ -2045,7 +2045,7 @@  df_dump_region (FILE *file)
 
       EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
 	{
-	  basic_block bb = BASIC_BLOCK (bb_index);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
 	  dump_bb (file, bb, 0, TDF_DETAILS);
 	}
       fprintf (file, "\n");
diff --git a/gcc/df-problems.c b/gcc/df-problems.c
index c6349c8..2b42b48 100644
--- a/gcc/df-problems.c
+++ b/gcc/df-problems.c
@@ -353,7 +353,7 @@  df_rd_bb_local_compute_process_def (struct df_rd_bb_info *bb_info,
 static void
 df_rd_bb_local_compute (unsigned int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
   rtx insn;
 
@@ -835,7 +835,7 @@  df_lr_reset (bitmap all_blocks)
 static void
 df_lr_bb_local_compute (unsigned int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_lr_bb_info *bb_info = df_lr_get_bb_info (bb_index);
   rtx insn;
   df_ref *def_rec;
@@ -1462,7 +1462,7 @@  df_live_reset (bitmap all_blocks)
 static void
 df_live_bb_local_compute (unsigned int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_live_bb_info *bb_info = df_live_get_bb_info (bb_index);
   rtx insn;
   df_ref *def_rec;
@@ -1987,7 +1987,7 @@  df_chain_remove_problem (void)
       rtx insn;
       df_ref *def_rec;
       df_ref *use_rec;
-      basic_block bb = BASIC_BLOCK (bb_index);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
 
       if (df_chain_problem_p (DF_DU_CHAIN))
 	for (def_rec = df_get_artificial_defs (bb->index); *def_rec; def_rec++)
@@ -2105,7 +2105,7 @@  df_chain_create_bb_process_use (bitmap local_rd,
 static void
 df_chain_create_bb (unsigned int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_rd_bb_info *bb_info = df_rd_get_bb_info (bb_index);
   rtx insn;
   bitmap_head cpy;
@@ -2531,7 +2531,7 @@  df_word_lr_mark_ref (df_ref ref, bool is_set, regset live)
 static void
 df_word_lr_bb_local_compute (unsigned int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_word_lr_bb_info *bb_info = df_word_lr_get_bb_info (bb_index);
   rtx insn;
   df_ref *def_rec;
@@ -3154,7 +3154,7 @@  static void
 df_note_bb_compute (unsigned int bb_index,
 		    bitmap live, bitmap do_not_gen, bitmap artificial_uses)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   rtx insn;
   df_ref *def_rec;
   df_ref *use_rec;
@@ -4271,7 +4271,7 @@  df_md_bb_local_compute_process_def (struct df_md_bb_info *bb_info,
 static void
 df_md_bb_local_compute (unsigned int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
   rtx insn;
 
@@ -4327,7 +4327,7 @@  df_md_local_compute (bitmap all_blocks)
       bitmap kill = &df_md_get_bb_info (bb_index)->kill;
       EXECUTE_IF_SET_IN_BITMAP (&frontiers[bb_index], 0, df_bb_index, bi2)
 	{
-	  basic_block bb = BASIC_BLOCK (df_bb_index);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, df_bb_index);
 	  if (bitmap_bit_p (all_blocks, df_bb_index))
 	    bitmap_ior_and_into (&df_md_get_bb_info (df_bb_index)->init, kill,
 				 df_get_live_in (bb));
@@ -4360,7 +4360,7 @@  df_md_reset (bitmap all_blocks)
 static bool
 df_md_transfer_function (int bb_index)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   struct df_md_bb_info *bb_info = df_md_get_bb_info (bb_index);
   bitmap in = &bb_info->in;
   bitmap out = &bb_info->out;
diff --git a/gcc/df-scan.c b/gcc/df-scan.c
index eb7e4d4..5f0ba4a 100644
--- a/gcc/df-scan.c
+++ b/gcc/df-scan.c
@@ -669,8 +669,8 @@  df_scan_blocks (void)
   df_record_entry_block_defs (df->entry_block_defs);
   df_get_exit_block_use_set (df->exit_block_uses);
   df_record_exit_block_uses (df->exit_block_uses);
-  df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
-  df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
+  df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
+  df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
 
   /* Regular blocks */
   FOR_EACH_BB (bb)
@@ -1637,7 +1637,7 @@  df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
 
   EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
     {
-      basic_block bb = BASIC_BLOCK (bb_index);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
       rtx insn;
       df_ref *ref_rec;
 
@@ -1691,7 +1691,7 @@  df_reorganize_refs_by_reg_by_insn (struct df_ref_info *ref_info,
 
   EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
     {
-      basic_block bb = BASIC_BLOCK (bb_index);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
       rtx insn;
       df_ref *ref_rec;
 
@@ -1876,7 +1876,9 @@  df_reorganize_refs_by_insn (struct df_ref_info *ref_info,
 
       EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, index, bi)
 	{
-	  offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK (index), offset, ref_info,
+	  offset = df_reorganize_refs_by_insn_bb (BASIC_BLOCK_FOR_FN (cfun,
+								      index),
+						  offset, ref_info,
 						  include_defs, include_uses,
 						  include_eq_uses);
 	}
@@ -3616,7 +3618,7 @@  df_bb_refs_collect (struct df_collection_rec *collection_rec, basic_block bb)
 void
 df_bb_refs_record (int bb_index, bool scan_insns)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   rtx insn;
   int luid = 0;
 
@@ -3890,7 +3892,9 @@  df_record_entry_block_defs (bitmap entry_block_defs)
   df_entry_block_defs_collect (&collection_rec, entry_block_defs);
 
   /* Process bb_refs chain */
-  df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (ENTRY_BLOCK), NULL,
+  df_refs_add_to_chains (&collection_rec,
+			 BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK),
+			 NULL,
 			 copy_defs);
 }
 
@@ -3929,7 +3933,7 @@  df_update_entry_block_defs (void)
     {
       df_record_entry_block_defs (&refs);
       bitmap_copy (df->entry_block_defs, &refs);
-      df_set_bb_dirty (BASIC_BLOCK (ENTRY_BLOCK));
+      df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, ENTRY_BLOCK));
     }
   bitmap_clear (&refs);
 }
@@ -4061,7 +4065,9 @@  df_record_exit_block_uses (bitmap exit_block_uses)
   df_exit_block_uses_collect (&collection_rec, exit_block_uses);
 
   /* Process bb_refs chain */
-  df_refs_add_to_chains (&collection_rec, BASIC_BLOCK (EXIT_BLOCK), NULL,
+  df_refs_add_to_chains (&collection_rec,
+			 BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK),
+			 NULL,
 			 copy_uses);
 }
 
@@ -4100,7 +4106,7 @@  df_update_exit_block_uses (void)
     {
       df_record_exit_block_uses (&refs);
       bitmap_copy (df->exit_block_uses,& refs);
-      df_set_bb_dirty (BASIC_BLOCK (EXIT_BLOCK));
+      df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
     }
   bitmap_clear (&refs);
 }
diff --git a/gcc/dominance.c b/gcc/dominance.c
index 5ece3f6..e9d2265 100644
--- a/gcc/dominance.c
+++ b/gcc/dominance.c
@@ -884,10 +884,10 @@  nearest_common_dominator_for_set (enum cdi_direction dir, bitmap blocks)
   basic_block dom;
 
   first = bitmap_first_set_bit (blocks);
-  dom = BASIC_BLOCK (first);
+  dom = BASIC_BLOCK_FOR_FN (cfun, first);
   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
-    if (dom != BASIC_BLOCK (i))
-      dom = nearest_common_dominator (dir, dom, BASIC_BLOCK (i));
+    if (dom != BASIC_BLOCK_FOR_FN (cfun, i))
+      dom = nearest_common_dominator (dir, dom, BASIC_BLOCK_FOR_FN (cfun, i));
 
   return dom;
 }
diff --git a/gcc/gcse.c b/gcc/gcse.c
index 2c1ca21..8928c85 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -3337,7 +3337,7 @@  hoist_code (void)
 		  data->max_reg_pressure[pressure_class] += nregs;
 		  EXECUTE_IF_SET_IN_BITMAP (hoisted_bbs, 0, k, bi)
 		    {
-		      data = BB_DATA (BASIC_BLOCK (k));
+		      data = BB_DATA (BASIC_BLOCK_FOR_FN (cfun, k));
 		      data->max_reg_pressure[pressure_class] += nregs;
 		    }
 		}
@@ -3348,7 +3348,7 @@  hoist_code (void)
 		     hoisted.  */
 		  EXECUTE_IF_SET_IN_BITMAP (hoisted_bbs, 0, k, bi)
 		    {
-		      data = BB_DATA (BASIC_BLOCK (k));
+		      data = BB_DATA (BASIC_BLOCK_FOR_FN (cfun, k));
 		      bitmap_copy (data->live_in, data->backup);
 		      data->max_reg_pressure[pressure_class]
 			  = data->old_pressure;
diff --git a/gcc/graph.c b/gcc/graph.c
index b75135a..3f02cab 100644
--- a/gcc/graph.c
+++ b/gcc/graph.c
@@ -164,7 +164,7 @@  draw_cfg_nodes_no_loops (pretty_printer *pp, struct function *fun)
   for (i = n_basic_blocks_for_fn (fun) - n;
        i < n_basic_blocks_for_fn (fun); i++)
     {
-      basic_block bb = BASIC_BLOCK (rpo[i]);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
       draw_cfg_node (pp, fun->funcdef_no, bb);
       bitmap_set_bit (visited, bb->index);
     }
diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index ad6fe8f..e4ef9d4 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -2152,7 +2152,7 @@  param_change_prob (gimple stmt, int i)
 	max = 1;
 
       EXECUTE_IF_SET_IN_BITMAP (info.bb_set, 0, index, bi)
-	max = MIN (max, BASIC_BLOCK (index)->frequency);
+	max = MIN (max, BASIC_BLOCK_FOR_FN (cfun, index)->frequency);
 
       BITMAP_FREE (info.bb_set);
       if (max < bb->frequency)
@@ -2408,7 +2408,7 @@  estimate_function_body_sizes (struct cgraph_node *node, bool early)
   nblocks = pre_and_rev_post_order_compute (NULL, order, false);
   for (n = 0; n < nblocks; n++)
     {
-      bb = BASIC_BLOCK (order[n]);
+      bb = BASIC_BLOCK_FOR_FN (cfun, order[n]);
       freq = compute_call_stmt_bb_frequency (node->decl, bb);
 
       /* TODO: Obviously predicates can be propagated down across CFG.  */
diff --git a/gcc/ipa-split.c b/gcc/ipa-split.c
index d2e2d6f..eca86da 100644
--- a/gcc/ipa-split.c
+++ b/gcc/ipa-split.c
@@ -362,7 +362,8 @@  dominated_by_forbidden (basic_block bb)
 
   EXECUTE_IF_SET_IN_BITMAP (forbidden_dominators, 1, dom_bb, bi)
     {
-      if (dominated_by_p (CDI_DOMINATORS, bb, BASIC_BLOCK (dom_bb)))
+      if (dominated_by_p (CDI_DOMINATORS, bb,
+			  BASIC_BLOCK_FOR_FN (cfun, dom_bb)))
 	return true;
     }
 
diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c
index 557915f..9910b4e 100644
--- a/gcc/loop-unroll.c
+++ b/gcc/loop-unroll.c
@@ -2370,7 +2370,7 @@  apply_opt_in_copies (struct opt_info *opt_info,
 
   for (i = opt_info->first_new_block; i < (unsigned) last_basic_block; i++)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       orig_bb = get_bb_original (bb);
 
       /* bb->aux holds position in copy sequence initialized by
@@ -2446,7 +2446,7 @@  apply_opt_in_copies (struct opt_info *opt_info,
      get_bb_copy (get_bb_original (bb)) == bb.  */
   for (i = opt_info->first_new_block; i < (unsigned) last_basic_block; i++)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       orig_bb = get_bb_original (bb);
       if (get_bb_copy (orig_bb) != bb)
 	continue;
diff --git a/gcc/lower-subreg.c b/gcc/lower-subreg.c
index e67bc35..6c9d622 100644
--- a/gcc/lower-subreg.c
+++ b/gcc/lower-subreg.c
@@ -1647,7 +1647,7 @@  decompose_multiword_subregs (bool decompose_copies)
 	  rtx insn, end;
 	  edge fallthru;
 
-	  bb = BASIC_BLOCK (i);
+	  bb = BASIC_BLOCK_FOR_FN (cfun, i);
 	  insn = BB_HEAD (bb);
 	  end = BB_END (bb);
 
diff --git a/gcc/lra-lives.c b/gcc/lra-lives.c
index efc19f2..d2082fe 100644
--- a/gcc/lra-lives.c
+++ b/gcc/lra-lives.c
@@ -1001,7 +1001,7 @@  lra_create_live_ranges (bool all_p)
   lra_assert (n_blocks_inverted == n_basic_blocks_for_fn (cfun));
   for (i = n_blocks_inverted - 1; i >= 0; --i)
     {
-      bb = BASIC_BLOCK (post_order_rev_cfg[i]);
+      bb = BASIC_BLOCK_FOR_FN (cfun, post_order_rev_cfg[i]);
       if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun) || bb
 	  == ENTRY_BLOCK_PTR_FOR_FN (cfun))
 	continue;
diff --git a/gcc/predict.c b/gcc/predict.c
index e959a3b..1dec4dc 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -2596,7 +2596,7 @@  propagate_freq (basic_block head, bitmap tovisit)
       edge_iterator ei;
       int count = 0;
 
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
 
       FOR_EACH_EDGE (e, ei, bb->preds)
 	{
diff --git a/gcc/regrename.c b/gcc/regrename.c
index 5e86fa5..ac8b0f3 100644
--- a/gcc/regrename.c
+++ b/gcc/regrename.c
@@ -696,7 +696,7 @@  regrename_analyze (bitmap bb_mask)
 
   for (i = 0; i < n_bbs; i++)
     {
-      basic_block bb1 = BASIC_BLOCK (inverse_postorder[i]);
+      basic_block bb1 = BASIC_BLOCK_FOR_FN (cfun, inverse_postorder[i]);
       struct bb_rename_info *this_info;
       bool success;
       edge e;
diff --git a/gcc/regstat.c b/gcc/regstat.c
index 85678a7..48d27c3 100644
--- a/gcc/regstat.c
+++ b/gcc/regstat.c
@@ -120,7 +120,7 @@  regstat_bb_compute_ri (unsigned int bb_index,
 		       bitmap local_live, bitmap local_processed,
 		       int *local_live_last_luid)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   rtx insn;
   df_ref *def_rec;
   df_ref *use_rec;
@@ -440,7 +440,7 @@  regstat_get_setjmp_crosses (void)
 static void
 regstat_bb_compute_calls_crossed (unsigned int bb_index, bitmap live)
 {
-  basic_block bb = BASIC_BLOCK (bb_index);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
   rtx insn;
   df_ref *def_rec;
   df_ref *use_rec;
diff --git a/gcc/resource.c b/gcc/resource.c
index 4609c3a..3106a09 100644
--- a/gcc/resource.c
+++ b/gcc/resource.c
@@ -918,7 +918,8 @@  mark_target_live_regs (rtx insns, rtx target, struct resources *res)
 	 information, we can get it from there unless the insn at the
 	 start of the basic block has been deleted.  */
       if (tinfo && tinfo->block != -1
-	  && ! INSN_DELETED_P (BB_HEAD (BASIC_BLOCK (tinfo->block))))
+	  && ! INSN_DELETED_P (BB_HEAD (BASIC_BLOCK_FOR_FN (cfun,
+							    tinfo->block))))
 	b = tinfo->block;
     }
 
@@ -958,7 +959,7 @@  mark_target_live_regs (rtx insns, rtx target, struct resources *res)
      to use the LR problem.  Otherwise, we must assume everything is live.  */
   if (b != -1)
     {
-      regset regs_live = DF_LR_IN (BASIC_BLOCK (b));
+      regset regs_live = DF_LR_IN (BASIC_BLOCK_FOR_FN (cfun, b));
       rtx start_insn, stop_insn;
 
       /* Compute hard regs live at start of block.  */
@@ -967,7 +968,7 @@  mark_target_live_regs (rtx insns, rtx target, struct resources *res)
       /* Get starting and ending insn, handling the case where each might
 	 be a SEQUENCE.  */
       start_insn = (b == ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->index ?
-		    insns : BB_HEAD (BASIC_BLOCK (b)));
+		    insns : BB_HEAD (BASIC_BLOCK_FOR_FN (cfun, b)));
       stop_insn = target;
 
       if (NONJUMP_INSN_P (start_insn)
diff --git a/gcc/sched-ebb.c b/gcc/sched-ebb.c
index 955501a..73af0a7 100644
--- a/gcc/sched-ebb.c
+++ b/gcc/sched-ebb.c
@@ -737,7 +737,7 @@  ebb_fix_recovery_cfg (int bbi ATTRIBUTE_UNUSED, int jump_bbi,
   gcc_assert (last_bb->index != bbi);
 
   if (jump_bb_nexti == last_bb->index)
-    last_bb = BASIC_BLOCK (jump_bbi);
+    last_bb = BASIC_BLOCK_FOR_FN (cfun, jump_bbi);
 }
 
 #endif /* INSN_SCHEDULING */
diff --git a/gcc/sched-int.h b/gcc/sched-int.h
index 84b5cb5..22ece1d 100644
--- a/gcc/sched-int.h
+++ b/gcc/sched-int.h
@@ -1416,8 +1416,9 @@  extern int *containing_rgn;
 /* The mapping from ebb to block.  */
 extern int *ebb_head;
 #define BB_TO_BLOCK(ebb) (rgn_bb_table[ebb_head[ebb]])
-#define EBB_FIRST_BB(ebb) BASIC_BLOCK (BB_TO_BLOCK (ebb))
-#define EBB_LAST_BB(ebb) BASIC_BLOCK (rgn_bb_table[ebb_head[ebb + 1] - 1])
+#define EBB_FIRST_BB(ebb) BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (ebb))
+#define EBB_LAST_BB(ebb) \
+  BASIC_BLOCK_FOR_FN (cfun, rgn_bb_table[ebb_head[ebb + 1] - 1])
 #define INSN_BB(INSN) (BLOCK_TO_BB (BLOCK_NUM (INSN)))
 
 extern int current_nr_blocks;
diff --git a/gcc/sched-rgn.c b/gcc/sched-rgn.c
index 1663e2f..2d8b939 100644
--- a/gcc/sched-rgn.c
+++ b/gcc/sched-rgn.c
@@ -401,7 +401,8 @@  debug_region (int rgn)
 
   for (bb = 0; bb < rgn_table[rgn].rgn_nr_blocks; bb++)
     {
-      dump_bb (stderr, BASIC_BLOCK (rgn_bb_table[current_blocks + bb]),
+      dump_bb (stderr,
+	       BASIC_BLOCK_FOR_FN (cfun, rgn_bb_table[current_blocks + bb]),
 	       0, TDF_SLIM | TDF_BLOCKS);
       fprintf (stderr, "\n");
     }
@@ -440,7 +441,7 @@  dump_region_dot (FILE *f, int rgn)
       edge e;
       edge_iterator ei;
       int src_bb_num = rgn_bb_table[current_blocks + i];
-      basic_block bb = BASIC_BLOCK (src_bb_num);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, src_bb_num);
 
       FOR_EACH_EDGE (e, ei, bb->succs)
         if (bb_in_region_p (e->dest->index, rgn))
@@ -554,7 +555,7 @@  too_large (int block, int *num_bbs, int *num_insns)
 {
   (*num_bbs)++;
   (*num_insns) += (common_sched_info->estimate_number_of_insns
-                   (BASIC_BLOCK (block)));
+                   (BASIC_BLOCK_FOR_FN (cfun, block)));
 
   return ((*num_bbs > PARAM_VALUE (PARAM_MAX_SCHED_REGION_BLOCKS))
 	  || (*num_insns > PARAM_VALUE (PARAM_MAX_SCHED_REGION_INSNS)));
@@ -948,7 +949,8 @@  haifa_find_rgns (void)
 		  edge e;
 		  child = queue[++head];
 
-		  FOR_EACH_EDGE (e, ei, BASIC_BLOCK (child)->preds)
+		  FOR_EACH_EDGE (e, ei,
+				 BASIC_BLOCK_FOR_FN (cfun, child)->preds)
 		    {
 		      node = e->src->index;
 
@@ -1005,7 +1007,9 @@  haifa_find_rgns (void)
 			  CONTAINING_RGN (child) = nr_regions;
 			  queue[head] = queue[tail--];
 
-			  FOR_EACH_EDGE (e, ei, BASIC_BLOCK (child)->succs)
+			  FOR_EACH_EDGE (e, ei,
+					 BASIC_BLOCK_FOR_FN (cfun,
+							     child)->succs)
 			    if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
 			      --degree[e->dest->index];
 			}
@@ -1200,7 +1204,7 @@  extend_rgns (int *degree, int *idxp, sbitmap header, int *loop_hdr)
 	    {
 	      int hdr = -1;
 
-	      FOR_EACH_EDGE (e, ei, BASIC_BLOCK (bbn)->preds)
+	      FOR_EACH_EDGE (e, ei, BASIC_BLOCK_FOR_FN (cfun, bbn)->preds)
 		{
 		  int predn = e->src->index;
 
@@ -1304,7 +1308,7 @@  extend_rgns (int *degree, int *idxp, sbitmap header, int *loop_hdr)
 	      CONTAINING_RGN (bbn) = nr_regions;
 	      BLOCK_TO_BB (bbn) = 0;
 
-	      FOR_EACH_EDGE (e, ei, BASIC_BLOCK (bbn)->succs)
+	      FOR_EACH_EDGE (e, ei, BASIC_BLOCK_FOR_FN (cfun, bbn)->succs)
 		if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
 		  degree[e->dest->index]--;
 
@@ -1361,7 +1365,8 @@  extend_rgns (int *degree, int *idxp, sbitmap header, int *loop_hdr)
 
 		      idx++;
 
-		      FOR_EACH_EDGE (e, ei, BASIC_BLOCK (succn)->succs)
+		      FOR_EACH_EDGE (e, ei,
+				     BASIC_BLOCK_FOR_FN (cfun, succn)->succs)
 			if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
 			  degree[e->dest->index]--;
 		    }
@@ -1420,7 +1425,8 @@  compute_dom_prob_ps (int bb)
   /* Initialize dom[bb] to '111..1'.  */
   bitmap_ones (dom[bb]);
 
-  FOR_EACH_EDGE (in_edge, in_ei, BASIC_BLOCK (BB_TO_BLOCK (bb))->preds)
+  FOR_EACH_EDGE (in_edge, in_ei,
+		 BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (bb))->preds)
     {
       int pred_bb;
       edge out_edge;
@@ -1838,7 +1844,8 @@  update_live (rtx insn, int src)
   (bb_from == bb_to							\
    || IS_RGN_ENTRY (bb_from)						\
    || (bitmap_bit_p (ancestor_edges[bb_to],					\
-	 EDGE_TO_BIT (single_pred_edge (BASIC_BLOCK (BB_TO_BLOCK (bb_from)))))))
+	 EDGE_TO_BIT (single_pred_edge (BASIC_BLOCK_FOR_FN (cfun, \
+							    BB_TO_BLOCK (bb_from)))))))
 
 /* Turns on the fed_by_spec_load flag for insns fed by load_insn.  */
 
@@ -2655,7 +2662,7 @@  deps_join (struct deps_desc *succ_deps, struct deps_desc *pred_deps)
 static void
 propagate_deps (int bb, struct deps_desc *pred_deps)
 {
-  basic_block block = BASIC_BLOCK (BB_TO_BLOCK (bb));
+  basic_block block = BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (bb));
   edge_iterator ei;
   edge e;
 
@@ -2864,7 +2871,8 @@  sched_is_disabled_for_current_region_p (void)
   int bb;
 
   for (bb = 0; bb < current_nr_blocks; bb++)
-    if (!(BASIC_BLOCK (BB_TO_BLOCK (bb))->flags & BB_DISABLE_SCHEDULE))
+    if (!(BASIC_BLOCK_FOR_FN (cfun,
+			      BB_TO_BLOCK (bb))->flags & BB_DISABLE_SCHEDULE))
       return false;
 
   return true;
diff --git a/gcc/sched-vis.c b/gcc/sched-vis.c
index a965c4d..57b28a0 100644
--- a/gcc/sched-vis.c
+++ b/gcc/sched-vis.c
@@ -873,7 +873,7 @@  extern void debug_bb_n_slim (int);
 DEBUG_FUNCTION void
 debug_bb_n_slim (int n)
 {
-  basic_block bb = BASIC_BLOCK (n);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, n);
   debug_bb_slim (bb);
 }
 
diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 7dfc703..da84cce 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -3075,7 +3075,7 @@  sel_finish_global_and_expr (void)
     bbs.create (current_nr_blocks);
 
     for (i = 0; i < current_nr_blocks; i++)
-      bbs.quick_push (BASIC_BLOCK (BB_TO_BLOCK (i)));
+      bbs.quick_push (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i)));
 
     /* Clear AV_SETs and INSN_EXPRs.  */
     {
@@ -3627,7 +3627,7 @@  verify_backedges (void)
       edge_iterator ei;
 
       for (i = 0; i < current_nr_blocks; i++)
-        FOR_EACH_EDGE (e, ei, BASIC_BLOCK (BB_TO_BLOCK (i))->succs)
+        FOR_EACH_EDGE (e, ei, BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i))->succs)
           if (in_current_region_p (e->dest)
               && BLOCK_TO_BB (e->dest->index) < i)
             n++;
@@ -3897,7 +3897,7 @@  purge_empty_blocks (void)
   /* Do not attempt to delete the first basic block in the region.  */
   for (i = 1; i < current_nr_blocks; )
     {
-      basic_block b = BASIC_BLOCK (BB_TO_BLOCK (i));
+      basic_block b = BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i));
 
       if (maybe_tidy_empty_bb (b))
 	continue;
@@ -6346,7 +6346,7 @@  sel_remove_loop_preheader (void)
   /* Add blocks that aren't within the current loop to PREHEADER_BLOCKS.  */
   for (i = 0; i < RGN_NR_BLOCKS (cur_rgn); i++)
     {
-      bb = BASIC_BLOCK (BB_TO_BLOCK (i));
+      bb = BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i));
 
       /* If the basic block belongs to region, but doesn't belong to
 	 corresponding loop, then it should be a preheader.  */
diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c
index 1195f7e..3e1fd96 100644
--- a/gcc/sel-sched.c
+++ b/gcc/sel-sched.c
@@ -4903,7 +4903,8 @@  remove_insns_that_need_bookkeeping (fence_t fence, av_set_t *av_ptr)
 	  && (EXPR_SPEC (expr)
 	      || !EXPR_ORIG_BB_INDEX (expr)
 	      || !dominated_by_p (CDI_DOMINATORS,
-				  BASIC_BLOCK (EXPR_ORIG_BB_INDEX (expr)),
+				  BASIC_BLOCK_FOR_FN (cfun,
+						      EXPR_ORIG_BB_INDEX (expr)),
 				  BLOCK_FOR_INSN (FENCE_INSN (fence)))))
 	{
           if (sched_verbose >= 4)
@@ -6886,7 +6887,7 @@  current_region_empty_p (void)
 {
   int i;
   for (i = 0; i < current_nr_blocks; i++)
-    if (! sel_bb_empty_p (BASIC_BLOCK (BB_TO_BLOCK (i))))
+    if (! sel_bb_empty_p (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i))))
       return false;
 
   return true;
@@ -6945,7 +6946,7 @@  sel_region_init (int rgn)
   bbs.create (current_nr_blocks);
 
   for (i = 0; i < current_nr_blocks; i++)
-    bbs.quick_push (BASIC_BLOCK (BB_TO_BLOCK (i)));
+    bbs.quick_push (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i)));
 
   sel_init_bbs (bbs);
 
@@ -6980,13 +6981,14 @@  sel_region_init (int rgn)
      compute_live for the first insn of the loop.  */
   if (current_loop_nest)
     {
-      int header = (sel_is_loop_preheader_p (BASIC_BLOCK (BB_TO_BLOCK (0)))
-                    ? 1
-                    : 0);
+      int header =
+	(sel_is_loop_preheader_p (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (0)))
+	 ? 1
+	 : 0);
 
       if (current_nr_blocks == header + 1)
         update_liveness_on_insn
-          (sel_bb_head (BASIC_BLOCK (BB_TO_BLOCK (header))));
+          (sel_bb_head (BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (header))));
     }
 
   /* Set hooks so that no newly generated insn will go out unnoticed.  */
@@ -7024,7 +7026,7 @@  simplify_changed_insns (void)
 
   for (i = 0; i < current_nr_blocks; i++)
     {
-      basic_block bb = BASIC_BLOCK (BB_TO_BLOCK (i));
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, BB_TO_BLOCK (i));
       rtx insn;
 
       FOR_BB_INSNS (bb, insn)
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index b2adc3d..39715b8 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -2993,7 +2993,7 @@  execute_tm_mark (void)
 		  && sub & GTMA_MAY_ENTER_IRREVOCABLE)
 		continue;
 	    }
-	  expand_block_tm (r, BASIC_BLOCK (i));
+	  expand_block_tm (r, BASIC_BLOCK_FOR_FN (cfun, i));
 	}
     }
 
@@ -3184,7 +3184,7 @@  execute_tm_edges (void)
 
   FOR_EACH_VEC_ELT (bb_regions, i, r)
     if (r != NULL)
-      expand_block_edges (r, BASIC_BLOCK (i));
+      expand_block_edges (r, BASIC_BLOCK_FOR_FN (cfun, i));
 
   bb_regions.release ();
 
@@ -3700,7 +3700,7 @@  tm_memopt_compute_antic (struct tm_region *region,
       unsigned int i;
       bitmap_iterator bi;
       EXECUTE_IF_SET_IN_BITMAP (region->exit_blocks, 0, i, bi)
-	BB_VISITED_P (BASIC_BLOCK (i)) = true;
+	BB_VISITED_P (BASIC_BLOCK_FOR_FN (cfun, i)) = true;
     }
 
   qin = worklist;
@@ -4572,7 +4572,8 @@  ipa_tm_scan_irr_function (struct cgraph_node *node, bool for_clone)
       unsigned i;
 
       EXECUTE_IF_SET_IN_BITMAP (new_irr, 0, i, bmi)
-	ipa_tm_decrement_clone_counts (BASIC_BLOCK (i), for_clone);
+	ipa_tm_decrement_clone_counts (BASIC_BLOCK_FOR_FN (cfun, i),
+				       for_clone);
 
       if (old_irr)
 	{
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 2d7916b..a706730 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -672,7 +672,8 @@  make_edges (void)
 
   /* Create an edge from entry to the first block with executable
      statements in it.  */
-  make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), BASIC_BLOCK (NUM_FIXED_BLOCKS),
+  make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun),
+	     BASIC_BLOCK_FOR_FN (cfun, NUM_FIXED_BLOCKS),
 	     EDGE_FALLTHRU);
 
   /* Traverse the basic block array placing edges.  */
@@ -943,7 +944,7 @@  end_recording_case_labels (void)
   edge_to_cases = NULL;
   EXECUTE_IF_SET_IN_BITMAP (touched_switch_bbs, 0, i, bi)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
       if (bb)
 	{
 	  gimple stmt = last_stmt (bb);
@@ -1027,7 +1028,8 @@  label_to_block_fn (struct function *ifun, tree dest)
      and undefined variable warnings quite right.  */
   if (seen_error () && uid < 0)
     {
-      gimple_stmt_iterator gsi = gsi_start_bb (BASIC_BLOCK (NUM_FIXED_BLOCKS));
+      gimple_stmt_iterator gsi =
+	gsi_start_bb (BASIC_BLOCK_FOR_FN (cfun, NUM_FIXED_BLOCKS));
       gimple stmt;
 
       stmt = gimple_build_label (dest);
@@ -2082,8 +2084,8 @@  gimple_debug_bb (basic_block bb)
 basic_block
 gimple_debug_bb_n (int n)
 {
-  gimple_debug_bb (BASIC_BLOCK (n));
-  return BASIC_BLOCK (n);
+  gimple_debug_bb (BASIC_BLOCK_FOR_FN (cfun, n));
+  return BASIC_BLOCK_FOR_FN (cfun, n);
 }
 
 
@@ -7476,7 +7478,7 @@  gimple_flow_call_edges_add (sbitmap blocks)
      return or not...  */
   for (i = 0; i < last_bb; i++)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
       gimple_stmt_iterator gsi;
       gimple stmt, last_stmt;
 
@@ -7605,7 +7607,7 @@  remove_edge_and_dominated_blocks (edge e)
 
       EXECUTE_IF_SET_IN_BITMAP (df, 0, i, bi)
 	{
-	  bb = BASIC_BLOCK (i);
+	  bb = BASIC_BLOCK_FOR_FN (cfun, i);
 	  bitmap_set_bit (df_idom,
 			  get_immediate_dominator (CDI_DOMINATORS, bb)->index);
 	}
@@ -7643,7 +7645,7 @@  remove_edge_and_dominated_blocks (edge e)
      the dominance frontier of E.  Therefore, Y belongs to DF_IDOM.  */
   EXECUTE_IF_SET_IN_BITMAP (df_idom, 0, i, bi)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       for (dbb = first_dom_son (CDI_DOMINATORS, bb);
 	   dbb;
 	   dbb = next_dom_son (CDI_DOMINATORS, dbb))
@@ -7696,7 +7698,7 @@  gimple_purge_all_dead_eh_edges (const_bitmap blocks)
 
   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
 
       /* Earlier gimple_purge_dead_eh_edges could have removed
 	 this basic block already.  */
@@ -7753,7 +7755,7 @@  gimple_purge_all_dead_abnormal_call_edges (const_bitmap blocks)
 
   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
 
       /* Earlier gimple_purge_dead_abnormal_call_edges could have removed
 	 this basic block already.  */
diff --git a/gcc/tree-cfgcleanup.c b/gcc/tree-cfgcleanup.c
index ab8a394..76d9749 100644
--- a/gcc/tree-cfgcleanup.c
+++ b/gcc/tree-cfgcleanup.c
@@ -551,7 +551,7 @@  fixup_noreturn_call (gimple stmt)
 		  SET_USE (use_p, error_mark_node);
 	    }
 	  EXECUTE_IF_SET_IN_BITMAP (blocks, 0, bb_index, bi)
-	    delete_basic_block (BASIC_BLOCK (bb_index));
+	    delete_basic_block (BASIC_BLOCK_FOR_FN (cfun, bb_index));
 	  BITMAP_FREE (blocks);
 	  release_ssa_name (op);
 	}
@@ -586,7 +586,7 @@  split_bbs_on_noreturn_calls (void)
 	if (bb == NULL
 	    || bb->index < NUM_FIXED_BLOCKS
 	    || bb->index >= last_basic_block
-	    || BASIC_BLOCK (bb->index) != bb
+	    || BASIC_BLOCK_FOR_FN (cfun, bb->index) != bb
 	    || !gimple_call_noreturn_p (stmt))
 	  continue;
 
@@ -645,7 +645,7 @@  cleanup_tree_cfg_1 (void)
   n = last_basic_block;
   for (i = NUM_FIXED_BLOCKS; i < n; i++)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       if (bb)
 	retval |= cleanup_tree_cfg_bb (bb);
     }
@@ -658,7 +658,7 @@  cleanup_tree_cfg_1 (void)
       if (i < NUM_FIXED_BLOCKS)
 	continue;
 
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       if (!bb)
 	continue;
 
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index abc216d..1d1bc1e 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -2547,12 +2547,13 @@  copy_cfg_body (copy_body_data * id, gcov_type count, int frequency_scale,
   for (; last < last_basic_block; last++)
     {
       if (need_debug_cleanup)
-	maybe_move_debug_stmts_to_successors (id, BASIC_BLOCK (last));
-      BASIC_BLOCK (last)->aux = NULL;
+	maybe_move_debug_stmts_to_successors (id,
+					      BASIC_BLOCK_FOR_FN (cfun, last));
+      BASIC_BLOCK_FOR_FN (cfun, last)->aux = NULL;
       /* Update call edge destinations.  This can not be done before loop
 	 info is updated, because we may split basic blocks.  */
       if (id->transform_call_graph_edges == CB_CGE_DUPLICATE)
-	redirect_all_calls (id, BASIC_BLOCK (last));
+	redirect_all_calls (id, BASIC_BLOCK_FOR_FN (cfun, last));
     }
   entry_block_map->aux = NULL;
   exit_block_map->aux = NULL;
@@ -4443,11 +4444,11 @@  static void
 fold_marked_statements (int first, struct pointer_set_t *statements)
 {
   for (; first < n_basic_blocks_for_fn (cfun); first++)
-    if (BASIC_BLOCK (first))
+    if (BASIC_BLOCK_FOR_FN (cfun, first))
       {
         gimple_stmt_iterator gsi;
 
-	for (gsi = gsi_start_bb (BASIC_BLOCK (first));
+	for (gsi = gsi_start_bb (BASIC_BLOCK_FOR_FN (cfun, first));
 	     !gsi_end_p (gsi);
 	     gsi_next (&gsi))
 	  if (pointer_set_contains (statements, gsi_stmt (gsi)))
@@ -4473,7 +4474,7 @@  fold_marked_statements (int first, struct pointer_set_t *statements)
 			  break;
 			}
 		      if (gsi_end_p (i2))
-			i2 = gsi_start_bb (BASIC_BLOCK (first));
+			i2 = gsi_start_bb (BASIC_BLOCK_FOR_FN (cfun, first));
 		      else
 			gsi_next (&i2);
 		      while (1)
@@ -4497,7 +4498,8 @@  fold_marked_statements (int first, struct pointer_set_t *statements)
 				 is mood anyway.  */
 			      if (maybe_clean_or_replace_eh_stmt (old_stmt,
 								  new_stmt))
-				gimple_purge_dead_eh_edges (BASIC_BLOCK (first));
+				gimple_purge_dead_eh_edges (
+				  BASIC_BLOCK_FOR_FN (cfun, first));
 			      break;
 			    }
 			  gsi_next (&i2);
@@ -4517,7 +4519,8 @@  fold_marked_statements (int first, struct pointer_set_t *statements)
 						       new_stmt);
 
 		  if (maybe_clean_or_replace_eh_stmt (old_stmt, new_stmt))
-		    gimple_purge_dead_eh_edges (BASIC_BLOCK (first));
+		    gimple_purge_dead_eh_edges (BASIC_BLOCK_FOR_FN (cfun,
+								    first));
 		}
 	    }
       }
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index 0067cfe..ac10440 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -558,7 +558,7 @@  set_livein_block (tree var, basic_block bb)
 
       if (def_block_index == -1
 	  || ! dominated_by_p (CDI_DOMINATORS, bb,
-	                       BASIC_BLOCK (def_block_index)))
+	                       BASIC_BLOCK_FOR_FN (cfun, def_block_index)))
 	info->need_phi_state = NEED_PHI_STATE_MAYBE;
     }
   else
@@ -821,7 +821,7 @@  prune_unused_phi_nodes (bitmap phis, bitmap kills, bitmap uses)
   adef = 1;
   EXECUTE_IF_SET_IN_BITMAP (to_remove, 0, i, bi)
     {
-      def_bb = BASIC_BLOCK (i);
+      def_bb = BASIC_BLOCK_FOR_FN (cfun, i);
       defs[adef].bb_index = i;
       defs[adef].dfs_num = bb_dom_dfs_in (CDI_DOMINATORS, def_bb);
       defs[adef + 1].bb_index = i;
@@ -895,7 +895,8 @@  prune_unused_phi_nodes (bitmap phis, bitmap kills, bitmap uses)
 	p = b;
       else
 	{
-	  use_bb = get_immediate_dominator (CDI_DOMINATORS, BASIC_BLOCK (b));
+	  use_bb = get_immediate_dominator (CDI_DOMINATORS,
+					    BASIC_BLOCK_FOR_FN (cfun, b));
 	  p = find_dfsnum_interval (defs, n_defs,
 				    bb_dom_dfs_in (CDI_DOMINATORS, use_bb));
 	  if (!bitmap_bit_p (phis, p))
@@ -907,7 +908,7 @@  prune_unused_phi_nodes (bitmap phis, bitmap kills, bitmap uses)
 	continue;
 
       /* Add the new uses to the worklist.  */
-      def_bb = BASIC_BLOCK (p);
+      def_bb = BASIC_BLOCK_FOR_FN (cfun, p);
       FOR_EACH_EDGE (e, ei, def_bb->preds)
 	{
 	  u = e->src->index;
@@ -1004,7 +1005,7 @@  insert_phi_nodes_for (tree var, bitmap phi_insertion_points, bool update_p)
   /* And insert the PHI nodes.  */
   EXECUTE_IF_SET_IN_BITMAP (phi_insertion_points, 0, bb_index, bi)
     {
-      bb = BASIC_BLOCK (bb_index);
+      bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
       if (update_p)
 	mark_block_for_update (bb);
 
@@ -3021,8 +3022,9 @@  insert_updated_phi_nodes_for (tree var, bitmap_head *dfs, bitmap blocks,
 						    db->def_blocks);
 	  if (entry != ENTRY_BLOCK_PTR_FOR_FN (cfun))
 	    EXECUTE_IF_SET_IN_BITMAP (idf, 0, i, bi)
-	      if (BASIC_BLOCK (i) != entry
-		  && dominated_by_p (CDI_DOMINATORS, BASIC_BLOCK (i), entry))
+	      if (BASIC_BLOCK_FOR_FN (cfun, i) != entry
+		  && dominated_by_p (CDI_DOMINATORS,
+				     BASIC_BLOCK_FOR_FN (cfun, i), entry))
 		bitmap_set_bit (pruned_idf, i);
 	}
       else
@@ -3054,7 +3056,7 @@  insert_updated_phi_nodes_for (tree var, bitmap_head *dfs, bitmap blocks,
 	{
 	  edge e;
 	  edge_iterator ei;
-	  basic_block bb = BASIC_BLOCK (i);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
 
 	  FOR_EACH_EDGE (e, ei, bb->preds)
 	    if (e->src->index >= 0)
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 82005af..ebdf511 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -902,7 +902,7 @@  tree_ssa_dominator_optimize (void)
 	 iterator.  */
       EXECUTE_IF_SET_IN_BITMAP (need_eh_cleanup, 0, i, bi)
 	{
-	  basic_block bb = BASIC_BLOCK (i);
+	  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
 	  if (bb == NULL)
 	    continue;
 	  while (single_succ_p (bb)
diff --git a/gcc/tree-ssa-live.c b/gcc/tree-ssa-live.c
index 8ad5d9a..5d1a3b9 100644
--- a/gcc/tree-ssa-live.c
+++ b/gcc/tree-ssa-live.c
@@ -1057,7 +1057,7 @@  live_worklist (tree_live_info_p live)
   while (live->stack_top != live->work_stack)
     {
       b = *--(live->stack_top);
-      loe_visit_block (live, BASIC_BLOCK (b), visited, tmp);
+      loe_visit_block (live, BASIC_BLOCK_FOR_FN (cfun, b), visited, tmp);
     }
 
   BITMAP_FREE (tmp);
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index e1d55ff..de667ad 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -202,7 +202,7 @@  compute_live_loop_exits (bitmap live_exits, bitmap use_blocks,
 
   EXECUTE_IF_SET_IN_BITMAP (use_blocks, 0, i, bi)
     {
-      basic_block use_bb = BASIC_BLOCK (i);
+      basic_block use_bb = BASIC_BLOCK_FOR_FN (cfun, i);
       struct loop *use_loop = use_bb->loop_father;
       gcc_checking_assert (def_loop != use_loop
 			   && ! flow_loop_nested_p (def_loop, use_loop));
@@ -325,7 +325,7 @@  add_exit_phis_var (tree var, bitmap use_blocks, bitmap *loop_exits)
 
   EXECUTE_IF_SET_IN_BITMAP (live_exits, 0, index, bi)
     {
-      add_exit_phi (BASIC_BLOCK (index), var);
+      add_exit_phi (BASIC_BLOCK_FOR_FN (cfun, index), var);
     }
 
   BITMAP_FREE (live_exits);
@@ -461,7 +461,7 @@  find_uses_to_rename (bitmap changed_bbs, bitmap *use_blocks, bitmap need_phis)
 
   if (changed_bbs)
     EXECUTE_IF_SET_IN_BITMAP (changed_bbs, 0, index, bi)
-      find_uses_to_rename_bb (BASIC_BLOCK (index), use_blocks, need_phis);
+      find_uses_to_rename_bb (BASIC_BLOCK_FOR_FN (cfun, index), use_blocks, need_phis);
   else
     FOR_EACH_BB (bb)
       find_uses_to_rename_bb (bb, use_blocks, need_phis);
@@ -729,13 +729,13 @@  copy_phi_node_args (unsigned first_new_block)
   unsigned i;
 
   for (i = first_new_block; i < (unsigned) last_basic_block; i++)
-    BASIC_BLOCK (i)->flags |= BB_DUPLICATED;
+    BASIC_BLOCK_FOR_FN (cfun, i)->flags |= BB_DUPLICATED;
 
   for (i = first_new_block; i < (unsigned) last_basic_block; i++)
-    add_phi_args_after_copy_bb (BASIC_BLOCK (i));
+    add_phi_args_after_copy_bb (BASIC_BLOCK_FOR_FN (cfun, i));
 
   for (i = first_new_block; i < (unsigned) last_basic_block; i++)
-    BASIC_BLOCK (i)->flags &= ~BB_DUPLICATED;
+    BASIC_BLOCK_FOR_FN (cfun, i)->flags &= ~BB_DUPLICATED;
 }
 
 
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index f9ac337..dcce38a 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -2487,7 +2487,7 @@  compute_antic (void)
 	{
 	  if (bitmap_bit_p (changed_blocks, postorder[i]))
 	    {
-	      basic_block block = BASIC_BLOCK (postorder[i]);
+	      basic_block block = BASIC_BLOCK_FOR_FN (cfun, postorder[i]);
 	      changed |= compute_antic_aux (block,
 					    bitmap_bit_p (has_abnormal_preds,
 						      block->index));
@@ -2516,7 +2516,7 @@  compute_antic (void)
 	    {
 	      if (bitmap_bit_p (changed_blocks, postorder[i]))
 		{
-		  basic_block block = BASIC_BLOCK (postorder[i]);
+		  basic_block block = BASIC_BLOCK_FOR_FN (cfun, postorder[i]);
 		  changed
 		    |= compute_partial_antic_aux (block,
 						  bitmap_bit_p (has_abnormal_preds,
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 7145559..9108983 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -2028,7 +2028,8 @@  update_range_test (struct range_entry *range, struct range_entry *otherrange,
 {
   operand_entry_t oe = (*ops)[range->idx];
   tree op = oe->op;
-  gimple stmt = op ? SSA_NAME_DEF_STMT (op) : last_stmt (BASIC_BLOCK (oe->id));
+  gimple stmt = op ? SSA_NAME_DEF_STMT (op) :
+    last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
   location_t loc = gimple_location (stmt);
   tree optype = op ? TREE_TYPE (op) : boolean_type_node;
   tree tem = build_range_check (loc, optype, exp, in_p, low, high);
@@ -2281,7 +2282,8 @@  optimize_range_tests (enum tree_code opcode,
       oe = (*ops)[i];
       ranges[i].idx = i;
       init_range_entry (ranges + i, oe->op,
-			oe->op ? NULL : last_stmt (BASIC_BLOCK (oe->id)));
+			oe->op ? NULL :
+			  last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)));
       /* For | invert it now, we will invert it again before emitting
 	 the optimized expression.  */
       if (opcode == BIT_IOR_EXPR
diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c
index 947a58a..ecc1f6b 100644
--- a/gcc/tree-ssa-sink.c
+++ b/gcc/tree-ssa-sink.c
@@ -182,10 +182,10 @@  nearest_common_dominator_of_uses (gimple stmt, bool *debug_stmts)
 	  bitmap_set_bit (blocks, useblock->index);
 	}
     }
-  commondom = BASIC_BLOCK (bitmap_first_set_bit (blocks));
+  commondom = BASIC_BLOCK_FOR_FN (cfun, bitmap_first_set_bit (blocks));
   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, j, bi)
     commondom = nearest_common_dominator (CDI_DOMINATORS, commondom,
-					  BASIC_BLOCK (j));
+					  BASIC_BLOCK_FOR_FN (cfun, j));
   BITMAP_FREE (blocks);
   return commondom;
 }
diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c
index d722a9b..fbcbf78 100644
--- a/gcc/tree-ssa-tail-merge.c
+++ b/gcc/tree-ssa-tail-merge.c
@@ -454,7 +454,7 @@  same_succ_hash (const_same_succ e)
   int flags;
   unsigned int i;
   unsigned int first = bitmap_first_set_bit (e->bbs);
-  basic_block bb = BASIC_BLOCK (first);
+  basic_block bb = BASIC_BLOCK_FOR_FN (cfun, first);
   int size = 0;
   gimple_stmt_iterator gsi;
   gimple stmt;
@@ -502,8 +502,8 @@  same_succ_hash (const_same_succ e)
 
   EXECUTE_IF_SET_IN_BITMAP (e->succs, 0, s, bs)
     {
-      int n = find_edge (bb, BASIC_BLOCK (s))->dest_idx;
-      for (gsi = gsi_start_phis (BASIC_BLOCK (s)); !gsi_end_p (gsi);
+      int n = find_edge (bb, BASIC_BLOCK_FOR_FN (cfun, s))->dest_idx;
+      for (gsi = gsi_start_phis (BASIC_BLOCK_FOR_FN (cfun, s)); !gsi_end_p (gsi);
 	   gsi_next (&gsi))
 	{
 	  gimple phi = gsi_stmt (gsi);
@@ -572,8 +572,8 @@  same_succ_def::equal (const value_type *e1, const compare_type *e2)
   first1 = bitmap_first_set_bit (e1->bbs);
   first2 = bitmap_first_set_bit (e2->bbs);
 
-  bb1 = BASIC_BLOCK (first1);
-  bb2 = BASIC_BLOCK (first2);
+  bb1 = BASIC_BLOCK_FOR_FN (cfun, first1);
+  bb2 = BASIC_BLOCK_FOR_FN (cfun, first2);
 
   if (BB_SIZE (bb1) != BB_SIZE (bb2))
     return 0;
@@ -834,7 +834,7 @@  same_succ_flush_bbs (bitmap bbs)
   bitmap_iterator bi;
 
   EXECUTE_IF_SET_IN_BITMAP (bbs, 0, i, bi)
-    same_succ_flush_bb (BASIC_BLOCK (i));
+    same_succ_flush_bb (BASIC_BLOCK_FOR_FN (cfun, i));
 }
 
 /* Release the last vdef in BB, either normal or phi result.  */
@@ -887,7 +887,7 @@  update_worklist (void)
   same = same_succ_alloc ();
   EXECUTE_IF_SET_IN_BITMAP (deleted_bb_preds, 0, i, bi)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       gcc_assert (bb != NULL);
       find_same_succ_bb (bb, &same);
       if (same == NULL)
@@ -1075,7 +1075,7 @@  set_cluster (basic_block bb1, basic_block bb2)
       merge = BB_CLUSTER (bb1);
       merge_clusters (merge, old);
       EXECUTE_IF_SET_IN_BITMAP (old->bbs, 0, i, bi)
-	BB_CLUSTER (BASIC_BLOCK (i)) = merge;
+	BB_CLUSTER (BASIC_BLOCK_FOR_FN (cfun, i)) = merge;
       all_clusters[old->index] = NULL;
       update_rep_bb (merge, old->rep_bb);
       delete_cluster (old);
@@ -1320,7 +1320,7 @@  same_phi_alternatives (same_succ same_succ, basic_block bb1, basic_block bb2)
 
   EXECUTE_IF_SET_IN_BITMAP (same_succ->succs, 0, s, bs)
     {
-      succ = BASIC_BLOCK (s);
+      succ = BASIC_BLOCK_FOR_FN (cfun, s);
       e1 = find_edge (bb1, succ);
       e2 = find_edge (bb2, succ);
       if (e1->flags & EDGE_COMPLEX
@@ -1406,7 +1406,7 @@  find_clusters_1 (same_succ same_succ)
 
   EXECUTE_IF_SET_IN_BITMAP (same_succ->bbs, 0, i, bi)
     {
-      bb1 = BASIC_BLOCK (i);
+      bb1 = BASIC_BLOCK_FOR_FN (cfun, i);
 
       /* TODO: handle blocks with phi-nodes.  We'll have to find corresponding
 	 phi-nodes in bb1 and bb2, with the same alternatives for the same
@@ -1417,7 +1417,7 @@  find_clusters_1 (same_succ same_succ)
       nr_comparisons = 0;
       EXECUTE_IF_SET_IN_BITMAP (same_succ->bbs, i + 1, j, bj)
 	{
-	  bb2 = BASIC_BLOCK (j);
+	  bb2 = BASIC_BLOCK_FOR_FN (cfun, j);
 
 	  if (bb_has_non_vop_phi (bb2))
 	    continue;
@@ -1573,7 +1573,7 @@  apply_clusters (void)
       bitmap_clear_bit (c->bbs, bb2->index);
       EXECUTE_IF_SET_IN_BITMAP (c->bbs, 0, j, bj)
 	{
-	  bb1 = BASIC_BLOCK (j);
+	  bb1 = BASIC_BLOCK_FOR_FN (cfun, j);
 	  bitmap_clear_bit (update_bbs, bb1->index);
 
 	  replace_block_by (bb1, bb2);
@@ -1633,7 +1633,7 @@  update_debug_stmts (void)
       gimple stmt;
       gimple_stmt_iterator gsi;
 
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
 	{
 	  stmt = gsi_stmt (gsi);
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index ad727a1..9289c11 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -1412,7 +1412,7 @@  mark_threaded_blocks (bitmap threaded_blocks)
     {
       EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
 	{
-	  bb = BASIC_BLOCK (i);
+	  bb = BASIC_BLOCK_FOR_FN (cfun, i);
 	  if (EDGE_COUNT (bb->preds) > 1
 	      && !redirection_block_p (bb))
 	    {
@@ -1442,7 +1442,7 @@  mark_threaded_blocks (bitmap threaded_blocks)
      by trimming off the end of the jump thread path.  */
   EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
       FOR_EACH_EDGE (e, ei, bb->preds)
 	{
 	  if (e->aux)
@@ -1512,7 +1512,7 @@  mark_threaded_blocks (bitmap threaded_blocks)
      we have to iterate on those rather than the threaded_edges vector.  */
   EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
     {
-      bb = BASIC_BLOCK (i);
+      bb = BASIC_BLOCK_FOR_FN (cfun, i);
       FOR_EACH_EDGE (e, ei, bb->preds)
 	{
 	  if (e->aux)
@@ -1592,7 +1592,7 @@  thread_through_all_blocks (bool may_peel_loop_headers)
      loop structure.  */
   EXECUTE_IF_SET_IN_BITMAP (threaded_blocks, 0, i, bi)
     {
-      basic_block bb = BASIC_BLOCK (i);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
 
       if (EDGE_COUNT (bb->preds) > 0)
 	retval |= thread_block (bb, true);
diff --git a/gcc/tree-ssa-uncprop.c b/gcc/tree-ssa-uncprop.c
index 44194b8..92652de 100644
--- a/gcc/tree-ssa-uncprop.c
+++ b/gcc/tree-ssa-uncprop.c
@@ -214,7 +214,8 @@  associate_equivalences_with_edges (void)
 		      equivalency = XNEW (struct edge_equivalency);
 		      equivalency->rhs = x;
 		      equivalency->lhs = cond;
-		      find_edge (bb, BASIC_BLOCK (i))->aux = equivalency;
+		      find_edge (bb, BASIC_BLOCK_FOR_FN (cfun, i))->aux =
+			equivalency;
 		    }
 		}
 	      free (info);
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index d9da996..785e72f 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -5975,7 +5975,7 @@  find_assert_locations (void)
   need_asserts = false;
   for (i = rpo_cnt - 1; i >= 0; --i)
     {
-      basic_block bb = BASIC_BLOCK (rpo[i]);
+      basic_block bb = BASIC_BLOCK_FOR_FN (cfun, rpo[i]);
       edge e;
       edge_iterator ei;