瀏覽代碼

gcc: Add rudimentary `#pragma starpu initialize'.

* gcc-plugin/src/starpu.c (handle_pragma_initialize): New function.
  (register_pragmas): Register the `initialize' pragma.
  (lower_starpu): Emit a warning when FNDECL is the main function and
  does not call `starpu_init'.

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

* gcc-plugin/tests/no-initialize.c: New file.

* gcc-plugin/tests/lib.h (initialized): New variable.
  (starpu_init): New function.

* gcc-plugin/tests/base.c (main): Add `initialize' pragma; check
  INITIALIZED.

* gcc-plugin/tests/pointer-tasks.c, gcc-plugin/tests/pointers.c,
  gcc-plugin/tests/register-errors.c, gcc-plugin/tests/register.c,
  gcc-plugin/tests/scalar-tasks.c: Add `initialize' pragma.
Ludovic Courtès 14 年之前
父節點
當前提交
0acb162218

+ 46 - 11
gcc-plugin/src/starpu.c

@@ -69,6 +69,16 @@ static const char task_struct_name[] = "starpu_task";
 static tree build_codelet_declaration (tree task_decl);
 static tree build_task_body (const_tree task_decl);
 
+/* Lookup the StarPU function NAME in the global scope and store the result
+   in VAR (this can't be done from `lower_starpu'.)  */
+
+#define LOOKUP_STARPU_FUNCTION(var, name)				\
+  if ((var) == NULL_TREE)						\
+    {									\
+      (var) = lookup_name (get_identifier (name));			\
+      gcc_assert ((var) != NULL_TREE && TREE_CODE (var) == FUNCTION_DECL); \
+    }
+
 
 
 /* Useful code backported from GCC 4.6.  */
@@ -295,6 +305,21 @@ handle_pragma_hello (struct cpp_reader *reader)
   add_stmt (build_hello_world ());
 }
 
