This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Fix libMLIR.so and LLVM_LINK_LLVM_DYLIB
ClosedPublic

Authored by stephenneuendorffer on Apr 28 2020, 11:24 PM.

Details

Summary

Primarily, this patch moves all mlir references to LLVM libraries into
either LLVM_LINK_COMPONENTS or LINK_COMPONENTS. This enables magic in
the llvm cmake files to automatically replace reference to LLVM components
with references to libLLVM.so when necessary. Among other things, this
completes fixing libMLIR.so, which has been broken for some configurations
since D77515.

Unlike previously, the pattern is now that mlir libraries should almost
always use add_mlir_library. Previously, some libraries still used
add_llvm_library. However, this confuses the export of targets for use
out of tree because libraries specified with add_llvm_library are exported
by LLVM. Instead users which don't need/can't be linked into libMLIR.so
can specify EXCLUDE_FROM_LIBMLIR

A common error mode is linking with LLVM libraries outside of LINK_COMPONENTS.
This almost always results in symbol confusion or multiply defined options
in LLVM when the same object file is included as a static library and
as part of libLLVM.so. To catch these errors more directly, there's now
mlir_check_all_link_libraries.

To simplify usage of add_mlir_library, we assume that all mlir
libraries depend on LLVMSupport, so it's not necessary to separately specify
it.

tested with:
BUILD_SHARED_LIBS=on,
BUILD_SHARED_LIBS=off + LLVM_BUILD_LLVM_DYLIB,
BUILD_SHARED_LIBS=off + LLVM_BUILD_LLVM_DYLIB + LLVM_LINK_LLVM_DYLIB.

Diff Detail

Event Timeline

stephenneuendorffer retitled this revision from [MLIR][In progress] Fix libMLIR.so and LLVM_LINK_LLVM_DYLIB to [MLIR] Fix libMLIR.so and LLVM_LINK_LLVM_DYLIB.
stephenneuendorffer edited the summary of this revision. (Show Details)
rriddle marked 2 inline comments as done.May 1 2020, 10:20 AM
rriddle added inline comments.
mlir/cmake/modules/AddMLIR.cmake
156

nit: Remove the new line here.

mlir/examples/toy/Ch6/CMakeLists.txt
7

Wonder why this name doesn't match the naming scheme of everything else...

mlir/lib/ExecutionEngine/CMakeLists.txt
12

Maybe we should add a comment when using this?

mlir/lib/Target/CMakeLists.txt
85

nit: Add a newline before this.

stephenneuendorffer marked 2 inline comments as done.
mlir/examples/toy/Ch6/CMakeLists.txt
7

nativecodegen is a pseudo-component which is expanded by AddLLVM.cmake. It refers to 'codegen for whatever architecture I'm compiled for'. It makes the JIT work regardless of what architecture you're compiling on.

stephenneuendorffer marked an inline comment as done.May 3 2020, 11:35 PM
vchuravy accepted this revision.May 4 2020, 6:37 AM
rriddle accepted this revision.May 4 2020, 10:38 AM
This revision is now accepted and ready to land.May 4 2020, 10:38 AM

This landed as part of a squashed commit