This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[ira] patch to speed IRA up


The following patch removes regclass call and rebuilds IR only when we used regional register allocation in function with loops. It speeds IRA up.

2006-12-22 Vladimir Makarov <vmakarov@redhat.com>

	* rtl.h (setup_reg_classes): New function prototype.
	
	* regclass.c (setup_reg_classes): New function.

	* global.c (global_alloc): Dump information about register
	assigning.

* ira-int.h (ira_build): Change prototype signature.

	* ira-color.c (pseudo_compare_func): Rename to
	pseudo_priority_compare_func.
	(priority_coloring): Dump information about register
	assigning.

	* ira-build.c (ira_build): Return true if we have loops for the
	allocation.

	* ira.c (setup_preferred_alternate_classes): New function.
	(ira): Use it instead of regclass.  Rebuild only if we have loops.

Index: ira-int.h
===================================================================
--- ira-int.h	(revision 119881)
+++ ira-int.h	(working copy)
@@ -442,7 +442,7 @@ extern void allocate_pseudo_conflicts (p
 extern void print_expanded_pseudo (pseudo_t);
 extern copy_t create_copy (pseudo_t, pseudo_t, int, rtx);
 
-extern void ira_build (int);
+extern int ira_build (int);
 extern void ira_destroy (void);
 
 /* ira-costs.c */
Index: ira-color.c
===================================================================
--- ira-color.c	(revision 119881)
+++ ira-color.c	(working copy)
@@ -1,5 +1,3 @@
-/* conflict costs for conflict hard regs ??? */
-
 /* IRA allocation based on graph coloring.
    Contributed by Vladimir Makarov.
    Copyright (C) 2006 Free Software Foundation, Inc.
@@ -46,6 +44,7 @@ Software Foundation, 51 Franklin Street,
 
 static void update_copy_costs (pseudo_t, int);
 static int assign_hard_reg (pseudo_t, int);
+
 static void add_pseudo_to_bucket (pseudo_t, pseudo_t *);
 static void add_pseudo_to_ordered_bucket (pseudo_t, pseudo_t *);
 static void delete_pseudo_from_bucket (pseudo_t, pseudo_t *);
@@ -62,7 +61,7 @@ static void color_pseudos (void);
 
 static void print_loop_title (struct ira_loop_tree_node *);
 static void color_pass (struct ira_loop_tree_node *);
-static int pseudo_compare_func (const void *, const void *);
+static int pseudo_priority_compare_func (const void *, const void *);
 static void priority_coloring (void);
 static void do_coloring (void);
 
@@ -926,7 +925,7 @@ color_pass (struct ira_loop_tree_node *l
 /* The function is used to sort pseudos according to their priorities
    which are calculated analogous to ones in file `global.c'.  */
 static int
-pseudo_compare_func (const void *v1p, const void *v2p)
+pseudo_priority_compare_func (const void *v1p, const void *v2p)
 {
   pseudo_t p1 = *(const pseudo_t *) v1p, p2 = *(const pseudo_t *) v2p;
   int pri1, pri2;
@@ -969,11 +968,28 @@ priority_coloring (void)
 	      sizeof (int) * hard_regs_num);
     }
   bitmap_copy (consideration_pseudo_bitmap, coloring_pseudo_bitmap);
-  qsort (sorted_pseudos, pseudos_num, sizeof (pseudo_t), pseudo_compare_func);
+  qsort (sorted_pseudos, pseudos_num, sizeof (pseudo_t),
+	 pseudo_priority_compare_func);
   for (i = 0; i < pseudos_num; i++)
     {
       p = sorted_pseudos [i];
-      assign_hard_reg (p, FALSE);
+      if (ira_dump_file != NULL)
+	{
+	  fprintf (ira_dump_file, "  ");
+	  print_expanded_pseudo (p);
+	  fprintf (ira_dump_file, "  -- ");
+	}
+      if (assign_hard_reg (p, FALSE))
+	{
+	  if (ira_dump_file != NULL)
+	    fprintf (ira_dump_file, "assign reg %d\n",
+		     PSEUDO_HARD_REGNO (p));
+	}
+      else
+	{
+	  if (ira_dump_file != NULL)
+	    fprintf (ira_dump_file, "spill\n");
+	}
       PSEUDO_IN_GRAPH_P (p) = TRUE;
     }
 }
