On 05/14/2015 04:42 PM, Vladimir Makarov wrote:
The following patch is for solution of PR65862

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65862

In some cases, calculations of reg class costs are not enough to choose the right class. For example, in some cases you don't want to start fp unit for energy saving considerations if you don't really need it. Such case can occur when we have non-floating point mode pseudo and calculation costs in ira says that it would be profitable to put it in a floating point register.

The full solution will need to add a hook to mips.c. I hope mips maintainers will do that soon.

The patch was bootstrapped on x86-64.

Committed as rev. 223202.

2015-05-14  Vladimir Makarov  <vmaka...@redhat.com>

        PR rtl-optimization/65862
        * target.def (ira_change_pseudo_allocno_class): New hook.
        * targhooks.c (default_ira_change_pseudo_allocno_class): Default
        value of the hook.
        * targhooks.h (default_ira_change_pseudo_allocno_class): New
        extern
* doc/tm.texi.in (TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS): Add the
        hook.
        * ira-costs.c (find_costs_and_classes): Call the hook and change
        classes when it is necessary.
        * doc/tm.texi: Update.


Sorry, I missed to attach the patch.  Here it is.

Index: doc/tm.texi
===================================================================
--- doc/tm.texi	(revision 223198)
+++ doc/tm.texi	(working copy)
@@ -2837,6 +2837,13 @@ as below:
 @end smallexample
 @end defmac
 
+@deftypefn {Target Hook} reg_class_t TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS (int, @var{reg_class_t})
+A target hook which can change allocno class for given pseudo from
+  allocno class calculated by IRA.
+  
+  The default version of this target hook always returns given class.
+@end deftypefn
+
 @deftypefn {Target Hook} bool TARGET_LRA_P (void)
 A target hook which returns true if we use LRA instead of reload pass.  It means that LRA was ported to the target.    The default version of this target hook returns always false.
 @end deftypefn
Index: doc/tm.texi.in
===================================================================
--- doc/tm.texi.in	(revision 223198)
+++ doc/tm.texi.in	(working copy)
@@ -2475,6 +2475,8 @@ as below:
 @end smallexample
 @end defmac
 
+@hook TARGET_IRA_CHANGE_PSEUDO_ALLOCNO_CLASS
+
 @hook TARGET_LRA_P
 
 @hook TARGET_REGISTER_PRIORITY
Index: ira-costs.c
===================================================================
--- ira-costs.c	(revision 223198)
+++ ira-costs.c	(working copy)
@@ -1636,7 +1636,7 @@ find_costs_and_classes (FILE *dump_file)
   int i, k, start, max_cost_classes_num;
   int pass;
   basic_block bb;
-  enum reg_class *regno_best_class;
+  enum reg_class *regno_best_class, new_class;
 
   init_recog ();
   regno_best_class
@@ -1878,6 +1878,18 @@ find_costs_and_classes (FILE *dump_file)
 	      ira_assert (regno_aclass[i] != NO_REGS
 			  && ira_reg_allocno_class_p[regno_aclass[i]]);
 	    }
+	  if ((new_class
+	       = (reg_class) (targetm.ira_change_pseudo_allocno_class
+			      (i, regno_aclass[i]))) != regno_aclass[i])
+	    {
+	      regno_aclass[i] = new_class;
+	      if (hard_reg_set_subset_p (reg_class_contents[new_class],
+					 reg_class_contents[best]))
+		best = new_class;
+	      if (hard_reg_set_subset_p (reg_class_contents[new_class],
+					 reg_class_contents[alt_class]))
+		alt_class = new_class;
+	    }
 	  if (pass == flag_expensive_optimizations)
 	    {
 	      if (best_cost > i_mem_cost)
Index: target.def
===================================================================
--- target.def	(revision 223198)
+++ target.def	(working copy)
@@ -4763,6 +4763,16 @@ This is currently used only by the C and
  tree, (tree type, tree expr),
  hook_tree_tree_tree_null)
 
+/* Change pseudo allocno class calculated by IRA.  */
+DEFHOOK
+(ira_change_pseudo_allocno_class,
+ "A target hook which can change allocno class for given pseudo from\n\
+  allocno class calculated by IRA.\n\
+  \n\
+  The default version of this target hook always returns given class.",
+ reg_class_t, (int, reg_class_t),
+ default_ira_change_pseudo_allocno_class)
+
 /* Return true if we use LRA instead of reload.  */
 DEFHOOK
 (lra_p,
Index: targhooks.c
===================================================================
--- targhooks.c	(revision 223198)
+++ targhooks.c	(working copy)
@@ -914,6 +914,13 @@ default_branch_target_register_class (vo
   return NO_REGS;
 }
 
+reg_class_t
+default_ira_change_pseudo_allocno_class (int regno ATTRIBUTE_UNUSED,
+					 reg_class_t cl)
+{
+  return cl;
+}
+
 extern bool
 default_lra_p (void)
 {
Index: targhooks.h
===================================================================
--- targhooks.h	(revision 223198)
+++ targhooks.h	(working copy)
@@ -140,6 +140,7 @@ extern rtx default_static_chain (const_t
 extern void default_trampoline_init (rtx, tree, rtx);
 extern int default_return_pops_args (tree, tree, int);
 extern reg_class_t default_branch_target_register_class (void);
+extern reg_class_t default_ira_change_pseudo_allocno_class (int, reg_class_t);
 extern bool default_lra_p (void);
 extern int default_register_priority (int);
 extern bool default_register_usage_leveling_p (void);

Reply via email to