Hi!

On Mon, 1 Dec 2014 18:58:10 +0100, Tom de Vries <tom_devr...@mentor.com> wrote:
> On 01-12-14 09:43, Jakub Jelinek wrote:
> > On Mon, Dec 01, 2014 at 09:35:25AM +0100, Tom de Vries wrote:
> >> I've been adding an fn spec function attribute to some openacc builtin 
> >> functions:
> >> ...
> >> diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def
> >> index 9c05a94..4e34192 100644
> >> --- a/gcc/builtin-attrs.def
> >> +++ b/gcc/builtin-attrs.def
> >> @@ -64,6 +64,7 @@ DEF_ATTR_FOR_INT (6)
> >>     DEF_ATTR_TREE_LIST (ATTR_LIST_##ENUM, ATTR_NULL,     \
> >>                  ATTR_##ENUM, ATTR_NULL)
> >>   DEF_ATTR_FOR_STRING (STR1, "1")
> >> +DEF_ATTR_FOR_STRING (DOT_DOT_DOT_r_r_r, "...rrr")
> >>   #undef DEF_ATTR_FOR_STRING
> >>
> >>   /* Construct a tree for a list of two integers.  */
> >> @@ -127,6 +128,8 @@ DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LIST, ATTR_PURE,\
> >>                    ATTR_NULL, ATTR_NOTHROW_LIST)
> >>   DEF_ATTR_TREE_LIST (ATTR_PURE_NOTHROW_LEAF_LIST, ATTR_PURE,    \
> >>                    ATTR_NULL, ATTR_NOTHROW_LEAF_LIST)
> >> +DEF_ATTR_TREE_LIST 
> >> (ATTR_FNSPEC_DOT_DOT_DOT_NOCLOB_NOCLOB_NOCLOB_NOTHROW_LIST,\
> >> +                   ATTR_FNSPEC, ATTR_LIST_DOT_DOT_DOT_r_r_r, 
> >> ATTR_NOTHROW_LIST)
> >>   DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LIST, ATTR_NORETURN, \
> >>                    ATTR_NULL, ATTR_NOTHROW_LIST)
> >>   DEF_ATTR_TREE_LIST (ATTR_NORETURN_NOTHROW_LEAF_LIST, ATTR_NORETURN,\
> >> ...
> >>
> >> That worked well for c. When compiling the fortran compiler, I ran into 
> >> this error:
> >> ...
> >> In file included from gcc/fortran/f95-lang.c:1194:0:
> >> gcc/fortran/../oacc-builtins.def: In function 'void 
> >> gfc_init_builtin_functions()':
> >> gcc/fortran/../oacc-builtins.def:32:1: error:
> >> 'ATTR_FNSPEC_DOT_DOT_DOT_NOCLOB_NOCLOB_NOCLOB_NOTHROW_LIST' was not 
> >> declared
> >> in this scope
> >> make[2]: *** [fortran/f95-lang.o] Error 1
> >
> > Fortran FE uses gfc_build_library_function_decl_with_spec to build these.
> 
> Thanks for the pointer, that's useful. That's for library functions though, I 
> need a builtin.
> 
> I'm now trying the approach where I specify the attributes in two formats:
> ...
> DEF_GOACC_BUILTIN_FNSPEC (BUILT_IN_GOACC_DATA_START, "GOACC_data_start",
>                           BT_FN_VOID_INT_PTR_SIZE_PTR_PTR_PTR,
>                           ATTR_FNSPEC_DOT_DOT_DOT_r_r_r_NOTHROW_LIST,
>                           ATTR_NOTHROW_LIST,
>                           "...rrr")
> ...
> 
> In gcc/builtins.def, we use the first format (ATTRS):
> ...
> #undef DEF_GOACC_BUILTIN_FNSPEC
> #define DEF_GOACC_BUILTIN_FNSPEC(ENUM, NAME, TYPE, ATTRS, ATTRS2, FNSPEC) \
>    DEF_GOACC_BUILTIN(ENUM, NAME, TYPE, ATTRS)
> ...
> 
> And in gcc/fortran/f95-lang.c, we use the second format (ATTRS2, FNSPEC) and 
> a 
> new function gfc_define_builtin_with_spec:
> ...
> #undef DEF_GOACC_BUILTIN_FNSPEC
> #define DEF_GOACC_BUILTIN_FNSPEC(code, name, type, attr, attr2, fnspec) \
>        gfc_define_builtin_with_spec ("__builtin_" name, builtin_types[type], \
>                                     code, name, attr2, fnspec);
> ...
> 
> Where gfc_define_builtin_with_spec borrows from 
> gfc_build_library_function_decl_with_spec:
> ...
> +static void
> +gfc_define_builtin_with_spec (const char *name, tree fntype,
> +                             enum built_in_function code,
> +                             const char *library_name, int attr,
> +                             const char *fnspec)
> +{
> +  if (fnspec)
> +    {
> +      tree attr_args = build_tree_list (NULL_TREE,
> +                                       build_string (strlen (fnspec), 
> fnspec));
> +      tree attrs = tree_cons (get_identifier ("fn spec"),
> +                             attr_args, TYPE_ATTRIBUTES (fntype));
> +      fntype = build_type_attribute_variant (fntype, attrs);
> +    }
> +
> +  gfc_define_builtin (name, fntype, code, library_name, attr);
> +}
> ...

Committed to gomp-4_0-branch in r222277:

commit 0279da75a39a5bd3ca54b7c5f7e3e303e067cf2c
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Tue Apr 21 19:17:14 2015 +0000

    Add DEF_GOACC_BUILTIN_FNSPEC
    
        gcc/
        * builtins.def (DEF_GOACC_BUILTIN_FNSPEC): Define.
    
        gcc/fortran/
        * f95-lang.c (DEF_GOACC_BUILTIN_FNSPEC): Define.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@222277 
138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp         |    4 ++++
 gcc/builtins.def           |    7 +++++++
 gcc/fortran/ChangeLog.gomp |    2 ++
 gcc/fortran/f95-lang.c     |   11 +++++++++++
 gcc/omp-builtins.def       |    1 +
 5 files changed, 25 insertions(+)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index b499d04..b091dd5 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,3 +1,7 @@
+2015-04-21  Tom de Vries  <t...@codesourcery.com>
+
+       * builtins.def (DEF_GOACC_BUILTIN_FNSPEC): Define.
+
 2015-03-21  Tom de Vries  <t...@codesourcery.com>
 
        PR tree-optimization/65460
diff --git gcc/builtins.def gcc/builtins.def
index 55ce9f6..86fe9d2 100644
--- gcc/builtins.def
+++ gcc/builtins.def
@@ -174,6 +174,13 @@ along with GCC; see the file COPYING3.  If not see
               false, true, true, ATTRS, false, \
               (flag_openacc \
                || flag_offload_abi != OFFLOAD_ABI_UNSET))
