From patchwork Mon Jul 3 21:33:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 115494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp802678vqx; Mon, 3 Jul 2023 14:35:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFjE2BBJhhSeE1TYu1U3JmaoM2o4q6Nr71nsKXeMEbeONe8A44l1uhdlH7nLXPERtO5ALP5 X-Received: by 2002:aa7:d6d1:0:b0:51e:1a51:d414 with SMTP id x17-20020aa7d6d1000000b0051e1a51d414mr985364edr.32.1688420107789; Mon, 03 Jul 2023 14:35:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688420107; cv=none; d=google.com; s=arc-20160816; b=SKv6CGQNMVuDczfMrHOY029VB2Ntng8vTdolAYuICgMkbGcdX4l4jRosYCyn78OPhI /o6I2gJDe0YaslT7FnZ0YzCM5sD5Cv/pI9E6KvCOc0XTMT+gmMPMg7VSru1OC0dhKx4T kWLShPUG7jOi1BIvGwscTn67AEDvpmsouse+B1PuNg4BwQ46+Z0g61tKlYSA2QSzpo5j ptv/osPQK36VsphSgUfE/jXJDw7bB0gOo22HIEpcT0wZwWotbjb6tpSqPM684rQvu3Xw 4RKs5xwiepN/lasy+PpavQKIfMB7Rzshp0LI+E8qkSbP7+5Q5GPOBRitZbO5WodOiRjt Ht8Q== 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=KR0TI1H3IuqzzCMDZu9UQtxul+qNkx7eYCSqBLwpgFM=; fh=hjv/BLZXfesavC81yKN9rZNUPmZjTWdzJkx8i001DNY=; b=Q/Se2F/7gmmD/iMr+sS9/RVgf7yE+LiB5AOWzSHwIefZK6prWbdmIDF6Rjem4eqGmt tODWNepDw6YqLk6rj5ZJRiKhatZ8NkyLmFjSeoOYjyf6BuOFB54fim4f74NdBvA4o8ZD wcyjxmWF7wFsjRMAQSip+Y9lnmUm9+o2343Km/EoWS13nJ06I84sC+7DBA9WBH/CGFbK 89g7linff8tGQISgtYfFLEEKbgm/WSRVpxZBtM2sqpm1ZYCSaTyGi1/wA91jaNOIPvmY s/suT4mPo54dcTwfS6kGyd+kmIg/hxRAhGR6ggklJxnBTuPQ1OhLGh5AipFSQ4aTOcMS FJIA== 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 n15-20020aa7c68f000000b0051dd2c19606si6310011edq.465.2023.07.03.14.35.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 14:35:07 -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 5EEA2385482D for ; Mon, 3 Jul 2023 21:34:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 8C767385840F; Mon, 3 Jul 2023 21:33:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C767385840F 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,178,1684828800"; d="scan'208";a="12099558" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 03 Jul 2023 13:33:44 -0800 IronPort-SDR: sDKfqusResmXP4LskeXZbD+OsDzNleGwaVITILJ+Y1KSkrj5VjuZAru7S0tkWXOk99AWjxf1Y7 wTf7/Dyf1Orh5JPo6Q1uL0t+6U2s6fOCjwoSVY69+YV7Ao/EuozktdszXWZQJM0Xa52qQZHGGR WfX2OtPwXqTSRlsQxLiwY+Ex60ynPVntKSftwNS4tfoNrcgPvjaEs1r95WgIDiP1RKvo1SGJsJ Ej/ZDtItb7jdGYxYBv415V9lweDcuGSP0wtMS0iwpdCgCT/Bi2PAlKdPso1S1SOPphYCxcbE1K fs4= From: Julian Brown To: CC: , , Subject: [PATCH 1/5] OpenMP: Fix "exit data" for array sections for ref-to-ptr components Date: Mon, 3 Jul 2023 21:33:15 +0000 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770436803112939978?= X-GMAIL-MSGID: =?utf-8?q?1770436803112939978?= This patch fixes "exit data" for (C++) reference-to-pointer struct components with array sections, such as: struct S { int *&ptr; [...] }; ... #pragma omp target exit data map(from: str->ptr, str->ptr[0:n]) Such exits need two "detach" operations. We need to unmap both the pointer and the slice. That idiom is recognized by omp_resolve_clause_dependencies, but before omp_build_struct_sibling_lists finishes the resulting mapping nodes are represented like this: GOMP_MAP_FROM GOMP_MAP_DETACH GOMP_MAP_ATTACH_DETACH And at the moment, that won't be recognized as a single mapping group as it should be. This patch fixes that. (This is covered by a test case added in later patches in this series, e.g. libgomp/testsuite/libgomp.c++/array-shaping-8.C.) 2023-07-03 Julian Brown gcc/ * gimplify.cc (omp_get_attachment): Handle GOMP_MAP_DETACH here. (omp_group_last): Handle *, GOMP_MAP_DETACH, GOMP_MAP_ATTACH_DETACH groups for "exit data" of reference-to-pointer component array sections. (omp_group_base): Handle GOMP_MAP_DETACH. --- gcc/gimplify.cc | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 20aba45110f..6280eb7e028 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -9171,6 +9171,7 @@ omp_get_attachment (omp_mapping_group *grp) case GOMP_MAP_ATTACH_DETACH: case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION: + case GOMP_MAP_DETACH: return OMP_CLAUSE_DECL (node); default: @@ -9247,23 +9248,43 @@ omp_group_last (tree *start_p) == GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION) || (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION) + || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_DETACH || OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_ALWAYS_POINTER || omp_map_clause_descriptor_p (nc))) { - grp_last_p = &OMP_CLAUSE_CHAIN (c); - c = nc; tree nc2 = OMP_CLAUSE_CHAIN (nc); + if (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_DETACH) + { + /* In the specific case we're doing "exit data" on an array + slice of a reference-to-pointer struct component, we will see + DETACH followed by ATTACH_DETACH here. We want to treat that + as a single group. In other cases DETACH might represent a + stand-alone "detach" clause, so we don't want to consider + that part of the group. */ + if (nc2 + && OMP_CLAUSE_CODE (nc2) == OMP_CLAUSE_MAP + && OMP_CLAUSE_MAP_KIND (nc2) == GOMP_MAP_ATTACH_DETACH) + goto consume_two_nodes; + else + break; + } if (nc2 && OMP_CLAUSE_CODE (nc2) == OMP_CLAUSE_MAP && (OMP_CLAUSE_MAP_KIND (nc) == GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION) && OMP_CLAUSE_MAP_KIND (nc2) == GOMP_MAP_ATTACH) { + consume_two_nodes: grp_last_p = &OMP_CLAUSE_CHAIN (nc); c = nc2; - nc2 = OMP_CLAUSE_CHAIN (nc2); + nc = OMP_CLAUSE_CHAIN (nc2); + } + else + { + grp_last_p = &OMP_CLAUSE_CHAIN (c); + c = nc; + nc = nc2; } - nc = nc2; } break; @@ -9416,6 +9437,7 @@ omp_group_base (omp_mapping_group *grp, unsigned int *chained, case GOMP_MAP_ALWAYS_POINTER: case GOMP_MAP_ATTACH_DETACH: case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION: + case GOMP_MAP_DETACH: return *grp->grp_start; default: