diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2019-10-11 09:17:49 +0000 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2019-10-11 11:17:49 +0200 |
commit | 08c14aaaab2b01f1a31989a8d94bae312d87c8f7 (patch) | |
tree | 57787b2cb0e1cad4b4370339157e8b47155b5e12 /gcc/fortran | |
parent | b67e2ad80d3e080c5258ff64ddb6f40e8d783e0b (diff) | |
download | gcc-08c14aaaab2b01f1a31989a8d94bae312d87c8f7.zip gcc-08c14aaaab2b01f1a31989a8d94bae312d87c8f7.tar.gz gcc-08c14aaaab2b01f1a31989a8d94bae312d87c8f7.tar.bz2 |
[OpenMP,Fortran] Fix several OpenMP use_device_addr/map/update errors
gcc/fortran/
* f95-lang.c (LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR): Re-define to
gfc_omp_is_allocatable_or_ptr.
* trans-decl.c (create_function_arglist): Set GFC_DECL_OPTIONAL_ARGUMENT
only if not passed by value.
* trans-openmp.c (gfc_omp_is_allocatable_or_ptr): New.
(gfc_trans_omp_clauses): For MAP, handle (present) optional arguments;
for target update, handle allocatable/pointer scalars.
* trans.h (gfc_omp_is_allocatable_or_ptr): Declare.
gcc/
* langhooks-def.h (LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR): Define.
(LANG_HOOKS_DECLS): Add it.
* langhooks.h (lang_hooks_for_decls): Add omp_is_allocatable_or_ptr;
update comment for omp_is_optional_argument.
* omp-general.c (omp_is_allocatable_or_ptr): New.
* omp-general.h (omp_is_allocatable_or_ptr): Declare.
* omp-low.c (scan_sharing_clauses, lower_omp_target): Handle
Fortran's optional arguments and allocatable/pointer scalars
with use_device_addr.
libgomp/
* testsuite/libgomp.fortran/use_device_addr-1.f90: New.
* testsuite/libgomp.fortran/use_device_addr-2.f90: New.
From-SVN: r276875
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/fortran/f95-lang.c | 2 | ||||
-rw-r--r-- | gcc/fortran/trans-decl.c | 3 | ||||
-rw-r--r-- | gcc/fortran/trans-openmp.c | 32 | ||||
-rw-r--r-- | gcc/fortran/trans.h | 1 |
5 files changed, 44 insertions, 5 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0577659..82bc450 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2019-10-11 Tobias Burnus <tobias@codesourcery.com> + + * f95-lang.c (LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR): Re-define to + gfc_omp_is_allocatable_or_ptr. + * trans-decl.c (create_function_arglist): Set GFC_DECL_OPTIONAL_ARGUMENT + only if not passed by value. + * trans-openmp.c (gfc_omp_is_allocatable_or_ptr): New. + (gfc_trans_omp_clauses): For MAP, handle (present) optional arguments; + for target update, handle allocatable/pointer scalars. + * trans.h (gfc_omp_is_allocatable_or_ptr): Declare. + 2019-10-10 Tobias Burnus <tobias@codesourcery.com> * trans-openmp.c (gfc_trans_omp_clauses): Actually pass use_device_addr diff --git a/gcc/fortran/f95-lang.c b/gcc/fortran/f95-lang.c index 2467cd9..0f72ab9 100644 --- a/gcc/fortran/f95-lang.c +++ b/gcc/fortran/f95-lang.c @@ -113,6 +113,7 @@ static const struct attribute_spec gfc_attribute_table[] = #undef LANG_HOOKS_TYPE_FOR_MODE #undef LANG_HOOKS_TYPE_FOR_SIZE #undef LANG_HOOKS_INIT_TS +#undef LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR #undef LANG_HOOKS_OMP_IS_OPTIONAL_ARGUMENT #undef LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE #undef LANG_HOOKS_OMP_PREDETERMINED_SHARING @@ -146,6 +147,7 @@ static const struct attribute_spec gfc_attribute_table[] = #define LANG_HOOKS_TYPE_FOR_MODE gfc_type_for_mode #define LANG_HOOKS_TYPE_FOR_SIZE gfc_type_for_size #define LANG_HOOKS_INIT_TS gfc_init_ts +#define LANG_HOOKS_OMP_IS_ALLOCATABLE_OR_PTR gfc_omp_is_allocatable_or_ptr #define LANG_HOOKS_OMP_IS_OPTIONAL_ARGUMENT gfc_omp_is_optional_argument #define LANG_HOOKS_OMP_PRIVATIZE_BY_REFERENCE gfc_omp_privatize_by_reference #define LANG_HOOKS_OMP_PREDETERMINED_SHARING gfc_omp_predetermined_sharing diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index b701f49..3ad802e 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -2691,8 +2691,9 @@ create_function_arglist (gfc_symbol * sym) && (!f->sym->attr.proc_pointer && f->sym->attr.flavor != FL_PROCEDURE)) DECL_BY_REFERENCE (parm) = 1; - if (f->sym->attr.optional) + if (f->sym->attr.optional && !f->sym->attr.value) { + /* With value, the argument is passed as is. */ gfc_allocate_lang_decl (parm); GFC_DECL_OPTIONAL_ARGUMENT (parm) = 1; } diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 35c2f28..dad11a2 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -47,7 +47,21 @@ along with GCC; see the file COPYING3. If not see int ompws_flags; -/* True if OpenMP should treat this DECL as an optional argument. */ +/* True if OpenMP should regard this DECL as being a scalar which has Fortran's + allocatable or pointer attribute. */ + +bool +gfc_omp_is_allocatable_or_ptr (const_tree decl) +{ + return (DECL_P (decl) + && (GFC_DECL_GET_SCALAR_POINTER (decl) + || GFC_DECL_GET_SCALAR_ALLOCATABLE (decl))); +} + +/* True if OpenMP should treat this DECL as an optional argument; note: for + arguments with VALUE attribute, the DECL is identical to nonoptional + arguments; hence, we return false here. To check whether the variable is + present, use the DECL which is passed as hidden argument. */ bool gfc_omp_is_optional_argument (const_tree decl) @@ -2173,7 +2187,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, OMP_CLAUSE_DECL (node4) = decl; OMP_CLAUSE_SIZE (node4) = size_int (0); decl = build_fold_indirect_ref (decl); - if (TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE + if ((TREE_CODE (TREE_TYPE (orig_decl)) == REFERENCE_TYPE + || gfc_omp_is_optional_argument (orig_decl)) && (GFC_DECL_GET_SCALAR_POINTER (orig_decl) || GFC_DECL_GET_SCALAR_ALLOCATABLE (orig_decl))) { @@ -2417,7 +2432,11 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, { tree decl = gfc_trans_omp_variable (n->sym, false); if (gfc_omp_privatize_by_reference (decl)) - decl = build_fold_indirect_ref (decl); + { + if (gfc_omp_is_allocatable_or_ptr (decl)) + decl = build_fold_indirect_ref (decl); + decl = build_fold_indirect_ref (decl); + } else if (DECL_P (decl)) TREE_ADDRESSABLE (decl) = 1; if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))) @@ -2439,7 +2458,12 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, OMP_CLAUSE_SIZE (node), elemsz); } else - OMP_CLAUSE_DECL (node) = decl; + { + OMP_CLAUSE_DECL (node) = decl; + if (gfc_omp_is_allocatable_or_ptr (decl)) + OMP_CLAUSE_SIZE (node) + = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (decl))); + } } else { diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 405e88d..e96b22a 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -786,6 +786,7 @@ struct array_descr_info; bool gfc_get_array_descr_info (const_tree, struct array_descr_info *); /* In trans-openmp.c */ +bool gfc_omp_is_allocatable_or_ptr (const_tree); bool gfc_omp_is_optional_argument (const_tree); bool gfc_omp_privatize_by_reference (const_tree); enum omp_clause_default_kind gfc_omp_predetermined_sharing (tree); |