OSDN Git Service

* cfglayout.c (fixup_reorder_chain): Don't do anything for
[pf3gnuchains/gcc-fork.git] / gcc / cfglayout.c
index 7121a3e..e887015 100644 (file)
@@ -1,5 +1,5 @@
 /* Basic block reordering routines for the GNU compiler.
-   Copyright (C) 2000, 2001, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -35,13 +35,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "target.h"
 #include "ggc.h"
 #include "alloc-pool.h"
+#include "flags.h"
 
 /* The contents of the current function definition are allocated
    in this obstack, and all are freed at the end of the function.  */
 extern struct obstack flow_obstack;
 
-alloc_pool cfg_layout_pool;
-
 /* Holds the interesting trailing notes for the function.  */
 rtx cfg_layout_function_footer, cfg_layout_function_header;
 
@@ -55,9 +54,8 @@ static void change_scope (rtx, tree, tree);
 
 void verify_insn_chain (void);
 static void fixup_fallthru_exit_predecessor (void);
-static rtx duplicate_insn_chain (rtx, rtx);
-static void break_superblocks (void);
 static tree insn_scope (rtx);
+static void update_unlikely_executed_notes (basic_block);
 \f
 rtx
 unlink_insn_chain (rtx first, rtx last)
@@ -89,9 +87,9 @@ skip_insns_after_block (basic_block bb)
 
   next_head = NULL_RTX;
   if (bb->next_bb != EXIT_BLOCK_PTR)
-    next_head = bb->next_bb->head;
+    next_head = BB_HEAD (bb->next_bb);
 
-  for (last_insn = insn = bb->end; (insn = NEXT_INSN (insn)) != 0; )
+  for (last_insn = insn = BB_END (bb); (insn = NEXT_INSN (insn)) != 0; )
     {
       if (insn == next_head)
        break;
@@ -148,7 +146,7 @@ skip_insns_after_block (basic_block bb)
      created by removing the basic block originally following
      NOTE_INSN_LOOP_BEG.  In such case reorder the notes.  */
 
-  for (insn = last_insn; insn != bb->end; insn = prev)
+  for (insn = last_insn; insn != BB_END (bb); insn = prev)
     {
       prev = PREV_INSN (insn);
       if (GET_CODE (insn) == NOTE)
@@ -172,12 +170,12 @@ skip_insns_after_block (basic_block bb)
 static rtx
 label_for_bb (basic_block bb)
 {
-  rtx label = bb->head;
+  rtx label = BB_HEAD (bb);
 
   if (GET_CODE (label) != CODE_LABEL)
     {
-      if (rtl_dump_file)
-       fprintf (rtl_dump_file, "Emitting label for block %d\n", bb->index);
+      if (dump_file)
+       fprintf (dump_file, "Emitting label for block %d\n", bb->index);
 
       label = block_label (bb);
     }
@@ -214,13 +212,13 @@ record_effective_endpoints (void)
     {
       rtx end;
 
-      if (PREV_INSN (bb->head) && next_insn != bb->head)
+      if (PREV_INSN (BB_HEAD (bb)) && next_insn != BB_HEAD (bb))
        bb->rbi->header = unlink_insn_chain (next_insn,
-                                             PREV_INSN (bb->head));
+                                             PREV_INSN (BB_HEAD (bb)));
       end = skip_insns_after_block (bb);
-      if (NEXT_INSN (bb->end) && bb->end != end)
-       bb->rbi->footer = unlink_insn_chain (NEXT_INSN (bb->end), end);
-      next_insn = NEXT_INSN (bb->end);
+      if (NEXT_INSN (BB_END (bb)) && BB_END (bb) != end)
+       bb->rbi->footer = unlink_insn_chain (NEXT_INSN (BB_END (bb)), end);
+      next_insn = NEXT_INSN (BB_END (bb));
     }
 
   cfg_layout_function_footer = next_insn;
@@ -310,10 +308,14 @@ insn_locators_initialize (void)
          switch (NOTE_LINE_NUMBER (insn))
            {
            case NOTE_INSN_BLOCK_BEG:
+             if (cfun->dont_emit_block_notes)
+               abort ();
              block = NOTE_BLOCK (insn);
              delete_insn (insn);
              break;
            case NOTE_INSN_BLOCK_END:
+             if (cfun->dont_emit_block_notes)
+               abort ();
              block = BLOCK_SUPERCONTEXT (block);
              if (block && TREE_CODE (block) == FUNCTION_DECL)
                block = 0;
@@ -328,11 +330,17 @@ insn_locators_initialize (void)
              break;
            }
        }
+
+      if (cfun->dont_emit_block_notes)
+       check_block_change (insn, &block);
     }
 
   /* Tag the blocks with a depth number so that change_scope can find
      the common parent easily.  */
   set_block_levels (DECL_INITIAL (cfun->decl), 0);
