Hello,
On 14 Oct 13:40, Joseph Myers wrote:
> On Wed, 14 Oct 2015, Kirill Yukhin wrote:
> 
> > Is it ok for trunk?
> 
> This patch has no documentation.  Documentation for new attributes must be 
> added to extend.texi.
Fixed. Extra entry to gcc/Changelog:
        * doc/extend.texi (simd): Document new attribute.

> > Enables creation of one or more versions that can process multiple 
> > arguments using SIMD instructions from a single invocation from a SIMD 
> > loop. It is ultimately an alias to `omp declare simd’ pragma, available 
> > w/o additional compiler switches. It is prohibited to use the attribute 
> > along with Cilk Plus’s `vector’ attribute. If the attribute is specified 
> > and `pragma omp declare simd’ presents on a decl, then the attribute is 
> > ignored.
> 
> This is missing the key information that it's not just about *creation* of 
> the versions, it's about (in the case of an external declaration) 
> *assuming* such versions were created in another translation unit.  And 
> you should have a link to the external ABI documents specifying for each 
> architecture for which this involves such an assumption exactly what 
> versions may be assumed to be present - this is what's required to be able 
> to use the attribute in headers for a library and know that future GCC 
> versions won't reinterpret the attribute as implying some versions for 
> future ISA extensions are also present.
I've put reference to x86_64 Vector ABI in the attribute documentation.


> I wonder whether the syntax for this attribute should allow optional 
> arguments to describe what versions are present, but maybe that can be 
> deferred until e.g. you want a way in future for a library to specify it 
> has an AVX1024 version of a function as well as the baseline ABI set of 
> versions.
We'll add it later when needed.

> Joseph S. Myers
> jos...@codesourcery.com

--
Thanks, K

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 2d24c21..b83c9d8 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -224,6 +224,9 @@ struct GTY(()) c_parser {
   /* Buffer to hold all the tokens from parsing the vector attribute for the
      SIMD-enabled functions (formerly known as elemental functions).  */
   vec <c_token, va_gc> *cilk_simd_fn_tokens;
+
+  /* Designates if "simd" attribute is specified in decl.  */
+  BOOL_BITFIELD simd_attr_present : 1;
 };
 
 
@@ -1700,7 +1703,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
       if (declarator == NULL)
        {
          if (omp_declare_simd_clauses.exists ()
-             || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
+             || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)
+             || parser->simd_attr_present)
            c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE,
                                       omp_declare_simd_clauses);
          c_parser_skip_to_end_of_block_or_statement (parser);
@@ -1796,7 +1800,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
                  if (!d)
                    d = error_mark_node;
                  if (omp_declare_simd_clauses.exists ()
-                     || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
+                     || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)
+                     || parser->simd_attr_present)
                    c_finish_omp_declare_simd (parser, d, NULL_TREE,
                                               omp_declare_simd_clauses);
                }
@@ -1809,7 +1814,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
                  if (!d)
                    d = error_mark_node;
                  if (omp_declare_simd_clauses.exists ()
-                     || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
+                     || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)
+                     || parser->simd_attr_present)
                    c_finish_omp_declare_simd (parser, d, NULL_TREE,
                                               omp_declare_simd_clauses);
                  start_init (d, asm_name, global_bindings_p ());
@@ -1838,7 +1844,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
                                   chainon (postfix_attrs,
                                            all_prefix_attrs));
              if (omp_declare_simd_clauses.exists ()
-                 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
+                 || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)
+                 || parser->simd_attr_present)
                {
                  tree parms = NULL_TREE;
                  if (d && TREE_CODE (d) == FUNCTION_DECL)
@@ -1967,7 +1974,8 @@ c_parser_declaration_or_fndef (c_parser *parser, bool 
fndef_ok,
                                       true, false, NULL, vNULL);
       store_parm_decls ();
       if (omp_declare_simd_clauses.exists ()
-         || !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
+         || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)
+         || parser->simd_attr_present)
        c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE,
                                   omp_declare_simd_clauses);
       DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus
@@ -3998,6 +4006,12 @@ c_parser_attributes (c_parser *parser)
              c_parser_cilk_simd_fn_vector_attrs (parser, *v_token);
              continue;
            }
+         if (is_attribute_p ("simd", attr_name))
+           {
+             parser->simd_attr_present = 1;
+             c_parser_consume_token (parser);
+             continue;
+           }
          c_parser_consume_token (parser);
          if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN))
            {
@@ -14210,9 +14224,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree 
fndecl, tree parms,
                           vec<c_token> clauses)
 {
   if (flag_cilkplus
-      && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
+      && (clauses.exists () || parser->simd_attr_present)
+      && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
     {
-      error ("%<#pragma omp declare simd%> cannot be used in the same "
+      error ("%<#pragma omp declare simd%> or __simd__ attribute cannot be 
used in the same "
             "function marked as a Cilk Plus SIMD-enabled function");
       vec_free (parser->cilk_simd_fn_tokens);
       return;
@@ -14245,7 +14260,7 @@ c_finish_omp_declare_simd (c_parser *parser, tree 
fndecl, tree parms,
   unsigned int tokens_avail = parser->tokens_avail;
   gcc_assert (parser->tokens == &parser->tokens_buf[0]);
   bool is_cilkplus_cilk_simd_fn = false;
-  
+ 
   if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens))
     {
       parser->tokens = parser->cilk_simd_fn_tokens->address ();
@@ -14257,41 +14272,63 @@ c_finish_omp_declare_simd (c_parser *parser, tree 
fndecl, tree parms,
       parser->tokens = clauses.address ();
       parser->tokens_avail = clauses.length ();
     }
-  
-  /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end.  */
-  while (parser->tokens_avail > 3)
+
+  if (parser->simd_attr_present
+      && is_cilkplus_cilk_simd_fn)
     {
-      c_token *token = c_parser_peek_token (parser);
-      if (!is_cilkplus_cilk_simd_fn) 
-       gcc_assert (token->type == CPP_NAME 
-                   && strcmp (IDENTIFIER_POINTER (token->value), "simd") == 0);
-      else
-       gcc_assert (token->type == CPP_NAME
-                   && is_cilkplus_vector_p (token->value));
-      c_parser_consume_token (parser);
-      parser->in_pragma = true;
+      error ("SIMD-enabled function attributes"
+            "are allowed when attribute __simd__ is specified");
+      clauses[0].type = CPP_EOF;
+      return;
+    }
 
+  /* Attach `omp declare simd’ attribute if __simd__ is specified AND no 
OpenMP clauses
+     present in decl.  */
+  if (parser->simd_attr_present
+      && parser->tokens_avail == 0)
+    {
       tree c = NULL_TREE;
-      if (is_cilkplus_cilk_simd_fn) 
-       c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
-                                     "SIMD-enabled functions attribute");
-      else 
-       c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
-                                     "#pragma omp declare simd");
-      c = c_omp_declare_simd_clauses_to_numbers (parms, c);
-      if (c != NULL_TREE)
-       c = tree_cons (NULL_TREE, c, NULL_TREE);
-      if (is_cilkplus_cilk_simd_fn) 
-       { 
-         tree k = build_tree_list (get_identifier ("cilk simd function"), 
-                                   NULL_TREE);
-         TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
-         DECL_ATTRIBUTES (fndecl) = k;
-       } 
       c = build_tree_list (get_identifier ("omp declare simd"), c);
       TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
       DECL_ATTRIBUTES (fndecl) = c;
     }
