OSDN Git Service

2010-04-28 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / ira-build.c
index 65e4ad7..c879efa 100644 (file)
@@ -1,5 +1,5 @@
 /* Building internal representation for IRA.
-   Copyright (C) 2006, 2007, 2008
+   Copyright (C) 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
 
@@ -58,7 +58,7 @@ ira_loop_tree_node_t ira_bb_nodes;
    array.  */
 ira_loop_tree_node_t ira_loop_nodes;
 
-/* Map regno -> allocnos with given regno (see comments for 
+/* Map regno -> allocnos with given regno (see comments for
    allocno member `next_regno_allocno').  */
 ira_allocno_t *ira_regno_allocno_map;
 
@@ -468,7 +468,7 @@ ira_create_allocno (int regno, bool cap_p, ira_loop_tree_node_t loop_tree_node)
   ALLOCNO_CONFLICT_HARD_REG_COSTS (a) = NULL;
   ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL;
   ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL;
-  ALLOCNO_LEFT_CONFLICTS_NUM (a) = -1;
+  ALLOCNO_LEFT_CONFLICTS_SIZE (a) = -1;
   ALLOCNO_COVER_CLASS (a) = NO_REGS;
   ALLOCNO_UPDATED_COVER_CLASS_COST (a) = 0;
   ALLOCNO_COVER_CLASS_COST (a) = 0;
@@ -848,7 +848,7 @@ ira_copy_allocno_live_range_list (allocno_live_range_t r)
 /* Merge ranges R1 and R2 and returns the result.  The function
    maintains the order of ranges and tries to minimize number of the
    result ranges.  */
