diff options
author | Julian Brown <julian@codesourcery.com> | 2023-02-28 15:56:02 +0000 |
---|---|---|
committer | Julian Brown <julian@codesourcery.com> | 2023-07-03 21:37:30 +0000 |
commit | 5d491f7ae2f99d60d70f6bb2dff5db11ba1328a4 (patch) | |
tree | 466d4f751af3469f2544a1c07265c4ad907dfac9 /gcc/c-family | |
parent | 7fdf3c7c94c35dccab4a5ee5cd5c3d7b9cee8d37 (diff) |
OpenMP: Allow complete replacement of clause during map/to/from expansion
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 <julian@codesourcery.com>
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.
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog.omp | 10 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 12 | ||||
-rw-r--r-- | gcc/c-family/c-omp.cc | 75 |
3 files changed, 55 insertions, 42 deletions
diff --git a/gcc/c-family/ChangeLog.omp b/gcc/c-family/ChangeLog.omp index 73abb6a7bc9..f84f583fbdf 100644 --- a/gcc/c-family/ChangeLog.omp +++ b/gcc/c-family/ChangeLog.omp @@ -1,3 +1,13 @@ +2023-07-03 Julian Brown <julian@codesourcery.com> + + * 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. + 2023-06-30 Julian Brown <julian@codesourcery.com> * c-common.h (omp_mapper_list): Add forward declaration. 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<omp_addr_token *> &, tree, unsigned *, - c_omp_region_type, bool); - tree expand_component_selector (tree, vec<omp_addr_token *> &, tree, - unsigned *); - tree expand_map_clause (tree, tree, vec<omp_addr_token *> &, - c_omp_region_type); + tree * expand_array_base (tree *, vec<omp_addr_token *> &, tree, unsigned *, + c_omp_region_type, bool); + tree * expand_component_selector (tree *, vec<omp_addr_token *> &, tree, + unsigned *); + tree * expand_map_clause (tree *, tree, vec<omp_addr_token *> &, + 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<omp_addr_token *> &addr_tokens, - unsigned *idx) +static tree * +omp_expand_access_chain (tree *pc, tree expr, + vec<omp_addr_token *> &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<omp_addr_token *> &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<omp_addr_token *> &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<omp_addr_token *> &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<omp_addr_token *> &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 |