From ee512e58a32f6a653ab47f2c8272e459b03c0bd8 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 22 Jun 2015 17:52:33 +0000 Subject: [PATCH] Prepare replacing ISL by its 'make dist' files Currently the Polly repository contains the ISL sources with bogus isl_config.h and gitversion.h. This is problematic. In this state a macro #define __attribute__(x) becomes active in the source, leading to various problems e.g. when included before system header files. This patch will instead generate the two files specific to the host system at configure-time. For CMake, we replicate the tests that ISL's configure performs using try_compile(). In autotools build, we just invoke ISL's configure to generate the two files. This consequently required regenerating autoconf/configure. 'make dist' distributions of ISL contain a file GIT_HEAD_ID which contains the version the distribution is derived from. The repository files themselves do not contain such a hint. In a later commit we will replace the isl directory by the contents of such a .tar.gz. It does not contain the files imdrover.c iprime.c pi.c and rsamath.c currently compiled into Polly, but not used and therefore are removed by this patch. In the long term we plan to generate a dedicated library for ISL instead of adding its files to Polly. This also does not yet include the switch to small-integer optimized ISL nor enabling C99 mode required for the former. Those will come as well in separate patches. Differential version: http://reviews.llvm.org/D10603 Reviewers: grosser llvm-svn: 240301 --- polly/CMakeLists.txt | 1 + polly/Makefile.config.in | 1 + polly/autoconf/configure.ac | 3 + polly/configure | 154 +++++++++++++++++++++++++++++++++- polly/lib/CMakeLists.txt | 66 ++++++++++++++- polly/lib/External/gitversion.h.cmake | 1 + polly/lib/External/isl_config.h.cmake | 25 ++++++ polly/lib/Makefile | 6 +- 8 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 polly/lib/External/gitversion.h.cmake create mode 100644 polly/lib/External/isl_config.h.cmake diff --git a/polly/CMakeLists.txt b/polly/CMakeLists.txt index 80fc6d3..cb7b91f 100644 --- a/polly/CMakeLists.txt +++ b/polly/CMakeLists.txt @@ -114,6 +114,7 @@ include_directories( BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/JSON/include + ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/imath ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl diff --git a/polly/Makefile.config.in b/polly/Makefile.config.in index 15e9d0a..993b9d3 100644 --- a/polly/Makefile.config.in +++ b/polly/Makefile.config.in @@ -46,6 +46,7 @@ CUDALIB_FOUND := @cuda_found@ # Set include directories POLLY_INC := @cuda_inc@ \ + -I$(POLLY_OBJ_ROOT)/lib/External/isl \ -I$(POLLY_SRC_ROOT)/lib/JSON/include \ -I$(POLLY_SRC_ROOT)/lib/External/isl/include \ -I$(POLLY_SRC_ROOT)/lib/External/isl/imath \ diff --git a/polly/autoconf/configure.ac b/polly/autoconf/configure.ac index 67e53b3..d5d705f 100644 --- a/polly/autoconf/configure.ac +++ b/polly/autoconf/configure.ac @@ -95,6 +95,9 @@ dnl ************************************************************************** dnl * Create the output files dnl ************************************************************************** +dnl Let ISL's configure generate isl_config.h and gitversion.h +AC_CONFIG_SUBDIRS(lib/External/isl) + dnl This must be last AC_CONFIG_HEADERS(include/polly/Config/config.h) AC_OUTPUT diff --git a/polly/configure b/polly/configure index afc169b..bbaac84 100755 --- a/polly/configure +++ b/polly/configure @@ -585,8 +585,10 @@ PACKAGE_BUGREPORT='polly-dev@googlegroups.com' PACKAGE_URL='' ac_unique_file=""lib/Analysis/ScopInfo.cpp"" +enable_option_checking=no ac_subst_vars='LTLIBOBJS LIBOBJS +subdirs cuda_ld cuda_lib cuda_inc @@ -655,7 +657,7 @@ LDFLAGS LIBS CPPFLAGS CCC' - +ac_subdirs_all='lib/External/isl' # Initialize some variables set by options. ac_init_help= @@ -2492,6 +2494,11 @@ $as_echo "#define CUDALIB_FOUND 1" >>confdefs.h fi + + +subdirs="$subdirs lib/External/isl" + + ac_config_headers="$ac_config_headers include/polly/Config/config.h" cat >confcache <<\_ACEOF @@ -3775,6 +3782,151 @@ if test "$no_create" != yes; then # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi + +# +# CONFIG_SUBDIRS section. +# +if test "$no_recursion" != yes; then + + # Remove --cache-file, --srcdir, and --disable-option-checking arguments + # so they do not pile up. + ac_sub_configure_args= + ac_prev= + eval "set x $ac_configure_args" + shift + for ac_arg + do + if test -n "$ac_prev"; then + ac_prev= + continue + fi + case $ac_arg in + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* \ + | --c=*) + ;; + --config-cache | -C) + ;; + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + ;; + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + ;; + --disable-option-checking) + ;; + *) + case $ac_arg in + *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append ac_sub_configure_args " '$ac_arg'" ;; + esac + done + + # Always prepend --prefix to ensure using the same prefix + # in subdir configurations. + ac_arg="--prefix=$prefix" + case $ac_arg in + *\'*) ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + ac_sub_configure_args="'$ac_arg' $ac_sub_configure_args" + + # Pass --silent + if test "$silent" = yes; then + ac_sub_configure_args="--silent $ac_sub_configure_args" + fi + + # Always prepend --disable-option-checking to silence warnings, since + # different subdirs can have different --enable and --with options. + ac_sub_configure_args="--disable-option-checking $ac_sub_configure_args" + + ac_popdir=`pwd` + for ac_dir in : $subdirs; do test "x$ac_dir" = x: && continue + + # Do not complain, so a configure script can configure whichever + # parts of a large source tree are present. + test -d "$srcdir/$ac_dir" || continue + + ac_msg="=== configuring in $ac_dir (`pwd`/$ac_dir)" + $as_echo "$as_me:${as_lineno-$LINENO}: $ac_msg" >&5 + $as_echo "$ac_msg" >&6 + as_dir="$ac_dir"; as_fn_mkdir_p + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + cd "$ac_dir" + + # Check for guested configure; otherwise get Cygnus style configure. + if test -f "$ac_srcdir/configure.gnu"; then + ac_sub_configure=$ac_srcdir/configure.gnu + elif test -f "$ac_srcdir/configure"; then + ac_sub_configure=$ac_srcdir/configure + elif test -f "$ac_srcdir/configure.in"; then + # This should be Cygnus configure. + ac_sub_configure=$ac_aux_dir/configure + else + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: no configuration information is in $ac_dir" >&5 +$as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2;} + ac_sub_configure= + fi + + # The recursion is here. + if test -n "$ac_sub_configure"; then + # Make the cache file name correct relative to the subdirectory. + case $cache_file in + [\\/]* | ?:[\\/]* ) ac_sub_cache_file=$cache_file ;; + *) # Relative name. + ac_sub_cache_file=$ac_top_build_prefix$cache_file ;; + esac + + { $as_echo "$as_me:${as_lineno-$LINENO}: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&5 +$as_echo "$as_me: running $SHELL $ac_sub_configure $ac_sub_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_srcdir" >&6;} + # The eval makes quoting arguments work. + eval "\$SHELL \"\$ac_sub_configure\" $ac_sub_configure_args \ + --cache-file=\"\$ac_sub_cache_file\" --srcdir=\"\$ac_srcdir\"" || + as_fn_error $? "$ac_sub_configure failed for $ac_dir" "$LINENO" 5 + fi + + cd "$ac_popdir" + done +fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt index 7eaf070..3c8ccba 100644 --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -16,6 +16,69 @@ if (GPU_CODEGEN) set (GPGPU_CODEGEN_FILES) endif (GPU_CODEGEN) + +# External: Integer Set Library +set(ISL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External/isl") +set(ISL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/External/isl") + +# Determine version of isl +if (EXISTS "${ISL_SOURCE_DIR}/GIT_HEAD_ID") + # The source comes from a 'make dist' archive + file(READ "${ISL_SOURCE_DIR}/GIT_HEAD_ID" GIT_HEAD_ID) + string(STRIP "${GIT_HEAD_ID}" GIT_HEAD_ID) +elseif (EXISTS "${ISL_SOURCE_DIR}/gitversion.h") + # The source directory is preconfigured + file(READ "${ISL_SOURCE_DIR}/gitversion.h" GITVERSION_H) + string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" GIT_HEAD_ID "${GITVERSION_H}") +elseif () + # Unknown revision + set(GIT_HEAD_ID "UNKNOWN") +endif () + +message(STATUS "ISL version: ${GIT_HEAD_ID}") + +# Enable small integer optimization and imath +set(USE_GMP_FOR_MP OFF) +set(USE_IMATH_FOR_MP ON) +set(USE_SMALL_INT_OPT OFF) + +# Determine compiler characteristics +include(CheckCSourceCompiles) + +check_c_source_compiles(" + int func(void) __attribute__((__warn_unused_result__)); + int main() { return 0; } + " HAS_ATTRIBUTE_WARN_UNUSED_RESULT) +set(GCC_WARN_UNUSED_RESULT) +if (HAS_ATTRIBUTE_WARN_UNUSED_RESULT) + set(GCC_WARN_UNUSED_RESULT "__attribute__((__warn_unused_result__))") +endif () + +check_c_source_compiles(" + #include + int main() { ffs(0); return 0; } + " HAVE_DECL_FFS) +if (NOT HAVE_DECL_FFS) + set(HAVE_DECL_FFS 0) +endif () + +check_c_source_compiles(" + int main() { __builtin_ffs(0); return 0; } + " HAVE_DECL___BUILTIN_FFS) +if (NOT HAVE_DECL___BUILTIN_FFS) + set(HAVE_DECL___BUILTIN_FFS 0) +endif () + +check_c_source_compiles(" + static void foo(void) __attribute__ ((unused)); + int main() { return 0; } + " HAVE___ATTRIBUTE__) + +# Write configure result +configure_file("External/gitversion.h.cmake" "${ISL_BINARY_DIR}/gitversion.h") +configure_file("External/isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h") + +# ISL files to compile set (ISL_FILES External/isl/basis_reduction_tab.c External/isl/isl_aff.c @@ -92,9 +155,6 @@ set (ISL_FILES External/isl/imath/gmp_compat.c External/isl/imath/imath.c External/isl/imath/imrat.c - External/isl/imath/iprime.c - External/isl/imath/pi.c - External/isl/imath/rsamath.c ) diff --git a/polly/lib/External/gitversion.h.cmake b/polly/lib/External/gitversion.h.cmake new file mode 100644 index 0000000..8a6f36e --- /dev/null +++ b/polly/lib/External/gitversion.h.cmake @@ -0,0 +1 @@ +#define GIT_HEAD_ID "@GIT_HEAD_ID@" diff --git a/polly/lib/External/isl_config.h.cmake b/polly/lib/External/isl_config.h.cmake new file mode 100644 index 0000000..940eb81 --- /dev/null +++ b/polly/lib/External/isl_config.h.cmake @@ -0,0 +1,25 @@ + +/* most gcc compilers know a function __attribute__((__warn_unused_result__)) + */ +#define GCC_WARN_UNUSED_RESULT @GCC_WARN_UNUSED_RESULT@ + +/* Define to 1 if you have the declaration of `ffs', and to 0 if you don't. */ +#define HAVE_DECL_FFS @HAVE_DECL_FFS@ + +/* Define to 1 if you have the declaration of `__builtin_ffs', and to 0 if you + don't. */ +#define HAVE_DECL___BUILTIN_FFS @HAVE_DECL___BUILTIN_FFS@ + +/* define if your compiler has __attribute__ */ +#cmakedefine HAVE___ATTRIBUTE__ /**/ + +/* use gmp to implement isl_int */ +#cmakedefine USE_GMP_FOR_MP + +/* use imath to implement isl_int */ +#cmakedefine USE_IMATH_FOR_MP + +/* Use small integer optimization */ +#cmakedefine USE_SMALL_INT_OPT + +#include diff --git a/polly/lib/Makefile b/polly/lib/Makefile index 06e9f3d..0390338 100644 --- a/polly/lib/Makefile +++ b/polly/lib/Makefile @@ -104,11 +104,7 @@ ISL_FILES= External/isl/basis_reduction_tab.c \ External/isl/print.c \ External/isl/imath/gmp_compat.c \ External/isl/imath/imath.c \ - External/isl/imath/imdrover.c \ - External/isl/imath/imrat.c \ - External/isl/imath/iprime.c \ - External/isl/imath/pi.c \ - External/isl/imath/rsamath.c + External/isl/imath/imrat.c SOURCES= Polly.cpp \ Support/GICHelper.cpp \ -- 2.7.4