public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work062)] Add target hook for asm operand validation.
@ 2021-07-31  4:00 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2021-07-31  4:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e03b6c270d73f2c90bb7b97a6cc26d89cbe608f6

commit e03b6c270d73f2c90bb7b97a6cc26d89cbe608f6
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jul 30 23:59:29 2021 -0400

    Add target hook for asm operand validation.
    
    The PowerPC has noraml loads and stores and then it has prefixed loads and
    stores.  The prefixed loads and stores have different names and format
    than the normal loads and stores.  This patch adds a new hook that is run
    in the passes before reload to ensure that no prefixed memory is generated
    by optimizations.
    
    This patch is all of the machine independent changes to to add a hook to
    prevent asm from generating prefixed loads/stores with the '%m' constraint
    on the PowerPC.  The next patch will contain the PowerPC specific patches.
    
    2021-07-31  Michael Meissner  <meissner@linux.ibm.com>
    gcc/
            PR target/98519
            * doc/tm.texi (TARGET_MD_ASM_OPERAND_P): Document.
            * doc/tm.texi.in (TARGET_MD_ASM_OPERAND_P): Document.
            * target.def (md_asm_operand_p): New target hook.
            * targhooks.c (default_md_asm_operand_p): New default target
            hook.
            * targhooks.h (default_md_asm_operand_p): New declaration.

Diff:
---
 gcc/doc/tm.texi    | 11 +++++++++++
 gcc/doc/tm.texi.in |  2 ++
 gcc/recog.c        |  4 ++++
 gcc/target.def     | 15 +++++++++++++++
 gcc/targhooks.c    |  7 +++++++
 gcc/targhooks.h    |  1 +
 6 files changed, 40 insertions(+)

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index cb015283237..e95869152aa 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -5886,6 +5886,17 @@ Using the hook is usually simpler because it limits the number of
 files that are recompiled when changes are made.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_MD_ASM_OPERAND_P (rtx @var{op}, const char *@var{constraint}, const char **@var{constraints})
+This hook should return true if the operand is valid for being used in
+an asm statement.  The back end may impose additionsl constraints on
+what operands are valid for an asm statement.  The default behavior is
+to return true always.
+
+For example, the PowerPC has normal memory instructions and prefixed
+memory instructions.  Prefixed memory instructions are not valid for
+the normal @samp{%m} constraint.
+@end deftypefn
+
 @defmac TARGET_MEM_CONSTRAINT
 A single character to be used instead of the default @code{'m'}
 character for general memory addresses.  This defines the constraint
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 4a522ae7e2e..21e013fa274 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -4066,6 +4066,8 @@ accept.
 
 @hook TARGET_LEGITIMATE_ADDRESS_P
 
+@hook TARGET_MD_ASM_OPERAND_P
+
 @defmac TARGET_MEM_CONSTRAINT
 A single character to be used instead of the default @code{'m'}
 character for general memory addresses.  This defines the constraint
diff --git a/gcc/recog.c b/gcc/recog.c
index 5a42c45361d..04e52a71d3f 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -2174,6 +2174,10 @@ asm_operand_ok (rtx op, const char *constraint, const char **constraints)
   /* Use constrain_operands after reload.  */
   gcc_assert (!reload_completed);
 
+  /* Allow the backend to impose additional constraints.  */
+  if (!targetm.md_asm_operand_p (op, constraint, constraints))
+    return 0;
+
   /* Empty constraint string is the same as "X,...,X", i.e. X for as
      many alternatives as required to match the other operands.  */
   if (*constraint == '\0')
diff --git a/gcc/target.def b/gcc/target.def
index 68a46aaa832..0cd4c786aa2 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -2940,6 +2940,21 @@ files that are recompiled when changes are made.",
  bool, (machine_mode mode, rtx x, bool strict),
  default_legitimate_address_p)
 
+/* True if the given operand is a valid machine dependent assembler
+   operand.  */
+DEFHOOK
+(md_asm_operand_p,
+ "This hook should return true if the operand is valid for being used in\n\
+an asm statement.  The back end may impose additionsl constraints on\n\
+what operands are valid for an asm statement.  The default behavior is\n\
+to return true always.\n\
+\n\
+For example, the PowerPC has normal memory instructions and prefixed\n\
+memory instructions.  Prefixed memory instructions are not valid for\n\
+the normal @samp{%m} constraint.",
+ bool, (rtx op, const char *constraint, const char **constraints),
+ default_md_asm_operand_p)
+
 /* True if the given constant can be put into an object_block.  */
 DEFHOOK
 (use_blocks_for_constant_p,
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index eb5190910dc..7af4ef8660f 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -110,6 +110,13 @@ default_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED,
 #endif
 }
 
+bool default_md_asm_operand_p (rtx op ATTRIBUTE_UNUSED,
+			       const char *constraint ATTRIBUTE_UNUSED,
+			       const char **constraints ATTRIBUTE_UNUSED)
+{
+  return true;
+}
+
 void
 default_external_libcall (rtx fun ATTRIBUTE_UNUSED)
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index f92e102c450..19f54d97df3 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_TARGHOOKS_H
 
 extern bool default_legitimate_address_p (machine_mode, rtx, bool);
