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.
Hi Jakub,
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);
+}
...
Thanks,
- Tom