diff mbox

[2/3] tm.texi documentation on macro PREFERRED_RENAME_CLASS

Message ID 1288145771.1793.103.camel@yaolp
State New
Headers show

Commit Message

Yao Qi Oct. 27, 2010, 2:16 a.m. UTC
On Thu, 2010-10-21 at 22:04 +0000, Joseph S. Myers wrote:
> tm.texi is a generated file.  You need to patch tm.texi.in and regenerate 
> tm.texi.
> 
> In general new target macros should be avoided in favour of hooks (whose 
> documentation source should be in target.def with a minimal @hook 
> reference in tm.texi.in) unless one of the following applies:

Joseph,
It is patch 2 here, which adds target hook, doc and uses target hook.
This patch (patch 2) is dependent on patch 1
(http://gcc.gnu.org/ml/gcc-patches/2010-10/msg02197.html)

No regression when patch 1 and patch 2 are applied on
x86_64-unknown-gnu-linux.  OK for mainline?

Yao Qi
CodeSourcery 
yao@codesourcery.com (650) 331-3385 x739

Comments

Joseph Myers Oct. 27, 2010, 12:06 p.m. UTC | #1
On Wed, 27 Oct 2010, Yao Qi wrote:

> On Thu, 2010-10-21 at 22:04 +0000, Joseph S. Myers wrote:
> > tm.texi is a generated file.  You need to patch tm.texi.in and regenerate 
> > tm.texi.
> > 
> > In general new target macros should be avoided in favour of hooks (whose 
> > documentation source should be in target.def with a minimal @hook 
> > reference in tm.texi.in) unless one of the following applies:
> 
> Joseph,
> It is patch 2 here, which adds target hook, doc and uses target hook.
> This patch (patch 2) is dependent on patch 1
> (http://gcc.gnu.org/ml/gcc-patches/2010-10/msg02197.html)

Please see what I said about putting the documentation in target.def.  
tm.texi.in should *only* have the @hook line and not the rest of the 
documentation.  Using "" for documentation in DEFHOOK in target.def is a 
deprecated transitional measure for cases where documentation uses 
pre-existing GFDL-only text, unless and until the FSF works out viable 
arrangements for us to be able to move and copy text bidirectionally 
between code and manuals in whatever ways make technical sense.
Yao Qi Oct. 27, 2010, 4:09 p.m. UTC | #2
On Wed, 2010-10-27 at 12:06 +0000, Joseph S. Myers wrote:
> On Wed, 27 Oct 2010, Yao Qi wrote:
> 
> > On Thu, 2010-10-21 at 22:04 +0000, Joseph S. Myers wrote:
> > > tm.texi is a generated file.  You need to patch tm.texi.in and regenerate 
> > > tm.texi.
> > > 
> > > In general new target macros should be avoided in favour of hooks (whose 
> > > documentation source should be in target.def with a minimal @hook 
> > > reference in tm.texi.in) unless one of the following applies:
> > 
> > Joseph,
> > It is patch 2 here, which adds target hook, doc and uses target hook.
> > This patch (patch 2) is dependent on patch 1
> > (http://gcc.gnu.org/ml/gcc-patches/2010-10/msg02197.html)
> 
> Please see what I said about putting the documentation in target.def.  
> tm.texi.in should *only* have the @hook line and not the rest of the 
> documentation.  Using "" for documentation in DEFHOOK in target.def is a 
> deprecated transitional measure for cases where documentation uses 
> pre-existing GFDL-only text, unless and until the FSF works out viable 
> arrangements for us to be able to move and copy text bidirectionally 
> between code and manuals in whatever ways make technical sense.
> 

I misunderstood you a little bit in last mail.  Here is the new one.
Anatoly Sokolov Oct. 27, 2010, 4:22 p.m. UTC | #3
Hi

Use reg_class_t instead of enum reg_class in midle end.

> +       enum reg_class cl;
+       reg_class_t cl;
>        if (DEBUG_INSN_P (tmp->insn))
>   continue;
>        n_uses++;
 
>+       cl = (enum reg_class) 
>+  targetm.preferred_rename_class(tmp->cl);
+       cl = targetm.preferred_rename_class(tmp->cl);
>        IOR_COMPL_HARD_REG_SET (this_unavailable,
>-          reg_class_contents[tmp->cl]);
>+          reg_class_contents[cl]);
+          reg_class_contents[(int) cl]);

Anatoly.
Steve Ellcey Oct. 27, 2010, 5:59 p.m. UTC | #4
| Please see what I said about putting the documentation in target.def.
| tm.texi.in should *only* have the @hook line and not the rest of the
| documentation.  Using "" for documentation in DEFHOOK in target.def is a
| deprecated transitional measure for cases where documentation uses
| pre-existing GFDL-only text, unless and until the FSF works out viable
| arrangements for us to be able to move and copy text bidirectionally
| between code and manuals in whatever ways make technical sense.
| 
| --
| Joseph S. Myers
| joseph@codesourcery.com

When adding a new hook with documentation in target.def, does tm.texi.in
need to be changed to add the @hook line?  In adding the new
TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE hooks, it seems
that adding them (with the description) to target.def is enough to get
them into tm.texi without changing tm.texi.in.  Is the '@hook' in
tm.texi.in only needed if you want to control where the hooks are
documented or is putting @hook in tm.texi.in a requirement for all
hooks, even those documented in target.def?

Steve Ellcey
sje@cup.hp.com
Joseph Myers Oct. 27, 2010, 6:54 p.m. UTC | #5
On Wed, 27 Oct 2010, Steve Ellcey wrote:

> When adding a new hook with documentation in target.def, does tm.texi.in
> need to be changed to add the @hook line?  In adding the new
> TARGET_GET_RAW_RESULT_MODE and TARGET_GET_RAW_ARG_MODE hooks, it seems
> that adding them (with the description) to target.def is enough to get
> them into tm.texi without changing tm.texi.in.  Is the '@hook' in
> tm.texi.in only needed if you want to control where the hooks are
> documented or is putting @hook in tm.texi.in a requirement for all
> hooks, even those documented in target.def?

"if there is no matching @hook, the hook is emitted after the hook that 
precedes it in target.def"

Since that is not generally the best place and the divisions of hooks in 
the manual do not correspond to the ordering on target.def, you should 
generally work out the best place in the manual to put the hook and add 
the @hook line.
diff mbox

Patch

gcc/

	* target.def: New hook preferred_rename_class.
	* targhook.c (default_preferred_rename_class): New.
	* targhook.h: Declare it.
	* regrename.c (regrename_optimize): Call target hook
	preferred_rename_class to rename register class.
	* doc/tm.texi.in: New hook TARGET_PREFERRED_RENAME_CLASS.

diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index a9592b1..0983a2d 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -2585,6 +2585,19 @@  only if neither labeling works.
 This macro also has strict and non-strict variants.
 @end defmac
 
+@hook TARGET_PREFERRED_RENAME_CLASS
+A target hook that places additional restrictions on the register
+class to use when it is necessary to rename a register in class
+@var{class} to another class, or perhaps still @var{class},
+if you don't define macro @code{PREFERRED_RENAME_CLASS}.
+
+Sometimes returning a more restrictive class makes better code.  For
+example, on ARM, thumb-2 instructions using @code{LOW_REGS} may be 
+smaller than instructions using @code{GENERIC_REGS}.  By returning 
+@code{LOW_REGS} from @code{PREFERRED_RENAME_CLASS}, code size can 
+be reduced.
+@end deftypefn
+
 @hook TARGET_PREFERRED_RELOAD_CLASS
 A target hook that places additional restrictions on the register class
 to use when it is necessary to copy value @var{x} into a register in class
diff --git a/gcc/regrename.c b/gcc/regrename.c
index 11ae466..6189806 100644
--- a/gcc/regrename.c
+++ b/gcc/regrename.c
@@ -38,6 +38,7 @@ 
 #include "timevar.h"
 #include "tree-pass.h"
 #include "df.h"
+#include "target.h"
 
 #if HOST_BITS_PER_WIDE_INT <= MAX_RECOG_OPERANDS
 #error "Use a different bitmap implementation for untracked_operands."
@@ -384,12 +385,15 @@  regrename_optimize (void)
 	  n_uses = 0;
 	  for (tmp = this_head->first; tmp; tmp = tmp->next_use)
 	    {
+	      enum reg_class cl;
 	      if (DEBUG_INSN_P (tmp->insn))
 		continue;
 	      n_uses++;
 
+	      cl = (enum reg_class) 
+		targetm.preferred_rename_class(tmp->cl);
 	      IOR_COMPL_HARD_REG_SET (this_unavailable,
-				      reg_class_contents[tmp->cl]);
+				      reg_class_contents[cl]);
 	    }
 
 	  if (n_uses < 2)
