diff options
author | Julian Brown <julian@codesourcery.com> | 2019-05-19 10:42:20 -0700 |
---|---|---|
committer | Thomas Schwinge <thomas@codesourcery.com> | 2020-03-03 12:17:49 +0100 |
commit | b0e35852e8603f1edbee0fe3e9a035a2841f11f5 (patch) | |
tree | d36bd4071fcba52d568d3c91c66212d63172e9e9 | |
parent | f6ddcaeddf0bcb7999ac81c384707c06b1cb49af (diff) | |
download | gcc-b0e35852e8603f1edbee0fe3e9a035a2841f11f5.zip gcc-b0e35852e8603f1edbee0fe3e9a035a2841f11f5.tar.gz gcc-b0e35852e8603f1edbee0fe3e9a035a2841f11f5.tar.bz2 |
Fix references declared in lexically-enclosing OpenACC data region
gcc/fortran/
* trans-openmp.c (gfc_omp_finish_clause): Guard addition of clauses for
pointers with DECL_P.
gcc/
* gimplify.c (oacc_array_mapping_info): Add REF field.
(gimplify_scan_omp_clauses): Initialise above field for data blocks
passed by reference.
(gomp_oacc_needs_data_present): Handle references.
(gimplify_adjust_omp_clauses_1): Handle references and optional
arguments for variables declared in lexically-enclosing OpenACC data
region.
(cherry picked from openacc-gcc-9-branch commit
a2ed98fb31686fcdbaa7bd1396de5c31567b3729)
-rw-r--r-- | gcc/ChangeLog.omp | 10 | ||||
-rw-r--r-- | gcc/fortran/ChangeLog.omp | 5 | ||||
-rw-r--r-- | gcc/fortran/trans-openmp.c | 2 | ||||
-rw-r--r-- | gcc/gimplify.c | 51 |
4 files changed, 59 insertions, 9 deletions
diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 0088f56..eac7b7a 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,13 @@ +2019-05-19 Julian Brown <julian@codesourcery.com> + + * gimplify.c (oacc_array_mapping_info): Add REF field. + (gimplify_scan_omp_clauses): Initialise above field for data blocks + passed by reference. + (gomp_oacc_needs_data_present): Handle references. + (gimplify_adjust_omp_clauses_1): Handle references and optional + arguments for variables declared in lexically-enclosing OpenACC data + region. + 2019-05-16 Julian Brown <julian@codesourcery.com> * omp-oacc-kernels.c (find_omp_for_index_vars_1, diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp index 2554834..0234923 100644 --- a/gcc/fortran/ChangeLog.omp +++ b/gcc/fortran/ChangeLog.omp @@ -1,3 +1,8 @@ +2019-05-19 Julian Brown <julian@codesourcery.com> + + * trans-openmp.c (gfc_omp_finish_clause): Guard addition of clauses for + pointers with DECL_P. + 2019-01-09 Julian Brown <julian@codesourcery.com> * cpp.c (cpp_define_builtins): Update _OPENACC define to 201711. diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index f2d8997..b0dc2d7 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -1157,7 +1157,7 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p) tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE; if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR) return; - if (POINTER_TYPE_P (TREE_TYPE (decl))) + if (DECL_P (decl) && POINTER_TYPE_P (TREE_TYPE (decl))) { if (!gfc_omp_privatize_by_reference (decl) && !GFC_DECL_GET_SCALAR_POINTER (decl) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index dfd3173..7e46ef4 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -214,6 +214,7 @@ struct oacc_array_mapping_info tree mapping; tree pset; tree pointer; + tree ref; }; struct gimplify_omp_ctx @@ -8629,6 +8630,9 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, } if (base_ptr && OMP_CLAUSE_CODE (base_ptr) == OMP_CLAUSE_MAP + && !(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP + && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALLOC + || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER)) && OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_TO_PSET && ((OMP_CLAUSE_MAP_KIND (base_ptr) == GOMP_MAP_FIRSTPRIVATE_POINTER) @@ -8647,6 +8651,19 @@ gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p, ai.mapping = unshare_expr (c); ai.pset = pset ? unshare_expr (pset) : NULL; ai.pointer = unshare_expr (base_ptr); + ai.ref = NULL_TREE; + if (TREE_CODE (base_addr) == INDIRECT_REF + && (TREE_CODE (TREE_TYPE (TREE_OPERAND (base_addr, 0))) + == REFERENCE_TYPE)) + { + base_addr = TREE_OPERAND (base_addr, 0); + tree ref_clause = OMP_CLAUSE_CHAIN (base_ptr); + gcc_assert ((OMP_CLAUSE_CODE (ref_clause) + == OMP_CLAUSE_MAP) + && (OMP_CLAUSE_MAP_KIND (ref_clause) + == GOMP_MAP_POINTER)); + ai.ref = unshare_expr (ref_clause); + } ctx->decl_data_clause->put (base_addr, ai); } if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE) @@ -9694,20 +9711,22 @@ static oacc_array_mapping_info * gomp_oacc_needs_data_present (tree decl) { gimplify_omp_ctx *ctx = NULL; + bool ref_p = TREE_CODE (TREE_TYPE (decl)) == REFERENCE_TYPE; if (gimplify_omp_ctxp->region_type != ORT_ACC_PARALLEL && gimplify_omp_ctxp->region_type != ORT_ACC_KERNELS && gimplify_omp_ctxp->region_type != ORT_ACC_SERIAL) return NULL; - if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE - && TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE - && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE - && (TREE_CODE (TREE_TYPE (decl)) != POINTER_TYPE - || TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) != ARRAY_TYPE)) - return NULL; + tree type = TREE_TYPE (decl); + if (TREE_CODE (type) == REFERENCE_TYPE) + type = TREE_TYPE (type); - if (omp_is_optional_argument (decl)) + if (TREE_CODE (type) != ARRAY_TYPE + && TREE_CODE (type) != POINTER_TYPE + && TREE_CODE (type) != RECORD_TYPE + && (TREE_CODE (type) != POINTER_TYPE + || TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE)) return NULL; decl = get_base_address (decl); @@ -9834,6 +9853,9 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) { tree mapping = array_info->mapping; tree pointer = array_info->pointer; + const gomp_map_kind presence_kind + = omp_is_optional_argument (decl) ? GOMP_MAP_NO_ALLOC + : GOMP_MAP_FORCE_PRESENT; if (code == OMP_CLAUSE_FIRSTPRIVATE) /* Oops, we have the wrong type of clause. Rebuild it. */ @@ -9841,7 +9863,7 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) OMP_CLAUSE_MAP); OMP_CLAUSE_DECL (clause) = unshare_expr (OMP_CLAUSE_DECL (mapping)); - OMP_CLAUSE_SET_MAP_KIND (clause, GOMP_MAP_FORCE_PRESENT); + OMP_CLAUSE_SET_MAP_KIND (clause, presence_kind); OMP_CLAUSE_SIZE (clause) = unshare_expr (OMP_CLAUSE_SIZE (mapping)); /* Create a new data clause for the firstprivate pointer. */ @@ -9878,6 +9900,19 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data) OMP_CLAUSE_CHAIN (nc) = OMP_CLAUSE_CHAIN (clause); OMP_CLAUSE_CHAIN (clause) = psetc ? psetc : nc; + + if (array_info->ref) + { + tree refc = build_omp_clause (OMP_CLAUSE_LOCATION (clause), + OMP_CLAUSE_MAP); + OMP_CLAUSE_DECL (refc) + = unshare_expr (OMP_CLAUSE_DECL (array_info->ref)); + OMP_CLAUSE_SIZE (refc) + = unshare_expr (OMP_CLAUSE_SIZE (array_info->ref)); + OMP_CLAUSE_SET_MAP_KIND (refc, GOMP_MAP_POINTER); + OMP_CLAUSE_CHAIN (refc) = OMP_CLAUSE_CHAIN (nc); + OMP_CLAUSE_CHAIN (nc) = refc; + } } else if (code == OMP_CLAUSE_FIRSTPRIVATE && (flags & GOVD_EXPLICIT) == 0) OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (clause) = 1; |