This is an archive of the discontinued LLVM Phabricator instance.

[Polly][CMake] Use object library to build two flavours of Polly.

Authored by Meinersbur on Apr 24 2017, 10:23 AM.



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.

This is a less invasive alternative to D32392.

I did not manage to make LLVM_LINK_LLVM_DYLIB=ON build work entirely. check-polly works, but trying to install it gives an error

CMake Error at tools/polly/lib/cmake_install.cmake:40 (file):
  file INSTALL cannot find
Call Stack (most recent call first):
  tools/polly/cmake_install.cmake:46 (include)
  tools/cmake_install.cmake:37 (include)
  cmake_install.cmake:62 (include)

According to this has might not be Polly's fault. It occures with lld as well.

Diff Detail


Event Timeline

Meinersbur created this revision.Apr 24 2017, 10:23 AM
Meinersbur edited the summary of this revision. (Show Details)

Properly handle dylibs (e.g. if LLVM_LINK_LLVM_DYLIB=ON, do not link any LLVM component since it should be already in the

singam-sanjay added inline comments.
75 ↗(On Diff #96451)

Why can't we just add PollyCore as a dependency ?

131 ↗(On Diff #96451)

We need all these libraries and not just those that might be returned by llvm_map_components_to_libnames(nvptx_libs NVPTX) (I'm assuming that you mean nvptx_libs might turn out to be a subset of all possible NVPTX libraries).

Nevertheless, won't all LLVMNVPTX* libraries be included in nvptx_libs since they are all a part of the NVPTX backend ?

12 ↗(On Diff #96451)

patch failed to update this file because it couldn't find these comments. At which commit did you create the diff ?

singam-sanjay accepted this revision.Apr 27 2017, 4:31 AM
singam-sanjay added a reviewer: singam-sanjay.

This patch works on my system.

This revision is now accepted and ready to land.Apr 27 2017, 4:31 AM
Meinersbur added inline comments.Apr 27 2017, 5:16 AM
75 ↗(On Diff #96451)

That should work as well, if PollyCore was a static library. For OBJECT libraries, this is the only way to do. See

Here are the reasons:

  • LLVM also creates OBJECT libraries when it creates static and shared libraries in one build.
  • There is one less library that could be either a shared or static library.
  • Without it, the Polly and LLVM library would be empty. This could cause symbols of PollyCore to not get pulled-in by the linker, which gets us into trouble.
  • CMake might order PollyCore behind PollyISL and PollyPPCG in the linker command linker, meaning it would not pull anything from them because theirs symbols were not required then.
131 ↗(On Diff #96451)

There are two separate cases:

  • We are building inside the LLVM tree: Then cmake knowns which libraries NVPTX* depend on and adjust the linker command line accordingly. This is exactly how LLVM's CMakeLists.txt do this (using LLVM_LINK_COMPONENTS)
  • We are building out-of-tree: Then we don't know the NVPTX* dependencies. however, we link against all the libraries (using LLVM_LIBS), so all its dependencies are already available (including NVPTX*, so the second case is kind-of redundant, I might remove them).

I think I don't actually understood your question. What are "all" libraries? llvm_map_components_to_libnames returns: LLVMNVPTXCodeGen LLVMNVPTXInfo LLVMNVPTXDesc LLVMNVPTXAsmPrinter.

12 ↗(On Diff #96451)

The comments were added in r301095 ([CMake] Fix unittests in out-of-LLVM-tree builds.)

Meinersbur updated this revision to Diff 96926.Apr 27 2017, 9:20 AM

Pre-commit update.

  • Don't redundantly call target_link_libraries on Polly.
This revision was automatically updated to reflect the committed changes.