+/* Like DEF_GOACC_BUILTIN, but with an fn spec attribute.
+   KLUDGE: The ATTRS field needs to be a combination of ATTRS2 and FNSPEC.
+   In this file, we use the ATTRS field, and in gcc/fortran/f95-lang.c, we use
+   ATTRS2 and FNSPEC instead.  */
+#undef DEF_GOACC_BUILTIN_FNSPEC
+#define DEF_GOACC_BUILTIN_FNSPEC(ENUM, NAME, TYPE, ATTRS, ATTRS2, FNSPEC) \
+  DEF_GOACC_BUILTIN(ENUM, NAME, TYPE, ATTRS)
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(ENUM, NAME, TYPE, ATTRS) \
   DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,    \
diff --git gcc/fortran/ChangeLog.gomp gcc/fortran/ChangeLog.gomp
index 8c23900..78eb20d 100644
--- gcc/fortran/ChangeLog.gomp
+++ gcc/fortran/ChangeLog.gomp
@@ -1,5 +1,7 @@
 2015-04-21  Tom de Vries  <t...@codesourcery.com>
 
+       * f95-lang.c (DEF_GOACC_BUILTIN_FNSPEC): Define.
+
        * f95-lang.c (gfc_define_builtin_with_spec): New function.
 
 2015-01-13  Thomas Schwinge  <tho...@codesourcery.com>
