diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-05-26 09:35:21 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-05-26 09:35:21 +0200 |
commit | f1f862aec2c3b93dbd6adfc35b0e1b6034e59c21 (patch) | |
tree | 17585550346141aee0230a55878d86d63504b279 /gcc/cp | |
parent | 1c7f8cbcc7f77d6956624f2bb455c33f253524fd (diff) |
openmp: Ensure copy ctor for composite distribute parallel for class iterators is instantiated [PR95197]
During gimplification omp_finish_clause langhook is called in several places
to add the language specific info to the clause like what default/copy ctors,
dtors and assignment operators should be used.
Unfortunately, if it refers to some not yet instantiated method, during
gimplification it is too late and the methods will not be instantiated
anymore. For other cases, the genericizer has code to detect those and
instantiate whatever is needed, this change adds the same for
distribute parallel for class iterators where we under the hood need
a copy constructor for the iterator to implement it.
2020-05-26 Jakub Jelinek <jakub@redhat.com>
PR c++/95197
* gimplify.c (find_combined_omp_for): Move to omp-general.c.
* omp-general.h (find_combined_omp_for): Declare.
* omp-general.c: Include tree-iterator.h.
(find_combined_omp_for): New function, moved from gimplify.c.
* cp-gimplify.c: Include omp-general.h.
(cp_genericize_r) <case OMP_DISTRIBUTE>: For class iteration
variables in composite distribute parallel for, instantiate copy
ctor of their types.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/cp-gimplify.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index b60a319283f..53d715dcd89 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see #include "output.h" #include "file-prefix-map.h" #include "cgraph.h" +#include "omp-general.h" /* Forward declarations. */ @@ -1650,9 +1651,70 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) *stmt_p = genericize_spaceship (*stmt_p); break; + case OMP_DISTRIBUTE: + /* Need to explicitly instantiate copy ctors on class iterators of + composite distribute parallel for. */ + if (OMP_FOR_INIT (*stmt_p) == NULL_TREE) + { + tree *data[4] = { NULL, NULL, NULL, NULL }; + tree inner = walk_tree (&OMP_FOR_BODY (*stmt_p), + find_combined_omp_for, data, NULL); + if (inner != NULL_TREE + && TREE_CODE (inner) == OMP_FOR) + { + for (int i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INIT (inner)); i++) + if (OMP_FOR_ORIG_DECLS (inner) + && TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner), + i)) == TREE_LIST + && TREE_PURPOSE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner), + i))) + { + tree orig = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (inner), i); + /* Class iterators aren't allowed on OMP_SIMD, so the only + case we need to solve is distribute parallel for. */ + gcc_assert (TREE_CODE (inner) == OMP_FOR + && data[1]); + tree orig_decl = TREE_PURPOSE (orig); + tree c, cl = NULL_TREE; + for (c = OMP_FOR_CLAUSES (inner); + c; c = OMP_CLAUSE_CHAIN (c)) + if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE + || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE) + && OMP_CLAUSE_DECL (c) == orig_decl) + { + cl = c; + break; + } + if (cl == NULL_TREE) + { + for (c = OMP_PARALLEL_CLAUSES (*data[1]); + c; c = OMP_CLAUSE_CHAIN (c)) + if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE + && OMP_CLAUSE_DECL (c) == orig_decl) + { + cl = c; + break; + } + } + if (cl) + { + orig_decl = require_complete_type (orig_decl); + tree inner_type = TREE_TYPE (orig_decl); + if (orig_decl == error_mark_node) + continue; + if (TYPE_REF_P (TREE_TYPE (orig_decl))) + inner_type = TREE_TYPE (inner_type); + + while (TREE_CODE (inner_type) == ARRAY_TYPE) + inner_type = TREE_TYPE (inner_type); + get_copy_ctor (inner_type, tf_warning_or_error); + } + } + } + } + /* FALLTHRU */ case OMP_FOR: case OMP_SIMD: - case OMP_DISTRIBUTE: case OMP_LOOP: case OACC_LOOP: genericize_omp_for_stmt (stmt_p, walk_subtrees, data); |