2011-04-29 14:27:02 +08:00
|
|
|
# Check if this is a in tree build.
|
|
|
|
if (NOT DEFINED LLVM_MAIN_SRC_DIR)
|
|
|
|
project(Polly)
|
2020-04-22 23:15:05 +08:00
|
|
|
cmake_minimum_required(VERSION 3.13.4)
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
# Where is LLVM installed?
|
[Polly][CMake] Use the CMake Package instead of llvm-config in out-of-tree builds
Summary:
As of now, Polly uses llvm-config to set up LLVM dependencies in an out-of-tree build.
This is problematic for two reasons:
1) Right now, in-tree and out-of-tree builds in fact do different things. E.g., in an in-tree build, libPolly depends on a handful of LLVM libraries, while in an out-of-tree build it depends on all of them. This means that we often need to treat both paths seperately.
2) I'm specifically unhappy with the way libPolly is linked right now, because it just blindly links against all the LLVM libs. That doesn't make a lot of sense. For instance, one of these libs is LLVMTableGen, which contains a command line definition of a -o option. This means that I can not link an out-of-tree libPolly into a tool which might want to offer a -o option as well.
This patch (mostly) drop the use of llvm-config in favor of LLVMs exported cmake package. However, building Polly with unittests requires access to the gtest sources (in the LLVM source tree). If we're building against an LLVM installation, this source tree is unavailable and must specified. I'm using llvm-config to provide a default in this case.
Reviewers: Meinersbur, grosser
Reviewed By: grosser
Subscribers: tstellar, bollu, chapuni, mgorny, pollydev, llvm-commits
Differential Revision: https://reviews.llvm.org/D33299
llvm-svn: 307650
2017-07-11 19:24:25 +08:00
|
|
|
find_package(LLVM CONFIG REQUIRED)
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
include(AddLLVM)
|
2016-08-25 19:28:52 +08:00
|
|
|
|
[Polly][CMake] Use the CMake Package instead of llvm-config in out-of-tree builds
Summary:
As of now, Polly uses llvm-config to set up LLVM dependencies in an out-of-tree build.
This is problematic for two reasons:
1) Right now, in-tree and out-of-tree builds in fact do different things. E.g., in an in-tree build, libPolly depends on a handful of LLVM libraries, while in an out-of-tree build it depends on all of them. This means that we often need to treat both paths seperately.
2) I'm specifically unhappy with the way libPolly is linked right now, because it just blindly links against all the LLVM libs. That doesn't make a lot of sense. For instance, one of these libs is LLVMTableGen, which contains a command line definition of a -o option. This means that I can not link an out-of-tree libPolly into a tool which might want to offer a -o option as well.
This patch (mostly) drop the use of llvm-config in favor of LLVMs exported cmake package. However, building Polly with unittests requires access to the gtest sources (in the LLVM source tree). If we're building against an LLVM installation, this source tree is unavailable and must specified. I'm using llvm-config to provide a default in this case.
Reviewers: Meinersbur, grosser
Reviewed By: grosser
Subscribers: tstellar, bollu, chapuni, mgorny, pollydev, llvm-commits
Differential Revision: https://reviews.llvm.org/D33299
llvm-svn: 307650
2017-07-11 19:24:25 +08:00
|
|
|
# Add the llvm header path.
|
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
2015-09-12 04:47:14 +08:00
|
|
|
|
2016-08-25 20:36:15 +08:00
|
|
|
# Sources available, too?
|
[Polly][CMake] Use the CMake Package instead of llvm-config in out-of-tree builds
Summary:
As of now, Polly uses llvm-config to set up LLVM dependencies in an out-of-tree build.
This is problematic for two reasons:
1) Right now, in-tree and out-of-tree builds in fact do different things. E.g., in an in-tree build, libPolly depends on a handful of LLVM libraries, while in an out-of-tree build it depends on all of them. This means that we often need to treat both paths seperately.
2) I'm specifically unhappy with the way libPolly is linked right now, because it just blindly links against all the LLVM libs. That doesn't make a lot of sense. For instance, one of these libs is LLVMTableGen, which contains a command line definition of a -o option. This means that I can not link an out-of-tree libPolly into a tool which might want to offer a -o option as well.
This patch (mostly) drop the use of llvm-config in favor of LLVMs exported cmake package. However, building Polly with unittests requires access to the gtest sources (in the LLVM source tree). If we're building against an LLVM installation, this source tree is unavailable and must specified. I'm using llvm-config to provide a default in this case.
Reviewers: Meinersbur, grosser
Reviewed By: grosser
Subscribers: tstellar, bollu, chapuni, mgorny, pollydev, llvm-commits
Differential Revision: https://reviews.llvm.org/D33299
llvm-svn: 307650
2017-07-11 19:24:25 +08:00
|
|
|
if (LLVM_BUILD_MAIN_SRC_DIR)
|
|
|
|
set(LLVM_SOURCE_ROOT ${LLVM_BUILD_MAIN_SRC_DIR} CACHE PATH
|
|
|
|
"Path to LLVM source tree")
|
|
|
|
else()
|
|
|
|
execute_process(COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" --src-root
|
|
|
|
OUTPUT_VARIABLE MAIN_SRC_DIR
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
set(LLVM_SOURCE_ROOT ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
|
|
|
endif()
|
2016-08-25 20:36:15 +08:00
|
|
|
|
|
|
|
# Enable unit tests if available.
|
[Polly][CMake] Skip unit-tests in lit if gtest is not available
Summary:
There is a bug in the current lit configurations for the unittests. If gtest is not available, the site-config for the unit tests won't be generated. Because lit recurses through the test directory, the lit configuration for the unit tests will be discovered nevertheless, leading to a fatal error in lit.
This patch semi-gracefully skips the unittests if gtest is not available. As a result, running lit now prints this: `warning: test suite 'Polly-Unit' contained no test`.
If people think that this is too annoying, the alternative would be to pick apart the test directory, so that the lit testsuite discovery will always only find one configuration. In fact, both of these things could be combined. While it's certainly nice that running a single lit command runs all the tests, I suppose people use the `check-polly` make target over lit most of the time, so the difference might not be noticed.
Reviewers: Meinersbur, grosser
Reviewed By: grosser
Subscribers: mgorny, bollu, pollydev, llvm-commits
Tags: #polly
Differential Revision: https://reviews.llvm.org/D34053
llvm-svn: 307651
2017-07-11 19:37:35 +08:00
|
|
|
set(POLLY_GTEST_AVAIL 0)
|
2016-08-25 20:36:15 +08:00
|
|
|
set(UNITTEST_DIR ${LLVM_SOURCE_ROOT}/utils/unittest)
|
|
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
|
2020-08-05 16:15:41 +08:00
|
|
|
if (NOT TARGET gtest)
|
|
|
|
add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
[Polly][CMake] Use the CMake Package instead of llvm-config in out-of-tree builds
Summary:
As of now, Polly uses llvm-config to set up LLVM dependencies in an out-of-tree build.
This is problematic for two reasons:
1) Right now, in-tree and out-of-tree builds in fact do different things. E.g., in an in-tree build, libPolly depends on a handful of LLVM libraries, while in an out-of-tree build it depends on all of them. This means that we often need to treat both paths seperately.
2) I'm specifically unhappy with the way libPolly is linked right now, because it just blindly links against all the LLVM libs. That doesn't make a lot of sense. For instance, one of these libs is LLVMTableGen, which contains a command line definition of a -o option. This means that I can not link an out-of-tree libPolly into a tool which might want to offer a -o option as well.
This patch (mostly) drop the use of llvm-config in favor of LLVMs exported cmake package. However, building Polly with unittests requires access to the gtest sources (in the LLVM source tree). If we're building against an LLVM installation, this source tree is unavailable and must specified. I'm using llvm-config to provide a default in this case.
Reviewers: Meinersbur, grosser
Reviewed By: grosser
Subscribers: tstellar, bollu, chapuni, mgorny, pollydev, llvm-commits
Differential Revision: https://reviews.llvm.org/D33299
llvm-svn: 307650
2017-07-11 19:24:25 +08:00
|
|
|
endif()
|
2020-08-05 16:15:41 +08:00
|
|
|
set(POLLY_GTEST_AVAIL 1)
|
2016-08-25 20:36:15 +08:00
|
|
|
endif()
|
|
|
|
|
2020-08-27 16:59:51 +08:00
|
|
|
if (LLVM_ENABLE_PIC)
|
|
|
|
# Make sure the isl c files are built as fPIC if possible
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
|
|
|
endif ()
|
2017-04-23 07:02:53 +08:00
|
|
|
|
|
|
|
# Set directory for polly-isl-test.
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
2016-08-25 20:36:15 +08:00
|
|
|
else ()
|
|
|
|
set(LLVM_SOURCE_ROOT "${LLVM_MAIN_SRC_DIR}")
|
|
|
|
set(POLLY_GTEST_AVAIL 1)
|
|
|
|
endif ()
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
set(POLLY_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(POLLY_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2012-10-21 23:51:49 +08:00
|
|
|
# Add path for custom modules
|
|
|
|
set(CMAKE_MODULE_PATH
|
|
|
|
${CMAKE_MODULE_PATH}
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
|
|
|
)
|
|
|
|
|
|
|
|
include("polly_macros")
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
# Add appropriate flags for GCC
|
|
|
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
# FIXME: Turn off exceptions, RTTI:
|
|
|
|
# -fno-exceptions -fno-rtti
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -fno-exceptions -fno-rtti")
|
2015-07-21 20:22:36 +08:00
|
|
|
elseif (MSVC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
|
|
|
|
add_definitions("-D_HAS_EXCEPTIONS=0")
|
|
|
|
else ()
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
|
2011-04-29 14:27:02 +08:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Add path for custom modules
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
|
|
|
|
|
2014-02-22 21:28:31 +08:00
|
|
|
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
|
|
|
2012-08-03 20:50:07 +08:00
|
|
|
option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
|
2018-06-08 05:10:49 +08:00
|
|
|
set(GPU_CODEGEN FALSE)
|
2012-08-03 20:50:07 +08:00
|
|
|
if (POLLY_ENABLE_GPGPU_CODEGEN)
|
[Polly] Added OpenCL Runtime to GPURuntime Library for GPGPU CodeGen
Summary:
When compiling for GPU, one can now choose to compile for OpenCL or CUDA,
with the corresponding polly-gpu-runtime flag (libopencl / libcudart). The
GPURuntime library (GPUJIT) has been extended with the OpenCL Runtime library
for that purpose, correctly choosing the corresponding library calls to the
option chosen when compiling (via different initialization calls).
Additionally, a specific GPU Target architecture can now be chosen with -polly-gpu-arch (only nvptx64 implemented thus far).
Reviewers: grosser, bollu, Meinersbur, etherzhhb, singam-sanjay
Reviewed By: grosser, Meinersbur
Subscribers: singam-sanjay, llvm-commits, pollydev, nemanjai, mgorny, yaxunl, Anastasia
Tags: #polly
Differential Revision: https://reviews.llvm.org/D32431
llvm-svn: 302379
2017-05-08 05:03:46 +08:00
|
|
|
# Do not require CUDA/OpenCL, as GPU code generation test cases can be run
|
|
|
|
# without a CUDA/OpenCL library.
|
2018-06-08 05:10:49 +08:00
|
|
|
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
|
|
|
|
FIND_PACKAGE(CUDA)
|
|
|
|
FIND_PACKAGE(OpenCL)
|
|
|
|
set(GPU_CODEGEN TRUE)
|
|
|
|
else()
|
|
|
|
message(WARNING "The LLVM NVPTX target is required for GPU code generation")
|
|
|
|
endif()
|
2012-08-03 20:50:07 +08:00
|
|
|
endif(POLLY_ENABLE_GPGPU_CODEGEN)
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-07-14 18:22:19 +08:00
|
|
|
|
2012-06-06 20:16:10 +08:00
|
|
|
# Support GPGPU code generation if the library is available.
|
2017-06-07 03:20:48 +08:00
|
|
|
if (CUDA_FOUND)
|
[Polly] Added OpenCL Runtime to GPURuntime Library for GPGPU CodeGen
Summary:
When compiling for GPU, one can now choose to compile for OpenCL or CUDA,
with the corresponding polly-gpu-runtime flag (libopencl / libcudart). The
GPURuntime library (GPUJIT) has been extended with the OpenCL Runtime library
for that purpose, correctly choosing the corresponding library calls to the
option chosen when compiling (via different initialization calls).
Additionally, a specific GPU Target architecture can now be chosen with -polly-gpu-arch (only nvptx64 implemented thus far).
Reviewers: grosser, bollu, Meinersbur, etherzhhb, singam-sanjay
Reviewed By: grosser, Meinersbur
Subscribers: singam-sanjay, llvm-commits, pollydev, nemanjai, mgorny, yaxunl, Anastasia
Tags: #polly
Differential Revision: https://reviews.llvm.org/D32431
llvm-svn: 302379
2017-05-08 05:03:46 +08:00
|
|
|
add_definitions(-DHAS_LIBCUDART)
|
2017-06-07 03:20:48 +08:00
|
|
|
INCLUDE_DIRECTORIES( ${CUDA_INCLUDE_DIRS} )
|
|
|
|
endif(CUDA_FOUND)
|
[Polly] Added OpenCL Runtime to GPURuntime Library for GPGPU CodeGen
Summary:
When compiling for GPU, one can now choose to compile for OpenCL or CUDA,
with the corresponding polly-gpu-runtime flag (libopencl / libcudart). The
GPURuntime library (GPUJIT) has been extended with the OpenCL Runtime library
for that purpose, correctly choosing the corresponding library calls to the
option chosen when compiling (via different initialization calls).
Additionally, a specific GPU Target architecture can now be chosen with -polly-gpu-arch (only nvptx64 implemented thus far).
Reviewers: grosser, bollu, Meinersbur, etherzhhb, singam-sanjay
Reviewed By: grosser, Meinersbur
Subscribers: singam-sanjay, llvm-commits, pollydev, nemanjai, mgorny, yaxunl, Anastasia
Tags: #polly
Differential Revision: https://reviews.llvm.org/D32431
llvm-svn: 302379
2017-05-08 05:03:46 +08:00
|
|
|
if (OpenCL_FOUND)
|
|
|
|
add_definitions(-DHAS_LIBOPENCL)
|
|
|
|
INCLUDE_DIRECTORIES( ${OpenCL_INCLUDE_DIR} )
|
|
|
|
endif(OpenCL_FOUND)
|
2012-06-06 20:16:10 +08:00
|
|
|
|
2017-02-28 01:54:25 +08:00
|
|
|
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()
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
include_directories(
|
2014-05-29 00:54:42 +08:00
|
|
|
BEFORE
|
2011-04-29 14:27:02 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
2017-02-28 01:54:25 +08:00
|
|
|
${ISL_INCLUDE_DIRS}
|
2016-07-14 18:22:19 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External/pet/include
|
2016-07-15 15:50:36 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/External
|
2011-04-29 14:27:02 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
)
|
|
|
|
|
2016-06-22 02:14:01 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
install(DIRECTORY include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
)
|
|
|
|
|
|
|
|
install(DIRECTORY ${POLLY_BINARY_DIR}/include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN "CMakeFiles" EXCLUDE
|
|
|
|
)
|
|
|
|
endif()
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
add_definitions( -D_GNU_SOURCE )
|
|
|
|
|
2016-02-04 15:16:36 +08:00
|
|
|
add_subdirectory(docs)
|
2011-04-29 14:27:02 +08:00
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(test)
|
2016-08-25 20:36:15 +08:00
|
|
|
if (POLLY_GTEST_AVAIL)
|
|
|
|
add_subdirectory(unittests)
|
|
|
|
endif ()
|
2011-04-29 14:27:02 +08:00
|
|
|
add_subdirectory(tools)
|
2017-03-10 01:58:20 +08:00
|
|
|
add_subdirectory(cmake)
|
2011-04-29 14:27:02 +08:00
|
|
|
# TODO: docs.
|
|
|
|
|
|
|
|
|
|
|
|
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/polly/Config/config.h.cmake
|
|
|
|
${POLLY_BINARY_DIR}/include/polly/Config/config.h )
|
|
|
|
|
2013-02-15 00:19:16 +08:00
|
|
|
# Add target to check formatting of polly files
|
2016-08-25 20:36:15 +08:00
|
|
|
file( GLOB_RECURSE files *.h lib/*.cpp lib/*.c tools/*.cpp tools/*.c tools/*.h unittests/*.cpp)
|
2017-05-15 21:20:26 +08:00
|
|
|
file( GLOB_RECURSE external lib/External/*.h lib/External/*.c lib/External/*.cpp isl_config.h)
|
2017-02-05 23:26:56 +08:00
|
|
|
list( REMOVE_ITEM files ${external})
|
2015-09-15 00:59:50 +08:00
|
|
|
|
|
|
|
set(check_format_depends)
|
|
|
|
set(update_format_depends)
|
|
|
|
set(i 0)
|
|
|
|
foreach (file IN LISTS files)
|
|
|
|
add_custom_command(OUTPUT polly-check-format${i}
|
2015-10-15 20:18:37 +08:00
|
|
|
COMMAND clang-format -sort-includes -style=llvm ${file} | diff -u ${file} -
|
2015-09-15 00:59:50 +08:00
|
|
|
VERBATIM
|
|
|
|
COMMENT "Checking format of ${file}..."
|
|
|
|
)
|
|
|
|
list(APPEND check_format_depends "polly-check-format${i}")
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT polly-update-format${i}
|
2015-10-15 20:18:37 +08:00
|
|
|
COMMAND clang-format -sort-includes -i -style=llvm ${file}
|
2015-09-15 00:59:50 +08:00
|
|
|
VERBATIM
|
|
|
|
COMMENT "Updating format of ${file}..."
|
|
|
|
)
|
|
|
|
list(APPEND update_format_depends "polly-update-format${i}")
|
|
|
|
|
|
|
|
math(EXPR i ${i}+1)
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
add_custom_target(polly-check-format DEPENDS ${check_format_depends})
|
2015-07-21 20:40:01 +08:00
|
|
|
set_target_properties(polly-check-format PROPERTIES FOLDER "Polly")
|
2015-09-15 00:59:50 +08:00
|
|
|
|
|
|
|
add_custom_target(polly-update-format DEPENDS ${update_format_depends})
|
2015-07-21 20:40:01 +08:00
|
|
|
set_target_properties(polly-update-format PROPERTIES FOLDER "Polly")
|
2014-03-14 04:24:48 +08:00
|
|
|
|