]> 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)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Wed, 21 Apr 2021 16:33:49 +0000 (09:33 -0700)
...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.

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 f98933fd60fa153b4f0ec4b215b6139dad64c49b..7cb656d090b1a75381178ac9c049359472f64c9e 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-20  Julian Brown  <julian@codesourcery.com>
 
        * gimplify.c (gimplify_adjust_omp_clauses_1): Support implied no_alloc
index 923f89de3b1935230ded9b5dac7b6aaaf96da553..c3fe175448a297450ac563b02d21308437176fe1 100644 (file)
@@ -10169,25 +10169,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));
+       }
+    }
 }
 
 /* Gimplify a GIMPLE_OMP_CRITICAL statement.  This is a relatively simple
@@ -11444,20 +11455,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, &clist, ctx);
 
@@ -12646,7 +12644,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.  */
@@ -13723,6 +13721,24 @@ lower_omp_teams (gimple_stmt_iterator *gsi_p, omp_context *ctx)
     TREE_USED (block) = 1;
 }
 
+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;
+}
+
 /* Callback for lower_omp_1.  Return non-NULL if *tp needs to be
    regimplified.  If DATA is non-NULL, lower_omp_1 is outside
    of OMP context, but with task_shared_vars set.  */
@@ -14116,6 +14132,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 76847f7ab36737696a752ac2dbf709bd4a5ae969..46703b60a283c431274098d5559828504b0878d7 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-05-16  Julian Brown  <julian@codesourcery.com>
 
        * testsuite/libgomp.oacc-c-c++-common/kernels-for-index-reuse-1.c: New
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