Index: global.c
===================================================================
--- global.c	(revision 119881)
+++ global.c	(working copy)
@@ -606,10 +606,22 @@ global_alloc (void)
 	      {
 		find_reg (allocno_order[i], 0, 0, 0, 0);
 		if (reg_renumber[allocno[allocno_order[i]].reg] >= 0)
-		  continue;
+		  {
+		    if (dump_file)
+		      fprintf (dump_file, "Assign %d to %d\n",
+			       reg_renumber[allocno[allocno_order[i]].reg],
+			       allocno[allocno_order[i]].reg);
+		    continue;
+		  }
 	      }
 	    if (reg_alternate_class (allocno[allocno_order[i]].reg) != NO_REGS)
-	      find_reg (allocno_order[i], 0, 1, 0, 0);
+	      {
+		find_reg (allocno_order[i], 0, 1, 0, 0);
+		if (dump_file)
+		  fprintf (dump_file, "Assign %d to %d\n",
+			   reg_renumber[allocno[allocno_order[i]].reg],
+			   allocno[allocno_order[i]].reg);
+	      }
 	  }
 
       free (allocno_order);
Index: ira-build.c
===================================================================
--- ira-build.c	(revision 119881)
+++ ira-build.c	(working copy)
@@ -838,14 +838,19 @@ create_loop_tree_node_caps (struct ira_l
 
 
 /* This entry function creates internal representation for IRA
-   (pseudos, copies, loop tree nodes).  If LOOP_P is zero the nodes
+   (pseudos, copies, loop tree nodes).  If LOOPS_P is zero the nodes
    corresponding to the loops (except the root which corresponds the
    all function) and correspondingly pseudos for the loops will be not
    created (it will be done only for basic blocks).  Such value is
-   used for Chaitin-Briggs and Chow's priority coloring.  */
-void
-ira_build (int loop_p)
+   used for Chaitin-Briggs and Chow's priority coloring.  The function
+   returns nonzero if we generates loop structure (besides node
+   representing all function) for regional allocation.  */
+int
+ira_build (int loops_p)
 {
+  unsigned int i;
+  loop_p loop;
+
   build_df = df_init (DF_HARD_REGS);
   df_lr_add_problem (build_df, 0);
   df_ri_add_problem (build_df, DF_RI_LIFE);
@@ -856,7 +861,7 @@ ira_build (int loop_p)
   ira_assert (current_loops == NULL);
   flow_loops_find (&ira_loops);
   current_loops = &ira_loops;
-  create_loop_tree_nodes (loop_p);
+  create_loop_tree_nodes (loops_p);
   form_loop_tree ();
   free_dominance_info (CDI_DOMINATORS);
   create_pseudos ();
@@ -869,7 +874,12 @@ ira_build (int loop_p)
       traverse_loop_tree (ira_loop_tree_root, NULL,
 			  create_loop_tree_node_caps);
       ira_free_bitmap (local_pseudos_bitmap);
+      for (i = 0; VEC_iterate (loop_p, ira_loops.larray, i, loop); i++)
+	if (ira_loop_nodes [i].regno_pseudo_map != NULL
+	    && ira_loop_tree_root != &ira_loop_nodes [i])
+	  return TRUE;
     }
+  return FALSE;
 }
 
 /* The function releases data created by function ira_build.  */
Index: ira.c
===================================================================
--- ira.c	(revision 119881)
+++ ira.c	(working copy)
@@ -116,6 +116,8 @@ static void fix_reg_equiv_init (void);
 #ifdef ENABLE_IRA_CHECKING
 static void print_redundant_copies (void);
 #endif
