2016-10-03  Nathan Sidwell  <nathan@codesourcery.com>

	* gimplify.c (gimplify_scan_omp_clauses): No special handling for
	OMP_CLAUSE_TILE.
	* omp-low.c (scan_sharing_clauses): Allow OMP_CLAUSE_TILE.
	(expand_oacc_for): Remove out of date note.  Fix whitespace.
	(oacc_dim_call): New.
	(oacc_thread_numbers): Use it.
	(oacc_loop_fixed_partitions): Dump partitioning.
	* tree-nested.c (convert_nonlocal_omp_clauses): Allow OMP_CLAUSE_TILE.
	* internal-fn.def (GOACC_DIM_POS): Comment may be overly conservative.

Index: gimplify.c
===================================================================
--- gimplify.c	(revision 240724)
+++ gimplify.c	(working copy)
@@ -7555,16 +7555,6 @@ gimplify_scan_omp_clauses (tree *list_p,
 	    remove = true;
 	  break;
 
-	case OMP_CLAUSE_TILE:
-	  for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
-	       list = TREE_CHAIN (list))
-	    {
-	      if (gimplify_expr (&TREE_VALUE (list), pre_p, NULL,
-				 is_gimple_val, fb_rvalue) == GS_ERROR)
-		remove = true;
-	    }
-	  break;
-
 	case OMP_CLAUSE_DEVICE_RESIDENT:
 	  remove = true;
 	  break;
