[PATCH] D72583: [cmake] Add support for explicit STATIC libraries even when building mostly shared libraries.

Stephen Neuendorffer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 12 23:39:34 PST 2020


stephenneuendorffer created this revision.
stephenneuendorffer added reviewers: ftynse, mehdi_amini, nicolasvasilache, mravishankar, antiagainst, inouehrs, vchuravy.
Herald added subscribers: llvm-commits, liufengdb, aartbik, herhut, lucyrfox, mgester, arpith-jacob, csigg, shauheen, burmako, jpienaar, rriddle, mgorny, jholewinski.
Herald added 1 blocking reviewer(s): nicolasvasilache.
Herald added a project: LLVM.

By default when BUILD_SHARED_LIBS=ON, all libraries are forced to be
shared.  However, with circular dependencies between libraries this
becomes a problem.  This change allows libraries to be explicitly
marked as static in CMAKE to solve circular dependencies while getting
most of the build-time advantages from BUILD_SHARED_LIBS=ON

[examples] Fix CMakefiles for JITLink and OrcError library refactoring

The examples need explicit library dependencies when building with
BUILD_SHARED_LIBS=on

[MLIR] Mark application libraries as "BUILDTREE_ONLY"

These libraries are intended to be used as part of specific
applications (like mlir-opt).  If they are both included in a single
library (e.g. libLLVM.so), then their options will collide, because
static initializers will be called more than once.

[MLIR] Fix OpDefinition::classof check for shared libraries.

When using MLIR in a shared library, it is possible for the shared library
to load a different, but equivalent version of a class method.  As a result,
function pointer comparison is not a reliable check of class equivalence.
This causes problems related to this code in OpDefinition.h:

  /// Return true if this "op class" can match against the specified operation.
  static bool classof(Operation *op) {
    if (auto *abstractOp = op->getAbstractOperation()) {
      return &classof == abstractOp->classof;
    }
    return op->getName().getStringRef() == ConcreteType::getOperationName();
  }

It appears that the intention is to implement the normal LLVM cast<>/isa<>
mechanism, but without a fixed enum of Kinds.  Primarily, the operation
name check allows casting based on the operation name, which are assumed
to be unique for an operation class.  (Aside: is this enforced anywhere?)
Before this, another, more efficient, check based on pointer equality of
the classof method.  Unfortunately, this pointer equality check fails
if/when the classof method is inlined into a shared object (e.g. libLLVM.so)
and also exists in the main executable, resulting in triggering the assert()
inside cast<>.

This patch fixes this method to fall back to the slow, but accurate string
comparison if the function pointer comparison fails.

[MLIR] Fixes for BUILD_SHARED_LIBS=on

This patch enables the above cmake option, which builds most libraries
as DLLs instead of statically linked libraries.  The main effect of this is
that incrememntal build times are greatly reduced, since usually only one
library need be relinked in response to isolated code changes.

The bulk of this patch is fixing incorrect usage of cmake, where library
dependencies are listed under add_dependencies rather than under
target_link_libraries or under the LINK_LIBS tag.  Correct usage should be
like this:

add_dependencies(MLIRfoo MLIRfooIncGen)
target_link_libraries(MLIRfoo MLIRlib1 MLIRlib2)

[MLIR] Move from add_llvm_library to add_llvm_component_library

This results in most MLIR libraries being linked into libLLVM.so


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72583

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/examples/LLJITExamples/LLJITDumpObjects/CMakeLists.txt
  mlir/include/mlir/IR/OpDefinition.h
  mlir/lib/Analysis/CMakeLists.txt
  mlir/lib/Conversion/AffineToStandard/CMakeLists.txt
  mlir/lib/Conversion/GPUToCUDA/CMakeLists.txt
  mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt
  mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt
  mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt
  mlir/lib/Conversion/LinalgToLLVM/CMakeLists.txt
  mlir/lib/Conversion/LoopToStandard/CMakeLists.txt
  mlir/lib/Conversion/LoopsToGPU/CMakeLists.txt
  mlir/lib/Conversion/StandardToLLVM/CMakeLists.txt
  mlir/lib/Conversion/StandardToSPIRV/CMakeLists.txt
  mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt
  mlir/lib/Conversion/VectorToLoops/CMakeLists.txt
  mlir/lib/Dialect/AffineOps/CMakeLists.txt
  mlir/lib/Dialect/CMakeLists.txt
  mlir/lib/Dialect/FxpMathOps/CMakeLists.txt
  mlir/lib/Dialect/GPU/CMakeLists.txt
  mlir/lib/Dialect/LLVMIR/CMakeLists.txt
  mlir/lib/Dialect/Linalg/CMakeLists.txt
  mlir/lib/Dialect/LoopOps/CMakeLists.txt
  mlir/lib/Dialect/QuantOps/CMakeLists.txt
  mlir/lib/Dialect/SDBM/CMakeLists.txt
  mlir/lib/Dialect/SPIRV/CMakeLists.txt
  mlir/lib/Dialect/SPIRV/Serialization/CMakeLists.txt
  mlir/lib/Dialect/SPIRV/Transforms/CMakeLists.txt
  mlir/lib/Dialect/StandardOps/CMakeLists.txt
  mlir/lib/Dialect/VectorOps/CMakeLists.txt
  mlir/lib/EDSC/CMakeLists.txt
  mlir/lib/ExecutionEngine/CMakeLists.txt
  mlir/lib/IR/CMakeLists.txt
  mlir/lib/Parser/CMakeLists.txt
  mlir/lib/Pass/CMakeLists.txt
  mlir/lib/Quantizer/CMakeLists.txt
  mlir/lib/Support/CMakeLists.txt
  mlir/lib/TableGen/CMakeLists.txt
  mlir/lib/Target/CMakeLists.txt
  mlir/lib/Transforms/CMakeLists.txt
  mlir/lib/Transforms/Utils/CMakeLists.txt
  mlir/lib/Translation/CMakeLists.txt
  mlir/test/lib/IR/CMakeLists.txt
  mlir/test/lib/Pass/CMakeLists.txt
  mlir/test/lib/TestDialect/CMakeLists.txt
  mlir/test/lib/Transforms/CMakeLists.txt
  mlir/tools/mlir-opt/CMakeLists.txt

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72583.237580.patch
Type: text/x-patch
Size: 28574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200113/be9b401f/attachment.bin>


More information about the llvm-commits mailing list