OSDN Git Service

2009-10-19 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
[pf3gnuchains/gcc-fork.git] / gcc / ira-conflicts.c
index 9bdc3e7..6d84e56 100644 (file)
@@ -1,5 +1,5 @@
 /* IRA conflict builder.
-   Copyright (C) 2006, 2007, 2008
+   Copyright (C) 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
 
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "df.h"
 #include "sparseset.h"
 #include "ira-int.h"
+#include "addresses.h"
 
 /* This file contains code responsible for allocno conflict creation,
    allocno copy creation and allocno info accumulation on upper level
@@ -60,8 +61,10 @@ static IRA_INT_TYPE **conflicts;
 
 \f
 
-/* Build allocno conflict table by processing allocno live ranges.  */
-static void
+/* Build allocno conflict table by processing allocno live ranges.
+   Return true if the table was built.  The table is not built if it
+   is too big.  */
+static bool
 build_conflict_bit_table (void)
 {
   int i, num, id, allocated_words_num, conflict_bit_vec_words_num;
@@ -74,6 +77,26 @@ build_conflict_bit_table (void)
   int allocno_set_words;
 
   allocno_set_words = (ira_allocnos_num + IRA_INT_BITS - 1) / IRA_INT_BITS;
+  allocated_words_num = 0;
+  FOR_EACH_ALLOCNO (allocno, ai)
+    {
+      if (ALLOCNO_MAX (allocno) < ALLOCNO_MIN (allocno))
+         continue;
+      conflict_bit_vec_words_num
+       = ((ALLOCNO_MAX (allocno) - ALLOCNO_MIN (allocno) + IRA_INT_BITS)
+          / IRA_INT_BITS);
+      allocated_words_num += conflict_bit_vec_words_num;
+      if ((unsigned long long) allocated_words_num * sizeof (IRA_INT_TYPE)
+         > (unsigned long long) IRA_MAX_CONFLICT_TABLE_SIZE * 1024 * 1024)
+       {
+         if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
+           fprintf
+             (ira_dump_file,
+              "+++Conflict table will be too big(>%dMB) -- don't use it\n",
+              IRA_MAX_CONFLICT_TABLE_SIZE);
+         return false;
+       }
+    }
   allocnos_live = sparseset_alloc (ira_allocnos_num);
   conflicts = (IRA_INT_TYPE **) ira_allocate (sizeof (IRA_INT_TYPE *)
                                              * ira_allocnos_num);
@@ -114,7 +137,8 @@ build_conflict_bit_table (void)
          EXECUTE_IF_SET_IN_SPARSESET (allocnos_live, j)
            {
              live_a = ira_allocnos[j];
-             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) j)
                {
@@ -133,6 +157,7 @@ build_conflict_bit_table (void)
        sparseset_clear_bit (allocnos_live, ALLOCNO_NUM (r->allocno));
     }
   sparseset_free (allocnos_live);
+  return true;
 }
 
 \f
@@ -223,12 +248,10 @@ get_dup_num (int op_num, bool use_commut_op_p)
            break;
 
          case 'p':
-           GO_IF_LEGITIMATE_ADDRESS (VOIDmode, op, win_p);
+           if (address_operand (op, VOIDmode))
+             return -1;
            break;
-           
-         win_p:
-           return -1;
-         
+
          case 'g':
            return -1;
            
@@ -329,7 +352,8 @@ go_through_subreg (rtx x, int *offset)
    registers.  When nothing is changed, the function returns
    FALSE.  */
 static bool
-process_regs_for_copy (rtx reg1, rtx reg2, rtx insn, int freq)
+process_regs_for_copy (rtx reg1, rtx reg2, bool constraint_p,
+                      rtx insn, int freq)
 {
   int allocno_preferenced_hard_regno, cost, index, offset1, offset2;
   bool only_regs_p;
@@ -337,6 +361,7 @@ process_regs_for_copy (rtx reg1, rtx reg2, rtx insn, int freq)
   enum reg_class rclass, cover_class;
   enum machine_mode mode;
   ira_copy_t cp;
+  ira_loop_tree_node_t parent;
 
   gcc_assert (REG_SUBREG_P (reg1) && REG_SUBREG_P (reg2));
   only_regs_p = REG_P (reg1) && REG_P (reg2);
@@ -362,7 +387,8 @@ process_regs_for_copy (rtx reg1, rtx reg2, rtx insn, int freq)
     {
       cp = ira_add_allocno_copy (ira_curr_regno_allocno_map[REGNO (reg1)],
                                 ira_curr_regno_allocno_map[REGNO (reg2)],
-                                freq, insn, ira_curr_loop_tree_node);
+                                freq, constraint_p, insn,
+                                ira_curr_loop_tree_node);
       bitmap_set_bit (ira_curr_loop_tree_node->local_copies, cp->num); 
       return true;
     }