-allocno_live_range_t 
+allocno_live_range_t
 ira_merge_allocno_live_ranges (allocno_live_range_t r1,
                               allocno_live_range_t r2)
 {
@@ -1379,7 +1379,7 @@ ira_traverse_loop_tree (bool bb_p, ira_loop_tree_node_t loop_node,
 
   if (preorder_func != NULL)
     (*preorder_func) (loop_node);
-  
+
   if (bb_p)
     for (subloop_node = loop_node->children;
         subloop_node != NULL;
@@ -1388,11 +1388,11 @@ ira_traverse_loop_tree (bool bb_p, ira_loop_tree_node_t loop_node,
        {
          if (preorder_func != NULL)
            (*preorder_func) (subloop_node);
-  
+
          if (postorder_func != NULL)
            (*postorder_func) (subloop_node);
        }
-  
+
   for (subloop_node = loop_node->subloops;
        subloop_node != NULL;
        subloop_node = subloop_node->subloop_next)
@@ -1434,7 +1434,7 @@ create_insn_allocnos (rtx x, bool output_p)
 
          if ((a = ira_curr_regno_allocno_map[regno]) == NULL)
            a = ira_create_allocno (regno, false, ira_curr_loop_tree_node);
-         
+
          ALLOCNO_NREFS (a)++;
          ALLOCNO_FREQ (a) += REG_FREQ_FROM_BB (curr_bb);
          if (output_p)
@@ -1458,7 +1458,7 @@ create_insn_allocnos (rtx x, bool output_p)
       create_insn_allocnos (XEXP (x, 0), false);
       return;
     }
-  else if (code == PRE_DEC || code == POST_DEC || code == PRE_INC || 
+  else if (code == PRE_DEC || code == POST_DEC || code == PRE_INC ||
           code == POST_INC || code == POST_MODIFY || code == PRE_MODIFY)
     {
       create_insn_allocnos (XEXP (x, 0), true);
@@ -1491,7 +1491,7 @@ create_bb_allocnos (ira_loop_tree_node_t bb_node)
   curr_bb = bb = bb_node->bb;
   ira_assert (bb != NULL);
   FOR_BB_INSNS_REVERSE (bb, insn)
-    if (INSN_P (insn))
+    if (NONDEBUG_INSN_P (insn))
       create_insn_allocnos (PATTERN (insn), false);
   /* It might be a allocno living through from one subloop to
      another.  */
@@ -1549,7 +1549,7 @@ create_loop_tree_node_allocnos (ira_loop_tree_node_t loop_node)
       FOR_EACH_EDGE (e, ei, loop_node->loop->header->preds)
        if (e->src != loop_node->loop->latch)
          create_loop_allocnos (e);
-      
+
       edges = get_loop_exit_edges (loop_node->loop);
       for (i = 0; VEC_iterate (edge, edges, i, e); i++)
        create_loop_allocnos (e);
@@ -1583,8 +1583,8 @@ propagate_allocno_info (void)
   ira_loop_tree_node_t parent;
   enum reg_class cover_class;
 
-  if (flag_ira_algorithm != IRA_ALGORITHM_REGIONAL
-      && flag_ira_algorithm != IRA_ALGORITHM_MIXED)
+  if (flag_ira_region != IRA_REGION_ALL
+      && flag_ira_region != IRA_REGION_MIXED)
     return;
   for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
     for (a = ira_regno_allocno_map[i];
@@ -1663,10 +1663,10 @@ low_pressure_loop_node_p (ira_loop_tree_node_t node)
 {
   int i;
   enum reg_class cover_class;
-  
+
   if (node->bb != NULL)
     return false;
-  
+
   for (i = 0; i < ira_reg_class_cover_size; i++)
     {
       cover_class = ira_reg_class_cover[i];
@@ -1751,6 +1751,33 @@ mark_loops_for_removal (void)
   ira_free (sorted_loops);
 }
 
+/* Mark all loops but root for removing.  */
+static void
+mark_all_loops_for_removal (void)
+{
+  int i;
+  loop_p loop;
+
+  for (i = 0; VEC_iterate (loop_p, ira_loops.larray, i, loop); i++)
+    if (ira_loop_nodes[i].regno_allocno_map != NULL)
+      {
+       if (ira_loop_nodes[i].parent == NULL)
+         {
+           /* Don't remove the root.  */
+           ira_loop_nodes[i].to_remove_p = false;
+           continue;
+         }
+       ira_loop_nodes[i].to_remove_p = true;
+       if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
+         fprintf
+           (ira_dump_file,
+            "  Mark loop %d (header %d, freq %d, depth %d) for removal\n",
+            ira_loop_nodes[i].loop->num,
+            ira_loop_nodes[i].loop->header->index,
+            ira_loop_nodes[i].loop->header->frequency,
+            loop_depth (ira_loop_nodes[i].loop));
+      }
+}
 
 /* Definition of vector of loop tree nodes.  */
 DEF_VEC_P(ira_loop_tree_node_t);
@@ -1800,111 +1827,263 @@ remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_node_t node)
     }
 }
 
+/* Return TRUE if NODE is inside PARENT.  */
+static bool
+loop_is_inside_p (ira_loop_tree_node_t node, ira_loop_tree_node_t parent)
+{
+  for (node = node->parent; node != NULL; node = node->parent)
+    if (node == parent)
+      return true;
+  return false;
+}
+
+/* Sort allocnos according to their order in regno allocno list.  */
+static int
+regno_allocno_order_compare_func (const void *v1p, const void *v2p)
+{
+  ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
+  ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
+  ira_loop_tree_node_t n1 = ALLOCNO_LOOP_TREE_NODE (a1);
+  ira_loop_tree_node_t n2 = ALLOCNO_LOOP_TREE_NODE (a2);
+
+  if (loop_is_inside_p (n1, n2))
+    return -1;
+  else if (loop_is_inside_p (n2, n1))
+    return 1;
+  /* If allocnos are equally good, sort by allocno numbers, so that
+     the results of qsort leave nothing to chance.  We put allocnos
+     with higher number first in the list because it is the original
+     order for allocnos from loops on the same levels.  */
+  return ALLOCNO_NUM (a2) - ALLOCNO_NUM (a1);
+}
+
+/* This array is used to sort allocnos to restore allocno order in
+   the regno allocno list.  */
+static ira_allocno_t *regno_allocnos;
+
+/* Restore allocno order for REGNO in the regno allocno list.  */
+static void
+ira_rebuild_regno_allocno_list (int regno)
+{
+  int i, n;
+  ira_allocno_t a;
+
+  for (n = 0, a = ira_regno_allocno_map[regno];
+       a != NULL;
+       a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
+    regno_allocnos[n++] = a;
+  ira_assert (n > 0);
+  qsort (regno_allocnos, n, sizeof (ira_allocno_t),
+        regno_allocno_order_compare_func);
+  for (i = 1; i < n; i++)
+    ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[i - 1]) = regno_allocnos[i];
+  ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[n - 1]) = NULL;
+  ira_regno_allocno_map[regno] = regno_allocnos[0];
+  if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL)
+    fprintf (ira_dump_file, " Rebuilding regno allocno list for %d\n", regno);
+}
+
+/* Propagate info from allocno FROM_A to allocno A.  */
+static void
+propagate_some_info_from_allocno (ira_allocno_t a, ira_allocno_t from_a)
+{
+  enum reg_class cover_class;
+
+  IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
+                   ALLOCNO_CONFLICT_HARD_REGS (from_a));
+#ifdef STACK_REGS
+  if (ALLOCNO_NO_STACK_REG_P (from_a))
+    ALLOCNO_NO_STACK_REG_P (a) = true;
+#endif
+  ALLOCNO_NREFS (a) += ALLOCNO_NREFS (from_a);
+  ALLOCNO_FREQ (a) += ALLOCNO_FREQ (from_a);
+  ALLOCNO_CALL_FREQ (a) += ALLOCNO_CALL_FREQ (from_a);
+  IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a),
+                   ALLOCNO_TOTAL_CONFLICT_HARD_REGS (from_a));
+  ALLOCNO_CALLS_CROSSED_NUM (a) += ALLOCNO_CALLS_CROSSED_NUM (from_a);
+  ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a)
+    += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (from_a);
+  if (! ALLOCNO_BAD_SPILL_P (from_a))
+    ALLOCNO_BAD_SPILL_P (a) = false;
+#ifdef STACK_REGS
+  if (ALLOCNO_TOTAL_NO_STACK_REG_P (from_a))
+    ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
+#endif
+  cover_class = ALLOCNO_COVER_CLASS (from_a);
+  ira_assert (cover_class == ALLOCNO_COVER_CLASS (a));
+  ira_allocate_and_accumulate_costs (&ALLOCNO_HARD_REG_COSTS (a), cover_class,
+                                    ALLOCNO_HARD_REG_COSTS (from_a));
+  ira_allocate_and_accumulate_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a),
+                                    cover_class,
+                                    ALLOCNO_CONFLICT_HARD_REG_COSTS (from_a));
+  ALLOCNO_COVER_CLASS_COST (a) += ALLOCNO_COVER_CLASS_COST (from_a);
+  ALLOCNO_MEMORY_COST (a) += ALLOCNO_MEMORY_COST (from_a);
+}
+
 /* Remove allocnos from loops removed from the allocation
    consideration.  */
 static void
 remove_unnecessary_allocnos (void)
 {
   int regno;
-  bool merged_p;
-  enum reg_class cover_class;
+  bool merged_p, rebuild_p;
   ira_allocno_t a, prev_a, next_a, parent_a;
   ira_loop_tree_node_t a_node, parent;
   allocno_live_range_t r;
 
   merged_p = false;
+  regno_allocnos = NULL;
   for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--)
