Patchwork RFC: simd enabled functions (omp declare simd / elementals)

login
register
mail settings
Submitter Jakub Jelinek
Date Nov. 1, 2013, 12:35 p.m.
Message ID <20131101123535.GC27813@tucnak.zalov.cz>
Download mbox | patch
Permalink /patch/287800/
State New
Headers show

Comments

Jakub Jelinek - Nov. 1, 2013, 12:35 p.m.
Hi!

One more thing:

On Thu, Oct 31, 2013 at 10:04:45PM -0500, Aldy Hernandez wrote:
> +enum linear_stride_type {
> +  LINEAR_STRIDE_NO,
> +  LINEAR_STRIDE_YES_CONSTANT,
> +  LINEAR_STRIDE_YES_VARIABLE
> +};
...
> +  /* If the linear stride is a constant, `linear_stride' is
> +     LINEAR_STRIDE_YES_CONSTANT, and `linear_stride_num' holds
> +     the numeric stride.
> +
> +     If the linear stride is variable, `linear_stride' is
> +     LINEAR_STRIDE_YES_VARIABLE, and `linear_stride_num' contains
> +     the function argument containing the stride (as an index into the
> +     function arguments starting at 0).
> +
> +     Otherwise, `linear_stride' is LINEAR_STRIDE_NO and
> +     `linear_stride_num' is unused.  */
> +  enum linear_stride_type linear_stride;
> +  unsigned HOST_WIDE_INT linear_stride_num;
> +
> +  /* Variable alignment if available, otherwise 0.  */
> +  unsigned int alignment;
> +
> +  /* True if variable is uniform.  */
> +  unsigned int uniform : 1;
> +};

At least the OpenMP standard disallows one argument to be both
uniform and linear (but, apparently I forgot to diagnose, fixed thusly,
committed to trunk), and even if Cilk+ didn't disallow it explicitly,
linear together with uniform doesn't make sense (unless we consider
uniform a special case of linear with step 0).  The Intel mangling PDF
doesn't allow the same argument to be both uniform and linear either.
So, IMHO much better would be to have an enum simd_clone_arg_type which
would be
enum simd_clone_arg_type
{
  SIMD_CLONE_ARG_TYPE_VECTOR,
  SIMD_CLONE_ARG_TYPE_UNIFORM,
  SIMD_CLONE_ARG_TYPE_LINEAR_CONSTANT_STEP,
  SIMD_CLONE_ARG_TYPE_LINEAR_VARIABLE_STEP
};
drop uniform bitfield, change linear_stride_num to
say union { unsigned HOST_WIDE_INT linear_constant_step; int linear_step_argno; };
or similar.

2013-11-01  Jakub Jelinek  <jakub@redhat.com>

	* c-typeck.c (c_finish_omp_clauses) <case OMP_CLAUSE_UNIFORM>: Go to
	check_dup_generic at the end, unless remove is true.
	(c_finish_omp_clauses) <case OMP_CLAUSE_REDUCTION>: Add break; after
	remove = true;.
	(c_finish_omp_clauses) <case OMP_CLAUSE_COPYIN>: Likewise.

	* semantics.c (finish_omp_clauses) <case OMP_CLAUSE_UNIFORM>: Go to
	check_dup_generic at the end, unless remove is true.
	(finish_omp_clauses) <case OMP_CLAUSE_LINEAR>: Add break; after
	remove = true;.

	* gcc.dg/gomp/declare-simd-2.c (f12, f13, f14, f15, f16, f17): New
	tests.
	* g++.dg/gomp/declare-simd-2.C (f15, f16, f17, f18, f19, f20): New
	tests.


	Jakub

Patch

--- gcc/c/c-typeck.c.jj	2013-10-31 20:05:44.000000000 +0100
+++ gcc/c/c-typeck.c	2013-11-01 13:07:20.330051746 +0100
@@ -11316,6 +11316,7 @@  c_finish_omp_clauses (tree clauses)
 			    "%qE has invalid type for %<reduction(%s)%>",
 			    t, r_name);
 		  remove = true;
+		  break;
 		}
 	    }
 	  else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
@@ -11323,6 +11324,7 @@  c_finish_omp_clauses (tree clauses)
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"user defined reduction not found for %qD", t);
 	      remove = true;
+	      break;
 	    }
 	  else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
 	    {
@@ -11406,6 +11408,7 @@  c_finish_omp_clauses (tree clauses)
 	      error_at (OMP_CLAUSE_LOCATION (c),
 			"%qE must be %<threadprivate%> for %<copyin%>", t);
 	      remove = true;
+	      break;
 	    }
 	  goto check_dup_generic;
 