+
+  if (cfun->dont_emit_block_notes)
+    free_block_changes ();
 }
 
 /* For each lexical block, set BLOCK_NUMBER to the depth at which it is
@@ -415,6 +423,18 @@ insn_scope (rtx insn)
   int min = 0;
   int loc = INSN_LOCATOR (insn);
 
+  /* When block_locators_locs was initialized, the pro- and epilogue
+     insns didn't exist yet and can therefore not be found this way.
+     But we know that they belong to the outer most block of the
+     current function.
+     Without this test, the prologue would be put inside the block of
+     the first valid instruction in the function and when that first
+     insn is part of an inlined function then the low_pc of that
+     inlined function is messed up.  Likewise for the epilogue and
+     the last valid instruction.  */
+  if (loc == prologue_locator || loc == epilogue_locator)
+    return DECL_INITIAL (cfun->decl);
+
   if (!max || !loc)
     return NULL;
   while (1)
@@ -586,11 +606,11 @@ fixup_reorder_chain (void)
            insn = NEXT_INSN (insn);
        }
       if (insn)
-       NEXT_INSN (insn) = bb->head;
+       NEXT_INSN (insn) = BB_HEAD (bb);
       else
-       set_first_insn (bb->head);
-      PREV_INSN (bb->head) = insn;
-      insn = bb->end;
+       set_first_insn (BB_HEAD (bb));
+      PREV_INSN (BB_HEAD (bb)) = insn;
+      insn = BB_END (bb);
       if (bb->rbi->footer)
        {
          NEXT_INSN (insn) = bb->rbi->footer;
@@ -624,6 +644,7 @@ fixup_reorder_chain (void)
       edge e_fall, e_taken, e;
       rtx bb_end_insn;
       basic_block nb;
+      basic_block old_bb;
 
       if (bb->succ == NULL)
        continue;
@@ -637,15 +658,14 @@ fixup_reorder_chain (void)
        else if (! (e->flags & EDGE_EH))
          e_taken = e;
 
-      bb_end_insn = bb->end;
+      bb_end_insn = BB_END (bb);
       if (GET_CODE (bb_end_insn) == JUMP_INSN)
        {
          if (any_condjump_p (bb_end_insn))
            {
              /* If the old fallthru is still next, nothing to do.  */
              if (bb->rbi->next == e_fall->dest
-                 || (!bb->rbi->next
-                     && e_fall->dest == EXIT_BLOCK_PTR))
+                 || e_fall->dest == EXIT_BLOCK_PTR)
                continue;
 
              /* The degenerated case of conditional jump jumping to the next
@@ -663,9 +683,9 @@ fixup_reorder_chain (void)
 
                  e_fake = unchecked_make_edge (bb, e_fall->dest, 0);
 
-                 if (!redirect_jump (bb->end, block_label (bb), 0))
+                 if (!redirect_jump (BB_END (bb), block_label (bb), 0))
                    abort ();
-                 note = find_reg_note (bb->end, REG_BR_PROB, NULL_RTX);
+                 note = find_reg_note (BB_END (bb), REG_BR_PROB, NULL_RTX);
                  if (note)
                    {
                      int prob = INTVAL (XEXP (note, 0));
@@ -691,21 +711,38 @@ fixup_reorder_chain (void)
                  if (note
                      && INTVAL (XEXP (note, 0)) < REG_BR_PROB_BASE / 2
                      && invert_jump (bb_end_insn,
-                                     label_for_bb (e_fall->dest), 0))
+                                     (e_fall->dest == EXIT_BLOCK_PTR
+                                      ? NULL_RTX
+                                      : label_for_bb (e_fall->dest)), 0))
                    {
                      e_fall->flags &= ~EDGE_FALLTHRU;
+#ifdef ENABLE_CHECKING
+                     if (!could_fall_through (e_taken->src, e_taken->dest))
+                       abort ();
+#endif
                      e_taken->flags |= EDGE_FALLTHRU;
                      update_br_prob_note (bb);
                      e = e_fall, e_fall = e_taken, e_taken = e;
                    }
                }
 
+             /* If the "jumping" edge is a crossing edge, and the fall
+                through edge is non-crossing, leave things as they are.  */
+             else if (e_taken->crossing_edge && !e_fall->crossing_edge)
+               continue;
+
              /* Otherwise we can try to invert the jump.  This will
                 basically never fail, however, keep up the pretense.  */
              else if (invert_jump (bb_end_insn,
-                                   label_for_bb (e_fall->dest), 0))
+                                   (e_fall->dest == EXIT_BLOCK_PTR
+                                    ? NULL_RTX
+                                    : label_for_bb (e_fall->dest)), 0))
                {
                  e_fall->flags &= ~EDGE_FALLTHRU;
+#ifdef ENABLE_CHECKING
+                 if (!could_fall_through (e_taken->src, e_taken->dest))
+                   abort ();
+#endif
                  e_taken->flags |= EDGE_FALLTHRU;
                  update_br_prob_note (bb);
                  continue;
@@ -744,7 +781,7 @@ fixup_reorder_chain (void)
            continue;
 
          /* A fallthru to exit block.  */
-         if (!bb->rbi->next && e_fall->dest == EXIT_BLOCK_PTR)
+         if (e_fall->dest == EXIT_BLOCK_PTR)
            continue;
        }
 
