Add new memory_address_p target hook

Anatoly Sokolov aesok@post.ru
Thu Jul 3 11:54:00 GMT 2008


Hello.


>>   As the Zack Weinberg offered in the post:
>> http://gcc.gnu.org/ml/gcc-patches/2004-08/msg00511.html, this patch introduce
>> new TARGET_MEMORY_ADDRESS_P target hook instead GO_IF_LEGITIMATE_ADDRESS macro.
>> 2008-06-27  Anatoly Sokolov <aesok@post.ru>

>>        * reload.c (strict_memory_address_1_p): New function.
>>        (strict_memory_address_p): Use memory_address_p target hook.
>>        * recog.c: Include "target.h".
>>        (memory_address_1_p): New function.
>>        (memory_address_p): Use memory_address_p target hook.

> I don't like the names memory_address_1_p or
> strict_memory_address_1_p. ....
> How about default_legitimate_address_p and
> default_strict_legitimate_address_p?  Also the new functions need
> comments.  Also for future-proofing I think the functions should use
> #ifdef GO_IF_LEGITIMATE_ADDRESS and call gcc_unreachable() if it is
> not defined.

> Please submit an updated patch, with information on how it was tested.


I have change the function names, added new comments and also add guards
for uses of GO_IF_LEGITIMATE_ADDRESS with appropriate #ifdef in
default_strict_legitimate_address_p and default_legitimate_address_p
functions. Please, send further comments.

Patch was bootstrapped and regression tested on x86_64-unknown-linux-gnu.


2008-07-03  Anatoly Sokolov <aesok@post.ru>

       * target.h (struct gcc_target): Add memory_address_p field.
       * target-def.h (TARGET_MEMORY_ADDRESS_P): New.
       (TARGET_INITIALIZER): Use TARGET_MEMORY_ADDRESS_P.
       * targhooks.c (default_memory_address_p): New function.
       * targhooks.h (default_memory_address_p): Declare function.
       * recog.h (default_legitimate_address_p): (Ditto.).
       (default_strict_legitimate_address_p): (Ditto.).
       * reload.c (default_strict_legitimate_address_p): New function.
       (strict_memory_address_p): Use memory_address_p target hook.
       * recog.c: Include "target.h".
       (default_legitimate_address_p): New function.
       (memory_address_p): Use memory_address_p target hook.


Index: gcc/targhooks.c
===================================================================
--- gcc/targhooks.c     (revision 137392)
+++ gcc/targhooks.c     (working copy)
@@ -703,4 +703,17 @@
   return true;
 }
 
+/* Return true if ADDR is a valid memory address for mode MODE,
+   and if STRICT is true check that each pseudo reg has the proper kind of
+   hard reg.  */
+
+bool
+default_memory_address_p (enum machine_mode mode, rtx addr, bool strict)
+{
+  if (strict)
+    return default_strict_legitimate_address_p (mode, addr);
+  else
+    return default_legitimate_address_p (mode, addr);
+}
+
 #include "gt-targhooks.h"
Index: gcc/targhooks.h
===================================================================
--- gcc/targhooks.h     (revision 137392)
+++ gcc/targhooks.h     (working copy)
@@ -97,3 +97,5 @@
 extern tree default_mangle_decl_assembler_name (tree, tree);
 extern tree default_emutls_var_fields (tree, tree *);
 extern tree default_emutls_var_init (tree, tree, tree);
+
+extern bool default_memory_address_p (enum machine_mode, rtx, bool);
Index: gcc/reload.c
===================================================================
--- gcc/reload.c        (revision 137392)
+++ gcc/reload.c        (working copy)
@@ -2109,13 +2109,32 @@
    hard reg.  */
 
 int
-strict_memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
+strict_memory_address_p (enum machine_mode mode, rtx addr)
 {
+  return targetm.memory_address_p (mode, addr, true) ? 1 : 0; 
+}
+
+/* Return true if ADDR is a valid memory address for mode MODE,
+   and check that each pseudo reg has the proper kind of
+   hard reg.  */
+
+bool
+default_strict_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, 
+                                    rtx addr ATTRIBUTE_UNUSED)
+{
+#ifdef GO_IF_LEGITIMATE_ADDRESS
+
   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
-  return 0;
+  return false;
 
  win:
-  return 1;
+  return true;
+
+#else
+  
+  gcc_unreachable ();
+
+#endif   
 }
 

 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
