Patchwork RFC: LRA for x86/x86-64 [4/9]

login
register
mail settings
Submitter Vladimir Makarov
Date Sept. 27, 2012, 10:58 p.m.
Message ID <5064D9FC.7020704@redhat.com>
Download mbox | patch
Permalink /patch/187521/
State New
Headers show

Comments

Vladimir Makarov - Sept. 27, 2012, 10:58 p.m.
The following patch implements hooks (and their default values) will
be used by LRA.

2012-09-27  Vladimir Makarov  <vmakarov@redhat.com>

     * target.h: Include tm.h.
     * targhooks.h (default_lra_p): Declare.
     (default_register_bank): Ditto.
     (default_different_addr_displacement_p): Ditto.
     * targhooks.c (default_lra_p): New function.
     (default_register_bank): Ditto.
     (default_different_addr_displacement_p): Ditto.
     * target.def (lra_p): New hook.
     (register_bank): Ditto.
     (different_addr_displacement_p): Ditto.
     (spill_class, spill_class_mode): New hooks.
     * doc/tm.texi.in: Add TARGET_LRA_P, TARGET_REGISTER_BANK,
     TARGET_DIFFERENT_ADDR_DISPLACEMENT_P, TARGET_SPILL_CLASS, and
     TARGET_SPILL_CLASS_MODE.
     * doc/tm.texi: Update.
Joseph S. Myers - Sept. 27, 2012, 11:05 p.m.
On Thu, 27 Sep 2012, Vladimir Makarov wrote:

>     * target.h: Include tm.h.

That's a backward step; we'd like parts of the compiler that aren't using 
target macros directly not to end up including tm.h.  Why do you need 
this?
Vladimir Makarov - Sept. 27, 2012, 11:41 p.m.
On 09/27/2012 07:05 PM, Joseph S. Myers wrote:
> On Thu, 27 Sep 2012, Vladimir Makarov wrote:
>
>>      * target.h: Include tm.h.
> That's a backward step; we'd like parts of the compiler that aren't using
> target macros directly not to end up including tm.h.  Why do you need
> this?
>
Thanks, Joseph.

Hook spill_class returns a value of enum reg_class which is defined in 
target-depend include file.

If it is really bad, I'll try to find a solution but it will be probably 
not a pleasant one like the hook returning int which is converted to and 
from enum reg_class.
Joseph S. Myers - Sept. 28, 2012, 12:07 a.m.
On Thu, 27 Sep 2012, Vladimir Makarov wrote:

> Hook spill_class returns a value of enum reg_class which is defined in
> target-depend include file.

That's what reg_class_t is for: avoiding enum reg_class in hook 
interfaces.

Patch

Index: target.h
===================================================================
--- target.h	(revision 191771)
+++ target.h	(working copy)
@@ -51,6 +51,7 @@ 
 #define GCC_TARGET_H
 
 #include "insn-modes.h"
+#include "tm.h"
 
 #ifdef ENABLE_CHECKING
 
Index: targhooks.c
===================================================================
--- targhooks.c	(revision 191771)
+++ targhooks.c	(working copy)
@@ -840,6 +840,24 @@  default_branch_target_register_class (vo
   return NO_REGS;
 }
 