+  else
+    {
+      /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end.  
*/
+      while (parser->tokens_avail > 3)
+       {
+         c_token *token = c_parser_peek_token (parser);
+         if (!is_cilkplus_cilk_simd_fn)
+           gcc_assert (token->type == CPP_NAME
+                       && strcmp (IDENTIFIER_POINTER (token->value), "simd") 
== 0);
+         else
+           gcc_assert (token->type == CPP_NAME
+                       && is_cilkplus_vector_p (token->value));
+         c_parser_consume_token (parser);
+         parser->in_pragma = true;
+
+         tree c = NULL_TREE;
+         if (is_cilkplus_cilk_simd_fn)
+           c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK,
+                                         "SIMD-enabled functions attribute");
+         else
+           c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK,
+                                         "#pragma omp declare simd");
+         c = c_omp_declare_simd_clauses_to_numbers (parms, c);
+         if (c != NULL_TREE)
+           c = tree_cons (NULL_TREE, c, NULL_TREE);
+         if (is_cilkplus_cilk_simd_fn)
+           {
+             tree k = build_tree_list (get_identifier ("cilk simd function"),
+                                       NULL_TREE);
+             TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl);
+             DECL_ATTRIBUTES (fndecl) = k;
+           }
+         c = build_tree_list (get_identifier ("omp declare simd"), c);
+         TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl);
+         DECL_ATTRIBUTES (fndecl) = c;
+       }
+    }
 
   parser->tokens = &parser->tokens_buf[0];
   parser->tokens_avail = tokens_avail;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 79440d3..6296a80 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -3066,6 +3066,20 @@ This function attribute make a stack protection of the 
