]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openacc: Turn off worker partitioning if num_workers==1
authorJulian Brown <julian@codesourcery.com>
Mon, 29 Jun 2020 20:16:51 +0000 (13:16 -0700)
committerThomas Schwinge <thomas@codesourcery.com>
Fri, 17 Sep 2021 19:04:29 +0000 (21:04 +0200)
This patch turns off the middle-end worker-partitioning support if the
number of workers for an outlined offload function is one.  In that case,
we do not need to perform the broadcasting/neutering code transformation.

gcc/
* omp-oacc-neuter-broadcast.cc
(pass_omp_oacc_neuter_broadcast::gate): Disable if num_workers is
1.
(execute_omp_oacc_neuter_broadcast): Adjust.

Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>
gcc/omp-oacc-neuter-broadcast.cc

index d48627a6940c3c6417cb8cae1ceafc630f1cb25c..3fe92248c4e2b278cdea217acc1727918fef9fa2 100644 (file)
@@ -1378,18 +1378,17 @@ execute_omp_oacc_neuter_broadcast ()
 
   /* If this is a routine, calculate MASK as if the outer levels are already
      partitioned.  */
-  tree attr = oacc_get_fn_attrib (current_function_decl);
-  if (attr)
-    {
-      tree dims = TREE_VALUE (attr);
-      unsigned ix;
-      for (ix = 0; ix != GOMP_DIM_MAX; ix++, dims = TREE_CHAIN (dims))
-       {
-         tree allowed = TREE_PURPOSE (dims);
-         if (allowed && integer_zerop (allowed))
-           mask |= GOMP_DIM_MASK (ix);
-       }
-    }
+  {
+    tree attr = oacc_get_fn_attrib (current_function_decl);
+    tree dims = TREE_VALUE (attr);
+    unsigned ix;
+    for (ix = 0; ix != GOMP_DIM_MAX; ix++, dims = TREE_CHAIN (dims))
+      {
+       tree allowed = TREE_PURPOSE (dims);
+       if (allowed && integer_zerop (allowed))
+         mask |= GOMP_DIM_MASK (ix);
+      }
+  }
 
   parallel_g *par = omp_sese_discover_pars (&bb_stmt_map);
   populate_single_mode_bitmaps (par, worker_single, vector_single, mask, 0);
@@ -1506,11 +1505,27 @@ public:
   {}
 
   /* opt_pass methods: */
-  virtual bool gate (function *)
+  virtual bool gate (function *fun)
   {
-    return (flag_openacc
-           && targetm.goacc.create_worker_broadcast_record);
-  };
+    if (!flag_openacc)
+      return false;
+
+    if (!targetm.goacc.create_worker_broadcast_record)
+      return false;
+
+    /* Only relevant for OpenACC offloaded functions.  */
+    tree attr = oacc_get_fn_attrib (fun->decl);
+    if (!attr)
+      return false;
+
+    /* Not relevant for 'num_workers(1)'.  */
+    int worker_dim
+      = oacc_get_fn_dim_size (fun->decl, GOMP_DIM_WORKER);
+    if (worker_dim == 1)
+      return false;
+
+    return true;
+  }
 
   virtual unsigned int execute (function *)
     {