Polly comes in two library flavors: One loadable module to use the LLVM framework -load mechanism, and another one that host applications can link to. These have very different requirements for Polly's own dependencies.
The loadable module assumes that all its LLVM dependencies are already available in the address space of the host application, and is not allowed to bring in its own copy of any LLVM library (including the NVPTX backend in case of Polly-ACC).
The non-module library is intended to be linked to using target_link_libraries. CMake would then resolve all of its dependencies, including NVPTX and ensure that only a single instance of each library will be used.
The patch for LLVM will be:
diff --git a/tools/bugpoint/CMakeLists.txt b/tools/bugpoint/CMakeLists.txt index 7598657427e..0e00db4f5c4 100644 --- a/tools/bugpoint/CMakeLists.txt +++ b/tools/bugpoint/CMakeLists.txt @@ -16,6 +16,10 @@ set(LLVM_LINK_COMPONENTS Vectorize ) +if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) + list(APPEND LLVM_LINK_COMPONENTS Polly) +endif() + # Support plugins. set(LLVM_NO_DEAD_STRIP 1) @@ -34,9 +38,3 @@ add_llvm_tool(bugpoint intrinsics_gen ) export_executable_symbols(bugpoint) - -if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) - target_link_libraries(bugpoint Polly) - # Ensure LLVMTarget can resolve dependences in Polly. - target_link_libraries(bugpoint LLVMTarget) -endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) diff --git a/tools/opt/CMakeLists.txt b/tools/opt/CMakeLists.txt index 518396e3602..8fb95ef7483 100644 --- a/tools/opt/CMakeLists.txt +++ b/tools/opt/CMakeLists.txt @@ -19,6 +19,10 @@ set(LLVM_LINK_COMPONENTS Passes ) +if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) + list(APPEND LLVM_LINK_COMPONENTS Polly) +endif() + # Support plugins. set(LLVM_NO_DEAD_STRIP 1) @@ -35,7 +39,3 @@ add_llvm_tool(opt intrinsics_gen ) export_executable_symbols(opt) - -if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) - target_link_libraries(opt Polly) -endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
The patch for clang will be:
diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index 901b6d62e4..38bb34df79 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -16,6 +16,10 @@ set( LLVM_LINK_COMPONENTS Vectorize ) +if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) + list(APPEND LLVM_LINK_COMPONENTS Polly) +endif() + option(CLANG_PLUGIN_SUPPORT "Build clang with plugin support" ON) # Support plugins. This must be before add_clang_executable as it reads @@ -125,7 +129,3 @@ if(CLANG_ORDER_FILE AND (LD64_EXECUTABLE OR GOLD_EXECUTABLE)) set_target_properties(clang PROPERTIES LINK_DEPENDS ${CLANG_ORDER_FILE}) endif() endif() - -if(WITH_POLLY AND LINK_POLLY_INTO_TOOLS) - target_link_libraries(clang Polly) -endif(WITH_POLLY AND LINK_POLLY_INTO_TOOLS)
This patch uses LLVM's add_llvm_library, which is convenient because it handles all requirements and ensures consistency with LLVM, but also has other effects:
- Polly becomes part of libLLVM.so in case of LLVM_BUILD_LLVM_DYLIB=ON, even without LLVM_POLLY_LINK_INTO_TOOLS. This behavior could be avoided if we implement another option in add_llvm_library.
- The LLVM component system expects its component's names to begin with "LLVM". For this reason the targets "LLVMPolly" and "Polly" swap their meanings. This could be confusing to downstream users.
- The non-module Polly library is not available in out-of-LLVM-tree builds. This is no loss for Polly itself since it uses it only for LLVM_POLLY_LINK_INTO_TOOLS=ON, but maybe there are downstream users. llvm-config doesn't deliver enough information to get its dependency relations right anyway. Maybe importing the LLVMConfig.cmake would.