@@ -752,31 +789,61 @@ fixup_reorder_chain (void)
       nb = force_nonfallthru (e_fall);
       if (nb)
        {
-         cfg_layout_initialize_rbi (nb);
+         initialize_bb_rbi (nb);
          nb->rbi->visited = 1;
          nb->rbi->next = bb->rbi->next;
          bb->rbi->next = nb;
          /* Don't process this new block.  */
+         old_bb = bb;
          bb = nb;
+         
+         /* Make sure new bb is tagged for correct section (same as
+            fall-thru source).  */
+         e_fall->src->partition = bb->pred->src->partition;
+         if (flag_reorder_blocks_and_partition)
+           {
+             if (bb->pred->src->partition == COLD_PARTITION)
+               {
+                 rtx new_note;
+                 rtx note = BB_HEAD (e_fall->src);
+                 
+                 while (!INSN_P (note)
+                        && note != BB_END (e_fall->src))
+                   note = NEXT_INSN (note);
+                 
+                 new_note = emit_note_before 
+                                          (NOTE_INSN_UNLIKELY_EXECUTED_CODE, 
+                                          note);
+                 NOTE_BASIC_BLOCK (new_note) = bb;
+               }
+             if (GET_CODE (BB_END (bb)) == JUMP_INSN
+                 && !any_condjump_p (BB_END (bb))
+                 && bb->succ->crossing_edge )
+               REG_NOTES (BB_END (bb)) = gen_rtx_EXPR_LIST 
+                 (REG_CROSSING_JUMP, NULL_RTX, REG_NOTES (BB_END (bb)));
+           }
        }
     }
 
   /* Put basic_block_info in the new order.  */
 
-  if (rtl_dump_file)
+  if (dump_file)
     {
-      fprintf (rtl_dump_file, "Reordered sequence:\n");
-      for (bb = ENTRY_BLOCK_PTR->next_bb, index = 0; bb; bb = bb->rbi->next, index ++)
+      fprintf (dump_file, "Reordered sequence:\n");
+      for (bb = ENTRY_BLOCK_PTR->next_bb, index = 0;
+          bb;
+          bb = bb->rbi->next, index++)
        {
-         fprintf (rtl_dump_file, " %i ", index);
+         fprintf (dump_file, " %i ", index);
          if (bb->rbi->original)
-           fprintf (rtl_dump_file, "duplicate of %i ",
+           fprintf (dump_file, "duplicate of %i ",
                     bb->rbi->original->index);
-         else if (forwarder_block_p (bb) && GET_CODE (bb->head) != CODE_LABEL)
-           fprintf (rtl_dump_file, "compensation ");
+         else if (forwarder_block_p (bb)
+                  && GET_CODE (BB_HEAD (bb)) != CODE_LABEL)
+           fprintf (dump_file, "compensation ");
          else
-           fprintf (rtl_dump_file, "bb %i ", bb->index);
-         fprintf (rtl_dump_file, " [%i]\n", bb->frequency);
+           fprintf (dump_file, "bb %i ", bb->index);
+         fprintf (dump_file, " [%i]\n", bb->frequency);
        }
     }
 
@@ -789,6 +856,8 @@ fixup_reorder_chain (void)
       bb->index = index;
       BASIC_BLOCK (index) = bb;
 
+      update_unlikely_executed_notes (bb);
+
       bb->prev_bb = prev_bb;
       prev_bb->next_bb = bb;
     }