+extern bool default_md_asm_operand_p (rtx, const char *, const char **);
 
 extern void default_external_libcall (rtx);
 extern rtx default_legitimize_address (rtx, rtx, machine_mode);


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/meissner/heads/work062)] Add target hook for asm operand validation.
@ 2021-07-31  3:55 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2021-07-31  3:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:96decd044215f4c0dbecd951adaaed9637ae9f10

commit 96decd044215f4c0dbecd951adaaed9637ae9f10
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jul 30 23:55:09 2021 -0400

    Add target hook for asm operand validation.
    
    The PowerPC has noraml loads and stores and then it has prefixed loads and
    stores.  The prefixed loads and stores have different names and format
    than the normal loads and stores.  This patch adds a new hook that is run
    in the passes before reload to ensure that no prefixed memory is generated
    by optimizations.
    
    This patch is all of the machine independent changes to to add a hook to
    prevent asm from generating prefixed loads/stores with the '%m' constraint
    on the PowerPC.  The next patch will contain the PowerPC specific patches.
    
    2021-07-31  Michael Meissner  <meissner@linux.ibm.com>
    gcc/
            PR target/98519
            * doc/tm.texi (TARGET_MD_ASM_OPERAND_P): Document.
            * doc/tm.texi.in (TARGET_MD_ASM_OPERAND_P): Document.
            * target.def (md_asm_operand_p): New target hook.
            * targhooks.c (default_md_asm_operand_p): New default target
            hook.
            * targhooks.h (default_md_asm_operand_p): New declaration.

Diff:
---
 gcc/doc/tm.texi | 11 +++++++++++
 gcc/recog.c     |  4 ++++
 gcc/target.def  | 15 +++++++++++++++
 gcc/targhooks.c |  7 +++++++
 gcc/targhooks.h |  1 +
 5 files changed, 38 insertions(+)

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index cb015283237..e95869152aa 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -5886,6 +5886,17 @@ Using the hook is usually simpler because it limits the number of
 files that are recompiled when changes are made.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_MD_ASM_OPERAND_P (rtx @var{op}, const char *@var{constraint}, const char **@var{constraints})
+This hook should return true if the operand is valid for being used in
+an asm statement.  The back end may impose additionsl constraints on
+what operands are valid for an asm statement.  The default behavior is
+to return true always.
+
+For example, the PowerPC has normal memory instructions and prefixed
+memory instructions.  Prefixed memory instructions are not valid for
+the normal @samp{%m} constraint.
+@end deftypefn
+
 @defmac TARGET_MEM_CONSTRAINT
 A single character to be used instead of the default @code{'m'}
 character for general memory addresses.  This defines the constraint
diff --git a/gcc/recog.c b/gcc/recog.c
index 5a42c45361d..04e52a71d3f 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -2174,6 +2174,10 @@ asm_operand_ok (rtx op, const char *constraint, const char **constraints)
   /* Use constrain_operands after reload.  */
   gcc_assert (!reload_completed);
 
+  /* Allow the backend to impose additional constraints.  */
+  if (!targetm.md_asm_operand_p (op, constraint, constraints))
+    return 0;
+
   /* Empty constraint string is the same as "X,...,X", i.e. X for as
      many alternatives as required to match the other operands.  */
   if (*constraint == '\0')
diff --git a/gcc/target.def b/gcc/target.def
index 68a46aaa832..0cd4c786aa2 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -2940,6 +2940,21 @@ files that are recompiled when changes are made.",
  bool, (machine_mode mode, rtx x, bool strict),
  default_legitimate_address_p)
 
+/* True if the given operand is a valid machine dependent assembler
+   operand.  */
+DEFHOOK
+(md_asm_operand_p,
+ "This hook should return true if the operand is valid for being used in\n\
+an asm statement.  The back end may impose additionsl constraints on\n\
+what operands are valid for an asm statement.  The default behavior is\n\
+to return true always.\n\
+\n\
+For example, the PowerPC has normal memory instructions and prefixed\n\
+memory instructions.  Prefixed memory instructions are not valid for\n\
+the normal @samp{%m} constraint.",
+ bool, (rtx op, const char *constraint, const char **constraints),
+ default_md_asm_operand_p)
+
 /* True if the given constant can be put into an object_block.  */
 DEFHOOK
 (use_blocks_for_constant_p,
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index eb5190910dc..7af4ef8660f 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -110,6 +110,13 @@ default_legitimate_address_p (machine_mode mode ATTRIBUTE_UNUSED,
 #endif
 }
 
+bool default_md_asm_operand_p (rtx op ATTRIBUTE_UNUSED,
+			       const char *constraint ATTRIBUTE_UNUSED,
+			       const char **constraints ATTRIBUTE_UNUSED)
+{
+  return true;
+}
+
 void
 default_external_libcall (rtx fun ATTRIBUTE_UNUSED)
 {
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index f92e102c450..19f54d97df3 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #define GCC_TARGHOOKS_H
 
 extern bool default_legitimate_address_p (machine_mode, rtx, bool);
+extern bool default_md_asm_operand_p (rtx, const char *, const char **);
 
 extern void default_external_libcall (rtx);
 extern rtx default_legitimize_address (rtx, rtx, machine_mode);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-31  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-31  4:00 [gcc(refs/users/meissner/heads/work062)] Add target hook for asm operand validation Michael Meissner
  -- strict thread matches above, loose matches on Subject: below --
2021-07-31  3:55 Michael Meissner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).