@@ -383,16 +409,26 @@ process_regs_for_copy (rtx reg1, rtx reg2, rtx insn, int freq)
     /* Can not be tied.  It is not in the cover class.  */
     return false;
   if (HARD_REGISTER_P (reg1))
-    cost = ira_register_move_cost[mode][cover_class][rclass] * freq;
+    cost = ira_get_register_move_cost (mode, cover_class, rclass) * freq;
   else
-    cost = ira_register_move_cost[mode][rclass][cover_class] * freq;
-  ira_allocate_and_set_costs
-    (&ALLOCNO_HARD_REG_COSTS (a), cover_class,
-     ALLOCNO_COVER_CLASS_COST (a));
-  ira_allocate_and_set_costs
-    (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a), cover_class, 0);
-  ALLOCNO_HARD_REG_COSTS (a)[index] -= cost;
-  ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index] -= cost;
+    cost = ira_get_register_move_cost (mode, rclass, cover_class) * freq;
+  for (;;)
+    {
+      ira_allocate_and_set_costs
+       (&ALLOCNO_HARD_REG_COSTS (a), cover_class,
+        ALLOCNO_COVER_CLASS_COST (a));
+      ira_allocate_and_set_costs
+       (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a), cover_class, 0);
+      ALLOCNO_HARD_REG_COSTS (a)[index] -= cost;
+      ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index] -= cost;
+      if (ALLOCNO_HARD_REG_COSTS (a)[index] < ALLOCNO_COVER_CLASS_COST (a))
+       ALLOCNO_COVER_CLASS_COST (a) = ALLOCNO_HARD_REG_COSTS (a)[index];
+      if (ALLOCNO_CAP (a) != NULL)
+       a = ALLOCNO_CAP (a);
+      else if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL
+              || (a = parent->regno_allocno_map[ALLOCNO_REGNO (a)]) == NULL)
+       break;
+    }
   return true;
 }
 
@@ -415,7 +451,7 @@ process_reg_shuffles (rtx reg, int op_num, int freq)
          || recog_data.operand_type[i] != OP_OUT)
        continue;
       
-      process_regs_for_copy (reg, another_reg, NULL_RTX, freq);
+      process_regs_for_copy (reg, another_reg, false, NULL_RTX, freq);
     }
 }
 
@@ -440,7 +476,7 @@ add_insn_allocno_copies (rtx insn)
                        REG_P (SET_SRC (set))
                        ? SET_SRC (set)
                        : SUBREG_REG (SET_SRC (set))) != NULL_RTX)
-    process_regs_for_copy (SET_DEST (set), SET_SRC (set), insn, freq);
+    process_regs_for_copy (SET_DEST (set), SET_SRC (set), false, insn, freq);
   else
     {
       extract_insn (insn);
@@ -453,13 +489,14 @@ add_insn_allocno_copies (rtx insn)
                                ? operand : SUBREG_REG (operand)) != NULL_RTX)
            {
              str = recog_data.constraints[i];
-             while (*str == ' ' && *str == '\t')
+             while (*str == ' ' || *str == '\t')
                str++;
              bound_p = false;
              for (j = 0, commut_p = false; j < 2; j++, commut_p = true)
                if ((dup = get_dup (i, commut_p)) != NULL_RTX
                    && REG_SUBREG_P (dup)
-                   && process_regs_for_copy (operand, dup, NULL_RTX, freq))
+                   && process_regs_for_copy (operand, dup, true,
+                                             NULL_RTX, freq))
                  bound_p = true;
              if (bound_p)
                continue;
@@ -485,7 +522,7 @@ add_copies (ira_loop_tree_node_t loop_tree_node)
   if (bb == NULL)
     return;
   FOR_BB_INSNS (bb, insn)
-    if (INSN_P (insn))
+    if (NONDEBUG_INSN_P (insn))
       add_insn_allocno_copies (insn);
 }
 
@@ -513,57 +550,11 @@ propagate_copies (void)
        parent_a2 = parent->regno_allocno_map[ALLOCNO_REGNO (a2)];
       ira_assert (parent_a1 != NULL && parent_a2 != NULL);
       if (! CONFLICT_ALLOCNO_P (parent_a1, parent_a2))
