Browse Source

gcc: Error out when none of a task's implementations are usable.

* gcc-plugin/src/starpu.c (task_implementation_target_to_int): Add
  support for Gordon.
  (task_where, validate_task): New functions.
  (lower_starpu): Call `validate_task'.
Ludovic Courtès 13 years ago
parent
commit
109df305b8
2 changed files with 70 additions and 1 deletions
  1. 57 1
      gcc-plugin/src/starpu.c
  2. 13 0
      gcc-plugin/tests/task-errors.c

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

@@ -985,6 +985,9 @@ task_implementation_target_to_int (const_tree target)
   else if (!strncmp (TREE_STRING_POINTER (target), "cuda",
 		     TREE_STRING_LENGTH (target)))
     where_int = STARPU_CUDA;
+  else if (!strncmp (TREE_STRING_POINTER (target), "gordon",
+		     TREE_STRING_LENGTH (target)))
+    where_int = STARPU_GORDON;
   else
     where_int = 0;
 
@@ -1011,6 +1014,24 @@ task_implementation_where (const_tree task_impl)
   return task_implementation_target_to_int (where);
 }
 
+/* Return a bitwise-or of the supported targets of TASK_DECL.  */
+
+static int
+task_where (const_tree task_decl)
+{
+  gcc_assert (task_p (task_decl));
+
+  int where;
+  const_tree impl;
+
+  for (impl = task_implementation_list (task_decl), where = 0;
+       impl != NULL_TREE;
+       impl = TREE_CHAIN (impl))
+    where |= task_implementation_where (TREE_VALUE (impl));
+
+  return where;
+}
+
 /* Return the task implemented by TASK_IMPL.  */
 
 static tree
@@ -1734,6 +1755,39 @@ build_task_body (const_tree task_decl)
 				  insert_task_fn, args);
 }
 
+/* Raise warnings if TASK doesn't meet the basic criteria.  */
+
+static void
+validate_task (tree task)
+{
+  gcc_assert (task_p (task));
+
+  static const int supported = 0
+#ifdef STARPU_USE_CPU
+    | STARPU_CPU
+#endif
+#ifdef STARPU_USE_CUDA
+    | STARPU_CUDA
+#endif
+#ifdef STARPU_USE_OPENCL
+    | STARPU_OPENCL
+#endif
+#ifdef STARPU_USE_GORDON
+    | STARPU_GORDON
+#endif
+    ;
+
+  int where = task_where (task);
+
+  /* If TASK has no implementations, things will barf elsewhere anyway.  */
+
+  if (task_implementation_list (task) != NULL_TREE)
+    if ((where & supported) == 0)
+      error_at (DECL_SOURCE_LOCATION (task),
+		"none of the implementations of task %qE can be used",
+		DECL_NAME (task));
+}
+
 /* Raise an error when IMPL doesn't satisfy the constraints of a task
    implementations, such as not invoking another task.  */
 
@@ -1774,7 +1828,9 @@ lower_starpu (void)
 
   if (task_p (fndecl))
     {
-      /* Make sure the task implementations are valid.  */
+      /* Make sure the task and its implementations are valid.  */
+
+      validate_task (fndecl);
 
       for_each (validate_task_implementation,
 		task_implementation_list (fndecl));

+ 13 - 0
gcc-plugin/tests/task-errors.c

@@ -60,6 +60,15 @@ void my_task_that_invokes_task (int x, char *y)
 void my_task_that_invokes_task_cpu (int x, char *y)
   __attribute__ ((task_implementation ("cpu", my_task_that_invokes_task)));
 
+/* XXX: The assumption behind this test is that STARPU_USE_GORDON is not
+   defined.  */
+void my_task_with_no_usable_implementation (int x) /* (error "none of the implementations") */
+  __attribute__ ((task));
+
+static void my_task_with_no_usable_implementation_gordon (int x)
+  __attribute__ ((task_implementation ("gordon",
+				       my_task_with_no_usable_implementation)));
+
 /* XXX: In practice this test fails for large values of `STARPU_NMAXBUFS'.  */
 void my_task_with_too_many_pointer_params (/* (error "maximum .* exceeded") */
 					   char *x1, char *x2, char *x3,
@@ -118,3 +127,7 @@ my_task_that_invokes_task_cpu (int x, char *y)
   my_external_task (x, y); /* (error "cannot be invoked from task implementation") */
 }
 
+static void
+my_task_with_no_usable_implementation_gordon (int x)
+{
+}