+static void setup_preferred_alternate_classes (void);
+
 static bool gate_ira (void);
 static unsigned int rest_of_handle_ira (void);
 
@@ -1030,13 +1032,32 @@ print_redundant_copies (void)
 }
 #endif
 
+/* Setup preferred and alternative classes for pseudo-registers for
+   other passes.  */
+static void
+setup_preferred_alternate_classes (void)
+{
+  int i;
+  enum reg_class cover_class;
+  pseudo_t p;
+
+  for (i = 0; i < pseudos_num; i++)
+    {
+      p = pseudos [i];
+      cover_class = PSEUDO_COVER_CLASS (p);
+      if (cover_class == NO_REGS)
+	cover_class = GENERAL_REGS;
+      setup_reg_classes (PSEUDO_REGNO (p), cover_class, NO_REGS);
+    }
+}
+
 
 
 /* This is the main entry of IRA.  */
 void
 ira (FILE *f)
 {
-  int overall_cost_before;
+  int overall_cost_before, loops_p;
   int rebuild_p;
 
   ira_dump_file = f;
@@ -1066,8 +1087,7 @@ ira (FILE *f)
   overall_cost = reg_cost = mem_cost = 0;
   load_cost = store_cost = shuffle_cost = 0;
   move_loops_num = additional_jumps_num = 0;
-  ira_build (flag_ira_algorithm != IRA_ALGORITHM_CB
-	     && flag_ira_algorithm != IRA_ALGORITHM_PRIORITY);
+  loops_p = ira_build (flag_ira_algorithm == IRA_ALGORITHM_REGIONAL);
   ira_color ();
 
   ira_emit ();
@@ -1080,7 +1100,7 @@ ira (FILE *f)
   setup_reg_renumber ();
   no_new_pseudos = 1;
 
-  if (flag_ira_algorithm == IRA_ALGORITHM_REGIONAL)
+  if (loops_p)
     {
       /* Even if new registers are not created rebuild IRA internal
 	 representation to use correct regno pseudo map.  */
@@ -1118,9 +1138,7 @@ ira (FILE *f)
   
   fix_reg_equiv_init ();
 
-  /* ??? We need it only because subsequent optimization like
-     post-reload needs it.  */
-  regclass (get_insns (), max_regno);
+  setup_preferred_alternate_classes ();
 
 #ifdef ENABLE_IRA_CHECKING
   print_redundant_copies ();
Index: regclass.c
===================================================================
--- regclass.c	(revision 119881)
+++ regclass.c	(working copy)
@@ -893,6 +893,7 @@ reg_preferred_class (int regno)
 {
   if (reg_pref == 0)
     return GENERAL_REGS;
+
   return (enum reg_class) reg_pref[regno].prefclass;
 }
 
@@ -2296,6 +2297,22 @@ free_reg_info (void)
   regno_allocated = 0;
   reg_n_max = 0;
 }
+
+
+
+/* Set up preferred and alternate classes for REGNO as PREFCLASS and
+   ALTCLASS.  */
+void
+setup_reg_classes (int regno,
+		   enum reg_class prefclass, enum reg_class altclass)
+{
+  gcc_assert (reg_pref_buffer != NULL && (size_t) regno < regno_allocated);
+  if (reg_pref == NULL)
+    reg_pref = reg_pref_buffer;
+  reg_pref[regno].prefclass = prefclass;
+  reg_pref[regno].altclass = altclass;
+}
+
 
 /* This is the `regscan' pass of the compiler, run just before cse
    and again just before loop.
Index: rtl.h
===================================================================
--- rtl.h	(revision 119881)
+++ rtl.h	(working copy)
@@ -1778,6 +1778,7 @@ extern const char *decode_asm_operands (
 
 extern enum reg_class reg_preferred_class (int);
 extern enum reg_class reg_alternate_class (int);
+extern void setup_reg_classes (int, enum reg_class, enum reg_class);
 
 extern void split_all_insns (int);
 extern unsigned int split_all_insns_noflow (void);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]