-    for (prev_a = NULL, a = ira_regno_allocno_map[regno];
-        a != NULL;
-        a = next_a)
-      {
-       next_a = ALLOCNO_NEXT_REGNO_ALLOCNO (a);
-       a_node = ALLOCNO_LOOP_TREE_NODE (a);
-       if (! a_node->to_remove_p)
-         prev_a = a;
-       else
-         {
-           for (parent = a_node->parent;
-                (parent_a = parent->regno_allocno_map[regno]) == NULL
-                  && parent->to_remove_p;
-                parent = parent->parent)
-             ;
-           if (parent_a == NULL)
-             {
-               /* There are no allocnos with the same regno in upper
-                  region -- just move the allocno to the upper
-                  region.  */
-               prev_a = a;
-               ALLOCNO_LOOP_TREE_NODE (a) = parent;
-               parent->regno_allocno_map[regno] = a;
-               bitmap_set_bit (parent->all_allocnos, ALLOCNO_NUM (a));
-             }
-           else
-             {
-               /* Remove the allocno and update info of allocno in
-                  the upper region.  */
-               if (prev_a == NULL)
-                 ira_regno_allocno_map[regno] = next_a;
-               else
-                 ALLOCNO_NEXT_REGNO_ALLOCNO (prev_a) = next_a;
-               r = ALLOCNO_LIVE_RANGES (a);
-               change_allocno_in_range_list (r, parent_a);
-               ALLOCNO_LIVE_RANGES (parent_a)
-                 = ira_merge_allocno_live_ranges
-                   (r, ALLOCNO_LIVE_RANGES (parent_a));
-               merged_p = true;
-               ALLOCNO_LIVE_RANGES (a) = NULL;
-               IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (parent_a),
-                                 ALLOCNO_CONFLICT_HARD_REGS (a));
-#ifdef STACK_REGS
-               if (ALLOCNO_NO_STACK_REG_P (a))
-                 ALLOCNO_NO_STACK_REG_P (parent_a) = true;
-#endif
-               ALLOCNO_NREFS (parent_a) += ALLOCNO_NREFS (a);
-               ALLOCNO_FREQ (parent_a) += ALLOCNO_FREQ (a);
-               ALLOCNO_CALL_FREQ (parent_a) += ALLOCNO_CALL_FREQ (a);
-               IOR_HARD_REG_SET
-                 (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (parent_a),
-                  ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a));
-               ALLOCNO_CALLS_CROSSED_NUM (parent_a)
-                 += ALLOCNO_CALLS_CROSSED_NUM (a);
-               ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a)
-                 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a);
-               if (! ALLOCNO_BAD_SPILL_P (a))
-                 ALLOCNO_BAD_SPILL_P (parent_a) = false;
+    {
+      rebuild_p = false;
+      for (prev_a = NULL, a = ira_regno_allocno_map[regno];
+          a != NULL;
+          a = next_a)
+       {
+         next_a = ALLOCNO_NEXT_REGNO_ALLOCNO (a);
+         a_node = ALLOCNO_LOOP_TREE_NODE (a);
+         if (! a_node->to_remove_p)
+           prev_a = a;
+         else
+           {
+             for (parent = a_node->parent;
+                  (parent_a = parent->regno_allocno_map[regno]) == NULL
+                    && parent->to_remove_p;
+                  parent = parent->parent)
+               ;
+             if (parent_a == NULL)
+               {
+                 /* There are no allocnos with the same regno in
+                    upper region -- just move the allocno to the
+                    upper region.  */
+                 prev_a = a;
+                 ALLOCNO_LOOP_TREE_NODE (a) = parent;
+                 parent->regno_allocno_map[regno] = a;
+                 bitmap_set_bit (parent->all_allocnos, ALLOCNO_NUM (a));
+                 rebuild_p = true;
+               }
+             else
+               {
+                 /* Remove the allocno and update info of allocno in
+                    the upper region.  */
+                 if (prev_a == NULL)
+                   ira_regno_allocno_map[regno] = next_a;
+                 else
+                   ALLOCNO_NEXT_REGNO_ALLOCNO (prev_a) = next_a;
+                 r = ALLOCNO_LIVE_RANGES (a);
+                 change_allocno_in_range_list (r, parent_a);
+                 ALLOCNO_LIVE_RANGES (parent_a)
+                   = ira_merge_allocno_live_ranges
+                     (r, ALLOCNO_LIVE_RANGES (parent_a));
+                 merged_p = true;
+                 ALLOCNO_LIVE_RANGES (a) = NULL;
+                 propagate_some_info_from_allocno (parent_a, a);
+                 /* Remove it from the corresponding regno allocno
+                    map to avoid info propagation of subsequent
+                    allocno into this already removed allocno.  */
+                 a_node->regno_allocno_map[regno] = NULL;
+                 finish_allocno (a);
+               }
+           }
+       }
+      if (rebuild_p)
+       /* We need to restore the order in regno allocno list.  */
+       {
+         if (regno_allocnos == NULL)
+           regno_allocnos
+             = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t)
+                                               * ira_allocnos_num);
+         ira_rebuild_regno_allocno_list (regno);
+       }
+    }
+  if (merged_p)
+    ira_rebuild_start_finish_chains ();
+  if (regno_allocnos != NULL)
+    ira_free (regno_allocnos);
+}
+
+/* Remove allocnos from all loops but the root.  */
+static void
+remove_low_level_allocnos (void)
+{
+  int regno;
+  bool merged_p, propagate_p;
+  ira_allocno_t a, top_a;
+  ira_loop_tree_node_t a_node, parent;
+  allocno_live_range_t r;
+  ira_allocno_iterator ai;
+
+  merged_p = false;
+  FOR_EACH_ALLOCNO (a, ai)
+    {
+      a_node = ALLOCNO_LOOP_TREE_NODE (a);
+      if (a_node == ira_loop_tree_root || ALLOCNO_CAP_MEMBER (a) != NULL)
+       continue;
+      regno = ALLOCNO_REGNO (a);
+      if ((top_a = ira_loop_tree_root->regno_allocno_map[regno]) == NULL)
+       {
+         ALLOCNO_LOOP_TREE_NODE (a) = ira_loop_tree_root;
+         ira_loop_tree_root->regno_allocno_map[regno] = a;
+         continue;
+       }
+      propagate_p = a_node->parent->regno_allocno_map[regno] == NULL;
+      /* Remove the allocno and update info of allocno in the upper
+        region.  */
+      r = ALLOCNO_LIVE_RANGES (a);
+      change_allocno_in_range_list (r, top_a);
+      ALLOCNO_LIVE_RANGES (top_a)
+       = ira_merge_allocno_live_ranges (r, ALLOCNO_LIVE_RANGES (top_a));
+      merged_p = true;
+      ALLOCNO_LIVE_RANGES (a) = NULL;
+      if (propagate_p)
+       propagate_some_info_from_allocno (top_a, a);
+    }
+  FOR_EACH_ALLOCNO (a, ai)
+    {
+      a_node = ALLOCNO_LOOP_TREE_NODE (a);
+      if (a_node == ira_loop_tree_root)
+       continue;
+      parent = a_node->parent;
+      regno = ALLOCNO_REGNO (a);
+      if (ALLOCNO_CAP_MEMBER (a) != NULL)
+       ira_assert (ALLOCNO_CAP (a) != NULL);
+      else if (ALLOCNO_CAP (a) == NULL)
+       ira_assert (parent->regno_allocno_map[regno] != NULL);
+    }
+  FOR_EACH_ALLOCNO (a, ai)
+    {
+      regno = ALLOCNO_REGNO (a);
+      if (ira_loop_tree_root->regno_allocno_map[regno] == a)
+       {
+         ira_regno_allocno_map[regno] = a;
+         ALLOCNO_NEXT_REGNO_ALLOCNO (a) = NULL;
+         ALLOCNO_CAP_MEMBER (a) = NULL;
+         COPY_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
+                            ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a));
 #ifdef STACK_REGS
-               if (ALLOCNO_TOTAL_NO_STACK_REG_P (a))
-                 ALLOCNO_TOTAL_NO_STACK_REG_P (parent_a) = true;
+         if (ALLOCNO_TOTAL_NO_STACK_REG_P (a))
+           ALLOCNO_NO_STACK_REG_P (a) = true;
 #endif
-               cover_class = ALLOCNO_COVER_CLASS (a);
-               ira_assert (cover_class == ALLOCNO_COVER_CLASS (parent_a));
-               ira_allocate_and_accumulate_costs
-                 (&ALLOCNO_HARD_REG_COSTS (parent_a), cover_class,
-                  ALLOCNO_HARD_REG_COSTS (a));
-               ira_allocate_and_accumulate_costs
-                 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a),
-                  cover_class,
-                  ALLOCNO_CONFLICT_HARD_REG_COSTS (a));
-               ALLOCNO_COVER_CLASS_COST (parent_a)
-                 += ALLOCNO_COVER_CLASS_COST (a);
-               ALLOCNO_MEMORY_COST (parent_a) += ALLOCNO_MEMORY_COST (a);
-               finish_allocno (a);
-             }
-         }
-      }
+       }
+      else
+       finish_allocno (a);
+    }
   if (merged_p)
     ira_rebuild_start_finish_chains ();
 }
 