@@ -11615,8 +11618,9 @@  c_finish_omp_clauses (tree clauses)
 		error_at (OMP_CLAUSE_LOCATION (c),
 			  "%qE is not an argument in %<uniform%> clause", t);
 	      remove = true;
+	      break;
 	    }
-	  break;
+	  goto check_dup_generic;
 
 	case OMP_CLAUSE_NOWAIT:
 	  if (copyprivate_seen)
--- gcc/cp/semantics.c.jj	2013-10-31 20:05:44.000000000 +0100
+++ gcc/cp/semantics.c	2013-11-01 13:10:29.006068213 +0100
@@ -5188,12 +5188,16 @@  finish_omp_clauses (tree clauses)
 	  if (t == NULL_TREE)
 	    t = integer_one_node;
 	  if (t == error_mark_node)
-	    remove = true;
+	    {
+	      remove = true;
+	      break;
+	    }
 	  else if (!type_dependent_expression_p (t)
 		   && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
 	    {
 	      error ("linear step expression must be integral");
 	      remove = true;
+	      break;
 	    }
 	  else
 	    {
@@ -5210,7 +5214,10 @@  finish_omp_clauses (tree clauses)
 					   MINUS_EXPR, sizetype, t,
 					   OMP_CLAUSE_DECL (c));
 		      if (t == error_mark_node)
-			remove = true;
+			{
+			  remove = true;
+			  break;
+			}
 		    }
 		}
 	      OMP_CLAUSE_LINEAR_STEP (c) = t;
@@ -5626,8 +5633,9 @@  finish_omp_clauses (tree clauses)
 	      else
 		error ("%qE is not an argument in %<uniform%> clause", t);
 	      remove = true;
+	      break;
 	    }
-	  break;
+	  goto check_dup_generic;
 
 	case OMP_CLAUSE_NOWAIT:
 	case OMP_CLAUSE_ORDERED:
--- gcc/testsuite/gcc.dg/gomp/declare-simd-2.c.jj	2013-10-31 20:05:44.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/declare-simd-2.c	2013-11-01 12:56:58.124140252 +0100
@@ -39,3 +39,16 @@  struct D { int d; };
 
 #pragma omp declare simd aligned (e)    /* { dg-error "neither a pointer nor an array" } */
 int fn11 (struct D e);   
+
+#pragma omp declare simd linear(a:7) uniform(a)	/* { dg-error "appears more than once" } */
+int f12 (int a);
+#pragma omp declare simd linear(a) linear(a)	/* { dg-error "appears more than once" } */
+int f13 (int a);
+#pragma omp declare simd linear(a) linear(a:7)	/* { dg-error "appears more than once" } */
+int f14 (int a);
+#pragma omp declare simd linear(a:6) linear(a:6)/* { dg-error "appears more than once" } */
+int f15 (int a);
+#pragma omp declare simd uniform(a) uniform(a)	/* { dg-error "appears more than once" } */
+int f16 (int a);
+#pragma omp declare simd uniform(a) aligned (a: 32)
+int f17 (int *a);
--- gcc/testsuite/g++.dg/gomp/declare-simd-2.C.jj	2013-10-31 20:05:44.000000000 +0100
+++ gcc/testsuite/g++.dg/gomp/declare-simd-2.C	2013-11-01 12:58:08.277839837 +0100
@@ -82,4 +82,17 @@  int fn14 (double &d);
 #pragma omp declare simd aligned (e)	// { dg-error "neither a pointer nor an array" }
 int fn14 (D e);
 
+#pragma omp declare simd linear(a:7) uniform(a)	// { dg-error "appears more than once" }
+int f15 (int a);
+#pragma omp declare simd linear(a) linear(a)	// { dg-error "appears more than once" }
+int f16 (int a);
+#pragma omp declare simd linear(a) linear(a:7)	// { dg-error "appears more than once" }
+int f17 (int a);
+#pragma omp declare simd linear(a:6) linear(a:6)// { dg-error "appears more than once" }
+int f18 (int a);
+#pragma omp declare simd uniform(a) uniform(a)	// { dg-error "appears more than once" }
+int f19 (int a);
+#pragma omp declare simd uniform(a) aligned (a: 32)
+int f20 (int *a);
+
 // { dg-error "has no member" "" { target *-*-* } 61 }