Index: gcc/target.h
===================================================================
--- gcc/target.h        (revision 137392)
+++ gcc/target.h        (working copy)
@@ -564,6 +564,11 @@
   /* True if X is considered to be commutative.  */
   bool (* commutative_p) (const_rtx, int);
 
+  /* Return true if ADDR is a valid memory address for mode MODE,
+     and if strict is true check that each pseudo reg has the proper kind of
+     hard reg.  */
+  bool (* memory_address_p) (enum machine_mode mode, rtx addr, bool strict);
+
   /* Given an address RTX, undo the effects of LEGITIMIZE_ADDRESS.  */
   rtx (* delegitimize_address) (rtx);
 
Index: gcc/recog.c
===================================================================
--- gcc/recog.c	(revision 137392)
+++ gcc/recog.c	(working copy)
@@ -42,6 +42,7 @@
 #include "reload.h"
 #include "timevar.h"
 #include "tree-pass.h"
+#include "target.h"
 #include "df.h"
 
 #ifndef STACK_PUSH_CODE
@@ -1204,13 +1205,30 @@
 /* Return 1 if ADDR is a valid memory address for mode MODE.  */
 
 int
-memory_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, rtx addr)
+memory_address_p (enum machine_mode mode, rtx addr)
 {
+  return targetm.memory_address_p (mode, addr, false) ? 1 : 0; 
+}
+
+/* Return true if ADDR is a valid memory address for mode MODE.  */
+
+bool
+default_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED, 
+                              rtx addr ATTRIBUTE_UNUSED)
+{
+#ifdef GO_IF_LEGITIMATE_ADDRESS
+
   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
-  return 0;
+  return false;
 
  win:
-  return 1;
+  return true;
+  
+#else
+
+  gcc_unreachable ();
+
+#endif 
 }
 
 /* Return 1 if OP is a valid memory reference with mode MODE,
Index: gcc/recog.h
===================================================================
--- gcc/recog.h	(revision 137392)
+++ gcc/recog.h	(working copy)
@@ -85,7 +85,9 @@
 extern int constrain_operands (int);
 extern int constrain_operands_cached (int);
 extern int memory_address_p (enum machine_mode, rtx);
+extern bool default_legitimate_address_p (enum machine_mode, rtx);
 extern int strict_memory_address_p (enum machine_mode, rtx);
+extern bool default_strict_legitimate_address_p (enum machine_mode, rtx);
 extern int validate_replace_rtx (rtx, rtx, rtx);
 extern void validate_replace_rtx_group (rtx, rtx, rtx);
 extern void validate_replace_src_group (rtx, rtx, rtx);
Index: gcc/target-def.h
===================================================================
--- gcc/target-def.h    (revision 137392)
+++ gcc/target-def.h    (working copy)
@@ -457,6 +457,10 @@
 #define TARGET_VECTOR_OPAQUE_P hook_bool_const_tree_false
 #endif
 
+#ifndef TARGET_MEMORY_ADDRESS_P
+#define TARGET_MEMORY_ADDRESS_P default_memory_address_p
+#endif
+
 /* In hooks.c.  */
 #define TARGET_CANNOT_MODIFY_JUMPS_P hook_bool_void_false
 #define TARGET_BRANCH_TARGET_REGISTER_CLASS hook_int_void_no_regs
@@ -791,6 +795,7 @@
   TARGET_CANNOT_FORCE_CONST_MEM,               \
   TARGET_CANNOT_COPY_INSN_P,                   \
   TARGET_COMMUTATIVE_P,                                \
+  TARGET_MEMORY_ADDRESS_P,                     \
   TARGET_DELEGITIMIZE_ADDRESS,                 \
   TARGET_USE_BLOCKS_FOR_CONSTANT_P,            \
   TARGET_MIN_ANCHOR_OFFSET,                    \


Anatoly.



More information about the Gcc-patches mailing list