+/* Process `#pragma starpu initialize'.
+   TODO: Parse and initialize some of the fields of `starpu_conf'.  */
+
+static void
+handle_pragma_initialize (struct cpp_reader *reader)
+{
+  static tree init_fn;
+  LOOKUP_STARPU_FUNCTION (init_fn, "starpu_init");
+
+  /* Call `starpu_init (NULL)'.  */
+  tree init = build_call_expr (init_fn, 1, build_zero_cst (ptr_type_node));
+
+  add_stmt (init);
+}
+
 static void
 handle_pragma_wait (struct cpp_reader *reader)
 {
@@ -470,6 +495,8 @@ register_pragmas (void *gcc_data, void *user_data)
 {
   c_register_pragma (STARPU_PRAGMA_NAME_SPACE, "hello",
 		     handle_pragma_hello);
+  c_register_pragma_with_expansion (STARPU_PRAGMA_NAME_SPACE, "initialize",
+				    handle_pragma_initialize);
   c_register_pragma (STARPU_PRAGMA_NAME_SPACE, "wait",
 		     handle_pragma_wait);
   c_register_pragma_with_expansion (STARPU_PRAGMA_NAME_SPACE, "register",
@@ -480,17 +507,6 @@ register_pragmas (void *gcc_data, void *user_data)
 /* Attributes.  */
 
 
-/* Lookup the StarPU function NAME in the global scope and store the result
-   in VAR (this can't be done from `lower_starpu'.)  */
-
-#define LOOKUP_STARPU_FUNCTION(var, name)				\
-  if ((var) == NULL_TREE)						\
-    {									\
-      (var) = lookup_name (get_identifier (name));			\
-      gcc_assert ((var) != NULL_TREE && TREE_CODE (var) == FUNCTION_DECL); \
-    }
-
-
 /* Handle the `task' function attribute.  */
 
 static tree
@@ -1360,6 +1376,25 @@ lower_starpu (void)
   cgraph = cgraph_get_node (fndecl);
   gcc_assert (cgraph != NULL);
 
+  if (MAIN_NAME_P (DECL_NAME (fndecl)))
+    {
+      /* Check whether FNDECL initializes StarPU and emit a warning if it
+	 doesn't.  */
+      bool initialized;
+
+      for (initialized = false, callee = cgraph->callees;
+	   !initialized && callee != NULL;
+	   callee = callee->next_callee)
+	{
+	  initialized =
+	    DECL_NAME (callee->callee->decl) == get_identifier ("starpu_init");
+	}
+
+      if (!initialized)
+	warning_at (DECL_SOURCE_LOCATION (fndecl), 0,
+		    "%qE does not initialize StarPU", DECL_NAME (fndecl));
+    }
+
   for (callee = cgraph->callees;
        callee != NULL;
        callee = callee->next_callee)

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

@@ -21,7 +21,8 @@ gcc_tests =					\
   register-errors.c				\
   task-errors.c					\
   scalar-tasks.c				\
-  pointer-tasks.c
+  pointer-tasks.c				\
+  no-initialize.c
 
 dist_noinst_HEADERS = lib.h
 

+ 3 - 0
gcc-plugin/tests/base.c

@@ -44,6 +44,9 @@ my_scalar_task_opencl (int x, char y, int z)
 int
 main (int argc, char *argv[])
 {
+#pragma starpu initialize
+  assert (initialized == 1);
+
 #pragma starpu hello
 
   int x = 42, z = 99;

+ 12 - 0
gcc-plugin/tests/lib.h

@@ -218,3 +218,15 @@ starpu_vector_data_register (starpu_data_handle *handle,
   data_register_calls++;
   *handle = dummy_pointer_to_handle ((void *) ptr);
 }
+
+
+/* Initialization.  */
+
+static int initialized;
+
+int
+starpu_init (struct starpu_conf *config)
+{
+  initialized++;
+  return 0;
+}

+ 23 - 0
gcc-plugin/tests/no-initialize.c

@@ -0,0 +1,23 @@
+/* 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/>.  */
+
+/* (instructions compile) */
+
+int
+main (int argc, char *argv[]) /* (warning "does not initialize") */
+{
+  return 0;
+}

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

@@ -56,10 +56,7 @@ main (int argc, char *argv[])
   pointer_arg2 = malloc (COUNT * sizeof *pointer_arg2);
   memset (pointer_arg2, 0x77, COUNT * sizeof *pointer_arg2);
 
-  /* FIXME: Eventually remove calls to libstarpu and use pragmas or generated
-     code.  */
-
-  starpu_init (NULL);
+#pragma starpu initialize
 
   /* Register POINTER_ARG1 and POINTER_ARG2.  */
 #pragma starpu register pointer_arg1

+ 2 - 0
gcc-plugin/tests/pointers.c

@@ -66,6 +66,8 @@ my_mixed_task_opencl (int *x, char z, const long long *y)
 int
 main (int argc, char *argv[])
 {
+#pragma starpu initialize
+
   static const char z = 0x77;
   int x[] = { 42 };
   long long *y;

+ 2 - 0
gcc-plugin/tests/register-errors.c

@@ -23,6 +23,8 @@
 int
 main (int argc, char *argv[])
 {
+#pragma starpu initialize
+
 #pragma starpu register /* (error "unterminated") */
 
 #pragma starpu register argv 234 junk right here /* (error "junk after") */

+ 2 - 0
gcc-plugin/tests/register.c

@@ -34,6 +34,8 @@ foo (void)
 int
 main (int argc, char *argv[])
 {
+#pragma starpu initialize
+
   int x[123];
   double *y;
   static char z[345];

+ 1 - 4
gcc-plugin/tests/scalar-tasks.c

@@ -53,10 +53,7 @@ my_scalar_task_opencl (int x, int y)
 int
 main (int argc, char *argv[])
 {
-  /* FIXME: Eventually remove calls to libstarpu and use pragmas or generated
-     code.  */
-
-  starpu_init (NULL);
+#pragma starpu initialize
 
   /* Invoke the task, which should make sure it gets called with
      EXPECTED.  */