OSDN Git Service

* config/mips/mips.c (TARGET_SMALL_REGISTER_CLASSES_FOR_MODE_P): Undef.
[pf3gnuchains/gcc-fork.git] / gcc / ira-conflicts.c
index 6e7d769..70100ac 100644 (file)
@@ -1,5 +1,5 @@
 /* IRA conflict builder.
-   Copyright (C) 2006, 2007, 2008
+   Copyright (C) 2006, 2007, 2008, 2009, 2010
    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)
                {
@@ -128,11 +152,12 @@ build_conflict_bit_table (void)
                }
            }
        }
-         
+
       for (r = ira_finish_point_ranges[i]; r != NULL; r = r->finish_next)
        sparseset_clear_bit (allocnos_live, ALLOCNO_NUM (r->allocno));
     }
   sparseset_free (allocnos_live);
+  return true;
 }
 
 \f
@@ -210,7 +235,7 @@ get_dup_num (int op_num, bool use_commut_op_p)
          {
          case 'X':
            return -1;
-           
+
          case 'm':
          case 'o':
            /* Accept a register which might be placed in memory.  */
@@ -223,15 +248,13 @@ 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;
-           
+
          case 'r':
          case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
          case 'h': case 'j': case 'k': case 'l':
@@ -253,7 +276,7 @@ get_dup_num (int op_num, bool use_commut_op_p)
 #endif
              break;
            }
-           
+
          case '0': case '1': case '2': case '3': case '4':
          case '5': case '6': case '7': case '8': case '9':
            if (original != -1 && original != c)
@@ -279,21 +302,6 @@ get_dup_num (int op_num, bool use_commut_op_p)
   return dup;
 }
 
-/* Return the operand which should be, in any case, the same as
-   operand with number OP_NUM.  If USE_COMMUT_OP_P is TRUE, the
-   function makes temporarily commutative operand exchange before
-   this.  */
-static rtx
-get_dup (int op_num, bool use_commut_op_p)
-{
-  int n = get_dup_num (op_num, use_commut_op_p);
-
-  if (n < 0)
-    return NULL_RTX;
-  else
-    return recog_data.operand[n];
-}
-
 /* Check that X is REG or SUBREG of REG.  */
 #define REG_SUBREG_P(x)                                                        \
    (REG_P (x) || (GET_CODE (x) == SUBREG && REG_P (SUBREG_REG (x))))
@@ -366,7 +374,7 @@ process_regs_for_copy (rtx reg1, rtx reg2, bool constraint_p,
                                 ira_curr_regno_allocno_map[REGNO (reg2)],
                                 freq, constraint_p, insn,
                                 ira_curr_loop_tree_node);
-      bitmap_set_bit (ira_curr_loop_tree_node->local_copies, cp->num); 
+      bitmap_set_bit (ira_curr_loop_tree_node->local_copies, cp->num);
       return true;
     }
   else
@@ -386,9 +394,9 @@ process_regs_for_copy (rtx reg1, rtx reg2, bool constraint_p,
     /* 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;
+    cost = ira_get_register_move_cost (mode, rclass, cover_class) * freq;
   for (;;)
     {
       ira_allocate_and_set_costs
@@ -409,12 +417,12 @@ process_regs_for_copy (rtx reg1, rtx reg2, bool constraint_p,
   return true;
 }
 
-/* Process all of the output registers of the current insn and
-   the input register REG (its operand number OP_NUM) which dies in the
-   insn as if there were a move insn between them with frequency
-   FREQ.  */
+/* Process all of the output registers of the current insn which are
+   not bound (BOUND_P) and the input register REG (its operand number
+   OP_NUM) which dies in the insn as if there were a move insn between
+   them with frequency FREQ.  */
 static void
-process_reg_shuffles (rtx reg, int op_num, int freq)
+process_reg_shuffles (rtx reg, int op_num, int freq, bool *bound_p)
 {
   int i;
   rtx another_reg;
@@ -423,11 +431,12 @@ process_reg_shuffles (rtx reg, int op_num, int freq)
   for (i = 0; i < recog_data.n_operands; i++)
     {
       another_reg = recog_data.operand[i];
-      
+
       if (!REG_SUBREG_P (another_reg) || op_num == i
-         || recog_data.operand_type[i] != OP_OUT)
+         || recog_data.operand_type[i] != OP_OUT
+         || bound_p[i])
        continue;
-      
+
       process_regs_for_copy (reg, another_reg, false, NULL_RTX, freq);
     }
 }