-       ira_add_allocno_copy (parent_a1, parent_a1, cp->freq,
-                             cp->insn, cp->loop_tree_node);
+       ira_add_allocno_copy (parent_a1, parent_a2, cp->freq,
+                             cp->constraint_p, cp->insn, cp->loop_tree_node);
     }
 }
 
-/* Return TRUE if live ranges of allocnos A1 and A2 intersect.  It is
-   used to find a conflict for new allocnos or allocnos with the
-   different cover classes.  */
-bool
-ira_allocno_live_ranges_intersect_p (ira_allocno_t a1, ira_allocno_t a2)
-{
-  allocno_live_range_t r1, r2;
-
-  if (a1 == a2)
-    return false;
-  if (ALLOCNO_REG (a1) != NULL && ALLOCNO_REG (a2) != NULL
-      && (ORIGINAL_REGNO (ALLOCNO_REG (a1))
-         == ORIGINAL_REGNO (ALLOCNO_REG (a2))))
-    return false;
-  /* Remember the ranges are always kept ordered.  */
-  for (r1 = ALLOCNO_LIVE_RANGES (a1), r2 = ALLOCNO_LIVE_RANGES (a2);
-       r1 != NULL && r2 != NULL;)
-    {
-      if (r1->start > r2->finish)
-       r1 = r1->next;
-      else if (r2->start > r1->finish)
-       r2 = r2->next;
-      else
-       return true;
-    }
-  return false;
-}
-
-/* Return TRUE if live ranges of pseudo-registers REGNO1 and REGNO2
-   intersect.  This should be used when there is only one region.
-   Currently this is used during reload.  */
-bool
-ira_pseudo_live_ranges_intersect_p (int regno1, int regno2)
-{
-  ira_allocno_t a1, a2;
-
-  ira_assert (regno1 >= FIRST_PSEUDO_REGISTER
-             && regno2 >= FIRST_PSEUDO_REGISTER);
-  /* Reg info caclulated by dataflow infrastructure can be different
-     from one calculated by regclass.  */
-  if ((a1 = ira_loop_tree_root->regno_allocno_map[regno1]) == NULL
-      || (a2 = ira_loop_tree_root->regno_allocno_map[regno2]) == NULL)
-    return false;
-  return ira_allocno_live_ranges_intersect_p (a1, a2);
-}
-
 /* Array used to collect all conflict allocnos for given allocno.  */
 static ira_allocno_t *collected_conflict_allocnos;
 
@@ -587,8 +578,8 @@ build_allocno_conflicts (ira_allocno_t a)
                           ALLOCNO_MIN (a), ALLOCNO_MAX (a), i, asi)
     {
       another_a = ira_conflict_id_allocno_map[i];
-      ira_assert (ALLOCNO_COVER_CLASS (a)
-                 == ALLOCNO_COVER_CLASS (another_a));
+      ira_assert (ira_reg_classes_intersect_p
+                 [ALLOCNO_COVER_CLASS (a)][ALLOCNO_COVER_CLASS (another_a)]);
       collected_conflict_allocnos[px++] = another_a;
     }
   if (ira_conflict_vector_profitable_p (a, px))