@@ -806,6 +875,21 @@ fixup_reorder_chain (void)
     }
 }
 \f
+/* Update the basic block number information in any 
+   NOTE_INSN_UNLIKELY_EXECUTED_CODE notes within the basic block.  */
+
+static void
+update_unlikely_executed_notes (basic_block bb)
+{
+  rtx cur_insn;
+
+  for (cur_insn = BB_HEAD (bb); cur_insn != BB_END (bb); 
+       cur_insn = NEXT_INSN (cur_insn)) 
+    if (GET_CODE (cur_insn) == NOTE
+       && NOTE_LINE_NUMBER (cur_insn) == NOTE_INSN_UNLIKELY_EXECUTED_CODE)
+      NOTE_BASIC_BLOCK (cur_insn) = bb;
+}
+\f
 /* Perform sanity checks on the insn chain.
    1. Check that next/prev pointers are consistent in both the forward and
       reverse direction.
@@ -837,14 +921,20 @@ verify_insn_chain (void)
     abort ();
 }
 \f
-/* The block falling through to exit must be the last one in the
-   reordered chain.  Ensure that this condition is met.  */
+/* If we have assembler epilogues, the block falling through to exit must
+   be the last one in the reordered chain when we reach final.  Ensure
+   that this condition is met.  */
 static void
 fixup_fallthru_exit_predecessor (void)
 {
   edge e;
   basic_block bb = NULL;
 
+  /* This transformation is not valid before reload, because we might separate
+     a call from the instruction that copies the return value.  */
+  if (! reload_completed)
+    abort ();
+
   for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next)
     if (e->flags & EDGE_FALLTHRU)
       bb = e->src;
