From patchwork Fri Aug 18 17:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 136048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1570375vqi; Fri, 18 Aug 2023 10:42:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjlo6TOnnbDiOZ4CzCgFrDVAXwaS2VOjxu+jORxelMGJY7R0tN7NHCKxIt7OBYrUfi9CkV X-Received: by 2002:aa7:d989:0:b0:522:1d1d:1de8 with SMTP id u9-20020aa7d989000000b005221d1d1de8mr2568451eds.2.1692380553953; Fri, 18 Aug 2023 10:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692380553; cv=none; d=google.com; s=arc-20160816; b=mUn4iLeg261LKXpLAMKwGfHSmv9omsE2rky9emkVcRNOliNKGO5TlKnXFkKEJMahS+ fxBuu6q/bn6GU95yojXJE9z5rU77r5ZQcrEJtjA/gFBd7XD2Lfh0LNBWKlpy3pzndTRD yPgfz16VfDtYK7261siHjQ34ED3Qa7rgej5kUe/QPM4C54LuENyoU34apGs3vN6O4SPc fZiOtKYwA5mR1TxH1ECfYGGPSzxvpmVyXrV5eqfD0D6f73Hbw+I6Ou+t49+SLA50aR5s svUH1p8qE+UD8u9obM/TnDPA4GeP3YfsiNH02ceUavzIbYNZ2Wwkev5n+w83CG7d3JNs tVkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:ironport-sdr:dmarc-filter:delivered-to; bh=3+Px71hsbjEzYLAdse8xY0WHk+oumq4O1uPgJmLd+iM=; fh=FjmNZF1SyD2luHyimf3O/CuPis5iJRQL/WGF12E3/GM=; b=HlILj/4IyFvNeROXRmjfBOlYh9s39iBUOPmd2LmP2QDL3GxL6RgLV7dwp0x5sxrbWG QxreqVxOBz3e4Mp3BKwd8xXHlBNpXst6QgWVdTdgHFunA/QxD4YxOSt2i+AQn0Euragc Nw33zKJdX/r/mIVtI3a2X1xRpBtDHTUNlPM55otxnax7jVJSKxzr97nhAKvAFf7rC03e 9uvtlFoBxOzX3kbl5IDhgEmHLGmOpSK4gsLjnfx2JG2r9gSbCch40DKKqG1233OheaNk VF+4cdMeB8HMcK90Qk/AgghLQTKEmDGEoB2ghadxj75xcbaKXD9nQ3vxejYp3fIv4FEg 33mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d5-20020aa7ce05000000b005222a65b38esi1512919edv.66.2023.08.18.10.42.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 10:42:33 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74F5A388267E for ; Fri, 18 Aug 2023 17:41:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 563053850861 for ; Fri, 18 Aug 2023 17:40:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 563053850861 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.01,183,1684828800"; d="scan'208";a="14812578" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 18 Aug 2023 09:40:04 -0800 IronPort-SDR: MBlFImkfxpz656tqLZbM7+qg3FNF1sD7M79av0otUd4Vq0OYqTkQ7WPUS6iYf1yxqP+brBAYR5 Lw5p/ngJxC35jzMgKnU7o5hPpNn3lCmurrUD5CXuopjam75Fqnkju7+9LvDIR9AYiXEw+1h9BR 3372VplHLCifb1l60IqEW1wioxZauXOUVO/tRjIi8xS+2gZnvkWdihby2MvaVPTToV/sVVswGD wzsso+aT1M8ueYObDaeD7jXOAj+12BCNE0a7z9Q82IgARgo/JeIS77bRC685vAGzz0IFezLTkH wVY= From: Sandra Loosemore To: CC: , , Subject: [OG13, committed 2/3] OpenMP: C++ attribute syntax fixes/testcases for "declare mapper" Date: Fri, 18 Aug 2023 11:39:36 -0600 Message-ID: <20230818173938.430758-3-sandra@codesourcery.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230818173938.430758-1-sandra@codesourcery.com> References: <20230818173938.430758-1-sandra@codesourcery.com> MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-10.mgc.mentorg.com (147.34.90.210) To svr-orw-mbx-13.mgc.mentorg.com (147.34.90.213) X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774589631780280182 X-GMAIL-MSGID: 1774589631780280182 gcc/c-family/ChangeLog * c-omp.cc (c_omp_directives): Uncomment "declare mapper" entry. gcc/cp/ChangeLog * parser.cc (cp_parser_omp_declare_mapper): Allow commas between clauses. gcc/testsuite/ChangeLog * g++.dg/gomp/attrs-declare-mapper-3.C: New file. * g++.dg/gomp/attrs-declare-mapper-4.C: New file. * g++.dg/gomp/attrs-declare-mapper-5.C: New file. * g++.dg/gomp/attrs-declare-mapper-6.C: New file. --- gcc/c-family/ChangeLog.omp | 4 + gcc/c-family/c-omp.cc | 4 +- gcc/cp/ChangeLog.omp | 5 ++ gcc/cp/parser.cc | 2 + gcc/testsuite/ChangeLog.omp | 7 ++ .../g++.dg/gomp/attrs-declare-mapper-3.C | 31 ++++++++ .../g++.dg/gomp/attrs-declare-mapper-4.C | 74 +++++++++++++++++++ .../g++.dg/gomp/attrs-declare-mapper-5.C | 26 +++++++ .../g++.dg/gomp/attrs-declare-mapper-6.C | 22 ++++++ 9 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-4.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-5.C create mode 100644 gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-6.C diff --git a/gcc/c-family/ChangeLog.omp b/gcc/c-family/ChangeLog.omp index 60f5c29276f..40cb8e811e5 100644 --- a/gcc/c-family/ChangeLog.omp +++ b/gcc/c-family/ChangeLog.omp @@ -1,3 +1,7 @@ +2023-08-18 Sandra Loosemore + + * c-omp.cc (c_omp_directives): Uncomment "declare mapper" entry. + 2023-08-10 Julian Brown * c-common.h (c_omp_region_type): Add C_ORT_UPDATE and C_ORT_OMP_UPDATE diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc index 9ff09b59bc6..7bc69e9e2da 100644 --- a/gcc/c-family/c-omp.cc +++ b/gcc/c-family/c-omp.cc @@ -5500,8 +5500,8 @@ const struct c_omp_directive c_omp_directives[] = { C_OMP_DIR_STANDALONE, false }, { "critical", nullptr, nullptr, PRAGMA_OMP_CRITICAL, C_OMP_DIR_CONSTRUCT, false }, - /* { "declare", "mapper", nullptr, PRAGMA_OMP_DECLARE, - C_OMP_DIR_DECLARATIVE, false }, */ + { "declare", "mapper", nullptr, PRAGMA_OMP_DECLARE, + C_OMP_DIR_DECLARATIVE, false }, { "declare", "reduction", nullptr, PRAGMA_OMP_DECLARE, C_OMP_DIR_DECLARATIVE, true }, { "declare", "simd", nullptr, PRAGMA_OMP_DECLARE, diff --git a/gcc/cp/ChangeLog.omp b/gcc/cp/ChangeLog.omp index 6e154ea3426..1b2d71422d8 100644 --- a/gcc/cp/ChangeLog.omp +++ b/gcc/cp/ChangeLog.omp @@ -1,3 +1,8 @@ +2023-08-18 Sandra Loosemore + + * parser.cc (cp_parser_omp_declare_mapper): Allow commas between + clauses. + 2023-08-18 Sandra Loosemore * parser.cc (analyze_metadirective_body): Handle CPP_PRAGMA and diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 84ec0de6c69..0ce2a7be608 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -50358,6 +50358,8 @@ cp_parser_omp_declare_mapper (cp_parser *parser, cp_token *pragma_tok, while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL)) { + if (cp_lexer_next_token_is (parser->lexer, CPP_COMMA)) + cp_lexer_consume_token (parser->lexer); pragma_omp_clause c_kind = cp_parser_omp_clause_name (parser); if (c_kind != PRAGMA_OMP_CLAUSE_MAP) { diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index a9b4ac3d0a7..a7d11777988 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,10 @@ +2023-08-18 Sandra Loosemore + + * g++.dg/gomp/attrs-declare-mapper-3.C: New file. + * g++.dg/gomp/attrs-declare-mapper-4.C: New file. + * g++.dg/gomp/attrs-declare-mapper-5.C: New file. + * g++.dg/gomp/attrs-declare-mapper-6.C: New file. + 2023-08-18 Sandra Loosemore * g++.dg/gomp/attrs-metadirective-1.C: New file. diff --git a/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C new file mode 100644 index 00000000000..36345fe0dc2 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-3.C @@ -0,0 +1,31 @@ +// { dg-do compile { target c++11 } } +// { dg-additional-options "-fdump-tree-gimple" } + +#include + +// Test named mapper invocation. + +struct S { + int *ptr; + int size; +}; + +int main (int argc, char *argv[]) +{ + int N = 1024; + [[omp::directive (declare mapper (mapN:struct S s) + map(to:s.ptr, s.size) + map(s.ptr[:N]))]]; + + struct S s; + s.ptr = (int *) malloc (sizeof (int) * N); + + [[omp::directive (target map(mapper(mapN), tofrom: s))]] +// { dg-final { scan-tree-dump {map\(struct:s \[len: 2\]\) map\(alloc:s\.ptr \[len: [0-9]+\]\) map\(to:s\.size \[len: [0-9]+\]\) map\(tofrom:\*_[0-9]+ \[len: _[0-9]+\]\) map\(attach:s\.ptr \[bias: 0\]\)} "gimple" } } + { + for (int i = 0; i < N; i++) + s.ptr[i]++; + } + + return 0; +} diff --git a/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-4.C b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-4.C new file mode 100644 index 00000000000..75cb48e8e44 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-4.C @@ -0,0 +1,74 @@ +/* { dg-do compile { target c++11 } } */ +/* { dg-additional-options "-fdump-tree-original" } */ + +/* Check mapper binding clauses. */ + +struct Y { + int z; +}; + +struct Z { + int z; +}; + +[[omp::directive (declare mapper (struct Y y) map(tofrom: y))]]; +[[omp::directive (declare mapper (struct Z z) map(tofrom: z))]]; + +int foo (void) +{ + struct Y yy; + struct Z zz; + int dummy; + + [[omp::directive (target data map(dummy))]] + { + [[omp::directive (target)]] + { + yy.z++; + zz.z++; + } + yy.z++; + } + return yy.z; +} + +struct P +{ + struct Z *zp; +}; + +int bar (void) +{ + struct Y yy; + struct Z zz; + struct P pp; + struct Z t; + int dummy; + + pp.zp = &t; + + [[omp::directive (declare mapper (struct Y y) map(tofrom: y.z))]]; + [[omp::directive (declare mapper (struct Z z) map(tofrom: z.z))]]; + + [[omp::directive (target data map(dummy))]] + { + [[omp::directive (target)]] + { + yy.z++; + zz.z++; + } + yy.z++; + } + + [[omp::directive (declare mapper(struct P x) map(to:x.zp), map(tofrom:*x.zp))]]; + + [[omp::directive (target)]] + { + zz = *pp.zp; + } + + return zz.z; +} + +/* { dg-final { scan-tree-dump-times {mapper_binding\(struct Y,omp declare mapper ~1Y\) mapper_binding\(struct Z,omp declare mapper ~1Z\)} 2 "original" { target c++ } } } */ +/* { dg-final { scan-tree-dump {mapper_binding\(struct Z,omp declare mapper ~1Z\) mapper_binding\(struct P,omp declare mapper ~1P\)} "original" { target c++ } } } */ diff --git a/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-5.C b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-5.C new file mode 100644 index 00000000000..711f058dc2b --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-5.C @@ -0,0 +1,26 @@ +/* { dg-do compile { target c++11 } } */ + +typedef struct S_ { + int *myarr; + int size; +} S; + +[[omp::directive (declare mapper (named: struct S_ v) + map(to:v.size, v.myarr) + map(tofrom: v.myarr[0:v.size]))]]; +/* { dg-note "'#pragma omp declare mapper \\(named: S_\\)' previously defined here" "" { target c++ } .-3 } */ + +[[omp::directive (declare mapper (named: S v) + map(to:v.size, v.myarr) + map(tofrom: v.myarr[0:v.size]))]]; +/* { dg-error "redefinition of '#pragma omp declare mapper \\(named: S\\)'" "" { target c++ } .-3 } */ + +[[omp::directive (declare mapper (struct S_ v) + map(to:v.size, v.myarr) + map(tofrom: v.myarr[0:v.size]))]]; +/* { dg-note "'#pragma omp declare mapper \\(S_\\)' previously defined here" "" { target c++ } .-3 } */ + +[[omp::directive (declare mapper (S v) + map(to:v.size, v.myarr) + map(tofrom: v.myarr[0:v.size]))]]; +/* { dg-error "redefinition of '#pragma omp declare mapper \\(S\\)'" "" { target c++ } .-3 } */ diff --git a/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-6.C b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-6.C new file mode 100644 index 00000000000..fb3a0deb5ef --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/attrs-declare-mapper-6.C @@ -0,0 +1,22 @@ +/* { dg-do compile { target c++11 } } */ + +int x = 5; + +struct Q { + int *arr1; + int *arr2; + int *arr3; +}; + +[[omp::directive (declare mapper (struct Q myq) map(myq.arr2[0:x]))]]; + +struct R { + int *arr1; + int *arr2; + int *arr3; +}; + +[[omp::directive (declare mapper (struct R myr) map(myr.arr3[0:y]))]]; +/* { dg-error "'y' was not declared in this scope" "" { target c++ } .-1 } */ + +int y = 7;