]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Apply gangprivate attribute to innermost decl
authorJulian Brown <julian@codesourcery.com>
Tue, 28 May 2019 15:42:10 +0000 (08:42 -0700)
committerThomas Schwinge <thomas@codesourcery.com>
Tue, 3 Mar 2020 11:18:27 +0000 (12:18 +0100)
...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)

gcc/ChangeLog.omp
gcc/omp-low.c
libgomp/ChangeLog.omp
libgomp/testsuite/libgomp.oacc-fortran/gangprivate-attrib-2.f90 [new file with mode: 0644]

index e7f2688175482646a2910ff5785dac047b7ae6af..15c9c0844134a60ac5311edfd01ffb06569410c3 100644 (file)
@@ -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
index fcbc90834b0470035890deb05875b8ee75e86281..249cc1aac5352fd61416e62b4914c3144f3e173a 100644 (file)
@@ -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;
     }
index 8f9cd6116c7e87e92e447c8fede4733b91d06ed6..b3bcb3113f148cdb60060d9d550aeca2ddc86878 100644 (file)
@@ -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 (file)
index 0000000..d147229
--- /dev/null
@@ -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