diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-25 15:06:43 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-28 19:05:42 +0200 |
commit | 6201277441db4023b833e6d643de8077fe38ed6e (patch) | |
tree | f352e3cda43ffefe86c022ec52655ebee1dc9f89 /gcc/d | |
parent | ed06274eacc17a224b87f23111d7ca874ea53b7c (diff) | |
download | gcc-6201277441db4023b833e6d643de8077fe38ed6e.zip gcc-6201277441db4023b833e6d643de8077fe38ed6e.tar.gz gcc-6201277441db4023b833e6d643de8077fe38ed6e.tar.bz2 |
d: Add `@simd` and `@simd_clones` attributes to compiler and library
The `@simd` attribute is equivalent to `__attribute__((simd))`, and
`@simd_clones` is a convenience alias to allow specifying whether the
compiler should generated masked or non-masked simd clones.
gcc/d/ChangeLog:
* d-attribs.cc (handle_omp_declare_simd_attribute): New function.
(d_handle_simd_attribute): New function.
(d_langhook_common_attribute_table): Add 'omp declare simd' attribute.
(d_langhook_attribute_table): Add simd attribute.
libphobos/ChangeLog:
* libdruntime/gcc/attributes.d (simd): Define.
gcc/testsuite/ChangeLog:
* gdc.dg/attr_simd1.d: New test.
* gdc.dg/attr_simd2.d: New test.
Diffstat (limited to 'gcc/d')
-rw-r--r-- | gcc/d/d-attribs.cc | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gcc/d/d-attribs.cc b/gcc/d/d-attribs.cc index 1dd806f..04f7f16 100644 --- a/gcc/d/d-attribs.cc +++ b/gcc/d/d-attribs.cc @@ -58,6 +58,7 @@ static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); static tree handle_transaction_pure_attribute (tree *, tree, tree, int, bool *); static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *); static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *); +static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *); /* D attribute handlers for user defined attributes. */ static tree d_handle_noinline_attribute (tree *, tree, tree, int, bool *); @@ -80,6 +81,7 @@ static tree d_handle_restrict_attribute (tree *, tree, tree, int, bool *); static tree d_handle_used_attribute (tree *, tree, tree, int, bool *); static tree d_handle_visibility_attribute (tree *, tree, tree, int, bool *); static tree d_handle_no_sanitize_attribute (tree *, tree, tree, int, bool *); +static tree d_handle_simd_attribute (tree *, tree, tree, int, bool *); /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ @@ -186,6 +188,8 @@ const attribute_spec d_langhook_common_attribute_table[] = handle_type_generic_attribute, NULL), ATTR_SPEC ("fn spec", 1, 1, false, true, true, false, handle_fnspec_attribute, NULL), + ATTR_SPEC ("omp declare simd", 0, -1, true, false, false, false, + handle_omp_declare_simd_attribute, NULL), ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL), }; @@ -228,6 +232,8 @@ const attribute_spec d_langhook_attribute_table[] = d_handle_register_attribute, NULL), ATTR_SPEC ("restrict", 0, 0, true, false, false, false, d_handle_restrict_attribute, NULL), + ATTR_SPEC ("simd", 0, 1, true, false, false, false, + d_handle_simd_attribute, NULL), ATTR_SPEC ("used", 0, 0, true, false, false, false, d_handle_used_attribute, NULL), ATTR_SPEC ("visibility", 1, 1, false, false, false, false, @@ -664,6 +670,16 @@ handle_fnspec_attribute (tree *, tree, tree args, int, bool *) return NULL_TREE; } +/* Handle an "omp declare simd" attribute; arguments as in + struct attribute_spec.handler. */ + +tree +handle_omp_declare_simd_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + return NULL_TREE; +} + /* Language specific attribute handlers. These functions take the arguments: (tree *node, tree name, tree args, int flags, bool *no_add_attrs) */ @@ -1474,6 +1490,55 @@ d_handle_restrict_attribute (tree *node, tree name, tree, int, return NULL_TREE; } +/* Handle a "simd" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +d_handle_simd_attribute (tree *node, tree name, tree args, int, + bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + return NULL_TREE; + } + + tree omp_attr = get_identifier ("omp declare simd"); + tree omp_flags = NULL_TREE; + if (args) + { + tree id = TREE_VALUE (args); + + if (TREE_CODE (id) != STRING_CST) + { + error ("%qE attribute argument not a string constant", name); + *no_add_attrs = true; + return NULL_TREE; + } + + if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0) + omp_flags = build_omp_clause (DECL_SOURCE_LOCATION (*node), + OMP_CLAUSE_NOTINBRANCH); + else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0) + omp_flags = build_omp_clause (DECL_SOURCE_LOCATION (*node), + OMP_CLAUSE_INBRANCH); + else + { + error ("only %<inbranch%> and %<notinbranch%> flags are " + "allowed for %<simd%> attribute"); + *no_add_attrs = true; + return NULL_TREE; + } + } + + DECL_ATTRIBUTES (*node) = + tree_cons (omp_attr, build_tree_list (NULL_TREE, omp_flags), + DECL_ATTRIBUTES (*node)); + + return NULL_TREE; +} + /* Handle a "used" attribute; arguments as in struct attribute_spec.handler. */ |