]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix references declared in lexically-enclosing OpenACC data region
authorJulian Brown <julian@codesourcery.com>
Sun, 19 May 2019 17:42:20 +0000 (10:42 -0700)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 21 Jun 2022 13:11:14 +0000 (14:11 +0100)
gcc/fortran/
* trans-openmp.cc (gfc_omp_finish_clause): Guard addition of clauses for
pointers with DECL_P.

gcc/
* gimplify.cc (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.

gcc/ChangeLog.omp
gcc/fortran/ChangeLog.omp
gcc/fortran/trans-openmp.cc
gcc/gimplify.cc

index be388cc9d6f3cbe0be9901a473c0a5ba88b139ab..286ff0fda02c8b2b3a4992c5c274222e1d370d87 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-19  Julian Brown  <julian@codesourcery.com>
+
+       * gimplify.cc (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-01-23  Thomas Schwinge  <thomas@codesourcery.com>
 
        * params.opt (openacc_kernels): Default to decompose.
index 23e93c873232e2dd067e04d5ea202df1c4734c6a..c234fadfe508c7a071c6dc59853c0e295ceb5635 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-19  Julian Brown  <julian@codesourcery.com>
+
+       * trans-openmp.cc (gfc_omp_finish_clause): Guard addition of clauses for
+       pointers with DECL_P.
+
 2018-12-13  Cesar Philippidis  <cesar@codesourcery.com>
            Nathan Sidwell  <nathan@acm.org>
            Julian Brown  <julian@codesourcery.com>
index 42eb069bdee2634231971b26c3cbdc4eba76db03..8f4e27cfad17695783f4e864554a29075af70df1 100644 (file)
@@ -1511,7 +1511,7 @@ gfc_omp_finish_clause (tree c, gimple_seq *pre_p, bool openacc)
 
   tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
   tree present = gfc_omp_check_optional_argument (decl, true);
-  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)
index 4565716369144a1e41e73d4c09daefa408aef4d3..355b5b0bf56fe9066ff9e272e60dc8580310b80c 100644 (file)
@@ -231,6 +231,7 @@ struct oacc_array_mapping_info
   tree mapping;
   tree pset;
   tree pointer;
+  tree ref;
 };
 
 struct gimplify_omp_ctx
@@ -9541,6 +9542,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)
@@ -9559,6 +9563,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)
@@ -11149,16 +11166,21 @@ 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)
     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))
+  tree type = TREE_TYPE (decl);
+  if (TREE_CODE (type) == REFERENCE_TYPE)
+    type = TREE_TYPE (type);
+
+  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);
@@ -11314,6 +11336,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_check_optional_argument (decl, false) ? GOMP_MAP_IF_PRESENT
+                                                   : GOMP_MAP_FORCE_PRESENT;
 
       if (code == OMP_CLAUSE_FIRSTPRIVATE)
        /* Oops, we have the wrong type of clause.  Rebuild it.  */
@@ -11321,7 +11346,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.  */
@@ -11358,6 +11383,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;