-/* Remove loops from consideration.  We remove loops for which a
-   separate allocation will not improve the result.  We have to do
-   this after allocno creation and their costs and cover class
-   evaluation because only after that the register pressure can be
-   known and is calculated.  */
+/* Remove loops from consideration.  We remove all loops except for
+   root if ALL_P or loops for which a separate allocation will not
+   improve the result.  We have to do this after allocno creation and
+   their costs and cover class evaluation because only after that the
+   register pressure can be known and is calculated.  */
 static void
-remove_unnecessary_regions (void)
+remove_unnecessary_regions (bool all_p)
 {
-  mark_loops_for_removal ();
+  if (all_p)
+    mark_all_loops_for_removal ();
+  else
+    mark_loops_for_removal ();
   children_vec
     = VEC_alloc (ira_loop_tree_node_t, heap,
                 last_basic_block + VEC_length (loop_p, ira_loops.larray));
@@ -1913,7 +2092,10 @@ remove_unnecessary_regions (void)
                 last_basic_block + VEC_length (loop_p, ira_loops.larray));
   remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_root) ;
   VEC_free (ira_loop_tree_node_t, heap, children_vec);
-  remove_unnecessary_allocnos ();
+  if (all_p)
+    remove_low_level_allocnos ();
+  else
+    remove_unnecessary_allocnos ();
   while (VEC_length (ira_loop_tree_node_t, removed_loop_vec) > 0)
     finish_loop_tree_node (VEC_pop (ira_loop_tree_node_t, removed_loop_vec));
   VEC_free (ira_loop_tree_node_t, heap, removed_loop_vec);
