From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58005 invoked by alias); 10 Nov 2015 08:44:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 57994 invoked by uid 89); 10 Nov 2015 08:44:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f169.google.com Received: from mail-qk0-f169.google.com (HELO mail-qk0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 10 Nov 2015 08:44:52 +0000 Received: by qkao63 with SMTP id o63so40479436qka.2 for ; Tue, 10 Nov 2015 00:44:50 -0800 (PST) X-Received: by 10.55.72.70 with SMTP id v67mr2591713qka.83.1447145090231; Tue, 10 Nov 2015 00:44:50 -0800 (PST) Received: from msticlxl57.ims.intel.com (jfdmzpr06-ext.jf.intel.com. [134.134.137.75]) by smtp.gmail.com with ESMTPSA id z76sm900898qgz.46.2015.11.10.00.44.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2015 00:44:48 -0800 (PST) Date: Tue, 10 Nov 2015 08:44:00 -0000 From: Kirill Yukhin To: Jakub Jelinek Cc: Joseph Myers , Jeff Law , GCC Patches Subject: Re: [PATCH, VECTOR ABI] Add __attribute__((__simd__)) to GCC. Message-ID: <20151110084414.GA62112@msticlxl57.ims.intel.com> References: <20151015143909.GF478@tucnak.redhat.com> <20151015144739.GB2191@msticlxl57.ims.intel.com> <20151022115151.GA58371@msticlxl57.ims.intel.com> <20151023141102.GA63293@msticlxl57.ims.intel.com> <20151027140655.GC46998@msticlxl57.ims.intel.com> <20151027141505.GG478@tucnak.redhat.com> <20151028091601.GA53647@msticlxl57.ims.intel.com> <20151029085447.GP478@tucnak.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151029085447.GP478@tucnak.redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg01155.txt.bz2 Hi Jakub, On 29 Oct 09:54, Jakub Jelinek wrote: > On Wed, Oct 28, 2015 at 12:16:04PM +0300, Kirill Yukhin wrote: > > Bootstrapped. Regtested. Is it ok for trunk? > > > > > > gcc/ > > * omp-low.c (pass_omp_simd_clone::gate): If target allows - call > > without additional conditions. > > * doc/extend.texi (simd): Document new attribute. > > gcc/cp/ > > * parser.h (cp_parser): Add simd_attr_present. > > * parser.c (cp_parser_late_return_type_opt): Handle simd_attr_present, > > require comman in __vector__ attribute. > > (cp_parser_gnu_attribute_list): Ditto. > > gcc/c/ > > * c-parser.c (c_parser): Add simd_attr_present flag. > > (c_parser_declaration_or_fndef): Call c_parser_declaration_or_fndef > > if simd_attr_present is set. > > (c_finish_omp_declare_simd): Handle simd_attr_present. > > Actually, do you plan to eventually add some clauses/operands to the simd > attribute, or is the plan to just say that simd attribute is > #pragma omp declare simd > with no clauses as if -fopenmp-simd has been enabled? I think so/ > If you don't plan to add any clauses, I wonder whether you really need to > add any parser changes at all, whether this couldn't be all handled in > c-family/c-common.c - handle_simd_attribute, adding simd to the attribute > table in there as a function decl attribute, and simply when processing it > add > tree c = build_tree_list (get_identifier ("omp declare simd"), NULL_TREE); > TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); > DECL_ATTRIBUTES (fndecl) = c; > (after checking whether the attribute isn't already present and erroring out > if there is "cilk simd function" attribute). > The reason for the (admittedly ugly) parser changes for #pragma omp declare simd is > that the clauses on the directive refer to parameters that will be declared > later, so we need to save the tokens of the pragma and then after parsing > the parameter declarations actually parse the clauses. But, in the simd > attribute case, there are no clauses, there is nothing to parse later. I've refactored the patch. New tests pass except one, which fails due to PR68158. Bootstrapped and reg-tested. Is it ok for trunk? gcc/ * omp-low.c (pass_omp_simd_clone::gate): If target allows - call without additional conditions. * doc/extend.texi (@item simd): New. gcc/c-family/ * c-common.c (handle_simd_attribute): New. (struct attribute_spec): Add entry for "simd". (handle_simd_attribute): New gcc/c/ * c-parser.c (c_finish_omp_declare_simd): Look for "simd" attribute as well. Update error message. gcc/cp/ * parser.c (cp_parser_late_parsing_cilk_simd_fn_info): Look for "simd" attribute as well. Update error message. gcc/testsuite/ * c-c++-common/attr-simd.c: New test. * c-c++-common/attr-simd-2.c: Ditto. * c-c++-common/attr-simd-3.c: Ditto. > Jakub -- Thanks, K diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 1c75921..08ab220 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -392,6 +392,7 @@ static tree handle_warn_unused_attribute (tree *, tree, tree, int, bool *); static tree handle_returns_nonnull_attribute (tree *, tree, tree, int, bool *); static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *); +static tree handle_simd_attribute (tree *, tree, tree, int, bool *); static tree handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *); static tree handle_designated_init_attribute (tree *, tree, tree, int, bool *); @@ -818,6 +819,8 @@ const struct attribute_spec c_common_attribute_table[] = handle_omp_declare_simd_attribute, false }, { "cilk simd function", 0, -1, true, false, false, handle_omp_declare_simd_attribute, false }, + { "simd", 0, -1, true, false, false, + handle_simd_attribute, false }, { "omp declare target", 0, 0, true, false, false, handle_omp_declare_target_attribute, false }, { "alloc_align", 1, 1, false, true, true, @@ -8955,6 +8958,37 @@ handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *) return NULL_TREE; } +/* Handle an "simd" attribute. */ + +static tree +handle_simd_attribute (tree *node, tree name, tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + if (TREE_CODE (*node) == FUNCTION_DECL) + { + if (lookup_attribute ("cilk simd function", DECL_ATTRIBUTES (*node)) != NULL) + { + error_at (DECL_SOURCE_LOCATION (*node), + "%<__simd__%> attribute cannot be " + "used in the same function marked as a Cilk Plus SIMD-enabled function"); + *no_add_attrs = true; + } + else + { + DECL_ATTRIBUTES (*node) + = tree_cons (get_identifier ("omp declare simd"), + NULL_TREE, DECL_ATTRIBUTES (*node)); + } + } + else + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle an "omp declare target" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index c8c6a2d..3dce493 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -15388,9 +15388,11 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, vec clauses) { if (flag_cilkplus - && clauses.exists () && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) + && (clauses.exists () + || lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl))) + && !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 % attribute cannot be used in the same " "function marked as a Cilk Plus SIMD-enabled function"); vec_free (parser->cilk_simd_fn_tokens); return; @@ -15429,6 +15431,16 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, parser->tokens = parser->cilk_simd_fn_tokens->address (); parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens); is_cilkplus_cilk_simd_fn = true; + + if (lookup_attribute ("simd", DECL_ATTRIBUTES (fndecl)) != NULL) + { + error_at (DECL_SOURCE_LOCATION (fndecl), + "%<__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; + } + } else { @@ -15460,12 +15472,12 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, 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; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7555bf3..f3831b9 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -34534,10 +34534,11 @@ cp_parser_late_parsing_cilk_simd_fn_info (cp_parser *parser, tree attrs) cp_omp_declare_simd_data *info = parser->cilk_simd_fn_info; int ii = 0; - if (parser->omp_declare_simd != NULL) + if (parser->omp_declare_simd != NULL + || lookup_attribute ("simd", attrs)) { - error ("%<#pragma omp declare simd%> cannot be used in the same function" - " marked as a Cilk Plus SIMD-enabled function"); + error ("%<#pragma omp declare simd%> of % attribute cannot be used " + "in the same function marked as a Cilk Plus SIMD-enabled function"); XDELETE (parser->cilk_simd_fn_info); parser->cilk_simd_fn_info = NULL; return attrs; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index fdb1547..32994a2 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -3066,6 +3066,21 @@ 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 and @code{-fopenmp} or @code{-fopenmp-simd} +switch is specified, 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 ad7c017..232dc5c 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -17412,10 +17412,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..e9afc11 --- /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 "omp declare simd" "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..6fd757a --- /dev/null +++ b/gcc/testsuite/c-c++-common/attr-simd.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-fdump-tree-optimized" } */ + +__attribute__((__simd__)) +static int simd_attr (void) +{ + return 0; +} + +__attribute__((simd)) +static int simd_attr2 (void) +{ + return 0; +} + +/* { dg-final { scan-tree-dump "simd_attr\[ \\t\]simdclone|vector" "optimized" } } */ +/* { dg-final { scan-tree-dump "simd_attr2\[ \\t\]simdclone|vector" "optimized" } } */