From patchwork Mon Jul 3 21:33:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1802942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QvzjZ0LyWz20Pf for ; Tue, 4 Jul 2023 07:35:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 187EB388203D for ; Mon, 3 Jul 2023 21:35: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 6851D385771F; Mon, 3 Jul 2023 21:33:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6851D385771F 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="12099586" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 03 Jul 2023 13:33:48 -0800 IronPort-SDR: UbJM7IE3AgBx98ebVFSE54WbIFm7YaHcaRyv9/PYPOxY9Rp7DdysIbDlWjoUvbfQM62e46Y2dt ZnbRTVJKfneJ3C5juwNG95bnNEZj1vHgyl7nroBykqwY4QFC0mU5iJ3qT0tmGVjdgz1XxK20mM 08CNGVwm0MlOHv24Cv+iVzHdpE/BjeQB6xqWvyKegicXK0hgxBicEv1KjaZ+lQnF+XX0bdNSpR QyYUszVyNEnXATI2AwRWkA5XfBX9IeThvKvVJRLd8w0H5lmkj+RaM6iMlIOJly2wAO7E7g1/0J ne0= From: Julian Brown To: CC: , , Subject: [PATCH 2/5] OpenMP: Allow complete replacement of clause during map/to/from expansion Date: Mon, 3 Jul 2023 21:33:16 +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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" At present, map/to/from clauses on OpenMP "target" directives may be expanded into several mapping nodes if they describe array sections with pointer or reference bases, or similar. This patch allows the original clause to be replaced during that expansion, mostly by passing the list pointer to the node to various functions rather than the node itself. This is needed by the following patch. There shouldn't be any functional changes introduced by this patch itself. 2023-07-03 Julian Brown gcc/c-family/ * c-common.h (expand_array_base, expand_component_selector, expand_map_clause): Adjust member declarations. * c-omp.cc (omp_expand_access_chain): Pass and return pointer to clause. (c_omp_address_inspector::expand_array_base): Likewise. (c_omp_address_inspector::expand_component_selector): Likewise. (c_omp_address_inspector::expand_map_clause): Likewise. gcc/c/ * c-typeck.cc (handle_omp_array_sections): Pass pointer to clause to process instead of clause. (c_finish_omp_clauses): Update calls to handle_omp_array_sections. Handle cases where initial clause might be replaced. gcc/cp/ * semantics.cc (handle_omp_array_sections): Pass pointer to clause instead of clause. Add PNEXT return parameter for next clause in list to process. (finish_omp_clauses): Update calls to handle_omp_array_sections. Handle cases where initial clause might be replaced. --- gcc/c-family/c-common.h | 12 +++---- gcc/c-family/c-omp.cc | 75 +++++++++++++++++++++-------------------- gcc/c/c-typeck.cc | 32 +++++++++++------- gcc/cp/semantics.cc | 37 +++++++++++++------- 4 files changed, 88 insertions(+), 68 deletions(-) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index acd0c861a55..756358f3fd8 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1375,12 +1375,12 @@ public: bool maybe_zero_length_array_section (tree); - tree expand_array_base (tree, vec &, tree, unsigned *, - c_omp_region_type, bool); - tree expand_component_selector (tree, vec &, tree, - unsigned *); - tree expand_map_clause (tree, tree, vec &, - c_omp_region_type); + tree * expand_array_base (tree *, vec &, tree, unsigned *, + c_omp_region_type, bool); + tree * expand_component_selector (tree *, vec &, tree, + unsigned *); + tree * expand_map_clause (tree *, tree, vec &, + c_omp_region_type); }; enum c_omp_directive_kind { diff --git a/gcc/c-family/c-omp.cc b/gcc/c-family/c-omp.cc index 16b620fcb3d..17f3d71c655 100644 --- a/gcc/c-family/c-omp.cc +++ b/gcc/c-family/c-omp.cc @@ -4130,11 +4130,12 @@ c_omp_address_inspector::maybe_zero_length_array_section (tree clause) expression types here, because e.g. you can't have an array of references. See also gimplify.cc:omp_expand_access_chain. */ -static tree -omp_expand_access_chain (tree c, tree expr, vec &addr_tokens, - unsigned *idx) +static tree * +omp_expand_access_chain (tree *pc, tree expr, + vec &addr_tokens, unsigned *idx) { using namespace omp_addr_tokenizer; + tree c = *pc; location_t loc = OMP_CLAUSE_LOCATION (c); unsigned i = *idx; tree c2 = NULL_TREE; @@ -4172,35 +4173,36 @@ omp_expand_access_chain (tree c, tree expr, vec &addr_tokens, break; default: - return error_mark_node; + return NULL; } if (c2) { OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); OMP_CLAUSE_CHAIN (c) = c2; - c = c2; + pc = &OMP_CLAUSE_CHAIN (c); } *idx = ++i; if (i < addr_tokens.length () && addr_tokens[i]->type == ACCESS_METHOD) - return omp_expand_access_chain (c, expr, addr_tokens, idx); + return omp_expand_access_chain (pc, expr, addr_tokens, idx); - return c; + return pc; } /* Translate "array_base_decl access_method" to OMP mapping clauses. */ -tree -c_omp_address_inspector::expand_array_base (tree c, +tree * +c_omp_address_inspector::expand_array_base (tree *pc, vec &addr_tokens, tree expr, unsigned *idx, c_omp_region_type ort, bool decl_p) { using namespace omp_addr_tokenizer; + tree c = *pc; location_t loc = OMP_CLAUSE_LOCATION (c); int i = *idx; tree decl = addr_tokens[i + 1]->expr; @@ -4225,7 +4227,7 @@ c_omp_address_inspector::expand_array_base (tree c, || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_DETACH)) { *idx = ++i; - return c; + return pc; } switch (addr_tokens[i + 1]->u.access_kind) @@ -4474,7 +4476,7 @@ c_omp_address_inspector::expand_array_base (tree c, default: *idx = i + consume_tokens; - return error_mark_node; + return NULL; } if (c3) @@ -4487,7 +4489,7 @@ c_omp_address_inspector::expand_array_base (tree c, OMP_CLAUSE_MAP_IMPLICIT (c2) = 1; OMP_CLAUSE_MAP_IMPLICIT (c3) = 1; } - c = c3; + pc = &OMP_CLAUSE_CHAIN (c2); } else if (c2) { @@ -4495,27 +4497,28 @@ c_omp_address_inspector::expand_array_base (tree c, OMP_CLAUSE_CHAIN (c) = c2; if (implicit_p) OMP_CLAUSE_MAP_IMPLICIT (c2) = 1; - c = c2; + pc = &OMP_CLAUSE_CHAIN (c); } i += consume_tokens; *idx = i; if (chain_p && map_p) - return omp_expand_access_chain (c, expr, addr_tokens, idx); + return omp_expand_access_chain (pc, expr, addr_tokens, idx); - return c; + return pc; } /* Translate "component_selector access_method" to OMP mapping clauses. */ -tree -c_omp_address_inspector::expand_component_selector (tree c, +tree * +c_omp_address_inspector::expand_component_selector (tree *pc, vec &addr_tokens, tree expr, unsigned *idx) { using namespace omp_addr_tokenizer; + tree c = *pc; location_t loc = OMP_CLAUSE_LOCATION (c); unsigned i = *idx; tree c2 = NULL_TREE, c3 = NULL_TREE; @@ -4622,7 +4625,7 @@ c_omp_address_inspector::expand_component_selector (tree c, default: *idx = i + 2; - return error_mark_node; + return NULL; } if (c3) @@ -4630,29 +4633,29 @@ c_omp_address_inspector::expand_component_selector (tree c, OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c); OMP_CLAUSE_CHAIN (c2) = c3; OMP_CLAUSE_CHAIN (c) = c2; - c = c3; + pc = &OMP_CLAUSE_CHAIN (c2); } else if (c2) { OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c); OMP_CLAUSE_CHAIN (c) = c2; - c = c2; + pc = &OMP_CLAUSE_CHAIN (c); } i += 2; *idx = i; if (chain_p && map_p) - return omp_expand_access_chain (c, expr, addr_tokens, idx); + return omp_expand_access_chain (pc, expr, addr_tokens, idx); - return c; + return pc; } /* Expand a map clause into a group of mapping clauses, creating nodes to attach/detach pointers and so forth as necessary. */ -tree -c_omp_address_inspector::expand_map_clause (tree c, tree expr, +tree * +c_omp_address_inspector::expand_map_clause (tree *pc, tree expr, vec &addr_tokens, c_omp_region_type ort) { @@ -4668,18 +4671,18 @@ c_omp_address_inspector::expand_map_clause (tree c, tree expr, && addr_tokens[i]->u.structure_base_kind == BASE_DECL && addr_tokens[i + 1]->type == ACCESS_METHOD) { - c = expand_array_base (c, addr_tokens, expr, &i, ort, true); - if (c == error_mark_node) - return error_mark_node; + pc = expand_array_base (pc, addr_tokens, expr, &i, ort, true); + if (pc == NULL) + return NULL; } else if (remaining >= 2 && addr_tokens[i]->type == ARRAY_BASE && addr_tokens[i]->u.structure_base_kind == BASE_ARBITRARY_EXPR && addr_tokens[i + 1]->type == ACCESS_METHOD) { - c = expand_array_base (c, addr_tokens, expr, &i, ort, false); - if (c == error_mark_node) - return error_mark_node; + pc = expand_array_base (pc, addr_tokens, expr, &i, ort, false); + if (pc == NULL) + return NULL; } else if (remaining >= 2 && addr_tokens[i]->type == STRUCTURE_BASE @@ -4706,18 +4709,18 @@ c_omp_address_inspector::expand_map_clause (tree c, tree expr, i++; break; default: - return error_mark_node; + return NULL; } } else if (remaining >= 2 && addr_tokens[i]->type == COMPONENT_SELECTOR && addr_tokens[i + 1]->type == ACCESS_METHOD) { - c = expand_component_selector (c, addr_tokens, expr, &i); + pc = expand_component_selector (pc, addr_tokens, expr, &i); /* We used 'expr', so these must have been the last tokens. */ gcc_assert (i == length); - if (c == error_mark_node) - return error_mark_node; + if (pc == NULL) + return NULL; } else if (remaining >= 3 && addr_tokens[i]->type == COMPONENT_SELECTOR @@ -4735,9 +4738,9 @@ c_omp_address_inspector::expand_map_clause (tree c, tree expr, } if (i == length) - return c; + return pc; - return error_mark_node; + return NULL; } /* Given a mapper function MAPPER_FN, recursively scan through the map clauses diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index f9244da9eba..a54d310403a 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -14082,8 +14082,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, /* Handle array sections for clause C. */ static bool -handle_omp_array_sections (tree c, enum c_omp_region_type ort) +handle_omp_array_sections (tree *pc, enum c_omp_region_type ort) { + tree c = *pc; bool maybe_zero_len = false; unsigned int first_non_one = 0; bool non_contiguous = false; @@ -14322,8 +14323,8 @@ handle_omp_array_sections (tree c, enum c_omp_region_type ort) c_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t); - tree nc = ai.expand_map_clause (c, first, addr_tokens, ort); - if (nc != error_mark_node) + tree *npc = ai.expand_map_clause (pc, first, addr_tokens, ort); + if (npc != NULL) { if (ai.maybe_zero_length_array_section (c)) OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; @@ -14672,12 +14673,13 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == OMP_ARRAY_SECTION) { - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, ort)) { remove = true; break; } + c = *pc; t = OMP_CLAUSE_DECL (c); if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION && OMP_CLAUSE_REDUCTION_INSCAN (c)) @@ -15410,10 +15412,12 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) last_iterators = NULL_TREE; if (TREE_CODE (t) == OMP_ARRAY_SECTION) { - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, ort)) remove = true; - else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND - && OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_DEPOBJ) + else if ((c = *pc) + && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND + && (OMP_CLAUSE_DEPEND_KIND (c) + == OMP_CLAUSE_DEPEND_DEPOBJ)) { error_at (OMP_CLAUSE_LOCATION (c), "% clause with % dependence " @@ -15529,10 +15533,11 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) grp_start_p = pc; grp_sentinel = OMP_CLAUSE_CHAIN (c); - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, ort)) remove = true; else { + c = *pc; t = OMP_CLAUSE_DECL (c); if (!omp_mappable_type (TREE_TYPE (t))) { @@ -15822,10 +15827,10 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) { grp_start_p = pc; grp_sentinel = OMP_CLAUSE_CHAIN (c); - tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c), - addr_tokens, ort); - if (nc != error_mark_node) - c = nc; + tree *npc = ai.expand_map_clause (pc, OMP_CLAUSE_DECL (c), + addr_tokens, ort); + if (npc != NULL) + c = *npc; } } break; @@ -15925,10 +15930,11 @@ c_finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == OMP_ARRAY_SECTION) { - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, ort)) remove = true; else { + c = *pc; t = OMP_CLAUSE_DECL (c); while (TREE_CODE (t) == ARRAY_REF) t = TREE_OPERAND (t, 0); diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 78c4e243e88..4505f0b49f6 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5562,8 +5562,9 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, /* Handle array sections for clause C. */ static bool -handle_omp_array_sections (tree &c, enum c_omp_region_type ort) +handle_omp_array_sections (tree *pc, tree **pnext, enum c_omp_region_type ort) { + tree c = *pc; bool maybe_zero_len = false; unsigned int first_non_one = 0; bool non_contiguous = false; @@ -5838,23 +5839,27 @@ handle_omp_array_sections (tree &c, enum c_omp_region_type ort) cp_omp_address_inspector ai (OMP_CLAUSE_LOCATION (c), t); - tree nc = ai.expand_map_clause (c, first, addr_tokens, ort); - if (nc != error_mark_node) + tree* npc = ai.expand_map_clause (pc, first, addr_tokens, ort); + if (npc != NULL) { using namespace omp_addr_tokenizer; + c = *pc; + if (ai.maybe_zero_length_array_section (c)) OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1; /* !!! If we're accessing a base decl via chained access methods (e.g. multiple indirections), duplicate clause detection won't work properly. Skip it in that case. */ - if ((addr_tokens[0]->type == STRUCTURE_BASE + if (pnext + && (addr_tokens[0]->type == STRUCTURE_BASE || addr_tokens[0]->type == ARRAY_BASE) && addr_tokens[0]->u.structure_base_kind == BASE_DECL && addr_tokens[1]->type == ACCESS_METHOD && omp_access_chain_p (addr_tokens, 1)) - c = nc; + /* NPC points to the last node in the new sequence. */ + *pnext = npc; return false; } @@ -6983,7 +6988,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == OMP_ARRAY_SECTION) { - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, NULL, ort)) { remove = true; break; @@ -8131,7 +8136,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) if (TREE_CODE (t) == OMP_ARRAY_SECTION) { - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, NULL, ort)) remove = true; else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND && (OMP_CLAUSE_DEPEND_KIND (c) @@ -8300,10 +8305,13 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) grp_start_p = pc; grp_sentinel = OMP_CLAUSE_CHAIN (c); - if (handle_omp_array_sections (c, ort)) + tree *pnext = NULL; + if (handle_omp_array_sections (pc, &pnext, ort)) remove = true; else { + /* We might have replaced the clause, so refresh C. */ + c = *pc; t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) != OMP_ARRAY_SECTION && !type_dependent_expression_p (t) @@ -8401,6 +8409,8 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) clauses, reset the OMP_CLAUSE_SIZE (representing a bias) to zero here. */ OMP_CLAUSE_SIZE (c) = size_zero_node; + if (pnext) + c = *pnext; break; } else if (type_dependent_expression_p (t)) @@ -8646,10 +8656,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) { grp_start_p = pc; grp_sentinel = OMP_CLAUSE_CHAIN (c); - tree nc = ai.expand_map_clause (c, OMP_CLAUSE_DECL (c), - addr_tokens, ort); - if (nc != error_mark_node) - c = nc; + tree *npc = ai.expand_map_clause (pc, OMP_CLAUSE_DECL (c), + addr_tokens, ort); + if (npc != NULL) + c = *npc; } } break; @@ -8887,10 +8897,11 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = OMP_CLAUSE_DECL (c); if (TREE_CODE (t) == OMP_ARRAY_SECTION) { - if (handle_omp_array_sections (c, ort)) + if (handle_omp_array_sections (pc, NULL, ort)) remove = true; else { + c = *pc; t = OMP_CLAUSE_DECL (c); while (TREE_CODE (t) == OMP_ARRAY_SECTION) t = TREE_OPERAND (t, 0);