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: 67865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp31729wrd; Fri, 10 Mar 2023 15:55:11 -0800 (PST) X-Google-Smtp-Source: AK7set/X4bveggPJKwbdFihQet18Yiq7FU0aijCmYVdNfHMhifU5SnpV7ioUavbU7hOBGkapFeCD X-Received: by 2002:a17:906:3002:b0:8b2:fb3d:9f22 with SMTP id 2-20020a170906300200b008b2fb3d9f22mr26101968ejz.33.1678492511687; Fri, 10 Mar 2023 15:55:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678492511; cv=none; d=google.com; s=arc-20160816; b=FBw+rZXumNeN/pba7mNcy1RCrhctbGRvx5Lcb0U9xxR1BUB9P1V1tcSxENdyIQpNEt vDNZV/kksie2pem/VXxPkkNIUqngJZ9j8qHujfW7rLfcn2fuHajVLR8RcE7WOCkEyvWy fw6UkF3u0lzM2HzAhPPut0yIS4ETVdsmxUq/c6p9/Hlhvlzp4RtfcphT0gp5ZknKRPcD R99RR96qyTSUpSXoBIoNI8LyQ9vLlawWMOLd6s2jKwMWzVymLT2sGHGGgZ+caQvtP4wG 99BRyvobU1VaAZILXSRAHgF/J1CABd+nMmfcbZihjBI27lPHIMSTXk1oYql5EHm1fKN4 Jn3Q== 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=9A9Ze0BySlfpOzQ9rzXb8LHM4vFNH3UY+s/a+Ligcq8=; b=GWsiR4UV1tySbxlk1o5qwN9JUfPKxC3RnY0j0/dTtzsj0EEoP7XntorJvAO7GM1wnU k4WgJpYNzHiVV1iAisFblDnEA58zB4c0v0KwlngVlMfcL9F3bvc+fVQMeEGOm19aVLhq 4OMtf6uabAkbzIRyL7irw23j9aeeVdy3UFOrs36jjKnOO67GqHqPKjIAP+qFgSm0IfnT /t2rNpvx8a+IEL0tRLesM0ZyZsL+MsDSMGUa8QNK5TYXGpt6i8d4U0idkftgYcVsCFPV GpFIIsTDX15JXktfGyFu06GGr7XAfovhvxuOio5GJLvstM36qLQww/RsaXkAu4w0damy yeDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n4-20020aa7c684000000b004ab4c6b22dfsi1305461edq.336.2023.03.10.15.55.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 15:55:11 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 507CA385783F for ; Fri, 10 Mar 2023 23:54:32 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760026963632226740?= X-GMAIL-MSGID: =?utf-8?q?1760026963632226740?= 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: