From patchwork Fri Mar 10 23:53:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 66264 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB95D3851405 for ; Fri, 10 Mar 2023 23:54:23 +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 7A9B23858410 for ; Fri, 10 Mar 2023 23:53:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A9B23858410 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="5.98,251,1673942400"; d="scan'208";a="101174176" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 10 Mar 2023 15:53:21 -0800 IronPort-SDR: 42qKCZ3VQz4BSEPOAqG9xm2IE4Qzg4cH9ptQe0UjS5VgKdmoOLBpXuxVYxkDXmFWt2sUtzfUgt SBbBBdEYhVSpxdf1O22SAxsZ4lo6mOH6NaNzn3Y2fL3H5BBlYEysm7XfnThna3ejXDbLqHigbp CFHw0oqa+B0eVg6NtO+8PltqE6kol2YdSRj5zQ1XmFFxjkqbShAW+aeT54wdKZt/Ari0fxkoQy qCzionwz5WRUONBtnopLu6581PzT/cwvqLbnM/NJSR0Jkk5DS8jAvLjThEH0ioJXoYc22jqupe /jM= From: Julian Brown To: CC: , Subject: [PATCH 1/3] OpenMP: Fix "exit data" for array sections for ref-to-ptr components Date: Fri, 10 Mar 2023 15:53:05 -0800 Message-ID: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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-03-10 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 f3c97932608a..ae2fbc65c690 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -9067,6 +9067,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: @@ -9143,23 +9144,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_CLAUSE_MAP_KIND (nc) == GOMP_MAP_TO_PSET)) { - 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; @@ -9305,6 +9326,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: