[Cmake] Optionally use a system isl version.

This patch adds an option to build against a version of libisl already
installed on the system. The installation is autodetected using the
pkg-config file shipped with isl.

The detection of the library is in the FindISL.cmake module that creates
an imported target.

Contributed-by: Philip Pfaffe <philip.pfaffe@gmail.com>

Differential Revision: https://reviews.llvm.org/D30043

llvm-svn: 296361
This commit is contained in:
Michael Kruse 2017-02-27 17:54:25 +00:00
parent 47e7d7fe85
commit 6469380daa
5 changed files with 212 additions and 162 deletions

View File

@ -158,12 +158,24 @@ if (CUDALIB_FOUND)
INCLUDE_DIRECTORIES( ${CUDALIB_INCLUDE_DIR} )
endif(CUDALIB_FOUND)
option(POLLY_BUNDLED_ISL "Use the bundled version of libisl included in Polly" ON)
if (NOT POLLY_BUNDLED_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

24
polly/cmake/FindISL.cmake Normal file
View File

@ -0,0 +1,24 @@
find_package(PkgConfig REQUIRED)
pkg_search_module(ISL isl)
if (NOT ISL_FOUND EQUAL 1)
message(FATAL_ERROR "No libisl found on this system. Consider setting PKG_CONFIG_PATH.")
endif()
add_library(ISL INTERFACE IMPORTED)
foreach (incl IN LISTS ISL_INCLUDE_DIRS)
set_property(TARGET ISL APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${incl})
endforeach()
foreach (libname IN LISTS ISL_LIBRARIES)
if (ISL_LIBRARY_DIRS)
foreach (dir IN LISTS ISL_LIBRARY_DIRS)
list(APPEND hints ${dir})
endforeach()
endif()
find_library(lib NAMES ${libname} HINTS ${hints} NO_DEFAULT_PATH)
set_property(TARGET ISL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${lib})
endforeach()
foreach (opt IN LISTS ISL_CFLAGS ISL_CFLAGS_OTHER)
set_property(TARGET ISL APPEND PROPERTY INTERFACE_COMPILE_OPTIONS ${opt})
endforeach()

View File

@ -66,7 +66,7 @@ if (GPU_CODEGEN)
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

View File

@ -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")
if (POLLY_BUNDLED_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 ()
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)
# 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 <strings.h>
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 <intrin.h>
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 <strings.h>
int main() { (void)strcasecmp(\"\", \"\"); return 0; }
" HAVE_DECL_STRCASECMP)
check_c_source_compiles_numeric("
check_c_source_compiles_numeric("
#include <string.h>
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 <strings.h>
int main() { (void)strncasecmp(\"\", \"\", 0); return 0; }
" HAVE_DECL_STRNCASECMP)
check_c_source_compiles_numeric("
check_c_source_compiles_numeric("
#include <string.h>
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 <stdio.h>
int main() { snprintf((void*)0, 0, \" \"); return 0; }
" HAVE_DECL_SNPRINTF)
check_c_source_compiles_numeric("
check_c_source_compiles_numeric("
#include <stdio.h>
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 ()
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 <stdint.h>")
elseif (HAVE_INTTYPES_H)
set(INCLUDE_STDINT_H "#include <inttypes.h>")
elseif (HAVE_SYS_INTTYPES_H)
set(INCLUDE_STDINT_H "#include <sys/inttypes.h>")
else ()
message(FATAL_ERROR "No stdint.h or compatible 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 <stdint.h>")
elseif (HAVE_INTTYPES_H)
set(INCLUDE_STDINT_H "#include <inttypes.h>")
elseif (HAVE_SYS_INTTYPES_H)
set(INCLUDE_STDINT_H "#include <sys/inttypes.h>")
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)
# 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)
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")
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}
)
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 @@ set (ISL_FILES
isl/imath/imrat.c
)
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
add_polly_library(PollyISL
${ISL_FILES}
)
endif()
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
)
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()
# 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)
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
)
# 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 (POLLY_BUNDLED_ISL)
set(PET_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/pet")
set(PPCG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ppcg")
@ -335,7 +336,7 @@ add_polly_library(PollyPPCG
${PPCG_FILES}
)
target_link_libraries(PollyPPCG PollyISL)
target_link_libraries(PollyPPCG ${ISL_TARGET})
# Disable warnings for upstream projects.
if (MSVC)
@ -346,13 +347,16 @@ if (MSVC)
-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 (POLLY_BUNDLED_ISL)
target_compile_options(PollyISL PRIVATE ${DISABLE_WARNING_FLAGS})
target_compile_options(polly-isl-test PRIVATE ${DISABLE_WARNING_FLAGS})
endif (POLLY_BUNDLED_ISL)
target_compile_options(PollyPPCG PRIVATE ${DISABLE_WARNING_FLAGS})
else ()
set_target_properties(PollyISL polly-isl-test PollyPPCG PROPERTIES
COMPILE_FLAGS "-w"
)
if (POLLY_BUNDLED_ISL)
set_target_properties(PollyISL polly-isl-test PROPERTIES COMPILE_FLAGS "-w")
endif (POLLY_BUNDLED_ISL)
set_target_properties(PollyPPCG PROPERTIES COMPILE_FLAGS "-w")
endif ()
if(MSVC)

View File

@ -20,7 +20,9 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
# 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 (POLLY_BUNDLED_ISL)
set(POLLY_TEST_DEPS LLVMPolly polly-isl-test)
endif (POLLY_BUNDLED_ISL)
if (POLLY_GTEST_AVAIL)
list(APPEND POLLY_TEST_DEPS PollyUnitTests)
endif ()
@ -101,21 +103,27 @@ if (NOT DEFINED LLVM_MAIN_SRC_DIR)
${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")
set_target_properties(check-polly-isl PROPERTIES FOLDER "Polly")
if (POLLY_BUNDLED_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 (POLLY_BUNDLED_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 (POLLY_BUNDLED_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 @@ else (NOT DEFINED LLVM_MAIN_SRC_DIR)
${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 (POLLY_BUNDLED_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 (POLLY_BUNDLED_ISL)
# Run polly-check-format as part of polly-check only if we are compiling with
# clang, so clang-format is available.