@@ -853,6 +943,18 @@ fixup_fallthru_exit_predecessor (void)
     {
       basic_block c = ENTRY_BLOCK_PTR->next_bb;
 
+      /* If the very first block is the one with the fall-through exit
+        edge, we have to split that block.  */
+      if (c == bb)
+       {
+         bb = split_block (bb, NULL)->dest;
+         initialize_bb_rbi (bb);
+         bb->rbi->next = c->rbi->next;
+         c->rbi->next = bb;
+         bb->rbi->footer = c->rbi->footer;
+         c->rbi->footer = NULL;
+       }
+
       while (c->rbi->next != bb)
        c = c->rbi->next;
 
@@ -867,35 +969,30 @@ fixup_fallthru_exit_predecessor (void)
 \f
 /* Return true in case it is possible to duplicate the basic block BB.  */
 
+/* We do not want to declare the function in a header file, since it should
+   only be used through the cfghooks interface, and we do not want to move
+   it to cfgrtl.c since it would require also moving quite a lot of related
+   code.  */
+extern bool cfg_layout_can_duplicate_bb_p (basic_block);
+
 bool
 cfg_layout_can_duplicate_bb_p (basic_block bb)
 {
-  edge s;
-
-  if (bb == EXIT_BLOCK_PTR || bb == ENTRY_BLOCK_PTR)
-    return false;
-
-  /* Duplicating fallthru block to exit would require adding a jump
-     and splitting the real last BB.  */
-  for (s = bb->succ; s; s = s->succ_next)
-    if (s->dest == EXIT_BLOCK_PTR && s->flags & EDGE_FALLTHRU)
-       return false;
-
   /* Do not attempt to duplicate tablejumps, as we need to unshare
      the dispatch table.  This is difficult to do, as the instructions
      computing jump destination may be hoisted outside the basic block.  */
-  if (tablejump_p (bb->end, NULL, NULL))
+  if (tablejump_p (BB_END (bb), NULL, NULL))
     return false;
 
   /* Do not duplicate blocks containing insns that can't be copied.  */
   if (targetm.cannot_copy_insn_p)
     {
-      rtx insn = bb->head;
+      rtx insn = BB_HEAD (bb);
       while (1)
        {
-         if (INSN_P (insn) && (*targetm.cannot_copy_insn_p) (insn))
+         if (INSN_P (insn) && targetm.cannot_copy_insn_p (insn))
            return false;
-         if (insn == bb->end)
+         if (insn == BB_END (bb))
            break;
          insn = NEXT_INSN (insn);
        }
@@ -904,7 +1001,7 @@ cfg_layout_can_duplicate_bb_p (basic_block bb)
   return true;
 }
 
-static rtx
+rtx
 duplicate_insn_chain (rtx from, rtx to)
 {
   rtx insn, last;
@@ -976,6 +1073,7 @@ duplicate_insn_chain (rtx from, rtx to)
              abort ();
              break;
            case NOTE_INSN_REPEATED_LINE_NUMBER:
+           case NOTE_INSN_UNLIKELY_EXECUTED_CODE:
              emit_note_copy (insn);
              break;
 
@@ -995,28 +1093,21 @@ duplicate_insn_chain (rtx from, rtx to)
   delete_insn (last);
   return insn;
 }
-/* Create a duplicate of the basic block BB and redirect edge E into it.
-   If E is not specified, BB is just copied, but updating the frequencies
-   etc. is left to the caller.  */
+/* Create a duplicate of the basic block BB.  */
+
+/* We do not want to declare the function in a header file, since it should
+   only be used through the cfghooks interface, and we do not want to move
+   it to cfgrtl.c since it would require also moving quite a lot of related
+   code.  */
+extern basic_block cfg_layout_duplicate_bb (basic_block);
 
 basic_block
-cfg_layout_duplicate_bb (basic_block bb, edge e)
+cfg_layout_duplicate_bb (basic_block bb)
 {
   rtx insn;
-  edge s, n;
   basic_block new_bb;
-  gcov_type new_count = e ? e->count : 0;
 
-  if (bb->count < new_count)
-    new_count = bb->count;
-  if (!bb->pred)
-    abort ();
-#ifdef ENABLE_CHECKING
-  if (!cfg_layout_can_duplicate_bb_p (bb))
-    abort ();
-#endif
-
-  insn = duplicate_insn_chain (bb->head, bb->end);
+  insn = duplicate_insn_chain (BB_HEAD (bb), BB_END (bb));
   new_bb = create_basic_block (insn,
                               insn ? get_last_insn () : NULL,
                               EXIT_BLOCK_PTR->prev_bb);
@@ -1049,63 +1140,10 @@ cfg_layout_duplicate_bb (basic_block bb, edge e)
       COPY_REG_SET (new_bb->global_live_at_end, bb->global_live_at_end);
     }
 
-  new_bb->loop_depth = bb->loop_depth;
-  new_bb->flags = bb->flags;
-  for (s = bb->succ; s; s = s->succ_next)
-    {
-      /* Since we are creating edges from a new block to successors
-        of another block (which therefore are known to be disjoint), there
-        is no need to actually check for duplicated edges.  */
-      n = unchecked_make_edge (new_bb, s->dest, s->flags);
-      n->probability = s->probability;
-      if (e && bb->count)
-       {
-         /* Take care for overflows!  */
-         n->count = s->count * (new_count * 10000 / bb->count) / 10000;
-         s->count -= n->count;
-       }
-      else
-       n->count = s->count;
-      n->aux = s->aux;
-    }
-
-  if (e)
-    {
-      new_bb->count = new_count;
-      bb->count -= new_count;
-
-      new_bb->frequency = EDGE_FREQUENCY (e);
-      bb->frequency -= EDGE_FREQUENCY (e);
-
-      redirect_edge_and_branch_force (e, new_bb);
-
-      if (bb->count < 0)
-       bb->count = 0;
-      if (bb->frequency < 0)
-       bb->frequency = 0;
-    }
-  else
-    {
-      new_bb->count = bb->count;
-      new_bb->frequency = bb->frequency;
-    }
-
-  new_bb->rbi->original = bb;
-  bb->rbi->copy = new_bb;
-
   return new_bb;
 }
 \f
-void
-cfg_layout_initialize_rbi (basic_block bb)
-{
-  if (bb->rbi)
-    abort ();
-  bb->rbi = pool_alloc (cfg_layout_pool);
-  memset (bb->rbi, 0, sizeof (struct reorder_block_def));
-}
-\f
-/* Main entry point to this module - initialize the datastructures for
+/* Main entry point to this module - initialize the data structures for
    CFG layout changes.  It keeps LOOPS up-to-date if not null.  */
 
 void
@@ -1113,13 +1151,12 @@ cfg_layout_initialize (void)
 {
   basic_block bb;
 
-  /* Our algorithm depends on fact that there are now dead jumptables
+  /* Our algorithm depends on fact that there are no dead jumptables
      around the code.  */
-  cfg_layout_pool =
-    create_alloc_pool ("cfg layout pool", sizeof (struct reorder_block_def),
-                      n_basic_blocks + 2);
+  alloc_rbi_pool ();
+
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
-    cfg_layout_initialize_rbi (bb);
+    initialize_bb_rbi (bb);
 
   cfg_layout_rtl_register_cfg_hooks ();
 
@@ -1129,23 +1166,22 @@ cfg_layout_initialize (void)
 }
 
 /* Splits superblocks.  */
-static void
+void
 break_superblocks (void)
 {
   sbitmap superblocks;
-  int i, need;
+  bool need = false;
+  basic_block bb;
 
-  superblocks = sbitmap_alloc (n_basic_blocks);
+  superblocks = sbitmap_alloc (last_basic_block);
   sbitmap_zero (superblocks);
 
-  need = 0;
-
-  for (i = 0; i < n_basic_blocks; i++)
-    if (BASIC_BLOCK(i)->flags & BB_SUPERBLOCK)
+  FOR_EACH_BB (bb)
+    if (bb->flags & BB_SUPERBLOCK)
       {
-       BASIC_BLOCK(i)->flags &= ~BB_SUPERBLOCK;
-       SET_BIT (superblocks, i);
-       need = 1;
+       bb->flags &= ~BB_SUPERBLOCK;
+       SET_BIT (superblocks, bb->index);
+       need = true;
       }
 
   if (need)
@@ -1169,14 +1205,19 @@ cfg_layout_finalize (void)
   verify_flow_info ();
 #endif
   rtl_register_cfg_hooks ();
-  fixup_fallthru_exit_predecessor ();
+  if (reload_completed
+#ifdef HAVE_epilogue
+      && !HAVE_epilogue
+#endif
+      )
+    fixup_fallthru_exit_predecessor ();
   fixup_reorder_chain ();
 
 #ifdef ENABLE_CHECKING
   verify_insn_chain ();
 #endif
 
-  free_alloc_pool (cfg_layout_pool);
+  free_rbi_pool ();
   FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR, NULL, next_bb)
     bb->rbi = NULL;
 
@@ -1209,7 +1250,7 @@ can_copy_bbs_p (basic_block *bbs, unsigned n)
            goto end;
          }
 
