Browse Source

gcc: Add `-fplugin-arg-starpu-verbose'.

* gcc-plugin/src/starpu.c (verbose_output_p): New variable.
  (build_codelet_initializer): Use it along with `inform' instead of
  plain `printf' calls.
  (lower_starpu): Likewise.
  (plugin_init): Set VERBOSE_OUTPUT_P when the `verbose' argument is
  passed.

* doc/chapters/c-extensions.texi: Document `-fplugin-arg-starpu-verbose'.

* gcc-plugin/tests/Makefile.am (gcc_tests): Add `verbose.c'.
* gcc-plugin/tests/verbose.c: New file.

* gcc-plugin/examples/Makefile.am (AM_CFLAGS): Add
  `-fplugin-arg-starpu-verbose'.
Ludovic Courtès 13 years ago
parent
commit
7e36b7364e

+ 4 - 0
doc/chapters/c-extensions.texi

@@ -30,6 +30,10 @@ $ gcc -c -fplugin=`pkg-config starpu-1.0 --variable=gccplugin` foo.c
 When the plug-in is not available, the above @command{pkg-config}
 command returns the empty string.
 
+In addition, the @code{-fplugin-arg-starpu-verbose} flag can be used to
+obtain feedback from the compiler as it analyzes the C extensions used
+in source files.
+
 This section describes the C extensions implemented by StarPU's GCC
 plug-in.  It does not require detailed knowledge of the StarPU library.
 

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

@@ -35,6 +35,7 @@ AM_CPPFLAGS =						\
 AM_CFLAGS =							\
   -fplugin="$(builddir)/../src/.libs/starpu.so"			\
   -fplugin-arg-starpu-include-dir="$(top_srcdir)/include"	\
+  -fplugin-arg-starpu-verbose					\
   -Wall
 
 noinst_HEADERS =				\

+ 16 - 6
gcc-plugin/src/starpu.c

@@ -64,6 +64,9 @@ int plugin_is_GPL_compatible;
 /* The name of this plug-in.  */
 static const char plugin_name[] = "starpu";
 
+/* Whether to enable verbose output.  */
+static bool verbose_output_p = false;
+
 /* Names of public attributes.  */
 static const char task_attribute_name[] = "task";
 static const char task_implementation_attribute_name[] = "task_implementation";
@@ -1726,7 +1729,10 @@ build_codelet_initializer (tree task_decl)
 	impl_decl = TREE_VALUE (impl);
 	gcc_assert (TREE_CODE (impl_decl) == FUNCTION_DECL);
 
-	printf ("   `%s'\n", IDENTIFIER_POINTER (DECL_NAME (impl_decl)));
+	if (verbose_output_p)
+	  /* List the implementations of TASK_DECL.  */
+	  inform (DECL_SOURCE_LOCATION (impl_decl),
+		  "   %qE", DECL_NAME (impl_decl));
 
 	where_int |= task_implementation_where (impl_decl);
       }
@@ -1806,8 +1812,9 @@ build_codelet_initializer (tree task_decl)
 					nreverse (modes));
   }
 
-  printf ("implementations for `%s':\n",
-	  IDENTIFIER_POINTER (DECL_NAME (task_decl)));
+  if (verbose_output_p)
+    inform (DECL_SOURCE_LOCATION (task_decl),
+	    "implementations for task %qE:", DECL_NAME (task_decl));
 
   tree impls, inits;
 
@@ -2168,9 +2175,10 @@ lower_starpu (void)
       if (lookup_attribute (task_attribute_name,
 			    DECL_ATTRIBUTES (callee_decl)))
 	{
-	  printf ("%s: `%s' calls task `%s'\n", __func__,
-		  IDENTIFIER_POINTER (DECL_NAME (fndecl)),
-		  IDENTIFIER_POINTER (DECL_NAME (callee_decl)));
+	  if (verbose_output_p)
+	    inform (gimple_location (callee->call_stmt),
+		    "%qE calls task %qE",
+		    DECL_NAME (fndecl), DECL_NAME (callee_decl));
 
 	  /* TODO: Insert analysis to check whether the pointer arguments
 	     need to be registered.  */
@@ -2257,6 +2265,8 @@ plugin_init (struct plugin_name_args *plugin_info,
 	    /* XXX: We assume that `value' has an infinite lifetime.  */
 	    include_dir = plugin_info->argv[arg].value;
 	}
+      else if (strcmp (plugin_info->argv[arg].key, "verbose") == 0)
+	verbose_output_p = true;
       else
 	error_at (UNKNOWN_LOCATION, "invalid StarPU plug-in argument %qs",
 		  plugin_info->argv[arg].key);

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

@@ -34,6 +34,7 @@ gcc_tests =					\
   wait-errors.c					\
   heap-allocated.c				\
   heap-allocated-errors.c			\
+  verbose.c					\
   debug-tree.c					\
   shutdown-errors.c
 

+ 46 - 0
gcc-plugin/tests/verbose.c

@@ -0,0 +1,46 @@
+/* GCC-StarPU
+   Copyright (C) 2012 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 (cflags "-fplugin-arg-starpu-verbose")) */
+
+#ifndef STARPU_GCC_PLUGIN
+# error barf!
+#endif
+
+static void my_task (int x)	      /* (note "implementations for task") */
+  __attribute__ ((task));
+
+static void my_task_cpu (int x)
+  __attribute__ ((task_implementation ("cpu", my_task)));
+extern void my_task_cpu_sse (int x)	       /* (note "my_task_cpu_sse") */
+  __attribute__ ((task_implementation ("cpu", my_task)));
+extern void my_task_opencl (int x)		/* (note "my_task_opencl") */
+  __attribute__ ((task_implementation ("opencl", my_task)));
+extern void my_task_cuda (int x)		  /* (note "my_task_cuda") */
+  __attribute__ ((task_implementation ("cuda", my_task)));
+
+static void
+my_task_cpu (int x)				  /* (note "my_task_cpu") */
+{
+  /* Nothing.  */
+}
+
+int
+bar (int x)
+{
+  my_task (x);					  /* (note "calls task") */
+  return 42;
+}