]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Assumed-size arrays with non-lexical data mappings
authorJulian Brown <julian@codesourcery.com>
Fri, 5 Jul 2019 01:14:41 +0000 (18:14 -0700)
committerThomas Schwinge <thomas@codesourcery.com>
Tue, 3 Mar 2020 11:49:59 +0000 (12:49 +0100)
gcc/
* gimplify.c (gimplify_adjust_omp_clauses_1): Raise error for
assumed-size arrays in map clauses for Fortran/OpenMP.
* omp-low.c (lower_omp_target): Set the size of assumed-size Fortran
arrays to one to allow use of data already mapped on the offload device.

gcc/fortran/
* trans-openmp.c (gfc_omp_finish_clause): Change clauses mapping
assumed-size arrays to use the GOMP_MAP_FORCE_PRESENT map type.

(cherry picked from openacc-gcc-9-branch commit
cfc73bde082700240f0ac9560c2af884cc9930d1)

gcc/ChangeLog.omp
gcc/fortran/ChangeLog.omp
gcc/fortran/trans-openmp.c
gcc/gimplify.c
gcc/omp-low.c

index 455f67f5eae617b4f89f97dd6dc1395ab9043522..aa6db4f63443b34b4c846b67951c7533624dc503 100644 (file)
@@ -1,3 +1,11 @@
+2019-07-10  Cesar Philippidis  <cesar@codesourcery.com>
+           Julian Brown  <julian@codesourcery.com>
+
+       * gimplify.c (gimplify_adjust_omp_clauses_1): Raise error for
+       assumed-size arrays in map clauses for Fortran/OpenMP.
+       * omp-low.c (lower_omp_target): Set the size of assumed-size Fortran
+       arrays to one to allow use of data already mapped on the offload device.
+
 2019-07-10  Julian Brown  <julian@codesourcery.com>
 
        * gimplify.c (insert_struct_comp_map): Handle GOMP_MAP_ATTACH_DETACH.
index c44a5ebdb3bb36dbd58269f4d38bf8146c708f83..c8456e4bd0a49efe4a7b0c5c5f4c9a55b1c265d9 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-10  Julian Brown  <julian@codesourcery.com>
+
+       * trans-openmp.c (gfc_omp_finish_clause): Change clauses mapping
+       assumed-size arrays to use the GOMP_MAP_FORCE_PRESENT map type.
+
 2019-07-10  Julian Brown  <julian@codesourcery.com>
 
        * openmp.c (resolve_oacc_data_clauses): Allow polymorphic allocatable
index d5ae0b717df2699e014150dfff97a05ab4811edc..d1799d7ebc21620f9074955a1a5fa3b44c9671d5 100644 (file)
@@ -1137,10 +1137,18 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
   tree decl = OMP_CLAUSE_DECL (c);
 
   /* Assumed-size arrays can't be mapped implicitly, they have to be mapped
-     explicitly using array sections.  An exception is if the array is
-     mapped explicitly in an enclosing data construct for OpenACC, in which
-     case we see GOMP_MAP_FORCE_PRESENT here and do not need to raise an
-     error.  */
+     explicitly using array sections.  For OpenACC this restriction is lifted
+     if the array has already been mapped:
+
+       - Using a lexically-enclosing data region: in that case we see the
+         GOMP_MAP_FORCE_PRESENT mapping kind here.
+
+       - Using a non-lexical data mapping ("acc enter data").
+
+     In the latter case we change the mapping type to GOMP_MAP_FORCE_PRESENT.
+     This raises an error for OpenMP in the caller
+     (gimplify.c:gimplify_adjust_omp_clauses_1).  OpenACC will raise a runtime
+     error if the implicitly-referenced assumed-size array is not mapped.  */
   if (OMP_CLAUSE_MAP_KIND (c) != GOMP_MAP_FORCE_PRESENT
       && TREE_CODE (decl) == PARM_DECL
       && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
@@ -1148,11 +1156,7 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
       && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
                                GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
         == NULL)
-    {
-      error_at (OMP_CLAUSE_LOCATION (c),
-               "implicit mapping of assumed size array %qD", decl);
-      return;
-    }
+    OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_FORCE_PRESENT);
 
   tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
   if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR)
index 60e04ff83539c6e1ab0b654a80b610e39765f070..58142c9eb901ba7fdd0053e150f57e29d8f3aad9 100644 (file)
@@ -10088,7 +10088,21 @@ gimplify_adjust_omp_clauses_1 (splay_tree_node n, void *data)
   *list_p = clause;
   struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
   gimplify_omp_ctxp = ctx->outer_context;
+  gomp_map_kind kind = (code == OMP_CLAUSE_MAP) ? OMP_CLAUSE_MAP_KIND (clause)
+                                               : (gomp_map_kind) GOMP_MAP_LAST;
   lang_hooks.decls.omp_finish_clause (clause, pre_p);
+  /* Allow OpenACC to have implicit assumed-size arrays via FORCE_PRESENT,
+     which should work as long as the array has previously been mapped
+     explicitly on the target (e.g. by "enter data").  Raise an error for
+     OpenMP.  */
+  if (lang_GNU_Fortran ()
+      && code == OMP_CLAUSE_MAP
+      && (ctx->region_type & ORT_ACC) == 0
+      && kind == GOMP_MAP_TOFROM
+      && OMP_CLAUSE_MAP_KIND (clause) == GOMP_MAP_FORCE_PRESENT)
+    error_at (OMP_CLAUSE_LOCATION (clause),
+             "implicit mapping of assumed size array %qD",
+             OMP_CLAUSE_DECL (clause));
   if (gimplify_omp_ctxp)
     for (; clause != chain; clause = OMP_CLAUSE_CHAIN (clause))
       if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_MAP
index 249cc1aac5352fd61416e62b4914c3144f3e173a..97c00217d9f11372b40f0cb001f880f22a043381 100644 (file)
@@ -10453,6 +10453,11 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
              s = OMP_CLAUSE_SIZE (c);
            if (s == NULL_TREE)
              s = TYPE_SIZE_UNIT (TREE_TYPE (ovar));
+           /* Fortran assumed-size arrays have zero size because the type is
+              incomplete.  Set the size to one to allow the runtime to remap
+              any existing data that is already present on the accelerator.  */
+           if (s == NULL_TREE && is_gimple_omp_oacc (ctx->stmt))
+             s = integer_one_node;
            s = fold_convert (size_type_node, s);
            decl_args = append_decl_arg (ovar, decl_args, ctx);
            purpose = size_int (map_idx++);