-      if (!cfg_layout_can_duplicate_bb_p (bbs[i]))
+      if (!can_duplicate_block_p (bbs[i]))
        {
          ret = false;
          break;
@@ -1241,7 +1282,7 @@ end:
 void
 copy_bbs (basic_block *bbs, unsigned n, basic_block *new_bbs,
          edge *edges, unsigned n_edges, edge *new_edges,
-         struct loop *base, struct loops *loops)
+         struct loop *base)
 {
   unsigned i, j;
   basic_block bb, new_bb, dom_bb;
@@ -1252,11 +1293,10 @@ copy_bbs (basic_block *bbs, unsigned n, basic_block *new_bbs,
     {
       /* Duplicate.  */
       bb = bbs[i];
-      new_bb = new_bbs[i] = cfg_layout_duplicate_bb (bb, NULL);
+      new_bb = new_bbs[i] = duplicate_block (bb, NULL);
       bb->rbi->duplicated = 1;
       /* Add to loop.  */
       add_bb_to_loop (new_bb, bb->loop_father->copy);
-      add_to_dominance_info (loops->cfg.dom, new_bb);
       /* Possibly set header.  */
       if (bb->loop_father->header == bb && bb->loop_father != base)
        new_bb->loop_father->header = new_bb;
@@ -1271,11 +1311,11 @@ copy_bbs (basic_block *bbs, unsigned n, basic_block *new_bbs,
       bb = bbs[i];
       new_bb = new_bbs[i];
 
-      dom_bb = get_immediate_dominator (loops->cfg.dom, bb);
+      dom_bb = get_immediate_dominator (CDI_DOMINATORS, bb);
       if (dom_bb->rbi->duplicated)
        {
          dom_bb = dom_bb->rbi->copy;
-         set_immediate_dominator (loops->cfg.dom, new_bb, dom_bb);
+         set_immediate_dominator (CDI_DOMINATORS, new_bb, dom_bb);
        }
     }