Просмотр исходного кода

gcc: Determine the data mode based on the constness of the pointed-to type.

* gcc-plugin/src/starpu.c (build_task_submission): For pointers,
  determine the mode based on the constness of the pointed-to type.

* gcc-plugin/tests/pointer-tasks.c (my_pointer_task): Mark `x' as
  `const int *'.
  (pointer_arg1): Mark as `const'.

* gcc-plugin/tests/pointers.c (my_pointer_task): Mark `x' as `const int *'.
  (my_mixed_task): Mark `y' as `const long long *'.
  (main): Update EXPECTED_POINTER_TASK and EXPECTED_MIXED_TASK accordingly.
Ludovic Courtès лет назад: 14
Родитель
Сommit
f974683ba6
3 измененных файлов с 25 добавлено и 17 удалено
  1. 8 1
      gcc-plugin/src/starpu.c
  2. 5 4
      gcc-plugin/tests/pointer-tasks.c
  3. 12 12
      gcc-plugin/tests/pointers.c

+ 8 - 1
gcc-plugin/src/starpu.c

@@ -1154,8 +1154,15 @@ build_task_submission (tree task_decl, gimple call)
 	  gcc_assert (TREE_CODE (arg) == VAR_DECL
 		      || TREE_CODE (arg) == ADDR_EXPR);
 
+	  /* If TYPE points to a const-qualified type, then mark the data as
+	     read-only; otherwise default to read-write.
+	     FIXME: Add an attribute to specify write-only.  */
+	  int mode =
+	    (TYPE_QUALS (TREE_TYPE (type)) & TYPE_QUAL_CONST)
+	    ? STARPU_R : STARPU_RW;
+
 	  VEC_safe_push (tree, heap, args,
-			 build_int_cst (integer_type_node, STARPU_RW));
+			 build_int_cst (integer_type_node, mode));
 	  VEC_safe_push (tree, heap, args, build_pointer_lookup (arg, &body));
 	}
       else

+ 5 - 4
gcc-plugin/tests/pointer-tasks.c

@@ -23,19 +23,20 @@
 
 /* The task under test.  */
 
-static void my_pointer_task (int *x, char a, long long *y, int b) __attribute__ ((task));
+static void my_pointer_task (const int *x, char a, long long *y, int b)
+  __attribute__ ((task));
 
-static void my_pointer_task_cpu (int *x, char a, long long *y, int b)
+static void my_pointer_task_cpu (const int *x, char a, long long *y, int b)
   __attribute__ ((task_implementation ("cpu", my_pointer_task), noinline));
 
 static int implementations_called;
 
 /* The input arguments.  */
-static int pointer_arg1[] = { 42, 1, 2, 3, 4, 5 };
+static const int pointer_arg1[] = { 42, 1, 2, 3, 4, 5 };
 static long long *pointer_arg2;
 
 static void
-my_pointer_task_cpu (int *x, char a, long long *y, int b)
+my_pointer_task_cpu (const int *x, char a, long long *y, int b)
 {
   implementations_called |= STARPU_CPU;
   assert (x == pointer_arg1);

+ 12 - 12
gcc-plugin/tests/pointers.c

@@ -21,42 +21,42 @@
 
 /* The tasks under test.  */
 
-static void my_pointer_task (int *x, long long *y) __attribute__ ((task));
+static void my_pointer_task (const int *x, long long *y) __attribute__ ((task));
 
-static void my_pointer_task_cpu (int *, long long *)
+static void my_pointer_task_cpu (const int *, long long *)
   __attribute__ ((task_implementation ("cpu", my_pointer_task)));
-static void my_pointer_task_opencl (int *, long long *)
+static void my_pointer_task_opencl (const int *, long long *)
   __attribute__ ((task_implementation ("opencl", my_pointer_task)));
 
 static void
-my_pointer_task_cpu (int *x, long long *y)
+my_pointer_task_cpu (const int *x, long long *y)
 {
   printf ("%s: x = %p, y = %p\n", __func__, x, y);
 }
 
 static void
-my_pointer_task_opencl (int *x, long long *y)
+my_pointer_task_opencl (const int *x, long long *y)
 {
   printf ("%s: x = %p, y = %p\n", __func__, x, y);
 }
 
 
 
-static void my_mixed_task (int *x, char z, long long *y)
+static void my_mixed_task (int *x, char z, const long long *y)
   __attribute__ ((task));
-static void my_mixed_task_cpu (int *, char, long long *)
+static void my_mixed_task_cpu (int *, char, const long long *)
   __attribute__ ((task_implementation ("cpu", my_mixed_task)));
-static void my_mixed_task_opencl (int *, char, long long *)
+static void my_mixed_task_opencl (int *, char, const long long *)
   __attribute__ ((task_implementation ("opencl", my_mixed_task)));
 
 static void
-my_mixed_task_cpu (int *x, char z, long long *y)
+my_mixed_task_cpu (int *x, char z, const long long *y)
 {
   printf ("%s: x = %p, y = %p, z = %i\n", __func__, x, y, (int) z);
 }
 
 static void
-my_mixed_task_opencl (int *x, char z, long long *y)
+my_mixed_task_opencl (int *x, char z, const long long *y)
 {
   printf ("%s: x = %p, y = %p, z = %i\n", __func__, x, y, (int) z);
 }
@@ -75,7 +75,7 @@ main (int argc, char *argv[])
 
   struct insert_task_argument expected_pointer_task[] =
     {
-      { STARPU_RW, x },
+      { STARPU_R,  x },
       { STARPU_RW, y },
       { 0, 0, 0 }
     };
@@ -95,7 +95,7 @@ main (int argc, char *argv[])
     {
       { STARPU_RW, x },
       { STARPU_VALUE, &z, sizeof z },
-      { STARPU_RW, y },
+      { STARPU_R,  y },
       { 0, 0, 0 }
     };