diff --git a/gcc/target.def b/gcc/target.def
index 82f3040..84c0710 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -2089,6 +2089,12 @@  DEFHOOK
  bool, (reg_class_t rclass),
  default_class_likely_spilled_p)
 
+DEFHOOK
+(preferred_rename_class,
+ "",
+ reg_class_t, (reg_class_t rclass),
+ default_preferred_rename_class)
+
 /* This target hook allows the backend to perform additional
    processing while initializing for variable expansion.  */
 DEFHOOK
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index 5948e3f..ea94c87 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1256,6 +1256,16 @@  default_preferred_output_reload_class (rtx x ATTRIBUTE_UNUSED,
 #endif
 }
 
+reg_class_t
+default_preferred_rename_class (reg_class_t rclass)
+{
+#ifdef PREFERRED_RENAME_CLASS
+  return PREFERRED_RENAME_CLASS ((enum reg_class)rclass);
+#else
+  return rclass;
+#endif
+}
+
 /* The default implementation of TARGET_CLASS_LIKELY_SPILLED_P.  */
 
 bool
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 7b640cc..ba3dd17 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -156,6 +156,7 @@  extern int default_register_move_cost (enum machine_mode, reg_class_t,
 extern bool default_profile_before_prologue (void);
 extern reg_class_t default_preferred_reload_class (rtx, reg_class_t);
 extern reg_class_t default_preferred_output_reload_class (rtx, reg_class_t);
+extern reg_class_t default_preferred_rename_class (reg_class_t rclass);
 extern bool default_class_likely_spilled_p (reg_class_t);
 
 extern enum unwind_info_type default_debug_unwind_info (void);