function if
 flags @option{fstack-protector} or @option{fstack-protector-strong}
 or @option{fstack-protector-explicit} are set.
 
+@item simd
+@cindex @code{simd} function attribute.
+This attribute enables creation of one or more function versions that
+can process multiple arguments using SIMD instructions from a
+single invocation.  Specifying this attribute allows compiler to
+assume that such a versions are available at link time (provided
+in the same or another translation unit).  Generated versions are
+target dependent and described in corresponding Vector ABI document.  For
+x86_64 target this document can be found
+@w{@uref{https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt,here}}.
+It is prohibited to use the attribute along with Cilk Plus's @code{vector}
+attribute. If the attribute is specified and @code{#pragma omp declare simd}
+presented on a declaration, then the attribute is ignored.
+
 @item target (@var{options})
 @cindex @code{target} function attribute
 Multiple target back ends implement the @code{target} attribute
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index cdcf9d6..87537cd 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -13919,10 +13919,7 @@ public:
 bool
 pass_omp_simd_clone::gate (function *)
 {
-  return ((flag_openmp || flag_openmp_simd
-          || flag_cilkplus
-          || (in_lto_p && !flag_wpa))
-         && (targetm.simd_clone.compute_vecsize_and_simdlen != NULL));
+  return targetm.simd_clone.compute_vecsize_and_simdlen != NULL;
 }
 
 } // anon namespace
diff --git a/gcc/testsuite/c-c++-common/attr-simd-2.c 
b/gcc/testsuite/c-c++-common/attr-simd-2.c
new file mode 100644
index 0000000..263fa9a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-simd-2.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-optimized -fopenmp-simd" } */
+
+#pragma omp declare simd
+__attribute__((__simd__))
+static int simd_attr (void)
+{
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "simdclone" "optimized" } } */
diff --git a/gcc/testsuite/c-c++-common/attr-simd-3.c 
b/gcc/testsuite/c-c++-common/attr-simd-3.c
new file mode 100644
index 0000000..2bbdf04
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-simd-3.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-fcilkplus" } */
+/* { dg-prune-output "undeclared here \\(not in a function\\)|\[^\n\r\]* was 
not declared in this scope" } */
+
+void f () __attribute__((__simd__, __vector__)); /* { dg-error "in the same 
function marked as a Cilk Plus" } */
diff --git a/gcc/testsuite/c-c++-common/attr-simd.c 
b/gcc/testsuite/c-c++-common/attr-simd.c
new file mode 100644
index 0000000..5dad89c
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attr-simd.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-optimized" } */
+
+__attribute__((__simd__))
+static int simd_attr (void)
+{
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "simdclone" "optimized" } } */

Reply via email to