On 1/24/19 4:05 PM, Jakub Jelinek wrote:
> On Thu, Jan 24, 2019 at 03:57:56PM +0100, Martin Liška wrote:
>> --- a/gcc/config/i386/i386.c
>> +++ b/gcc/config/i386/i386.c
>> @@ -29577,6 +29577,17 @@ ix86_warn_parameter_passing_abi (cumulative_args_t 
>> cum_v, tree type)
>>    cum->warn_empty = false;
>>  }
>>  
>> +static const char *
> 
> Missing function comment.  Usually a copy of the target hook description,
> perhaps with arch details.
> 
>> +ix86_get_multilib_abi_name (void)
>> +{
>> +  if (!(TARGET_64BIT_P (ix86_isa_flags)))
>> +    return "i386";
>> +  else if (TARGET_X32_P (ix86_isa_flags))
>> +    return "x32";
>> +  else
>> +    return "x86_64";
>> +}
>> +
>>  /* Compute the alignment for a variable for Intel MCU psABI.  TYPE is
>>     the data type, and ALIGN is the alignment that the object would
>>     ordinarily have.  */
>> @@ -51804,6 +51815,10 @@ ix86_run_selftests (void)
>>  #undef TARGET_WARN_PARAMETER_PASSING_ABI
>>  #define TARGET_WARN_PARAMETER_PASSING_ABI ix86_warn_parameter_passing_abi
>>  
>> +#undef TARGET_GET_MULTILIB_ABI_NAME
>> +#define TARGET_GET_MULTILIB_ABI_NAME \
>> +ix86_get_multilib_abi_name
> 
> All other #define TARGET_* that need to wrap line indent the next line
> by two spaces, please do that too.
> 
>> -/* Match a !GCC$ builtin (b) attributes simd flags form:
>> +/* Match a !GCC$ builtin (b) attributes simd flags if(target) form:
>>  
>>     The parameter b is name of a middle-end built-in.
>> -   Flags are one of:
>> -     - (empty)
>> +   FLAGS is optional and must be one of:
>>       - inbranch
>>       - notinbranch
> 
> FLAGS must be one of (inbranch) or (notinbranch) actually.
> 
>>  match
>>  gfc_match_gcc_builtin (void)
>>  {
>>    char builtin[GFC_MAX_SYMBOL_LEN + 1];
>> +  char target[GFC_MAX_SYMBOL_LEN + 1];
>>  
>>    if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES)
>>      return MATCH_ERROR;
>> @@ -11361,6 +11365,13 @@ gfc_match_gcc_builtin (void)
>>    else if (gfc_match (" ( inbranch ) ") == MATCH_YES)
>>      clause = SIMD_INBRANCH;
>>  
>> +  if (gfc_match (" if ( %n ) ", target) == MATCH_YES)
>> +    {
>> +      const char *abi = targetm.get_multilib_abi_name ();
>> +      if (abi == NULL || strcmp (abi, target) != 0)
>> +    return MATCH_YES;
>> +    }
> 
> Wonder whether we want if (x86_64) or if ('x86_64'), I'd lean for the
> latter.
> 
>> +
>>    if (gfc_vectorized_builtins == NULL)
>>      gfc_vectorized_builtins = new hash_map<nofree_string_hash, int> ();
>>  
>> diff --git a/gcc/target.def b/gcc/target.def
>> index 05c9cc1da28..4ba6b167e26 100644
>> --- a/gcc/target.def
>> +++ b/gcc/target.def
>> @@ -5791,6 +5791,12 @@ call_2 may be NULL or a call insn.",
>>   rtx_insn *, (rtx_insn *call_1, rtx_insn *call_2),
>>   NULL)
>>  
>> +DEFHOOK
>> +(get_multilib_abi_name,
>> + "This hook returns name of multilib ABI name.",
>> + const char *, (void),
>> + NULL)
>> +
>>  DEFHOOK
>>  (remove_extra_call_preserved_regs,
>>   "This hook removes registers from the set of call-clobbered registers\n\
>> diff --git a/gcc/targhooks.c b/gcc/targhooks.c
>> index 529590b55df..a03b967b913 100644
>> --- a/gcc/targhooks.c
>> +++ b/gcc/targhooks.c
>> @@ -2379,4 +2379,10 @@ default_remove_extra_call_preserved_regs (rtx_insn *, 
>> HARD_REG_SET *)
>>  {
>>  }
>>  
>> +const char *
>> +default_get_multilib_abi_name (void)
>> +{
>> +  return NULL;
>> +}
> 
> Just use hook_constcharptr_void_null instead of adding yet another hook that
> does the same thing?
> 
>       Jakub
> 

Thanks for comments, I'm sending new version.

Martin
>From 3dce4e127c7810c4aff38f38ecb789fedc893082 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Mon, 21 Jan 2019 08:46:06 +0100
Subject: [PATCH] Support if statement in !GCC$ builtin directive.

gcc/ChangeLog:

2019-01-24  Martin Liska  <mli...@suse.cz>

	* config/i386/i386.c (ix86_get_multilib_abi_name): New function.
	(TARGET_GET_MULTILIB_ABI_NAME): New macro defined.
	* doc/tm.texi: Document new target hook.
	* doc/tm.texi.in: Likewise.
	* target.def: Add new target macro.

gcc/fortran/ChangeLog:

2019-01-24  Martin Liska  <mli...@suse.cz>

	* decl.c (gfc_match_gcc_builtin): Add support for filtering
	of builtin directive based on multilib ABI name.

gcc/testsuite/ChangeLog:

2019-01-24  Martin Liska  <mli...@suse.cz>

	* gfortran.dg/simd-builtins-7.f90: New test.
	* gfortran.dg/simd-builtins-7.h: New test.
---
 gcc/config/i386/i386.c                        | 17 +++++++++++++++
 gcc/doc/tm.texi                               |  4 ++++
 gcc/doc/tm.texi.in                            |  2 ++
 gcc/fortran/decl.c                            | 21 ++++++++++++++-----
 gcc/target.def                                |  6 ++++++
 gcc/testsuite/gfortran.dg/simd-builtins-7.f90 | 19 +++++++++++++++++
 gcc/testsuite/gfortran.dg/simd-builtins-7.h   |  2 ++
 7 files changed, 66 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/simd-builtins-7.f90
 create mode 100644 gcc/testsuite/gfortran.dg/simd-builtins-7.h

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index e0d7c74fcec..7b594cc46ac 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -29577,6 +29577,19 @@ ix86_warn_parameter_passing_abi (cumulative_args_t cum_v, tree type)
   cum->warn_empty = false;
 }
 
+/* This hook returns name of multilib ABI.  */
+
+static const char *
+ix86_get_multilib_abi_name (void)
+{
+  if (!(TARGET_64BIT_P (ix86_isa_flags)))
+    return "i386";
+  else if (TARGET_X32_P (ix86_isa_flags))
+    return "x32";
+  else
+    return "x86_64";
+}
+
 /* Compute the alignment for a variable for Intel MCU psABI.  TYPE is
    the data type, and ALIGN is the alignment that the object would
    ordinarily have.  */
