From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1005) id 874773858432; Sat, 31 Jul 2021 04:00:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 874773858432 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Michael Meissner To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/meissner/heads/work062)] Add target hook for asm operand validation. X-Act-Checkin: gcc X-Git-Author: Michael Meissner X-Git-Refname: refs/users/meissner/heads/work062 X-Git-Oldrev: ea49c2b488aa704d0d46176a94d0dbbb77dc93a6 X-Git-Newrev: e03b6c270d73f2c90bb7b97a6cc26d89cbe608f6 Message-Id: <20210731040012.874773858432@sourceware.org> Date: Sat, 31 Jul 2021 04:00:12 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Jul 2021 04:00:12 -0000 https://gcc.gnu.org/g:e03b6c270d73f2c90bb7b97a6cc26d89cbe608f6 commit e03b6c270d73f2c90bb7b97a6cc26d89cbe608f6 Author: Michael Meissner 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 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);