Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -1,7 +1,7 @@ # Check if this is a in tree build. if (NOT DEFINED LLVM_MAIN_SRC_DIR) project(Polly) - cmake_minimum_required(VERSION 2.8) + cmake_minimum_required(VERSION 3.4.3) # Where is LLVM installed? set(LLVM_INSTALL_ROOT "" CACHE PATH "Root of LLVM install.") @@ -158,12 +158,24 @@ INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} ) endif(CUDALIB_FOUND) +option(POLLY_USE_EXTERNAL_ISL "Use a system libisl version" OFF) +if (POLLY_USE_EXTERNAL_ISL) + find_package(ISL MODULE REQUIRED) + message(STATUS "Using external libisl ${ISL_VERSION} in: ${ISL_PREFIX}") + set(ISL_TARGET ISL) +else() + set(ISL_INCLUDE_DIRS + ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include + ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include + ) + set(ISL_TARGET PollyISL) +endif() + include_directories( BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include + ${ISL_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/JSON/include - ${CMAKE_CURRENT_BINARY_DIR}/lib/External/isl/include - ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/isl/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include ${CMAKE_CURRENT_SOURCE_DIR}/lib/External ${CMAKE_CURRENT_BINARY_DIR}/include @@ -195,6 +207,7 @@ add_subdirectory(unittests) endif () add_subdirectory(tools) +add_subdirectory(cmake) # TODO: docs. Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -66,7 +66,7 @@ target_link_libraries(Polly PollyPPCG) endif (GPU_CODEGEN) -target_link_libraries(Polly PollyISL) +target_link_libraries(Polly ${ISL_TARGET}) if (BUILD_SHARED_LIBS) target_link_libraries(Polly Index: lib/External/CMakeLists.txt =================================================================== --- lib/External/CMakeLists.txt +++ lib/External/CMakeLists.txt @@ -1,181 +1,182 @@ # External: Integer Set Library -set(ISL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/isl") -set(ISL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/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" ISL_GIT_HEAD_ID) - string(STRIP "${ISL_GIT_HEAD_ID}" ISL_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" ISL_GIT_HEAD_ID "${GITVERSION_H}") -elseif () - # Unknown revision - # TODO: We could look for a .git and get the revision from HEAD - set(ISL_GIT_HEAD_ID "UNKNOWN") -endif () - -message(STATUS "ISL version: ${ISL_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 ON) - -# Determine compiler characteristics -include(CheckCSourceCompiles) - -# Like check_c_source_compiles, but sets the result to either -# 0 (error while compiling) or 1 (compiled successfully) -# Required for compatibility with autotool's AC_CHECK_DECLS -function (check_c_source_compiles_numeric _prog _var) - check_c_source_compiles("${_prog}" "${_var}") - if ("${${_var}}") - set("${_var}" 1 PARENT_SCOPE) - else () - set("${_var}" 0 PARENT_SCOPE) +if (NOT POLLY_USE_EXTERNAL_ISL) + set(ISL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/isl") + set(ISL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/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" ISL_GIT_HEAD_ID) + string(STRIP "${ISL_GIT_HEAD_ID}" ISL_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" ISL_GIT_HEAD_ID "${GITVERSION_H}") + elseif () + # Unknown revision + # TODO: We could look for a .git and get the revision from HEAD + set(ISL_GIT_HEAD_ID "UNKNOWN") endif () -endfunction () - -# Check for the existance of a type -function (check_c_type_exists _type _files _variable) - set(_includes "") - foreach (file_name ${_files}) - set(_includes "${_includes}#include<${file_name}>\n") - endforeach() - check_c_source_compiles(" + + message(STATUS "ISL version: ${ISL_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 ON) + + # Determine compiler characteristics + include(CheckCSourceCompiles) + + # Like check_c_source_compiles, but sets the result to either + # 0 (error while compiling) or 1 (compiled successfully) + # Required for compatibility with autotool's AC_CHECK_DECLS + function (check_c_source_compiles_numeric _prog _var) + check_c_source_compiles("${_prog}" "${_var}") + if ("${${_var}}") + set("${_var}" 1 PARENT_SCOPE) + else () + set("${_var}" 0 PARENT_SCOPE) + endif () + endfunction () + + # Check for the existance of a type + function (check_c_type_exists _type _files _variable) + set(_includes "") + foreach (file_name ${_files}) + set(_includes "${_includes}#include<${file_name}>\n") + endforeach() + check_c_source_compiles(" ${_includes} ${_type} typeVar; int main() { - return 0; + return 0; } " ${_variable}) -endfunction () + endfunction () -check_c_source_compiles(" + 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 () + 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(" + check_c_source_compiles(" __attribute__ ((unused)) static void foo(void); int main() { return 0; } " HAVE___ATTRIBUTE__) -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { (void)ffs(0); return 0; } " HAVE_DECL_FFS) -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" int main() { (void)__builtin_ffs(0); return 0; } " HAVE_DECL___BUILTIN_FFS) -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { (void)_BitScanForward(NULL, 0); return 0; } " HAVE_DECL__BITSCANFORWARD) -if (NOT HAVE_DECL_FFS AND - NOT HAVE_DECL___BUILTIN_FFS AND - NOT HAVE_DECL__BITSCANFORWARD) - message(FATAL_ERROR "No ffs implementation found") -endif () + if (NOT HAVE_DECL_FFS AND + NOT HAVE_DECL___BUILTIN_FFS AND + NOT HAVE_DECL__BITSCANFORWARD) + message(FATAL_ERROR "No ffs implementation found") + endif () -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { (void)strcasecmp(\"\", \"\"); return 0; } " HAVE_DECL_STRCASECMP) -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { (void)_stricmp(\"\", \"\"); return 0; } " HAVE_DECL__STRICMP) -if (NOT HAVE_DECL_STRCASECMP AND NOT HAVE_DECL__STRICMP) - message(FATAL_ERROR "No strcasecmp implementation found") -endif () + if (NOT HAVE_DECL_STRCASECMP AND NOT HAVE_DECL__STRICMP) + message(FATAL_ERROR "No strcasecmp implementation found") + endif () -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { (void)strncasecmp(\"\", \"\", 0); return 0; } " HAVE_DECL_STRNCASECMP) -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { (void)_strnicmp(\"\", \"\", 0); return 0; } " HAVE_DECL__STRNICMP) -if (NOT HAVE_DECL_STRNCASECMP AND NOT HAVE_DECL__STRNICMP) - message(FATAL_ERROR "No strncasecmp implementation found") -endif () + if (NOT HAVE_DECL_STRNCASECMP AND NOT HAVE_DECL__STRNICMP) + message(FATAL_ERROR "No strncasecmp implementation found") + endif () -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { snprintf((void*)0, 0, \" \"); return 0; } " HAVE_DECL_SNPRINTF) -check_c_source_compiles_numeric(" + check_c_source_compiles_numeric(" #include int main() { _snprintf((void*)0, 0, \" \"); return 0; } " HAVE_DECL__SNPRINTF) -if (NOT HAVE_DECL_SNPRINTF AND NOT HAVE_DECL__SNPRINTF) - message(FATAL_ERROR "No snprintf implementation found") -endif () - - -check_c_type_exists(uint8_t "" HAVE_UINT8T) -check_c_type_exists(uint8_t "stdint.h" HAVE_STDINT_H) -check_c_type_exists(uint8_t "inttypes.h" HAVE_INTTYPES_H) -check_c_type_exists(uint8_t "sys/types.h" HAVE_SYS_INTTYPES_H) -if (HAVE_UINT8T) - set(INCLUDE_STDINT_H "") -elseif (HAVE_STDINT_H) - set(INCLUDE_STDINT_H "#include ") -elseif (HAVE_INTTYPES_H) - set(INCLUDE_STDINT_H "#include ") -elseif (HAVE_SYS_INTTYPES_H) - set(INCLUDE_STDINT_H "#include ") -else () - message(FATAL_ERROR "No stdint.h or compatible found") -endif () - -# Write configure result -# configure_file(... COPYONLY) avoids that the time stamp changes if the file is identical -file(WRITE "${ISL_BINARY_DIR}/gitversion.h.tmp" - "#define GIT_HEAD_ID \"${ISL_GIT_HEAD_ID}\"") -configure_file("${ISL_BINARY_DIR}/gitversion.h.tmp" - "${ISL_BINARY_DIR}/gitversion.h" COPYONLY) + if (NOT HAVE_DECL_SNPRINTF AND NOT HAVE_DECL__SNPRINTF) + message(FATAL_ERROR "No snprintf implementation found") + endif () -file(WRITE "${ISL_BINARY_DIR}/include/isl/stdint.h.tmp" - "${INCLUDE_STDINT_H}\n") -configure_file("${ISL_BINARY_DIR}/include/isl/stdint.h.tmp" - "${ISL_BINARY_DIR}/include/isl/stdint.h" COPYONLY) -configure_file("isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h") -configure_file("isl_srcdir.c.cmake" "${ISL_BINARY_DIR}/isl_srcdir.c") + check_c_type_exists(uint8_t "" HAVE_UINT8T) + check_c_type_exists(uint8_t "stdint.h" HAVE_STDINT_H) + check_c_type_exists(uint8_t "inttypes.h" HAVE_INTTYPES_H) + check_c_type_exists(uint8_t "sys/types.h" HAVE_SYS_INTTYPES_H) + if (HAVE_UINT8T) + set(INCLUDE_STDINT_H "") + elseif (HAVE_STDINT_H) + set(INCLUDE_STDINT_H "#include ") + elseif (HAVE_INTTYPES_H) + set(INCLUDE_STDINT_H "#include ") + elseif (HAVE_SYS_INTTYPES_H) + set(INCLUDE_STDINT_H "#include ") + else () + message(FATAL_ERROR "No stdint.h or compatible found") + endif () -include_directories(BEFORE - ${ISL_BINARY_DIR} - ${ISL_SOURCE_DIR}/imath - ${ISL_SOURCE_DIR}/include - ${ISL_SOURCE_DIR} -) + # Write configure result + # configure_file(... COPYONLY) avoids that the time stamp changes if the file is identical + file(WRITE "${ISL_BINARY_DIR}/gitversion.h.tmp" + "#define GIT_HEAD_ID \"${ISL_GIT_HEAD_ID}\"") + configure_file("${ISL_BINARY_DIR}/gitversion.h.tmp" + "${ISL_BINARY_DIR}/gitversion.h" COPYONLY) + + file(WRITE "${ISL_BINARY_DIR}/include/isl/stdint.h.tmp" + "${INCLUDE_STDINT_H}\n") + configure_file("${ISL_BINARY_DIR}/include/isl/stdint.h.tmp" + "${ISL_BINARY_DIR}/include/isl/stdint.h" COPYONLY) + + configure_file("isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h") + configure_file("isl_srcdir.c.cmake" "${ISL_BINARY_DIR}/isl_srcdir.c") + + include_directories(BEFORE + ${ISL_BINARY_DIR} + ${ISL_SOURCE_DIR}/imath + ${ISL_SOURCE_DIR}/include + ${ISL_SOURCE_DIR} + ) -# ISL files to compile -set (ISL_FILES + # ISL files to compile + set (ISL_FILES isl/basis_reduction_tab.c isl/isl_aff.c isl/isl_affine_hull.c @@ -258,36 +259,36 @@ isl/imath/imrat.c ) -add_polly_library(PollyISL - ${ISL_FILES} -) + add_polly_library(PollyISL + ${ISL_FILES} + ) -# TODO: optionally use system isl instead -if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) - install(DIRECTORY - ${ISL_SOURCE_DIR}/include/ - ${ISL_BINARY_DIR}/include/ - DESTINATION include/polly - FILES_MATCHING - PATTERN "*.h" - PATTERN "CMakeFiles" EXCLUDE - PATTERN ".svn" EXCLUDE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ + DESTINATION include/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE + PATTERN ".svn" EXCLUDE + ) + endif() + + add_executable(polly-isl-test + isl/isl_test.c ) -endif() + set_target_properties(polly-isl-test PROPERTIES FOLDER "Polly") -add_executable(polly-isl-test - isl/isl_test.c -) -set_target_properties(polly-isl-test PROPERTIES FOLDER "Polly") - -target_link_libraries(polly-isl-test - PollyISL -) + target_link_libraries(polly-isl-test + PollyISL + ) -# ISL requires at least C99 to compile. gcc < 5.0 use -std=gnu89 as default. -target_enable_c99(PollyISL) -target_enable_c99(polly-isl-test) + # ISL requires at least C99 to compile. gcc < 5.0 use -std=gnu89 as default. + target_enable_c99(PollyISL) + target_enable_c99(polly-isl-test) +endif (NOT POLLY_USE_EXTERNAL_ISL) set(PET_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pet") set(PPCG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ppcg") @@ -335,7 +336,7 @@ ${PPCG_FILES} ) -target_link_libraries(PollyPPCG PollyISL) +target_link_libraries(PollyPPCG ${ISL_TARGET}) # Disable warnings for upstream projects. if (MSVC) @@ -346,13 +347,16 @@ -wd4201 # nonstandard extension used: nameless struct/union -wd4334 # 'operator': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) ) - target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS}) - target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS}) + if (NOT POLLY_USE_EXTERNAL_ISL) + target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS}) + target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS}) + endif (NOT POLLY_USE_EXTERNAL_ISL) target_compile_options(PollyPPCG PRIVATE ${DISABLE_WARNING_FLAGS}) else () - set_target_properties(PollyISL polly-isl-test PollyPPCG PROPERTIES - COMPILE_FLAGS "-w" - ) + if (NOT POLLY_USE_EXTERNAL_ISL) + set_target_properties(PollyISL polly-isl-test PROPERTIES COMPILE_FLAGS "-w") + endif (NOT POLLY_USE_EXTERNAL_ISL) + set_target_properties(PollyPPCG PROPERTIES COMPILE_FLAGS "-w") endif () if(MSVC) Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -20,7 +20,9 @@ # We are building polly out of tree, adjust the settings. # FIXME: FileCheck is not available in llvm install directory at the moment. set(LLVM_LIT ${LLVM_INSTALL_ROOT}/bin/llvm-lit) - set(POLLY_TEST_DEPS LLVMPolly polly-isl-test) + if (NOT POLLY_USE_EXTERNAL_ISL) + set(POLLY_TEST_DEPS LLVMPolly polly-isl-test) + endif (NOT POLLY_USE_EXTERNAL_ISL) if (POLLY_GTEST_AVAIL) list(APPEND POLLY_TEST_DEPS PollyUnitTests) endif () @@ -101,21 +103,27 @@ ${CMAKE_CURRENT_SOURCE_DIR}/UnitIsl/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg) - add_custom_target(check-polly-isl - command ${LLVM_LIT} - --param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg - --param build_config=${CMAKE_CFG_INTDIR} - -sv ${POLLY_TEST_EXTRA_ARGS} - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS polly-isl-test - COMMENT "Running isl unit tests") + + if (NOT POLLY_USE_EXTERNAL_ISL) + add_custom_target(check-polly-isl + command ${LLVM_LIT} + --param polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg + --param build_config=${CMAKE_CFG_INTDIR} + -sv ${POLLY_TEST_EXTRA_ARGS} + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS polly-isl-test + COMMENT "Running isl unit tests") set_target_properties(check-polly-isl PROPERTIES FOLDER "Polly") + endif (NOT POLLY_USE_EXTERNAL_ISL) endif() else (NOT DEFINED LLVM_MAIN_SRC_DIR) set(LLVM_LIT ${LLVM_TOOLS_BINARY_DIR}/llvm-lit) - set(POLLY_TEST_DEPS llvm-config opt LLVMPolly FileCheck not polly-isl-test) + set(POLLY_TEST_DEPS llvm-config opt LLVMPolly FileCheck not) + if (NOT POLLY_USE_EXTERNAL_ISL) + list(APPEND POLLY_TEST_DEPS polly-isl-test) + endif() if (POLLY_GTEST_AVAIL) list(APPEND POLLY_TEST_DEPS PollyUnitTests) endif () @@ -158,12 +166,14 @@ ${CMAKE_CURRENT_SOURCE_DIR}/UnitIsl/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg) - add_lit_testsuite(check-polly-isl "Running isl unit tests only" - ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl - PARAMS polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg - DEPENDS polly-isl-test - ) - set_target_properties(check-polly-isl PROPERTIES FOLDER "Polly") + if (NOT POLLY_USE_EXTERNAL_ISL) + add_lit_testsuite(check-polly-isl "Running isl unit tests only" + ${CMAKE_CURRENT_BINARY_DIR}/UnitIsl + PARAMS polly_site_config=${CMAKE_CURRENT_BINARY_DIR}/UnitIsl/lit.site.cfg + DEPENDS polly-isl-test + ) + set_target_properties(check-polly-isl PROPERTIES FOLDER "Polly") + endif (NOT POLLY_USE_EXTERNAL_ISL) # Run polly-check-format as part of polly-check only if we are compiling with # clang, so clang-format is available.