+extern bool
+default_lra_p (void)
+{
+  return false;
+}
+
+int
+default_register_bank (int hard_regno ATTRIBUTE_UNUSED)
+{
+  return 0;
+}
+
+extern bool
+default_different_addr_displacement_p (void)
+{
+  return false;
+}
+
 reg_class_t
 default_secondary_reload (bool in_p ATTRIBUTE_UNUSED, rtx x ATTRIBUTE_UNUSED,
 			  reg_class_t reload_class_i ATTRIBUTE_UNUSED,
Index: targhooks.h
===================================================================
--- targhooks.h	(revision 191771)
+++ targhooks.h	(working copy)
@@ -132,6 +132,9 @@  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 bool default_lra_p (void);
+extern int default_register_bank (int);
+extern bool default_different_addr_displacement_p (void);
 extern reg_class_t default_secondary_reload (bool, rtx, reg_class_t,
 					     enum machine_mode,
 					     secondary_reload_info *);
Index: doc/tm.texi
===================================================================
--- doc/tm.texi	(revision 191771)
+++ doc/tm.texi	(working copy)
@@ -2893,6 +2893,26 @@  as below:
 @end smallexample
 @end defmac
 
+@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
+
+@deftypefn {Target Hook} int TARGET_REGISTER_BANK (int)
+A target hook which returns the register bank number to which the  register @var{hard_regno} belongs to.  The smaller the number, the  more preferable the hard register usage (when all other conditions are  the same).  This hook can be used to prefer some hard register over  others in LRA.  For example, some x86-64 register usage needs  additional prefix which makes instructions longer.  The hook can  return bigger bank number for such registers make them less favorable  and as result making the generated code smaller.    The default version of this target hook returns always zero.
+@end deftypefn
+
+@deftypefn {Target Hook} bool TARGET_DIFFERENT_ADDR_DISPLACEMENT_P (void)
+A target hook which returns true if an address with the same structure  can have different maximal legitimate displacement.  For example, the  displacement can depend on memory mode or on operand combinations in  the insn.    The default version of this target hook returns always false.
+@end deftypefn
+
+@deftypefn {Target Hook} {enum reg_class} TARGET_SPILL_CLASS (enum @var{reg_class})
+This hook defines a class of registers which could be used for spilled pseudos  of given class instead of memory
+@end deftypefn
+
+@deftypefn {Target Hook} {enum machine_mode} TARGET_SPILL_CLASS_MODE (enum @var{reg_class}, enum @var{reg_class}, enum @var{machine_mode})
+This hook defines mode in which a pseudo of given mode and of the first  register class can be spilled into the second register class
+@end deftypefn
+
 @node Old Constraints
 @section Obsolete Macros for Defining Constraints
 @cindex defining constraints, obsolete method
Index: doc/tm.texi.in
===================================================================
--- doc/tm.texi.in	(revision 191771)
+++ doc/tm.texi.in	(working copy)
@@ -2869,6 +2869,16 @@  as below:
 @end smallexample
 @end defmac
 
+@hook TARGET_LRA_P
+
+@hook TARGET_REGISTER_BANK
+
+@hook TARGET_DIFFERENT_ADDR_DISPLACEMENT_P
+
+@hook TARGET_SPILL_CLASS
+
+@hook TARGET_SPILL_CLASS_MODE
+
 @node Old Constraints
 @section Obsolete Macros for Defining Constraints
 @cindex defining constraints, obsolete method
Index: target.def
===================================================================
--- target.def	(revision 191771)
+++ target.def	(working copy)
@@ -2349,6 +2349,61 @@  DEFHOOK
  bool, (const_tree field, enum machine_mode mode),
  default_member_type_forces_blk)
 
+/* Return true if we use LRA instead of reload.  */
+DEFHOOK
+(lra_p,
+ "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.",
+ bool, (void),
+ default_lra_p)
+
+/* Return register bank of given hard regno for the current target.  */
+DEFHOOK
+(register_bank,
+ "A target hook which returns the register bank number to which the\
+  register @var{hard_regno} belongs to.  The smaller the number, the\
+  more preferable the hard register usage (when all other conditions are\
+  the same).  This hook can be used to prefer some hard register over\
+  others in LRA.  For example, some x86-64 register usage needs\
+  additional prefix which makes instructions longer.  The hook can\
+  return bigger bank number for such registers make them less favorable\
+  and as result making the generated code smaller.\
+  \
+  The default version of this target hook returns always zero.",
+ int, (int),
+ default_register_bank)
+
+/* Return true if maximal address displacement can be different.  */
+DEFHOOK
+(different_addr_displacement_p,
+ "A target hook which returns true if an address with the same structure\
+  can have different maximal legitimate displacement.  For example, the\
+  displacement can depend on memory mode or on operand combinations in\
+  the insn.\
+  \
+  The default version of this target hook returns always false.",
+ bool, (void),
+ default_different_addr_displacement_p)
+
+/* Determine class of registers which could be used for spilled
+   pseudos instead of memory.  */
+DEFHOOK
+(spill_class,
+ "This hook defines a class of registers which could be used for spilled pseudos\
+  of given class instead of memory",
+ enum reg_class, (enum reg_class),
+ NULL)
+
+/* Determine mode for spilling pseudos into registers instead of memory.  */
+DEFHOOK
+(spill_class_mode,
+ "This hook defines mode in which a pseudo of given mode and of the first\
+  register class can be spilled into the second register class",
+ enum machine_mode, (enum reg_class, enum reg_class, enum machine_mode),
+ NULL)
+
 /* Return the class for a secondary reload, and fill in extra information.  */
 DEFHOOK
 (secondary_reload,