@@ -440,8 +449,8 @@ add_insn_allocno_copies (rtx insn)
 {
   rtx set, operand, dup;
   const char *str;
-  bool commut_p, bound_p;
-  int i, j, freq;
+  bool commut_p, bound_p[MAX_RECOG_OPERANDS];
+  int i, j, n, freq;
   
   freq = REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn));
   if (freq == 0)
@@ -453,38 +462,51 @@ 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), false, insn, freq);
-  else
     {
-      extract_insn (insn);
-      for (i = 0; i < recog_data.n_operands; i++)
-       {
-         operand = recog_data.operand[i];
-         if (REG_SUBREG_P (operand)
-             && find_reg_note (insn, REG_DEAD,
-                               REG_P (operand)
-                               ? operand : SUBREG_REG (operand)) != NULL_RTX)
-           {
-             str = recog_data.constraints[i];
-             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, true,
-                                             NULL_RTX, freq))
-                 bound_p = true;
-             if (bound_p)
-               continue;
-             /* If an operand dies, prefer its hard register for the
-                output operands by decreasing the hard register cost
-                or creating the corresponding allocno copies.  The
-                cost will not correspond to a real move insn cost, so
-                make the frequency smaller.  */
-             process_reg_shuffles (operand, i, freq < 8 ? 1 : freq / 8);
-           }
-       }
+      process_regs_for_copy (SET_DEST (set), SET_SRC (set), false, insn, freq);
+      return;
+    }
+  /* Fast check of possibility of constraint or shuffle copies.  If
+     there are no dead registers, there will be no such copies.  */
+  if (! find_reg_note (insn, REG_DEAD, NULL_RTX))
+    return;
+  extract_insn (insn);
+  for (i = 0; i < recog_data.n_operands; i++)
+    bound_p[i] = false;
+  for (i = 0; i < recog_data.n_operands; i++)
+    {
+      operand = recog_data.operand[i];
+      if (! REG_SUBREG_P (operand))
+       continue;
+      str = recog_data.constraints[i];
+      while (*str == ' ' || *str == '\t')
+       str++;
+      for (j = 0, commut_p = false; j < 2; j++, commut_p = true)
+       if ((n = get_dup_num (i, commut_p)) >= 0)
+         {
+           bound_p[n] = true;
+           dup = recog_data.operand[n];
+           if (REG_SUBREG_P (dup)
+               && find_reg_note (insn, REG_DEAD,
+                                 REG_P (operand)
+                                 ? operand
+                                 : SUBREG_REG (operand)) != NULL_RTX)
+             process_regs_for_copy (operand, dup, true, NULL_RTX, freq);
+         }
+    }
+  for (i = 0; i < recog_data.n_operands; i++)
+    {
+      operand = recog_data.operand[i];
+      if (REG_SUBREG_P (operand)
+         && find_reg_note (insn, REG_DEAD,
+                           REG_P (operand)
+                           ? operand : SUBREG_REG (operand)) != NULL_RTX)
+       /* If an operand dies, prefer its hard register for the output
+          operands by decreasing the hard register cost or creating
+          the corresponding allocno copies.  The cost will not
+          correspond to a real move insn cost, so make the frequency
+          smaller.  */
+       process_reg_shuffles (operand, i, freq < 8 ? 1 : freq / 8, bound_p);
     }
 }
 
@@ -499,7 +521,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);
 }
 
@@ -555,8 +577,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))
@@ -592,8 +614,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)
@@ -639,7 +661,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))
@@ -659,7 +681,60 @@ print_hard_reg_set (FILE *file, const char *title, HARD_REG_SET set)
          start = -1;
        }
     }
