From patchwork Thu Nov 5 05:18:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 540267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D3CE9140E31 for ; Thu, 5 Nov 2015 16:18:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=KYsycdHT; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=J2tJBaQkXEdo5oPEhFwWigWd2fb2xpi3UAgt91GLHzoRMGv7moCES EjdnWAfXo2gWFVgFqEWOm9e4tdPSej3e8PmjSGgEP+Oh7JeLl3Rwx1GM4oYzo4kM FYW8phq6qsrNDe07aqMi9cyGE5rViuh8Ke6Zt2ICx/dyukHXhwR77Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=zsV/0mShBRpr38vnJo/7KrHH2Uk=; b=KYsycdHTGfl+WtuwMGTj Op5ikAWbnB/oxFFck2kvNniXQzzYUQZHJ98T1vWk38srmq3cL7iKAXWoXNvqC2pL PHYR77fsw7bvGgKAhth5S6VOWx60Qo1G6LXXmbIBI8zeJ+7fj82QfM+V8FjWtAn3 kPS2+vq9uwYM8LzvDox72eM= Received: (qmail 58220 invoked by alias); 5 Nov 2015 05:18:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 58209 invoked by uid 89); 5 Nov 2015 05:18:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Nov 2015 05:18:42 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1ZuCwY-0005XK-8T from Cesar_Philippidis@mentor.com for gcc-patches@gcc.gnu.org; Wed, 04 Nov 2015 21:18:38 -0800 Received: from [127.0.0.1] (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Wed, 4 Nov 2015 21:18:38 -0800 From: Cesar Philippidis Subject: [gomp4] assorted trunk backports To: "gcc-patches@gcc.gnu.org" Message-ID: <563AE6AD.1080408@codesourcery.com> Date: Wed, 4 Nov 2015 21:18:37 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 I've applied this patch to gomp-4_0-branch which does the following: * reverts some of the fortran changes that Jakub rejected for trunk, specifically those involving resolve_omp_duplicate_list * updates how num_gangs, num_workers and vector_length are parsed by the c++ FE * changes how errors are reported for acc update when no clauses are specified and updates the test cases for c, c++ and fortran * shuffles around various code to match trunk in the fortran FE We probably should update the way the c FE handles num_gangs, num_workers and vector_length too, but I left it as-is since it works. The c++ FE would have had problems with template support eventually because it was doing type checking during scanning. Cesar 2015-11-04 Cesar Philippidis gcc/c/ * c-parser.c (c_parser_oacc_update): Update the error message for missing clauses. gcc/cp/ * parser.c (cp_parser_oacc_simple_clause): New function. (cp_parser_oacc_clause_vector_length): Delete. (cp_parser_omp_clause_num_gangs): Delete. (cp_parser_omp_clause_num_workers): Delete. (cp_parser_oacc_all_clauses): Use cp_parser_oacc_simple_clause for num_gangs, num_workers and vector_length. (cp_parser_oacc_update): Update the error message for missing clauses. gcc/fortran/ * openmp.c (gfc_match_omp_clauses): Update how default is parsed. (gfc_match_oacc_update): Update error message. (resolve_omp_clauses): Don't use resolve_omp_duplicate_list for omp clauses. (oacc_code_to_statement): Merge atomic placement from trunk. gcc/testsuite/ * c-c++-common/goacc/update-1.c: Update expected error. * gfortran.dg/goacc/update.f95: Likewise. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 45e4248..fa70055 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -14060,7 +14060,7 @@ c_parser_oacc_update (c_parser *parser) { error_at (loc, "%<#pragma acc update%> must contain at least one " - "% or % clause"); + "% or % or % clause"); return; } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 1e2afdb..ce8bc6a 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -29652,6 +29652,39 @@ cp_parser_oacc_simple_clause (cp_parser * /* parser */, return c; } + /* OpenACC: + num_gangs ( expression ) + num_workers ( expression ) + vector_length ( expression ) */ + +static tree +cp_parser_oacc_single_int_clause (cp_parser *parser, omp_clause_code code, + const char *str, tree list) +{ + location_t loc = cp_lexer_peek_token (parser->lexer)->location; + + if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) + return list; + + tree t = cp_parser_assignment_expression (parser, NULL, false, false); + + if (t == error_mark_node + || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) + { + cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, + /*or_comma=*/false, + /*consume_paren=*/true); + return list; + } + + check_no_duplicate_clause (list, code, str, loc); + + tree c = build_omp_clause (loc, code); + OMP_CLAUSE_OPERAND (c, 0) = t; + OMP_CLAUSE_CHAIN (c) = list; + return c; +} + /* OpenACC: gang [( gang-arg-list )] @@ -29923,45 +29956,6 @@ cp_parser_oacc_clause_tile (cp_parser *parser, tree list, location_t here) return c; } -/* OpenACC: - vector_length ( expression ) */ - -static tree -cp_parser_oacc_clause_vector_length (cp_parser *parser, tree list) -{ - tree t, c; - location_t location = cp_lexer_peek_token (parser->lexer)->location; - bool error = false; - - if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) - return list; - - t = cp_parser_condition (parser); - if (t == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (t))) - { - error_at (location, "expected positive integer expression"); - error = true; - } - - if (error || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) - { - cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, - /*or_comma=*/false, - /*consume_paren=*/true); - return list; - } - - check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length", - location); - - c = build_omp_clause (location, OMP_CLAUSE_VECTOR_LENGTH); - OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; - OMP_CLAUSE_CHAIN (c) = list; - list = c; - - return list; -} - /* OpenACC 2.0 Parse wait clause or directive parameters. */ @@ -30345,42 +30339,6 @@ cp_parser_omp_clause_nowait (cp_parser * /*parser*/, return c; } -/* OpenACC: - num_gangs ( expression ) */ - -static tree -cp_parser_omp_clause_num_gangs (cp_parser *parser, tree list) -{ - tree t, c; - location_t location = cp_lexer_peek_token (parser->lexer)->location; - - if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) - return list; - - t = cp_parser_condition (parser); - - if (t == error_mark_node - || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) - cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, - /*or_comma=*/false, - /*consume_paren=*/true); - - if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) - { - error_at (location, "expected positive integer expression"); - return list; - } - - check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs", location); - - c = build_omp_clause (location, OMP_CLAUSE_NUM_GANGS); - OMP_CLAUSE_NUM_GANGS_EXPR (c) = t; - OMP_CLAUSE_CHAIN (c) = list; - list = c; - - return list; -} - /* OpenMP 2.5: num_threads ( expression ) */ @@ -30589,43 +30547,6 @@ cp_parser_omp_clause_defaultmap (cp_parser *parser, tree list, return list; } -/* OpenACC: - num_workers ( expression ) */ - -static tree -cp_parser_omp_clause_num_workers (cp_parser *parser, tree list) -{ - tree t, c; - location_t location = cp_lexer_peek_token (parser->lexer)->location; - - if (!cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN)) - return list; - - t = cp_parser_condition (parser); - - if (t == error_mark_node - || !cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN)) - cp_parser_skip_to_closing_parenthesis (parser, /*recovering=*/true, - /*or_comma=*/false, - /*consume_paren=*/true); - - if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) - { - error_at (location, "expected positive integer expression"); - return list; - } - - check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_gangs", - location); - - c = build_omp_clause (location, OMP_CLAUSE_NUM_WORKERS); - OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t; - OMP_CLAUSE_CHAIN (c) = list; - list = c; - - return list; -} - /* OpenMP 2.5: ordered @@ -31687,6 +31608,7 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, { location_t here; pragma_omp_clause c_kind; + omp_clause_code code; const char *c_name; tree prev = clauses; @@ -31803,12 +31725,16 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, c_name = "nohost"; break; case PRAGMA_OACC_CLAUSE_NUM_GANGS: - clauses = cp_parser_omp_clause_num_gangs (parser, clauses); + code = OMP_CLAUSE_NUM_GANGS; c_name = "num_gangs"; + clauses = cp_parser_oacc_single_int_clause (parser, code, c_name, + clauses); break; case PRAGMA_OACC_CLAUSE_NUM_WORKERS: - clauses = cp_parser_omp_clause_num_workers (parser, clauses); c_name = "num_workers"; + code = OMP_CLAUSE_NUM_WORKERS; + clauses = cp_parser_oacc_single_int_clause (parser, code, c_name, + clauses); break; case PRAGMA_OACC_CLAUSE_PRESENT: clauses = cp_parser_oacc_data_clause (parser, c_kind, clauses); @@ -31859,8 +31785,10 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask, c_name, clauses); break; case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: - clauses = cp_parser_oacc_clause_vector_length (parser, clauses); c_name = "vector_length"; + code = OMP_CLAUSE_VECTOR_LENGTH; + clauses = cp_parser_oacc_single_int_clause (parser, code, c_name, + clauses); break; case PRAGMA_OACC_CLAUSE_WAIT: clauses = cp_parser_oacc_clause_wait (parser, clauses); @@ -35268,7 +35196,7 @@ cp_parser_oacc_update (cp_parser *parser, cp_token *pragma_tok) { error_at (pragma_tok->location, "%<#pragma acc update%> must contain at least one " - "% or % clause"); + "% or % or % clause"); return NULL_TREE; } diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index 4ca22cd..2b6422c 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -914,14 +914,15 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, uint64_t mask, if ((mask & OMP_CLAUSE_DEFAULT) && c->default_sharing == OMP_DEFAULT_UNKNOWN) { - if (!openacc && gfc_match ("default ( shared )") == MATCH_YES) + if (gfc_match ("default ( none )") == MATCH_YES) + c->default_sharing = OMP_DEFAULT_NONE; + else if (openacc) + /* c->default_sharing = OMP_DEFAULT_UNKNOWN */; + else if (gfc_match ("default ( shared )") == MATCH_YES) c->default_sharing = OMP_DEFAULT_SHARED; - else if (!openacc && gfc_match ("default ( private )") == MATCH_YES) + else if (gfc_match ("default ( private )") == MATCH_YES) c->default_sharing = OMP_DEFAULT_PRIVATE; - else if (gfc_match ("default ( none )") == MATCH_YES) - c->default_sharing = OMP_DEFAULT_NONE; - else if (!openacc - && gfc_match ("default ( firstprivate )") == MATCH_YES) + else if (gfc_match ("default ( firstprivate )") == MATCH_YES) c->default_sharing = OMP_DEFAULT_FIRSTPRIVATE; if (c->default_sharing != OMP_DEFAULT_UNKNOWN) continue; @@ -1547,7 +1548,7 @@ gfc_match_oacc_update (void) if (!c->lists[OMP_LIST_MAP]) { gfc_error ("% must contain at least one " - "% or % clause at %L", &here); + "% or % or % clause at %L", &here); return MATCH_ERROR; } @@ -3290,24 +3291,75 @@ resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses, && list != OMP_LIST_DEPEND && (list != OMP_LIST_MAP || openacc) && list != OMP_LIST_FROM - && list != OMP_LIST_TO) - resolve_omp_duplicate_list (omp_clauses->lists[list], openacc, list); + && list != OMP_LIST_TO + && (list != OMP_LIST_REDUCTION || !openacc)) + for (n = omp_clauses->lists[list]; n; n = n->next) + { + if (n->sym->mark) + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + else + n->sym->mark = 1; + } - resolve_omp_duplicate_list (omp_clauses->lists[OMP_LIST_FIRSTPRIVATE], - false, OMP_LIST_FIRSTPRIVATE); + gcc_assert (OMP_LIST_LASTPRIVATE == OMP_LIST_FIRSTPRIVATE + 1); + for (list = OMP_LIST_FIRSTPRIVATE; list <= OMP_LIST_LASTPRIVATE; list++) + for (n = omp_clauses->lists[list]; n; n = n->next) + if (n->sym->mark) + { + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + n->sym->mark = 0; + } + for (n = omp_clauses->lists[OMP_LIST_FIRSTPRIVATE]; n; n = n->next) + { + if (n->sym->mark) + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + else + n->sym->mark = 1; + } for (n = omp_clauses->lists[OMP_LIST_LASTPRIVATE]; n; n = n->next) n->sym->mark = 0; - resolve_omp_duplicate_list (omp_clauses->lists[OMP_LIST_LASTPRIVATE], - false, OMP_LIST_LASTPRIVATE); + for (n = omp_clauses->lists[OMP_LIST_LASTPRIVATE]; n; n = n->next) + { + if (n->sym->mark) + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + else + n->sym->mark = 1; + } for (n = omp_clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next) n->sym->mark = 0; - resolve_omp_duplicate_list (omp_clauses->lists[OMP_LIST_ALIGNED], - false, OMP_LIST_ALIGNED); + for (n = omp_clauses->lists[OMP_LIST_ALIGNED]; n; n = n->next) + { + if (n->sym->mark) + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + else + n->sym->mark = 1; + } + + /* OpenACC reductions. */ + if (openacc) + { + for (n = omp_clauses->lists[OMP_LIST_REDUCTION]; n; n = n->next) + n->sym->mark = 0; + for (n = omp_clauses->lists[OMP_LIST_REDUCTION]; n; n = n->next) + { + if (n->sym->mark) + gfc_error ("Symbol %qs present on multiple clauses at %L", + n->sym->name, &n->where); + else + n->sym->mark = 1; + } + } + for (n = omp_clauses->lists[OMP_LIST_TO]; n; n = n->next) n->sym->mark = 0; for (n = omp_clauses->lists[OMP_LIST_FROM]; n; n = n->next) @@ -4594,8 +4646,7 @@ oacc_code_to_statement (gfc_code *code) { switch (code->op) { - case EXEC_OACC_ATOMIC: - return ST_OACC_ATOMIC; + case EXEC_OACC_PARALLEL: return ST_OACC_PARALLEL; case EXEC_OACC_KERNELS: @@ -4610,6 +4661,8 @@ oacc_code_to_statement (gfc_code *code) return ST_OACC_KERNELS_LOOP; case EXEC_OACC_LOOP: return ST_OACC_LOOP; + case EXEC_OACC_ATOMIC: + return ST_OACC_ATOMIC; default: gcc_unreachable (); } diff --git a/gcc/testsuite/c-c++-common/goacc/update-1.c b/gcc/testsuite/c-c++-common/goacc/update-1.c index 97e9379..701ef36 100644 --- a/gcc/testsuite/c-c++-common/goacc/update-1.c +++ b/gcc/testsuite/c-c++-common/goacc/update-1.c @@ -1,7 +1,7 @@ void f (void) { -#pragma acc update /* { dg-error "'#pragma acc update' must contain at least one 'device' or 'host/self' clause" } */ +#pragma acc update /* { dg-error "'#pragma acc update' must contain at least one 'device' or 'host' or 'self' clause" } */ int i = 0; int a[10]; diff --git a/gcc/testsuite/gfortran.dg/goacc/update.f95 b/gcc/testsuite/gfortran.dg/goacc/update.f95 index ae23dfc..d88d20e 100644 --- a/gcc/testsuite/gfortran.dg/goacc/update.f95 +++ b/gcc/testsuite/gfortran.dg/goacc/update.f95 @@ -1,5 +1,5 @@ ! { dg-do compile } program foo - !$acc update ! { dg-error "must contain at least one 'device' or 'host/self' clause" } + !$acc update ! { dg-error "must contain at least one 'device' or 'host' or 'self' clause" } end program foo