Parcourir la source

gcc: Fix parameter declarations in task implementation wrappers.

* gcc-plugin/src/starpu.c
  (build_codelet_wrapper_definition)[build_parameters]: Add
  `wrapper_decl' parameter.  Set the `DECL_ARG_TYPE' of each parameter.
  Mark them as used.  Return a chained PARM_DECL, not a TREE_LIST.
  Set the `DECL_CONTEXT' of RESULT.

* gcc-plugin/tests/scalar-tasks.c: New file.

* gcc-plugin/tests/Makefile.am (check_PROGRAMS): Add `scalar-tasks'.
  (scalar_tasks_LDADD): New variable.
Ludovic Courtès il y a 14 ans
Parent
commit
2486487853
3 fichiers modifiés avec 98 ajouts et 15 suppressions
  1. 20 14
      gcc-plugin/src/starpu.c
  2. 3 1
      gcc-plugin/tests/Makefile.am
  3. 75 0
      gcc-plugin/tests/scalar-tasks.c

+ 20 - 14
gcc-plugin/src/starpu.c

@@ -554,20 +554,25 @@ build_codelet_wrapper_definition (tree task_impl)
   /* Return the parameter list of the wrapper:
      `(void **BUFFERS, void *CL_ARGS)'.  */
 
-  tree build_parameters (void)
+  tree build_parameters (tree wrapper_decl)
   {
-    tree void_ptr, void_ptr_ptr;
-
-    void_ptr = build_pointer_type (void_type_node);
-    void_ptr_ptr = build_pointer_type (void_ptr);
-
-    return chain_trees (build_decl (loc, PARM_DECL,
-				    create_tmp_var_name ("buffers"),
-				    void_ptr_ptr),
-			build_decl (loc, PARM_DECL,
-				    create_tmp_var_name ("cl_args"),
-				    void_ptr),
-			NULL_TREE);
+    tree param1, param2;
+
+    param1 = build_decl (loc, PARM_DECL,
+			 create_tmp_var_name ("buffers"),
+			 build_pointer_type (ptr_type_node));
+    DECL_ARG_TYPE (param1) = ptr_type_node;
+    DECL_CONTEXT (param1) = wrapper_decl;
+    TREE_USED (param1) = true;
+
+    param2 = build_decl (loc, PARM_DECL,
+			 create_tmp_var_name ("cl_args"),
+			 ptr_type_node);
+    DECL_ARG_TYPE (param2) = ptr_type_node;
+    DECL_CONTEXT (param2) = wrapper_decl;
+    TREE_USED (param2) = true;
+
+    return chainon (param1, param2);
   }
 
   tree decl, wrapper_name, vars, result;
@@ -579,9 +584,10 @@ build_codelet_wrapper_definition (tree task_impl)
   vars = build_scalar_var_chain (decl);
 
   DECL_CONTEXT (decl) = NULL_TREE;
-  DECL_ARGUMENTS (decl) = build_parameters ();
+  DECL_ARGUMENTS (decl) = build_parameters (decl);
 
   result = build_decl (loc, RESULT_DECL, NULL_TREE, void_type_node);
+  DECL_CONTEXT (result) = decl;
   DECL_ARTIFICIAL (result) = true;
   DECL_IGNORED_P (result) = true;
   DECL_RESULT (decl) = result;

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

@@ -16,7 +16,9 @@
 
 TESTS = $(check_PROGRAMS)
 
-check_PROGRAMS = base
+check_PROGRAMS = base scalar-tasks
+
+scalar_tasks_LDADD = $(top_builddir)/src/libstarpu.la
 
 # Unfortunately `libtool --mode=execute' doesn't help here, so
 # hard-code the real file name.

+ 75 - 0
gcc-plugin/tests/scalar-tasks.c

@@ -0,0 +1,75 @@
+/* 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/>.  */
+
+#undef NDEBUG
+
+#include <stdlib.h>
+#include <assert.h>
+
+
+/* The task under test.  */
+
+static void my_scalar_task (int x, int y) __attribute__ ((task));
+
+static void my_scalar_task_cpu (int, int)
+  __attribute__ ((task_implementation ("cpu", my_scalar_task), noinline));
+static void my_scalar_task_opencl (int, int)
+  __attribute__ ((task_implementation ("opencl", my_scalar_task), noinline));
+
+static int implementations_called;
+
+static void
+my_scalar_task_cpu (int x, int y)
+{
+  implementations_called |= STARPU_CPU;
+  assert (x == 42);
+  assert (y == 77);
+}
+
+static void
+my_scalar_task_opencl (int x, int y)
+{
+  implementations_called |= STARPU_OPENCL;
+  assert (x == 42);
+  assert (y == 77);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  int x = 42, y = 77;
+
+  /* FIXME: Eventually remove calls to libstarpu and use pragmas or generated
+     code.  */
+
+  starpu_init (NULL);
+
+  /* Invoke the task, which should make sure it gets called with
+     EXPECTED.  */
+  my_scalar_task (x, y);
+
+  starpu_task_wait_for_all ();
+
+  assert ((implementations_called & STARPU_CPU)
+	  || (implementations_called & STARPU_OPENCL));
+
+  assert ((implementations_called & ~(STARPU_CPU | STARPU_OPENCL)) == 0);
+
+  starpu_shutdown ();
+
+  return EXIT_SUCCESS;
+}