@@ -51804,6 +51817,10 @@ ix86_run_selftests (void)
 #undef TARGET_WARN_PARAMETER_PASSING_ABI
 #define TARGET_WARN_PARAMETER_PASSING_ABI ix86_warn_parameter_passing_abi
 
+#undef TARGET_GET_MULTILIB_ABI_NAME
+#define TARGET_GET_MULTILIB_ABI_NAME \
+  ix86_get_multilib_abi_name
+
 #if CHECKING_P
 #undef TARGET_RUN_TARGET_SELFTESTS
 #define TARGET_RUN_TARGET_SELFTESTS selftest::ix86_run_selftests
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 4347f89cd2f..8c8978bb13a 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -1931,6 +1931,10 @@ superset of all other ABIs.  @var{call_1} must always be a call insn,
 call_2 may be NULL or a call insn.
 @end deftypefn
 
+@deftypefn {Target Hook} {const char *} TARGET_GET_MULTILIB_ABI_NAME (void)
+This hook returns name of multilib ABI name.
+@end deftypefn
+
 @findex fixed_regs
 @findex call_used_regs
 @findex global_regs
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 41a6cb11cb0..fe1194ef91a 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -1711,6 +1711,8 @@ of @code{CALL_USED_REGISTERS}.
 
 @hook TARGET_RETURN_CALL_WITH_MAX_CLOBBERS
 
