Browse Source

gcc: Error out when using `pragma wait' from a task implementation.

* gcc-plugin/src/starpu.c (handle_pragma_wait): Bail out when
  CURRENT_FUNCTION_DECL is a task implementation.

* gcc-plugin/tests/Makefile.am (gcc_tests): Add `wait-errors.c'.

* gcc-plugin/tests/wait-errors.c: New file.
Ludovic Courtès 13 years ago
parent
commit
23ec58a451
3 changed files with 51 additions and 5 deletions
  1. 23 5
      gcc-plugin/src/starpu.c
  2. 1 0
      gcc-plugin/tests/Makefile.am
  3. 27 0
      gcc-plugin/tests/wait-errors.c

+ 23 - 5
gcc-plugin/src/starpu.c

@@ -75,6 +75,9 @@ static tree build_codelet_declaration (tree task_decl);
 static tree build_task_body (const_tree task_decl);
 static tree build_pointer_lookup (tree pointer);
 
+static bool task_p (const_tree decl);
+static bool task_implementation_p (const_tree decl);
+
 
 /* Lookup the StarPU function NAME in the global scope and store the result
    in VAR (this can't be done from `lower_starpu'.)  */
@@ -119,7 +122,9 @@ build_call_expr_loc_vec (location_t loc, tree fndecl, VEC(tree,gc) *vec)
 
 
 /* Build a reference to the INDEXth element of ARRAY.  `build_array_ref' is
-   not exported, so we roll our own.  */
+   not exported, so we roll our own.
+   FIXME: This version may not work for array types and doesn't do as much
+   type-checking as `build_array_ref'.  */
 
 static tree
 array_ref (tree array, size_t index)
@@ -347,12 +352,25 @@ handle_pragma_shutdown (struct cpp_reader *reader)
 static void
 handle_pragma_wait (struct cpp_reader *reader)
 {
-  tree fndecl;
+  if (task_implementation_p (current_function_decl))
+    {
+      location_t loc;
 
-  fndecl = lookup_name (get_identifier ("starpu_task_wait_for_all"));
-  gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
+      loc = cpp_peek_token (reader, 0)->src_loc;
+
+      /* TODO: In the future we could generate a task for the continuation
+	 and have it depend on what's before here.  */
+      error_at (loc, "task implementation is not allowed to wait");
+    }
+  else
+    {
+      tree fndecl;
 
-  add_stmt (build_call_expr (fndecl, 0));
+      fndecl = lookup_name (get_identifier ("starpu_task_wait_for_all"));
+      gcc_assert (TREE_CODE (fndecl) == FUNCTION_DECL);
+
+      add_stmt (build_call_expr (fndecl, 0));
+    }
 }
 
 /* The minimal C expression parser.  */

+ 1 - 0
gcc-plugin/tests/Makefile.am

@@ -28,6 +28,7 @@ gcc_tests =					\
   pointer-tasks.c				\
   no-initialize.c				\
   lib-user.c					\
+  wait-errors.c					\
   shutdown-errors.c
 
 dist_noinst_HEADERS = mocks.h

+ 27 - 0
gcc-plugin/tests/wait-errors.c

@@ -0,0 +1,27 @@
+/* GCC-StarPU
+   Copyright (C) 2011 Institut National de Recherche en Informatique et Automatique
+
+   GCC-StarPU is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   GCC-StarPU is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC-StarPU.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* The task under test.  */
+
+void task (int x, char y, int z) __attribute__ ((task));
+static void task_cpu (int x, char y, int z)
+  __attribute__ ((task_implementation ("cpu", task)));
+
+static void
+task_cpu (int x, char y, int z)
+{
+#pragma starpu wait /* (error "not allowed") */
+}