@@ -7573,6 +7563,7 @@ gimplify_scan_omp_clauses (tree *list_p,
 	case OMP_CLAUSE_ORDERED:
 	case OMP_CLAUSE_UNTIED:
 	case OMP_CLAUSE_COLLAPSE:
+	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE_AUTO:
 	case OMP_CLAUSE_SEQ:
 	case OMP_CLAUSE_INDEPENDENT:
Index: internal-fn.def
===================================================================
--- internal-fn.def	(revision 240724)
+++ internal-fn.def	(working copy)
@@ -175,7 +175,7 @@ DEF_INTERNAL_FN (UNIQUE, ECF_NOTHROW, NU
    dimension.  DIM_POS is pure (and not const) so that it isn't
    thought to clobber memory and can be gcse'd within a single
    parallel region, but not across FORK/JOIN boundaries.  They take a
-   single INTEGER_CST argument.  */
+   single INTEGER_CST argument.  This might be overly conservative.  */
 DEF_INTERNAL_FN (GOACC_DIM_SIZE, ECF_CONST | ECF_NOTHROW | ECF_LEAF, ".")
 DEF_INTERNAL_FN (GOACC_DIM_POS, ECF_PURE | ECF_NOTHROW | ECF_LEAF, ".")
 
Index: omp-low.c
===================================================================
--- omp-low.c	(revision 240724)
+++ omp-low.c	(working copy)
@@ -2221,6 +2221,7 @@ scan_sharing_clauses (tree clauses, omp_
 	case OMP_CLAUSE_INDEPENDENT:
 	case OMP_CLAUSE_AUTO:
 	case OMP_CLAUSE_SEQ:
+	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE_DEVICE_TYPE:
 	  break;
 
@@ -2234,7 +2235,6 @@ scan_sharing_clauses (tree clauses, omp_
 	case OMP_CLAUSE_BIND:
 	case OMP_CLAUSE_DEVICE_RESIDENT:
 	case OMP_CLAUSE_NOHOST:
-	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE__CACHE_:
 	default:
 	  gcc_unreachable ();
@@ -2395,6 +2395,7 @@ scan_sharing_clauses (tree clauses, omp_
 	case OMP_CLAUSE_INDEPENDENT:
 	case OMP_CLAUSE_AUTO:
 	case OMP_CLAUSE_SEQ:
+	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE__GRIDDIM_:
 	case OMP_CLAUSE_DEVICE_TYPE:
 	  break;
@@ -2402,7 +2403,6 @@ scan_sharing_clauses (tree clauses, omp_
 	case OMP_CLAUSE_BIND:
 	case OMP_CLAUSE_DEVICE_RESIDENT:
 	case OMP_CLAUSE_NOHOST:
-	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE__CACHE_:
 	default:
 	  gcc_unreachable ();
@@ -11244,11 +11244,7 @@ expand_omp_taskloop_for_inner (struct om
    <exit_bb> [incoming]
      V = B + ((range -/+ 1) / S +/- 1) * S [*]
 
-   [*] Needed if V live at end of loop
-
-   Note: CHUNKING & GWV mask are specified explicitly here.  This is a
-   transition, and will be specified by a more general mechanism shortly.
- */
+   [*] Needed if V live at end of loop.  */
 
 static void
 expand_oacc_for (struct omp_region *region, struct omp_for_data *fd)
@@ -11357,7 +11353,6 @@ expand_oacc_for (struct omp_region *regi
 	  ass = gimple_build_assign (fd->loop.n2, total);
 	  gsi_insert_before (&gsi, ass, GSI_SAME_STMT);
 	}
-      
     }
 
   tree b = fd->loop.n1;
@@ -18906,6 +18901,23 @@ omp_finish_file (void)
     }
 }
 
+/* Call dim_pos (POS == true) or dim_size (POS == false) builtins for
+   axis DIM.  Return a tmp var holding the result.  */
+
+static tree
+oacc_dim_call (bool pos, int dim, gimple_seq *seq)
+{
+  tree arg = build_int_cst (unsigned_type_node, dim);
+  tree size = create_tmp_var (integer_type_node);
+  enum internal_fn fn = pos ? IFN_GOACC_DIM_POS : IFN_GOACC_DIM_SIZE;
+  gimple *call = gimple_build_call_internal (fn, 1, arg);
+
+  gimple_call_set_lhs (call, size);
+  gimple_seq_add_stmt (seq, call);
+
+  return size;
+}
+
 /* Find the number of threads (POS = false), or thread number (POS =
    true) for an OpenACC region partitioned as MASK.  Setup code
    required for the calculation is added to SEQ.  */
@@ -18920,29 +18932,17 @@ oacc_thread_numbers (bool pos, int mask,
   for (ix = GOMP_DIM_GANG; ix != GOMP_DIM_MAX; ix++)
     if (GOMP_DIM_MASK (ix) & mask)
       {
-	tree arg = build_int_cst (unsigned_type_node, ix);
-
 	if (res)
 	  {
 	    /* We had an outer index, so scale that by the size of
 	       this dimension.  */
-	    tree n = create_tmp_var (integer_type_node);
-	    gimple *call
-	      = gimple_build_call_internal (IFN_GOACC_DIM_SIZE, 1, arg);
-	    
-	    gimple_call_set_lhs (call, n);
-	    gimple_seq_add_stmt (seq, call);
+	    tree n = oacc_dim_call (false, ix, seq);
 	    res = fold_build2 (MULT_EXPR, integer_type_node, res, n);
 	  }
 	if (pos)
 	  {
 	    /* Determine index in this dimension.  */
-	    tree id = create_tmp_var (integer_type_node);
-	    gimple *call = gimple_build_call_internal
-	      (IFN_GOACC_DIM_POS, 1, arg);
-
-	    gimple_call_set_lhs (call, id);
-	    gimple_seq_add_stmt (seq, call);
+	    tree id = oacc_dim_call (true, ix, seq);
 	    if (res)
 	      res = fold_build2 (PLUS_EXPR, integer_type_node, res, id);
 	    else
@@ -19829,9 +19829,14 @@ oacc_loop_fixed_partitions (oacc_loop *l
 	}
     }
 
-  loop->mask = this_mask;
   mask_all |= this_mask;
+  loop->mask = this_mask;
   
+  if (dump_file)
+    fprintf (dump_file, "Loop %s:%d user specified %d\n",
+	     LOCATION_FILE (loop->loc), LOCATION_LINE (loop->loc),
+	     loop->mask);
+
   if (loop->child)
     {
       loop->inner = oacc_loop_fixed_partitions (loop->child,
Index: tree-nested.c
===================================================================
--- tree-nested.c	(revision 240724)
+++ tree-nested.c	(working copy)
@@ -1191,6 +1191,7 @@ convert_nonlocal_omp_clauses (tree *pcla
 	case OMP_CLAUSE_DEFAULT:
 	case OMP_CLAUSE_COPYIN:
 	case OMP_CLAUSE_COLLAPSE:
+	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE_UNTIED:
 	case OMP_CLAUSE_MERGEABLE:
 	case OMP_CLAUSE_PROC_BIND:
@@ -1207,11 +1208,6 @@ convert_nonlocal_omp_clauses (tree *pcla
 	  /* TODO.  */
 	  gcc_unreachable ();
 
-	case OMP_CLAUSE_TILE:
-	  /* OpenACC tile clauses are discarded during gimplification, so we
-	     don't expect to see anything here.  */
-	  gcc_unreachable ();
-
 	case OMP_CLAUSE__CACHE_:
 	  /* These clauses belong to the OpenACC cache directive, which is
 	     discarded during gimplification, so we don't expect to see
@@ -1894,6 +1890,7 @@ convert_local_omp_clauses (tree *pclause
 	case OMP_CLAUSE_DEFAULT:
 	case OMP_CLAUSE_COPYIN:
 	case OMP_CLAUSE_COLLAPSE:
+	case OMP_CLAUSE_TILE:
 	case OMP_CLAUSE_UNTIED:
 	case OMP_CLAUSE_MERGEABLE:
 	case OMP_CLAUSE_PROC_BIND:
@@ -1910,11 +1907,6 @@ convert_local_omp_clauses (tree *pclause
 	  /* TODO.  */
 	  gcc_unreachable ();
 
-	case OMP_CLAUSE_TILE:
-	  /* OpenACC tile clauses are discarded during gimplification, so we
-	     don't expect to see anything here.  */
-	  gcc_unreachable ();
-
 	case OMP_CLAUSE__CACHE_:
 	  /* These clauses belong to the OpenACC cache directive, which is
 	     discarded during gimplification, so we don't expect to see