@@ -624,8 +615,8 @@ build_allocno_conflicts (ira_allocno_t a)
                           ALLOCNO_MIN (a), ALLOCNO_MAX (a), i, asi)
     {
       another_a = ira_conflict_id_allocno_map[i];
-      ira_assert (ALLOCNO_COVER_CLASS (a)
-                 == ALLOCNO_COVER_CLASS (another_a));
+      ira_assert (ira_reg_classes_intersect_p
+                 [ALLOCNO_COVER_CLASS (a)][ALLOCNO_COVER_CLASS (another_a)]);
       if ((another_parent_a = ALLOCNO_CAP (another_a)) == NULL
          && (another_parent_a = (parent->regno_allocno_map
                                  [ALLOCNO_REGNO (another_a)])) == NULL)
@@ -671,7 +662,7 @@ print_hard_reg_set (FILE *file, const char *title, HARD_REG_SET set)
 {
   int i, start;
 
-  fprintf (file, title);
+  fputs (title, file);
   for (start = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
     {
       if (TEST_HARD_REG_BIT (set, i))
@@ -691,7 +682,7 @@ print_hard_reg_set (FILE *file, const char *title, HARD_REG_SET set)
          start = -1;
        }
     }
-  fprintf (file, "\n");
+  putc ('\n', file);
 }
 
 /* Print information about allocno or only regno (if REG_P) conflicts
@@ -718,9 +709,9 @@ print_conflicts (FILE *file, bool reg_p)
            fprintf (file, "b%d", bb->index);
          else
            fprintf (file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop->num);
-         fprintf (file, ")");
+         putc (')', file);
        }
-      fprintf (file, " conflicts:");
+      fputs (" conflicts:", file);
       if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY (a) != NULL)
        FOR_EACH_ALLOCNO_CONFLICT (a, conflict_a, aci)
          {
@@ -752,7 +743,7 @@ print_conflicts (FILE *file, bool reg_p)
       print_hard_reg_set (file, ";;     conflict hard regs:",
                          conflicting_hard_regs);
     }
-  fprintf (file, "\n");
+  putc ('\n', file);
 }
 
 /* Print information about allocno or only regno (if REG_P) conflicts
@@ -772,46 +763,71 @@ ira_build_conflicts (void)
 {
   ira_allocno_t a;
   ira_allocno_iterator ai;
+  HARD_REG_SET temp_hard_reg_set;
 
-  if (optimize)
+  if (ira_conflicts_p)
     {
-      build_conflict_bit_table ();
-      build_conflicts ();
-      ira_traverse_loop_tree (true, ira_loop_tree_root, NULL, add_copies);
-      /* We need finished conflict table for the subsequent call.  */
-      if (flag_ira_algorithm == IRA_ALGORITHM_REGIONAL
-         || flag_ira_algorithm == IRA_ALGORITHM_MIXED)
-       propagate_copies ();
-      /* Now we can free memory for the conflict table (see function
-        build_allocno_conflicts for details).  */
-      FOR_EACH_ALLOCNO (a, ai)
+      ira_conflicts_p = build_conflict_bit_table ();
+      if (ira_conflicts_p)
        {
-         if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY (a) != conflicts[ALLOCNO_NUM (a)])
-           ira_free (conflicts[ALLOCNO_NUM (a)]);
+         build_conflicts ();
+         ira_traverse_loop_tree (true, ira_loop_tree_root, NULL, add_copies);
+         /* We need finished conflict table for the subsequent call.  */
+         if (flag_ira_region == IRA_REGION_ALL
+             || flag_ira_region == IRA_REGION_MIXED)
+           propagate_copies ();
+         /* Now we can free memory for the conflict table (see function
+            build_allocno_conflicts for details).  */
+         FOR_EACH_ALLOCNO (a, ai)
+           {
+             if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY (a)
+                 != conflicts[ALLOCNO_NUM (a)])
+               ira_free (conflicts[ALLOCNO_NUM (a)]);
+           }
+         ira_free (conflicts);
        }
-      ira_free (conflicts);
+    }
+  if (! CLASS_LIKELY_SPILLED_P (base_reg_class (VOIDmode, ADDRESS, SCRATCH)))
+    CLEAR_HARD_REG_SET (temp_hard_reg_set);
+  else
+    {
+      COPY_HARD_REG_SET (temp_hard_reg_set,
+                        reg_class_contents[base_reg_class (VOIDmode, ADDRESS, SCRATCH)]);
+      AND_COMPL_HARD_REG_SET (temp_hard_reg_set, ira_no_alloc_regs);
+      AND_HARD_REG_SET (temp_hard_reg_set, call_used_reg_set);
     }
   FOR_EACH_ALLOCNO (a, ai)
     {
-      if (ALLOCNO_CALLS_CROSSED_NUM (a) == 0)
-       continue;
-      if (! flag_caller_saves)
+      reg_attrs *attrs;
+      tree decl;
+
+      if ((! flag_caller_saves && ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
+         /* For debugging purposes don't put user defined variables in
+            callee-clobbered registers.  */
+         || (optimize == 0
+             && (attrs = REG_ATTRS (regno_reg_rtx [ALLOCNO_REGNO (a)])) != NULL
+             && (decl = attrs->decl) != NULL
+             && VAR_OR_FUNCTION_DECL_P (decl)
+             && ! DECL_ARTIFICIAL (decl)))
        {
          IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a),
                            call_used_reg_set);
-         if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
-           IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
-                             call_used_reg_set);
+         IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
+                           call_used_reg_set);
        }
-      else
+      else if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
        {
          IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a),
                            no_caller_save_reg_set);
-         if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
-           IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
-                             no_caller_save_reg_set);
+         IOR_HARD_REG_SET (ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a),
+                           temp_hard_reg_set);
+         IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
+                           no_caller_save_reg_set);
+         IOR_HARD_REG_SET (ALLOCNO_CONFLICT_HARD_REGS (a),
+                           temp_hard_reg_set);
        }
     }
-  if (optimize && internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
+  if (optimize && ira_conflicts_p
+      && internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
     print_conflicts (ira_dump_file, false);
 }