@@ -2044,9 +2226,10 @@ setup_min_max_allocno_live_range_point (void)
 }
 
 /* Sort allocnos according to their live ranges.  Allocnos with
-   smaller cover class are put first.  Allocnos with the same cove
-   class are ordered according their start (min).  Allocnos with the
-   same start are ordered according their finish (max).  */
+   smaller cover class are put first unless we use priority coloring.
+   Allocnos with the same cove class are ordered according their start
+   (min).  Allocnos with the same start are ordered according their
+   finish (max).  */
 static int
 allocno_range_compare_func (const void *v1p, const void *v2p)
 {
@@ -2054,7 +2237,8 @@ allocno_range_compare_func (const void *v1p, const void *v2p)
   ira_allocno_t a1 = *(const ira_allocno_t *) v1p;
   ira_allocno_t a2 = *(const ira_allocno_t *) v2p;
 
-  if ((diff = ALLOCNO_COVER_CLASS (a1) - ALLOCNO_COVER_CLASS (a2)) != 0)
+  if (flag_ira_algorithm != IRA_ALGORITHM_PRIORITY
+      && (diff = ALLOCNO_COVER_CLASS (a1) - ALLOCNO_COVER_CLASS (a2)) != 0)
     return diff;
   if ((diff = ALLOCNO_MIN (a1) - ALLOCNO_MIN (a2)) != 0)
     return diff;
@@ -2089,7 +2273,7 @@ sort_conflict_id_allocno_map (void)
 static void
 setup_min_max_conflict_allocno_ids (void)
 {
-  enum reg_class cover_class;
+  int cover_class;
   int i, j, min, max, start, finish, first_not_finished, filled_area_start;
   int *live_range_min, *last_lived;
   ira_allocno_t a;
@@ -2102,7 +2286,9 @@ setup_min_max_conflict_allocno_ids (void)
       a = ira_conflict_id_allocno_map[i];
       if (a == NULL)
        continue;
-      if (cover_class != ALLOCNO_COVER_CLASS (a))
+      if (cover_class < 0
+         || (flag_ira_algorithm != IRA_ALGORITHM_PRIORITY
+             && cover_class != (int) ALLOCNO_COVER_CLASS (a)))
        {
          cover_class = ALLOCNO_COVER_CLASS (a);
          min = i;
@@ -2120,7 +2306,7 @@ setup_min_max_conflict_allocno_ids (void)
                                         [first_not_finished]))
            first_not_finished++;
          min = first_not_finished;
-       }         
+       }
       if (min == i)
        /* We could increase min further in this case but it is good
           enough.  */
