aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Brown <julian@codesourcery.com>2019-05-28 08:42:10 -0700
committerThomas Schwinge <thomas@codesourcery.com>2020-03-03 12:18:27 +0100
commita7649ea738ea7f6c3ac367377c08ef1c2832d495 (patch)
treecc25b710b2332330a552c9448cdac79a0c5fd9ea
parent3a401f9ba1040a7a3bc6fe2c5acbcec6c2620748 (diff)
downloadgcc-a7649ea738ea7f6c3ac367377c08ef1c2832d495.zip
gcc-a7649ea738ea7f6c3ac367377c08ef1c2832d495.tar.gz
gcc-a7649ea738ea7f6c3ac367377c08ef1c2832d495.tar.bz2
Apply gangprivate attribute to innermost decl
...and fix parallelism-level calculation when applying the attribute. gcc/ * omp-low.c (mark_oacc_gangprivate): Add CTX parameter. Use to look up correct decl to add attribute to. (lower_omp_for): Move "oacc gangprivate" processing from here... (process_oacc_gangprivate_1): ...to here. New function. (lower_omp_target): Update call to mark_oacc_gangprivate. (execute_lower_omp): Call process_oacc_gangprivate_1 for each OMP context. libgomp/ * testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90: New test. (cherry picked from openacc-gcc-9-branch commit ac8b85410f6d8b0c02f130527713da488f243d57)
-rw-r--r--gcc/ChangeLog.omp10
-rw-r--r--gcc/omp-low.c77
-rw-r--r--libgomp/ChangeLog.omp4
-rw-r--r--libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f9023
4 files changed, 85 insertions, 29 deletions
diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp
index e7f2688..15c9c08 100644
--- a/gcc/ChangeLog.omp
+++ b/gcc/ChangeLog.omp
@@ -1,3 +1,13 @@
+2019-05-28 Julian Brown <julian@codesourcery.com>
+
+ * omp-low.c (mark_oacc_gangprivate): Add CTX parameter. Use to look up
+ correct decl to add attribute to.
+ (lower_omp_for): Move "oacc gangprivate" processing from here...
+ (process_oacc_gangprivate_1): ...to here. New function.
+ (lower_omp_target): Update call to mark_oacc_gangprivate.
+ (execute_lower_omp): Call process_oacc_gangprivate_1 for each OMP
+ context.
+
2019-05-30 Kwok Cheung Yeung <kcy@codesourcery.com>
* tree-vrp.c (extract_range_from_unary_expr): Set a varying range
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index fcbc908..249cc1a 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -8774,25 +8774,36 @@ oacc_record_vars_in_bind (omp_context *ctx, tree bindvars)
semantics are correct. */
static void
-mark_oacc_gangprivate (vec<tree> *decls)
+mark_oacc_gangprivate (vec<tree> *decls, omp_context *ctx)
{
int i;
tree decl;
FOR_EACH_VEC_ELT (*decls, i, decl)
- if (!lookup_attribute ("oacc gangprivate", DECL_ATTRIBUTES (decl)))
- {
- if (dump_file && (dump_flags & TDF_DETAILS))
- {
- fprintf (dump_file,
- "Setting 'oacc gangprivate' attribute for decl:");
- print_generic_decl (dump_file, decl, TDF_SLIM);
- fputc ('\n', dump_file);
- }
- DECL_ATTRIBUTES (decl)
- = tree_cons (get_identifier ("oacc gangprivate"),
- NULL, DECL_ATTRIBUTES (decl));
- }
+ {
+ for (omp_context *thisctx = ctx; thisctx; thisctx = thisctx->outer)
+ {
+ tree inner_decl = maybe_lookup_decl (decl, thisctx);
+ if (inner_decl)
+ {
+ decl = inner_decl;
+ break;
+ }
+ }
+ if (!lookup_attribute ("oacc gangprivate", DECL_ATTRIBUTES (decl)))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file,
+ "Setting 'oacc gangprivate' attribute for decl:");
+ print_generic_decl (dump_file, decl, TDF_SLIM);
+ fputc ('\n', dump_file);
+ }
+ DECL_ATTRIBUTES (decl)
+ = tree_cons (get_identifier ("oacc gangprivate"),
+ NULL, DECL_ATTRIBUTES (decl));
+ }
+ }
}
/* Lower code for an OMP loop directive. */
@@ -8968,20 +8979,7 @@ lower_omp_for (gimple_stmt_iterator *gsi_p, omp_context *ctx)
/* Add OpenACC partitioning and reduction markers just before the loop. */
if (oacc_head)
- {
- gimple_seq_add_seq (&body, oacc_head);
-
- unsigned level_total = 0;
- omp_context *thisctx;
-
- for (thisctx = ctx; thisctx; thisctx = thisctx->outer)
- level_total += thisctx->oacc_partitioning_levels;
-
- /* If the current context and parent contexts are distributed over a
- total of one parallelism level, we have gang partitioning. */
- if (level_total == 1)
- mark_oacc_gangprivate (ctx->oacc_addressable_var_decls);
- }
+ gimple_seq_add_seq (&body, oacc_head);
lower_omp_for_lastprivate (&fd, &body, &dlist, ctx);
@@ -10228,7 +10226,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
if (offloaded)
{
- mark_oacc_gangprivate (ctx->oacc_addressable_var_decls);
+ mark_oacc_gangprivate (ctx->oacc_addressable_var_decls, ctx);
/* Declare all the variables created by mapping and the variables
declared in the scope of the target body. */
@@ -11213,6 +11211,26 @@ lower_omp_grid_body (gimple_stmt_iterator *gsi_p, omp_context *ctx)
gimple_build_omp_return (false));
}
+/* Find gang-private variables in a context. */
+
+static int
+process_oacc_gangprivate_1 (splay_tree_node node, void *data)
+{
+ omp_context *ctx = (omp_context *) node->value;
+ unsigned level_total = 0;
+ omp_context *thisctx;
+
+ for (thisctx = ctx; thisctx; thisctx = thisctx->outer)
+ level_total += thisctx->oacc_partitioning_levels;
+
+ /* If the current context and parent contexts are distributed over a
+ total of one parallelism level, we have gang partitioning. */
+ if (level_total == 1)
+ mark_oacc_gangprivate (ctx->oacc_addressable_var_decls, ctx);
+
+ return 0;
+}
+
/* Helper to lookup dynamic array through nested omp contexts. Returns
TREE_LIST of dimensions, and the CTX where it was found in *CTX_P. */
@@ -11803,6 +11821,7 @@ execute_lower_omp (void)
if (all_contexts)
{
+ splay_tree_foreach (all_contexts, process_oacc_gangprivate_1, NULL);
splay_tree_delete (all_contexts);
all_contexts = NULL;
}
diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 8f9cd61..b3bcb31 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,7 @@
+2019-05-28 Julian Brown <julian@codesourcery.com>
+
+ * testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90: New test.
+
2019-01-30 Andrew Jenner <andrew@codesourcery.com>
* testsuite/libgomp.fortan/fortran.exp (lang_link_flags): Add
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90 b/libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90
new file mode 100644
index 0000000..d147229
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90
@@ -0,0 +1,23 @@
+! Test for lack of "oacc gangprivate" attribute on worker-private variables
+
+! { dg-do run }
+! { dg-additional-options "-fdump-tree-omplower-details" }
+! { dg-final { scan-tree-dump-times "Setting 'oacc gangprivate' attribute for decl" 0 "omplower" } } */
+
+program main
+ integer :: w, arr(0:31)
+
+ !$acc parallel num_gangs(32) num_workers(32) copyout(arr)
+ !$acc loop gang worker private(w)
+ do j = 0, 31
+ w = 0
+ !$acc loop seq
+ do i = 0, 31
+ w = w + 1
+ end do
+ arr(j) = w
+ end do
+ !$acc end parallel
+
+ if (any (arr .ne. 32)) stop 1
+end program main