+@hook TARGET_GET_MULTILIB_ABI_NAME
+
 @findex fixed_regs
 @findex call_used_regs
 @findex global_regs
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 3314e176881..945d3180834 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -28,6 +28,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "match.h"
 #include "parse.h"
 #include "constructor.h"
+#include "target.h"
 
 /* Macros to access allocate memory for gfc_data_variable,
    gfc_data_value and gfc_data.  */
@@ -11338,19 +11339,22 @@ gfc_match_gcc_unroll (void)
   return MATCH_ERROR;
 }
 
-/* Match a !GCC$ builtin (b) attributes simd flags form:
+/* Match a !GCC$ builtin (b) attributes simd flags if('target') form:
 
    The parameter b is name of a middle-end built-in.
-   Flags are one of:
-     - (empty)
-     - inbranch
-     - notinbranch
+   FLAGS is optional and must be one of:
+     - (inbranch)
+     - (notinbranch)
+
+   IF('target') is optional and TARGET is a name of a multilib ABI.
 
    When we come here, we have already matched the !GCC$ builtin string.  */
+
 match
 gfc_match_gcc_builtin (void)
 {
   char builtin[GFC_MAX_SYMBOL_LEN + 1];
+  char target[GFC_MAX_SYMBOL_LEN + 1];
 
   if (gfc_match (" ( %n ) attributes simd", builtin) != MATCH_YES)
     return MATCH_ERROR;
@@ -11361,6 +11365,13 @@ gfc_match_gcc_builtin (void)
   else if (gfc_match (" ( inbranch ) ") == MATCH_YES)
     clause = SIMD_INBRANCH;
 
+  if (gfc_match (" if ( '%n' ) ", target) == MATCH_YES)
+    {
+      const char *abi = targetm.get_multilib_abi_name ();
+      if (abi == NULL || strcmp (abi, target) != 0)
+	return MATCH_YES;
+    }
+
   if (gfc_vectorized_builtins == NULL)
     gfc_vectorized_builtins = new hash_map<nofree_string_hash, int> ();
 
diff --git a/gcc/target.def b/gcc/target.def
index 05c9cc1da28..66cee075018 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -5791,6 +5791,12 @@ call_2 may be NULL or a call insn.",
  rtx_insn *, (rtx_insn *call_1, rtx_insn *call_2),
  NULL)
 
+DEFHOOK
+(get_multilib_abi_name,
+ "This hook returns name of multilib ABI name.",
+ const char *, (void),
+ hook_constcharptr_void_null)
+
 DEFHOOK
 (remove_extra_call_preserved_regs,
  "This hook removes registers from the set of call-clobbered registers\n\
diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-7.f90 b/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
new file mode 100644
index 00000000000..c3ce5543779
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/simd-builtins-7.f90
@@ -0,0 +1,19 @@
+! { dg-do compile { target { i?86-*-linux* x86_64-*-linux* } } }
+! { dg-additional-options "-msse2 -mno-avx -nostdinc -Ofast -fpre-include=simd-builtins-7.h -fdump-tree-optimized" }
+
+program test_overloaded_intrinsic
+  real(4) :: x4(3200), y4(3200)
+  real(8) :: x8(3200), y8(3200)
+
+  y4 = sin(x4)
+  print *, y4
+
+  y4 = sin(x8)
+  print *, y8
+end
+
+! { dg-final { scan-tree-dump "sinf.simdclone" "optimized" { target ilp32 } } } */
+! { dg-final { scan-tree-dump-not "sin.simdclone" "optimized" { target ilp32 } } } */
+
+! { dg-final { scan-tree-dump "sin.simdclone" "optimized" { target lp64} } } */
+! { dg-final { scan-tree-dump-not "sinf.simdclone" "optimized" { target lp64 } } } */
diff --git a/gcc/testsuite/gfortran.dg/simd-builtins-7.h b/gcc/testsuite/gfortran.dg/simd-builtins-7.h
new file mode 100644
index 00000000000..1c19b88f877
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/simd-builtins-7.h
@@ -0,0 +1,2 @@
+!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
+!GCC$ builtin (sinf) attributes simd (notinbranch) if('i386')
-- 
2.20.1

Reply via email to