@@ -2136,7 +2322,9 @@ setup_min_max_conflict_allocno_ids (void)
       a = ira_conflict_id_allocno_map[i];
       if (a == NULL)
        continue;
-      if (cover_class != ALLOCNO_COVER_CLASS (a))
+      if (cover_class < 0
+         || (flag_ira_algorithm != IRA_ALGORITHM_PRIORITY
+             && cover_class != (int) ALLOCNO_COVER_CLASS (a)))
        {
          cover_class = ALLOCNO_COVER_CLASS (a);
          for (j = 0; j < ira_max_point; j++)
@@ -2210,7 +2398,8 @@ static ira_allocno_t *regno_top_level_allocno_map;
 static bool
 copy_info_to_removed_store_destinations (int regno)
 {
-  ira_allocno_t a, parent_a;
+  ira_allocno_t a;
+  ira_allocno_t parent_a = NULL;
   ira_loop_tree_node_t parent;
   allocno_live_range_t r;
   bool merged_p;
@@ -2327,7 +2516,7 @@ ira_flattening (int max_regno_before_emit, int ira_max_point_before_emit)
              continue;
            }
          ira_assert (ALLOCNO_CAP_MEMBER (parent_a) == NULL);
-         
+
          if (ALLOCNO_MEM_OPTIMIZED_DEST (a) != NULL)
            mem_dest_p = true;
          if (REGNO (ALLOCNO_REG (a)) == REGNO (ALLOCNO_REG (parent_a)))
@@ -2431,13 +2620,14 @@ ira_flattening (int max_regno_before_emit, int ira_max_point_before_emit)
                {
                  ira_allocno_t live_a = ira_allocnos[n];
 
-                 if (cover_class == ALLOCNO_COVER_CLASS (live_a)
+                 if (ira_reg_classes_intersect_p
+                     [cover_class][ALLOCNO_COVER_CLASS (live_a)]
                      /* Don't set up conflict for the allocno with itself.  */
                      && num != (int) n)
                    ira_add_allocno_conflict (a, live_a);
                }
            }
-         
+
          for (r = ira_finish_point_ranges[i]; r != NULL; r = r->finish_next)
            sparseset_clear_bit (allocnos_live, ALLOCNO_NUM (r->allocno));
        }
@@ -2589,7 +2779,7 @@ ira_build (bool loops_p)
   create_allocnos ();
   ira_costs ();
   ira_create_allocno_live_ranges ();
-  remove_unnecessary_regions ();
+  remove_unnecessary_regions (false);
   ira_compress_allocno_live_ranges ();
   update_bad_spill_attribute ();
   loops_p = more_one_region_p ();
@@ -2606,6 +2796,29 @@ ira_build (bool loops_p)
   sort_conflict_id_allocno_map ();
   setup_min_max_conflict_allocno_ids ();
   ira_build_conflicts ();
+  if (! ira_conflicts_p)
+    {
+      ira_allocno_t a;
+      ira_allocno_iterator ai;
+
+      /* Remove all regions but root one.  */
+      if (loops_p)
+       {
+         remove_unnecessary_regions (true);
+         loops_p = false;
+       }
+      /* We don't save hard registers around calls for fast allocation
+        -- add caller clobbered registers as conflicting ones to
+        allocno crossing calls.  */
+      FOR_EACH_ALLOCNO (a, ai)
+       if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
+         {
+           IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a),
+                             call_used_reg_set);
+           IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
+                             call_used_reg_set);
+         }
+    }
   if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
     print_copies (ira_dump_file);
   if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)