-  fprintf (file, "\n");
+  putc ('\n', file);
+}
+
+static void
+print_allocno_conflicts (FILE * file, bool reg_p, ira_allocno_t a)
+{
+  HARD_REG_SET conflicting_hard_regs;
+  ira_allocno_t conflict_a;
+  ira_allocno_conflict_iterator aci;
+  basic_block bb;
+
+  if (reg_p)
+    fprintf (file, ";; r%d", ALLOCNO_REGNO (a));
+  else
+    {
+      fprintf (file, ";; a%d(r%d,", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
+      if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
+        fprintf (file, "b%d", bb->index);
+      else
+        fprintf (file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop->num);
+      putc (')', file);
+    }
+  fputs (" conflicts:", file);
+  if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY (a) != NULL)
+    FOR_EACH_ALLOCNO_CONFLICT (a, conflict_a, aci)
+      {
+        if (reg_p)
+          fprintf (file, " r%d,", ALLOCNO_REGNO (conflict_a));
+        else
+          {
+           fprintf (file, " a%d(r%d,", ALLOCNO_NUM (conflict_a),
+                    ALLOCNO_REGNO (conflict_a));
+           if ((bb = ALLOCNO_LOOP_TREE_NODE (conflict_a)->bb) != NULL)
+             fprintf (file, "b%d)", bb->index);
+           else
+             fprintf (file, "l%d)",
+                      ALLOCNO_LOOP_TREE_NODE (conflict_a)->loop->num);
+         }
+      }
+  COPY_HARD_REG_SET (conflicting_hard_regs,
+                    ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a));
+  AND_COMPL_HARD_REG_SET (conflicting_hard_regs, ira_no_alloc_regs);
+  AND_HARD_REG_SET (conflicting_hard_regs,
+                   reg_class_contents[ALLOCNO_COVER_CLASS (a)]);
+  print_hard_reg_set (file, "\n;;     total conflict hard regs:",
+                     conflicting_hard_regs);
+  COPY_HARD_REG_SET (conflicting_hard_regs,
+                    ALLOCNO_CONFLICT_HARD_REGS (a));
+  AND_COMPL_HARD_REG_SET (conflicting_hard_regs, ira_no_alloc_regs);
+  AND_HARD_REG_SET (conflicting_hard_regs,
+                   reg_class_contents[ALLOCNO_COVER_CLASS (a)]);
+  print_hard_reg_set (file, ";;     conflict hard regs:",
+                     conflicting_hard_regs);
+  putc ('\n', file);
 }
 
 /* Print information about allocno or only regno (if REG_P) conflicts
@@ -669,58 +744,9 @@ print_conflicts (FILE *file, bool reg_p)
 {
   ira_allocno_t a;
   ira_allocno_iterator ai;
-  HARD_REG_SET conflicting_hard_regs;
 
   FOR_EACH_ALLOCNO (a, ai)
-    {
-      ira_allocno_t conflict_a;
-      ira_allocno_conflict_iterator aci;
-      basic_block bb;
-
-      if (reg_p)
-       fprintf (file, ";; r%d", ALLOCNO_REGNO (a));
-      else
-       {
-         fprintf (file, ";; a%d(r%d,", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
-         if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
-           fprintf (file, "b%d", bb->index);
-         else
-           fprintf (file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop->num);
-         fprintf (file, ")");
-       }
-      fprintf (file, " conflicts:");
-      if (ALLOCNO_CONFLICT_ALLOCNO_ARRAY (a) != NULL)
-       FOR_EACH_ALLOCNO_CONFLICT (a, conflict_a, aci)
-         {
-           if (reg_p)
-             fprintf (file, " r%d,", ALLOCNO_REGNO (conflict_a));
-           else
-             {
-               fprintf (file, " a%d(r%d,", ALLOCNO_NUM (conflict_a),
-                        ALLOCNO_REGNO (conflict_a));
-               if ((bb = ALLOCNO_LOOP_TREE_NODE (conflict_a)->bb) != NULL)
-                 fprintf (file, "b%d)", bb->index);
-               else
-                 fprintf (file, "l%d)",
-                          ALLOCNO_LOOP_TREE_NODE (conflict_a)->loop->num);
-             }
-         }
-      COPY_HARD_REG_SET (conflicting_hard_regs,
-                        ALLOCNO_TOTAL_CONFLICT_HARD_REGS (a));
-      AND_COMPL_HARD_REG_SET (conflicting_hard_regs, ira_no_alloc_regs);
-      AND_HARD_REG_SET (conflicting_hard_regs,
-                       reg_class_contents[ALLOCNO_COVER_CLASS (a)]);
-      print_hard_reg_set (file, "\n;;     total conflict hard regs:",
-                         conflicting_hard_regs);
-      COPY_HARD_REG_SET (conflicting_hard_regs,
-                        ALLOCNO_CONFLICT_HARD_REGS (a));
-      AND_COMPL_HARD_REG_SET (conflicting_hard_regs, ira_no_alloc_regs);
-      AND_HARD_REG_SET (conflicting_hard_regs,
-                       reg_class_contents[ALLOCNO_COVER_CLASS (a)]);
-      print_hard_reg_set (file, ";;     conflict hard regs:",
-                         conflicting_hard_regs);
-    }
-  fprintf (file, "\n");
+    print_allocno_conflicts (file, reg_p, a);
 }
 
 /* Print information about allocno or only regno (if REG_P) conflicts
@@ -740,46 +766,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);
 }