diff mbox series

[5/6,og8] Backport parts of upstream declare-allocate patch

Message ID 8899e93bb7b0b0c6160bcb67125eed0c4be26ff5.1542748807.git.julian@codesourcery.com
State New
Headers show
Series OpenACC attach/detach | expand

Commit Message

Julian Brown Nov. 20, 2018, 9:56 p.m. UTC
This patch adjusts mappings used for some special cases in Fortran
(e.g. allocatable scalars) on og8 to match code that is already upstream,
or that has been submitted but not yet reviewed. Parts taken from
https://gcc.gnu.org/ml/gcc-patches/2018-09/msg01205.html and parts
reverted from https://gcc.gnu.org/ml/gcc-patches/2017-01/msg02188.html.

	gcc/fortran/
	* trans-openmp.c (gfc_omp_finish_clause): Don't use
	GOMP_MAP_FIRSTPRIVATE_POINTER.
	(gfc_trans_omp_clauses_1): Adjust handling of allocatable scalars.

	gcc/
	* gimplify.c (demote_firstprivate_pointer): Remove.
	(gimplify_scan_omp_clauses): Remove special handling for OpenACC. Don't
	call demote_firstprivate_pointer.
	(gimplify_adjust_omp_clauses): Adjust promotion of reduction clauses.
	* omp-low.c (lower_omp_target): Remove special handling for Fortran.

	gcc/testsuite/
	* gfortran.dg/goacc/kernels-alias-3.f95: Revert comment changes and
	XFAIL.

	libgomp/
	* testsuite/libgomp.oacc-fortran/non-scalar-data.f90: Remove XFAIL for
	-O2 and -O3 and explanatory comment.
---
 gcc/fortran/trans-openmp.c                         |   22 ++++-----
 gcc/gimplify.c                                     |   49 ++-----------------
 gcc/omp-low.c                                      |    3 +-
 .../gfortran.dg/goacc/kernels-alias-3.f95          |    4 +-
 .../libgomp.oacc-fortran/non-scalar-data.f90       |    6 +--
 5 files changed, 20 insertions(+), 64 deletions(-)
diff mbox series

Patch

diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 98f40d1..71a3ebb 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -1084,7 +1084,7 @@  gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
 	return;
       tree orig_decl = decl;
       c4 = build_omp_clause (OMP_CLAUSE_LOCATION (c), OMP_CLAUSE_MAP);
-      OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_FIRSTPRIVATE_POINTER);
+      OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
       OMP_CLAUSE_DECL (c4) = decl;
       OMP_CLAUSE_SIZE (c4) = size_int (0);
       decl = build_fold_indirect_ref (decl);
@@ -1100,10 +1100,7 @@  gfc_omp_finish_clause (tree c, gimple_seq *pre_p)
 	  OMP_CLAUSE_SIZE (c3) = size_int (0);
 	  decl = build_fold_indirect_ref (decl);
 	  OMP_CLAUSE_DECL (c) = decl;
-	  OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
 	}
-      if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
-	OMP_CLAUSE_SET_MAP_KIND (c4, GOMP_MAP_POINTER);
     }
   if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
     {
@@ -2168,11 +2165,15 @@  gfc_trans_omp_clauses_1 (stmtblock_t *block, gfc_omp_clauses *clauses,
 					(TREE_TYPE (TREE_TYPE (field)))))
 		    {
 		      tree orig_decl = decl;
-		      enum gomp_map_kind gmk = GOMP_MAP_FIRSTPRIVATE_POINTER;
-		      if (GFC_DECL_GET_SCALAR_ALLOCATABLE (decl)
-			  && (n->sym->attr.oacc_declare_create)
-			  && clauses->update_allocatable)
-			gmk = ptr_map_kind;
+		      enum gomp_map_kind gmk = GOMP_MAP_POINTER;
+		      if (GFC_DECL_GET_SCALAR_ALLOCATABLE (field)
+			  && n->sym->attr.oacc_declare_create)
+			{
+			  if (clauses->update_allocatable)
+			    gmk = GOMP_MAP_ALWAYS_POINTER;
+			  else
+			    gmk = GOMP_MAP_FIRSTPRIVATE_POINTER;
+			}
 		      node4 = build_omp_clause (input_location,
 						OMP_CLAUSE_MAP);
 		      OMP_CLAUSE_SET_MAP_KIND (node4, gmk);
@@ -2189,10 +2190,7 @@  gfc_trans_omp_clauses_1 (stmtblock_t *block, gfc_omp_clauses *clauses,
 			  OMP_CLAUSE_DECL (node3) = decl;
 			  OMP_CLAUSE_SIZE (node3) = size_int (0);
 			  decl = build_fold_indirect_ref (decl);
-			  OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
 			}
-		      if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl)))
-			OMP_CLAUSE_SET_MAP_KIND (node4, GOMP_MAP_POINTER);
 		    }
 		  if (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (decl))
 		      && n->u.map_op != OMP_MAP_ATTACH
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 40bf586..7f55cfd 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -7634,37 +7634,6 @@  find_decl_expr (tree *tp, int *walk_subtrees, void *data)
   return NULL_TREE;
 }
 
