[PATCH] D32392: [Polly][CMake] Allow Polly to transitively pull in its dependencies into host programs.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 22 17:32:22 PDT 2017


Meinersbur created this revision.
Meinersbur added a project: Polly.
Herald added a subscriber: mgorny.

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.


https://reviews.llvm.org/D32392

Files:
  cmake/CMakeLists.txt
  lib/CMakeLists.txt
  test/CMakeLists.txt
  test/lit.site.cfg.in
  unittests/CMakeLists.txt

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32392.96291.patch
Type: text/x-patch
Size: 8430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170423/8934888c/attachment.bin>


More information about the llvm-commits mailing list