diff --git gcc/fortran/f95-lang.c gcc/fortran/f95-lang.c
index 1a14860..b012eb2 100644
--- gcc/fortran/f95-lang.c
+++ gcc/fortran/f95-lang.c
@@ -1217,6 +1217,12 @@ gfc_init_builtin_functions (void)
 #define DEF_GOACC_BUILTIN(code, name, type, attr) \
       gfc_define_builtin ("__builtin_" name, builtin_types[type], \
                          code, name, attr);
+/* Like DEF_GOACC_BUILTIN, but with an fn spec attribute.
+   KLUDGE: See gcc/builtins.def DEF_GOACC_BUILTIN_FNSPEC comment.  */
+#undef DEF_GOACC_BUILTIN_FNSPEC
+#define DEF_GOACC_BUILTIN_FNSPEC(code, name, type, attr, attr2, fnspec)        
\
+      gfc_define_builtin_with_spec ("__builtin_" name, builtin_types[type], \
+                                   code, name, attr2, fnspec);
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr) \
       gfc_define_builtin (name, builtin_types[type], code, name, attr);
@@ -1224,6 +1230,7 @@ gfc_init_builtin_functions (void)
 #define DEF_GOMP_BUILTIN(code, name, type, attr) /* ignore */
 #include "../omp-builtins.def"
 #undef DEF_GOACC_BUILTIN
+#undef DEF_GOACC_BUILTIN_FNSPEC
 #undef DEF_GOACC_BUILTIN_COMPILER
 #undef DEF_GOMP_BUILTIN
     }
@@ -1232,6 +1239,9 @@ gfc_init_builtin_functions (void)
     {
 #undef DEF_GOACC_BUILTIN
 #define DEF_GOACC_BUILTIN(code, name, type, attr) /* ignore */
+#undef DEF_GOACC_BUILTIN_FNSPEC
+#define DEF_GOACC_BUILTIN_FNSPEC(code, name, type, attr, attr2, fnspec)        
\
+      /* Ignore.  */
 #undef DEF_GOACC_BUILTIN_COMPILER
 #define DEF_GOACC_BUILTIN_COMPILER(code, name, type, attr)  /* ignore */
 #undef DEF_GOMP_BUILTIN
@@ -1240,6 +1250,7 @@ gfc_init_builtin_functions (void)
                          code, name, attr);
 #include "../omp-builtins.def"
 #undef DEF_GOACC_BUILTIN
+#undef DEF_GOACC_BUILTIN_FNSPEC
 #undef DEF_GOACC_BUILTIN_COMPILER
 #undef DEF_GOMP_BUILTIN
     }
diff --git gcc/omp-builtins.def gcc/omp-builtins.def
index 66bcf71..03955c4 100644
--- gcc/omp-builtins.def
+++ gcc/omp-builtins.def
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 /* Before including this file, you should define a macro:
 
      DEF_GOACC_BUILTIN (ENUM, NAME, TYPE, ATTRS)
+     DEF_GOACC_BUILTIN_FNSPEC (ENUM, NAME, TYPE, ATTRS, ATTRS2, FNSPEC)
      DEF_GOACC_BUILTIN_COMPILER (ENUM, NAME, TYPE, ATTRS)
      DEF_GOMP_BUILTIN (ENUM, NAME, TYPE, ATTRS)
 


Grüße,
 Thomas

Attachment: signature.asc
Description: PGP signature

Reply via email to