-static void
-demote_firstprivate_pointer (tree decl, gimplify_omp_ctx *ctx)
-{
-  if (!lang_GNU_Fortran ())
-    return;
-
-  while (ctx)
-    {
-      if (ctx->region_type == ORT_ACC_PARALLEL
-	  || ctx->region_type == ORT_ACC_KERNELS)
-	break;
-      ctx = ctx->outer_context;
-    }
-
-  if (ctx == NULL)
-    return;
-
-  tree clauses = ctx->clauses;
-
-  for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
-    {
-      if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
-	  && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER
-	  && OMP_CLAUSE_DECL (c) == decl)
-	{
-	  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_POINTER);
-	  return;
-	}
-    }
-}
-
 /* Insert a GOMP_MAP_ALLOC or GOMP_MAP_RELEASE node following a
    GOMP_MAP_STRUCT mapping.  C is an always_pointer mapping.  STRUCT_NODE is
    the struct node to insert the new mapping after (when the struct node is
@@ -7843,7 +7812,7 @@  gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
   outer_ctx = ctx->outer_context;
   if (code == OMP_TARGET)
     {
-      if (!lang_GNU_Fortran () || (region_type & ORT_ACC))
+      if (!lang_GNU_Fortran ())
 	ctx->target_map_pointers_as_0len_arrays = true;
       ctx->target_map_scalars_firstprivate = true;
     }
@@ -7971,7 +7940,6 @@  gimplify_scan_omp_clauses (tree *list_p, gimple_seq *pre_p,
 	  if (!(region_type & ORT_ACC))
 	    check_non_private = "reduction";
 	  decl = OMP_CLAUSE_DECL (c);
-	  demote_firstprivate_pointer (decl, ctx->outer_context);
 	  if (TREE_CODE (decl) == MEM_REF)
 	    {
 	      tree type = TREE_TYPE (decl);
@@ -9491,16 +9459,11 @@  gimplify_adjust_omp_clauses (gimple_seq *pre_p, gimple_seq body, tree *list_p,
 		      && kind != GOMP_MAP_FORCE_PRESENT
 		      && kind != GOMP_MAP_POINTER)
 		    {
-		      if (lang_hooks.decls.omp_privatize_by_reference (decl))
-			OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_POINTER);
-		      else
-			{
-			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
-				      "incompatible data clause with reduction "
-				      "on %qE; promoting to present_or_copy",
-				      DECL_NAME (t));
-			  OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
-			}
+		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
+				  "incompatible data clause with reduction "
+				  "on %qE; promoting to present_or_copy",
+				  DECL_NAME (t));
+		      OMP_CLAUSE_SET_MAP_KIND (c, GOMP_MAP_TOFROM);
 		    }
 		}
 	    }
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 1726451..a5fc2b1 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -9112,8 +9112,7 @@  lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
 		  }
 		else
 		  is_ref = omp_is_reference (var);
-		if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE
-		    || (lang_GNU_Fortran () && TREE_CODE (var) == PARM_DECL))
+		if (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_REFERENCE)
 		  is_ref = false;
 		bool ref_to_array = false;
 		if (is_ref)
diff --git a/gcc/testsuite/gfortran.dg/goacc/kernels-alias-3.f95 b/gcc/testsuite/gfortran.dg/goacc/kernels-alias-3.f95
index 09f0264..36b06d3 100644
--- a/gcc/testsuite/gfortran.dg/goacc/kernels-alias-3.f95
+++ b/gcc/testsuite/gfortran.dg/goacc/kernels-alias-3.f95
@@ -17,6 +17,4 @@  end program main
 
 ! Only the omp_data_i related loads should be annotated with cliques.
 ! { dg-final { scan-tree-dump-times "clique 1 base 1" 2 "ealias" } }
-! The following FAILs since/needs to be updated for the "Partially enable
-! GOMP_MAP_FIRSTPRIVATE_POINTER in gfortran" changes.
-! { dg-final { scan-tree-dump-times "(?n)clique 1 base 0" 3 "ealias" { xfail *-*-* } } }
+! { dg-final { scan-tree-dump-times "(?n)clique 1 base 0" 3 "ealias" } }
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90 b/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90
index 7562571..99bd692 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/non-scalar-data.f90
@@ -3,11 +3,9 @@ 
 ! present.
 
 ! { dg-do run }
-! TODO, for "-Os" see <https://gcc.gnu.org/PR80995>, and for the others, this
-! regressed with the "Partially enable GOMP_MAP_FIRSTPRIVATE_POINTER in
-! gfortran" changes.
+! TODO, <https://gcc.gnu.org/PR80995>.
 ! warning: OpenACC kernels construct will be executed sequentially; will by default avoid offloading to prevent data copy penalty
-! { dg-xfail-if "TODO" { openacc_nvidia_accel_selected } { "-Os" "-O2" "-O3" } { "" } }
+! { dg-xfail-if "TODO" { openacc_nvidia_accel_selected } { "-Os" } { "" } }
 
 program main
   implicit none