]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Add support for "simd" function attribute
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 18 Mar 2022 10:16:06 +0000 (11:16 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 19 May 2022 14:05:33 +0000 (14:05 +0000)
gcc/ada/

* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Function>: Also call
process_attributes for built-in functions.
(prepend_one_attribute_pragma): Deal with "simd" attribute.
* gcc-interface/utils.cc (handle_simd_attribute): New function.
(gnat_internal_attribute_table): Add entry for "simd" attribute.

gcc/ada/gcc-interface/decl.cc
gcc/ada/gcc-interface/utils.cc

index af6475e7307221f879d90aa1405f753ac0baa0f7..2d9b41f984c4895011207ea2ba1a0c270ef35dfc 100644 (file)
@@ -4002,6 +4002,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
          {
            gnu_decl = gnu_type;
            gnu_type = TREE_TYPE (gnu_decl);
+           process_attributes (&gnu_decl, &attr_list, true, gnat_entity);
            break;
          }
 
@@ -6864,7 +6865,9 @@ prepend_one_attribute_pragma (struct attrib **attr_list, Node_Id gnat_pragma)
 
       const char *const p = TREE_STRING_POINTER (gnu_arg1);
       const bool string_args
-       = strcmp (p, "target") == 0 || strcmp (p, "target_clones") == 0;
+       = strcmp (p, "simd") == 0
+         || strcmp (p, "target") == 0
+         || strcmp (p, "target_clones") == 0;
       gnu_arg1 = get_identifier (p);
       if (IDENTIFIER_LENGTH (gnu_arg1) == 0)
        return;
index 98bcb7063e33358889e8c39b9ff31e8804605248..d747c639a8fd3645e0705636cdd400ce9cd0972a 100644 (file)
@@ -107,6 +107,7 @@ static tree handle_flatten_attribute (tree *, tree, tree, int, bool *);
 static tree handle_used_attribute (tree *, tree, tree, int, bool *);
 static tree handle_cold_attribute (tree *, tree, tree, int, bool *);
 static tree handle_hot_attribute (tree *, tree, tree, int, bool *);
+static tree handle_simd_attribute (tree *, tree, tree, int, bool *);
 static tree handle_target_attribute (tree *, tree, tree, int, bool *);
 static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *);
 static tree handle_vector_size_attribute (tree *, tree, tree, int, bool *);
@@ -185,6 +186,8 @@ const struct attribute_spec gnat_internal_attribute_table[] =
     handle_cold_attribute, attr_cold_hot_exclusions },
   { "hot",          0, 0,  true,  false, false, false,
     handle_hot_attribute, attr_cold_hot_exclusions },
+  { "simd",         0, 1,  true,  false, false, false,
+    handle_simd_attribute, NULL },
   { "target",       1, -1, true,  false, false, false,
     handle_target_attribute, NULL },
   { "target_clones",1, -1, true,  false, false, false,
@@ -6880,6 +6883,54 @@ handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args),
   return NULL_TREE;
 }
 
+/* Handle a "simd" attribute.  */
+
+static tree
+handle_simd_attribute (tree *node, tree name, tree args, int, bool *no_add_attrs)
+{
+  if (TREE_CODE (*node) == FUNCTION_DECL)
+    {
+      tree t = get_identifier ("omp declare simd");
+      tree attr = NULL_TREE;
+      if (args)
+       {
+         tree id = TREE_VALUE (args);
+
+         if (TREE_CODE (id) != STRING_CST)
+           {
+             error ("attribute %qE argument not a string", name);
+             *no_add_attrs = true;
+             return NULL_TREE;
+           }
+
+         if (strcmp (TREE_STRING_POINTER (id), "notinbranch") == 0)
+           attr = build_omp_clause (DECL_SOURCE_LOCATION (*node),
+                                    OMP_CLAUSE_NOTINBRANCH);
+         else if (strcmp (TREE_STRING_POINTER (id), "inbranch") == 0)
+           attr = 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 (t, build_tree_list (NULL_TREE, attr),
+                    DECL_ATTRIBUTES (*node));
+    }
+  else
+    {
+      warning (OPT_Wattributes, "%qE attribute ignored", name);
+      *no_add_attrs = true;
+    }
+
+  return NULL_TREE;
+}
+
 /* Handle a "target" attribute.  */
 
 static tree