This is an archive of the discontinued LLVM Phabricator instance.

[Polly][CMake] Allow Polly to transitively pull in its dependencies into host programs.
AbandonedPublic

Authored by Meinersbur on Apr 22 2017, 5:32 PM.

Details

Summary

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.

Diff Detail

Event Timeline

Meinersbur created this revision.Apr 22 2017, 5:32 PM
Meinersbur edited the summary of this revision. (Show Details)Apr 22 2017, 6:09 PM
Meinersbur added a reviewer: philip.pfaffe.
grosser accepted this revision.Apr 23 2017, 12:12 AM

Hi Michael,

this seems to be a nice cmake cleanup now finally adding Polly with the right native cmake tools. I think it is OK to have Polly as part of libLLVM.so, as this is only the case if Polly is actually checked out. I also think it is OK to expose the core library not to external users. It is hard to guess which build artifacts they might need, if we neither know about their existence nor about their use cases. I personally would guess there are none, but if there are I am sure they will let us know when we break them. In this case we can always try to address their use case.

Best,
Tobias

This revision is now accepted and ready to land.Apr 23 2017, 12:12 AM

With having invested some extra effort, D32392 seems to work better. Other opinions?

Meinersbur abandoned this revision.Apr 26 2017, 11:02 AM

Abandoned in favor of D32442