diff mbox

[gomp4] openacc reduction simplification

Message ID 56328152.5080105@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Oct. 29, 2015, 8:28 p.m. UTC
I've committed this to gomp4.   It removes a no-longer needed field from 
omp_context &  simplifies the dummy head/tail generation needed for reductions 
at the outermost level.  Also incorporates the simplification I committed to 
trunk  earlier today.

nathan

Comments

Thomas Schwinge Oct. 30, 2015, 1:14 p.m. UTC | #1
Hi Nathan!

On Thu, 29 Oct 2015 13:28:02 -0700, Nathan Sidwell <nathan@acm.org> wrote:
> I've committed this to gomp4.   It removes a no-longer needed field from 
> omp_context &  simplifies the dummy head/tail generation needed for reductions 
> at the outermost level.  Also incorporates the simplification I committed to 
> trunk  earlier today.

> 	* omp-low.c (struct omp_context): Remove reductions field.
> 	(scan_sharing_clauses): Don't increment it.
> 	(lower_omp_target): Don't check it.  Move openacc dummy gang head
> 	& tail generation later & simplify.  Merge ifs.

Thanks for clearing that up.  When working through merge conflicts of a
recent merge from trunk into gomp-4_0-branch, I had noticed the same
oddities (unreachable "if" condition, too complicated reductions
handling), but at that time couldn't allocate time for working on it.


Grüße
 Thomas
diff mbox

Patch

2015-10-29  Nathan Sidwell  <nathan@codesourcery.com>

	* omp-low.c (struct omp_context): Remove reductions field.
	(scan_sharing_clauses): Don't increment it.
	(lower_omp_target): Don't check it.  Move openacc dummy gang head
	& tail generation later & simplify.  Merge ifs.

Index: gcc/omp-low.c
===================================================================
--- gcc/omp-low.c	(revision 229556)
+++ gcc/omp-low.c	(working copy)
@@ -201,9 +201,6 @@  struct omp_context
 
   /* True if this construct can be cancelled.  */
   bool cancellable;
-
-  /* The number of reductions in a loop.  */
-  int reductions;
 };
 
 /* A structure holding the elements of:
@@ -1946,7 +1943,6 @@  scan_sharing_clauses (tree clauses, omp_
 	  goto do_private;
 
 	case OMP_CLAUSE_REDUCTION:
-	  ctx->reductions++;
 	  decl = OMP_CLAUSE_DECL (c);
 	  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
 	      && TREE_CODE (decl) == MEM_REF)
@@ -15146,7 +15142,7 @@  lower_omp_target (gimple_stmt_iterator *
   tree child_fn, t, c;
   gomp_target *stmt = as_a <gomp_target *> (gsi_stmt (*gsi_p));
   gbind *tgt_bind, *bind, *dep_bind = NULL;
-  gimple_seq tgt_body, olist, ilist, orlist, irlist, fplist, new_body;
+  gimple_seq tgt_body, olist, ilist, fplist, new_body;
   location_t loc = gimple_location (stmt);
   bool offloaded, data_region;
   unsigned int map_cnt = 0;
@@ -15432,16 +15428,6 @@  lower_omp_target (gimple_stmt_iterator *
   else if (data_region)
     lower_omp (&tgt_body, ctx);
 
-  irlist = NULL;
-  orlist = NULL;
-
-  if (is_oacc_parallel (ctx))
-    /* If there are reductions on the offloaded region itself, treat
-       them as a dummy GANG loop.  */
-    lower_oacc_reductions (gimple_location (ctx->stmt), clauses,
-			   build_int_cst (unsigned_type_node, GOMP_DIM_GANG),
-			   false, NULL, NULL, &irlist, &orlist, ctx);
-
   if (offloaded)
     {
       /* Declare all the variables created by mapping and the variables
@@ -16213,34 +16199,37 @@  lower_omp_target (gimple_stmt_iterator *
 	    break;
 	  }
 
-      if (offloaded)
+      gimple_seq fork_seq = NULL;
+      gimple_seq join_seq = NULL;
+
+      if (is_oacc_parallel (ctx))
 	{
-	  if (is_oacc_kernels (ctx))
-	    {
-	      tree arg = build_int_cst (integer_type_node, GOMP_DIM_GANG);
-	      gcall *gang_single
-		= gimple_build_call_internal (IFN_GOACC_DIM_POS, 1, arg);
-	      gimple_seq_add_stmt (&new_body, gang_single);
-	    }
-	  gimple_seq_add_stmt (&new_body, gimple_build_omp_entry_end ());
-	  if (ctx->reductions)
-	    {
-	      gimple_seq_add_seq (&irlist, tgt_body);
-	      gimple_seq_add_seq (&new_body, irlist);
-	      gimple_seq_add_seq (&new_body, orlist);
-	    }
-	  else
-	    gimple_seq_add_seq (&new_body, tgt_body);
+	  /* If there are reductions on the offloaded region itself, treat
+	     them as a dummy GANG loop.  */
+	  tree level = build_int_cst (integer_type_node, GOMP_DIM_GANG);
 
-	  new_body = maybe_catch_exception (new_body);
+	  lower_oacc_reductions (gimple_location (ctx->stmt), clauses, level,
+				 false, NULL, NULL, &fork_seq, &join_seq, ctx);
 	}
-      else
-	gimple_seq_add_seq (&new_body, tgt_body);
-    }
-  else if (data_region)
-    new_body = tgt_body;
-  if (offloaded || data_region)
-    {
+
+      if (is_oacc_kernels (ctx))
+	{
+	  tree arg = build_int_cst (integer_type_node, GOMP_DIM_GANG);
+	  gcall *gang_single
+	    = gimple_build_call_internal (IFN_GOACC_DIM_POS, 1, arg);
+	  gimple_seq_add_stmt (&new_body, gang_single);
+	}
+
+      if (offloaded)
+	gimple_seq_add_stmt (&new_body, gimple_build_omp_entry_end ());
+
+      gimple_seq_add_seq (&new_body, fork_seq);
+      gimple_seq_add_seq (&new_body, tgt_body);
+      gimple_seq_add_seq (&new_body, join_seq);
+
+      if (offloaded)
+	new_body = maybe_catch_exception (new_body);
+
       gimple_seq_add_stmt (&new_body, gimple_build_omp_return (false));
       gimple_omp_set_body (stmt, new_body);
     }