From: Julian Brown Date: Tue, 28 May 2019 15:42:10 +0000 (-0700) Subject: Apply gangprivate attribute to innermost decl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7649ea738ea7f6c3ac367377c08ef1c2832d495;p=thirdparty%2Fgcc.git 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) --- diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index e7f268817548..15c9c0844134 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,13 @@ +2019-05-28 Julian Brown + + * 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 * 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 fcbc90834b04..249cc1aac535 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 *decls) +mark_oacc_gangprivate (vec *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 8f9cd6116c7e..b3bcb3113f14 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,7 @@ +2019-05-28 Julian Brown + + * testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90: New test. + 2019-01-30 Andrew Jenner * 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 000000000000..d147229d91e5 --- /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