diff --git a/gcc/resource.cc b/gcc/resource.cc
index 06fcfd3e44c7..0d8cde93570e 100644
--- a/gcc/resource.cc
+++ b/gcc/resource.cc
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm_p.h"
 #include "regs.h"
 #include "emit-rtl.h"
+#include "cfgrtl.h"
 #include "resource.h"
 #include "insn-attr.h"
 #include "function-abi.h"
@@ -75,7 +76,6 @@ static HARD_REG_SET current_live_regs;
 static HARD_REG_SET pending_dead_regs;
 
 static void update_live_status (rtx, const_rtx, void *);
-static int find_basic_block (rtx_insn *, int);
 static rtx_insn *next_insn_no_annul (rtx_insn *);
 
 /* Utility function called from mark_target_live_regs via note_stores.
@@ -113,46 +113,6 @@ update_live_status (rtx dest, const_rtx x, void *data ATTRIBUTE_UNUSED)
 	CLEAR_HARD_REG_BIT (pending_dead_regs, i);
       }
 }
-
-/* Find the number of the basic block with correct live register
-   information that starts closest to INSN.  Return -1 if we couldn't
-   find such a basic block or the beginning is more than
-   SEARCH_LIMIT instructions before INSN.  Use SEARCH_LIMIT = -1 for
-   an unlimited search.
-
-   The delay slot filling code destroys the control-flow graph so,
-   instead of finding the basic block containing INSN, we search
-   backwards toward a BARRIER where the live register information is
-   correct.  */
-
-static int
-find_basic_block (rtx_insn *insn, int search_limit)
-{
-  /* Scan backwards to the previous BARRIER.  Then see if we can find a
-     label that starts a basic block.  Return the basic block number.  */
-  for (insn = prev_nonnote_insn (insn);
-       insn && !BARRIER_P (insn) && search_limit != 0;
-       insn = prev_nonnote_insn (insn), --search_limit)
-    ;
-
-  /* The closest BARRIER is too far away.  */
-  if (search_limit == 0)
-    return -1;
-
-  /* The start of the function.  */
-  else if (insn == 0)
-    return ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb->index;
-
-  /* See if any of the upcoming CODE_LABELs start a basic block.  If we reach
-     anything other than a CODE_LABEL or note, we can't find this code.  */
-  for (insn = next_nonnote_insn (insn);
-       insn && LABEL_P (insn);
-       insn = next_nonnote_insn (insn))
-    if (BLOCK_FOR_INSN (insn))
-      return BLOCK_FOR_INSN (insn)->index;
-
-  return -1;
-}
 
 /* Similar to next_insn, but ignores insns in the delay slots of
    an annulled branch.  */
@@ -714,7 +674,8 @@ mark_target_live_regs (rtx_insn *insns, rtx target_maybe_return, struct resource
     }
 
   if (b == -1)
-    b = find_basic_block (target, param_max_delay_slot_live_search);
+    b = BLOCK_FOR_INSN (target)->index;
+  gcc_assert (b != -1);
 
   if (target_hash_table != NULL)
     {
@@ -722,7 +683,7 @@ mark_target_live_regs (rtx_insn *insns, rtx target_maybe_return, struct resource
 	{
 	  /* If the information is up-to-date, use it.  Otherwise, we will
 	     update it below.  */
-	  if (b == tinfo->block && b != -1 && tinfo->bb_tick == bb_ticks[b])
+	  if (b == tinfo->block && tinfo->bb_tick == bb_ticks[b])
 	    {
 	      res->regs = tinfo->live_regs;
 	      return;
@@ -905,7 +866,6 @@ void
 init_resource_info (rtx_insn *epilogue_insn)
 {
   int i;
-  basic_block bb;
 
   /* Indicate what resources are required to be valid at the end of the current
      function.  The condition code never is and memory always is.
@@ -975,10 +935,8 @@ init_resource_info (rtx_insn *epilogue_insn)
   target_hash_table = XCNEWVEC (struct target_info *, TARGET_HASH_PRIME);
   bb_ticks = XCNEWVEC (int, last_basic_block_for_fn (cfun));
 
-  /* Set the BLOCK_FOR_INSN of each label that starts a basic block.  */
-  FOR_EACH_BB_FN (bb, cfun)
-    if (LABEL_P (BB_HEAD (bb)))
-      BLOCK_FOR_INSN (BB_HEAD (bb)) = bb;
+  /* Set the BLOCK_FOR_INSN for each insn.  */
+  compute_bb_for_insn ();
 }
 
 /* Free up the resources allocated to mark_target_live_regs ().  This
@@ -987,8 +945,6 @@ init_resource_info (rtx_insn *epilogue_insn)
 void
 free_resource_info (void)
 {
-  basic_block bb;
-
   if (target_hash_table != NULL)
     {
       int i;
@@ -1015,9 +971,7 @@ free_resource_info (void)
       bb_ticks = NULL;
     }
 
-  FOR_EACH_BB_FN (bb, cfun)
-    if (LABEL_P (BB_HEAD (bb)))
-      BLOCK_FOR_INSN (BB_HEAD (bb)) = NULL;
+  free_bb_for_insn ();
 }
 
 /* Clear any hashed information that we have stored for INSN.  */
@@ -1063,10 +1017,10 @@ clear_hashed_info_until_next_barrier (rtx_insn *insn)
 void
 incr_ticks_for_insn (rtx_insn *insn)
 {
-  int b = find_basic_block (insn, param_max_delay_slot_live_search);
+  int b = BLOCK_FOR_INSN (insn)->index;
+  gcc_assert (b != -1);
 
-  if (b != -1)
-    bb_ticks[b]++;
+  bb_ticks[b]++;
 }
 
 /* Add TRIAL to the set of resources used at the end of the current
