Browse Source

gcc: Check for specific GCC functions.

* m4/gcc.m4 (_STARPU_WITH_GCC_PLUGIN_API): New macro.
  (STARPU_GCC_PLUGIN_SUPPORT): Use it.  Check for the declarations of
  `build_call_expr_loc_vec' and `build_call_expr_loc_array'.

* gcc-plugin/src/starpu-gcc-config.h.in: New file.

* configure.ac: Output <starpu-gcc-config.h>.

* gcc-plugin/src/starpu.c: Include <starpu-gcc-config.h>.
  (build_call_expr_loc_array)[!HAVE_DECL_BUILD_CALL_EXPR_LOC_ARRAY]: New
  function.
  (build_call_expr_loc_vec)[!HAVE_DECL_BUILD_CALL_EXPR_LOC_VEC]: New
  function.
Ludovic Courtès 14 years ago
parent
commit
d8e018850b
5 changed files with 90 additions and 15 deletions
  1. 1 0
      .gitignore
  2. 2 0
      configure.ac
  3. 23 0
      gcc-plugin/src/starpu-gcc-config.h.in
  4. 29 0
      gcc-plugin/src/starpu.c
  5. 35 15
      m4/gcc.m4

+ 1 - 0
.gitignore

@@ -21,3 +21,4 @@ Makefile.in
 *.lo
 *.la
 .dirstamp
+/gcc-plugin/src/starpu-gcc-config.h

+ 2 - 0
configure.ac

@@ -1169,6 +1169,8 @@ AC_CONFIG_COMMANDS([executable-scripts], [chmod +x ]tests/regression/regression.
 AC_CONFIG_FILES(tests/regression/regression.sh tests/regression/profiles tests/regression/profiles.build.only)
 AC_CONFIG_HEADER(src/common/config.h include/starpu_config.h)
 
+AC_CONFIG_HEADERS([gcc-plugin/src/starpu-gcc-config.h])
+
 AC_OUTPUT([
 	Makefile
 	src/Makefile

+ 23 - 0
gcc-plugin/src/starpu-gcc-config.h.in

@@ -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/>.  */
+
+/* Hand-written config.h template for GCC-StarPU.  Autoheader's generated
+   template cannot be used because it defines PACKAGE_NAME & co., which GCC's
+   <auto-host.h> header shamelessly defines.  */
+
+#undef HAVE_DECL_BUILD_CALL_EXPR_LOC_ARRAY
+
+#undef HAVE_DECL_BUILD_CALL_EXPR_LOC_VEC

+ 29 - 0
gcc-plugin/src/starpu.c

@@ -17,6 +17,8 @@
 /* Use extensions of the GNU C Library.  */
 #define _GNU_SOURCE 1
 
+#include <starpu-gcc-config.h>
+
 int plugin_is_GPL_compatible;
 
 /* #define ENABLE_TREE_CHECKING 1 */
@@ -68,6 +70,33 @@ static tree build_codelet_declaration (tree task_decl);
 
 
 
+/* Useful code backported from GCC 4.6.  */
+
+#if !HAVE_DECL_BUILD_CALL_EXPR_LOC_ARRAY
+
+static tree
+build_call_expr_loc_array (location_t loc, tree fndecl, int n, tree *argarray)
+{
+  tree fntype = TREE_TYPE (fndecl);
+  tree fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
+
+  return fold_builtin_call_array (loc, TREE_TYPE (fntype), fn, n, argarray);
+}
+
+#endif
+
+#if !HAVE_DECL_BUILD_CALL_EXPR_LOC_VEC
+
+static tree
+build_call_expr_loc_vec (location_t loc, tree fndecl, VEC(tree,gc) *vec)
+{
+  return build_call_expr_loc_array (loc, fndecl, VEC_length (tree, vec),
+				    VEC_address (tree, vec));
+}
+
+#endif
+
+
 /* Debugging helpers.  */
 
 static tree build_printf (const char *, ...)

+ 35 - 15
m4/gcc.m4

@@ -13,29 +13,49 @@ dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 dnl
 dnl See the GNU Lesser General Public License in COPYING.LGPL for more details.
 
+dnl Run its argument with CPPFLAGS pointing to GCC's plug-in API.
+AC_DEFUN([_STARPU_WITH_GCC_PLUGIN_API], [
+  GCC_PLUGIN_INCLUDE_DIR="`"$CC" -print-file-name=plugin`/include"
+
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="-I$GCC_PLUGIN_INCLUDE_DIR"
+
+  $1
+
+  CPPFLAGS="$save_CPPFLAGS"
+])
+
 dnl Check whether GCC plug-in support is available (GCC 4.5+).
 AC_DEFUN([STARPU_GCC_PLUGIN_SUPPORT], [
   AC_REQUIRE([AC_PROG_CC])
   AC_CACHE_CHECK([whether GCC supports plug-ins], [ac_cv_have_gcc_plugins], [
     if test "x$GCC" = xyes; then
-      GCC_PLUGIN_INCLUDE_DIR="`"$CC" -print-file-name=plugin`/include"
-
-      save_CPPFLAGS="$CPPFLAGS"
-      CPPFLAGS="-I$GCC_PLUGIN_INCLUDE_DIR"
-
-      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gcc-plugin.h>
-	    #include <tree.h>
-	    #include <gimple.h>
-	    tree fndecl; gimple call;]],
-	  [[fndecl = lookup_name (get_identifier ("puts"));
-	    call = gimple_build_call (fndecl, 0);]])],
-	[ac_cv_have_gcc_plugins="yes"],
-	[ac_cv_have_gcc_plugins="no"])
-
-      CPPFLAGS="$save_CPPFLAGS"
+      _STARPU_WITH_GCC_PLUGIN_API([
+	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gcc-plugin.h>
+	      #include <tree.h>
+	      #include <gimple.h>
+	      tree fndecl; gimple call;]],
+	    [[fndecl = lookup_name (get_identifier ("puts"));
+	      call = gimple_build_call (fndecl, 0);]])],
+	  [ac_cv_have_gcc_plugins="yes"],
+	  [ac_cv_have_gcc_plugins="no"])
+      ])
     else
       ac_cv_have_gcc_plugins="no"
     fi
   ])
+
+  if test "x$ac_cv_have_gcc_plugins" = "xyes"; then
+    dnl Check for specific features.
+    dnl
+    dnl Reason:
+    dnl   build_call_expr_loc_array -- not in GCC 4.5.x; appears in 4.6
+    dnl   build_call_expr_loc_vec   -- likewise
+    _STARPU_WITH_GCC_PLUGIN_API([
+      AC_CHECK_DECLS([build_call_expr_loc_array, build_call_expr_loc_vec],
+        [], [], [#include <tree.h>])
+    ])
+  fi
+
   AC_SUBST([GCC_PLUGIN_INCLUDE_DIR])
 ])