Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Putting this up mainly for discussion on how this should be done. I am interested in MLIR from the Julia side and we currently have a strong preference to dynamically linking against the LLVM shared library, and would like to have a MLIR shared library. This patch adds a new cmake function add_mlir_library() which accumulates a list of targets to be compiled into libMLIR.so. Note that not all libraries make sense to be compiled into libMLIR.so. In particular, we want to avoid libraries which primarily exist to support certain tools (such as mlir-opt and mlir-cpu-runner). Note that the resulting libMLIR.so depends on LLVM, but does not contain any LLVM components. As a result, it is necessary to link with libLLVM.so to avoid linkage errors. So, libMLIR.so requires LLVM_BUILD_LLVM_DYLIB=on FYI, Currently it appears that LLVM_LINK_LLVM_DYLIB is broken because mlir-tblgen is linked against libLLVM.so and and independent LLVM components (updated by Stephen Neuendorffer) Differential Revision: https://reviews.llvm.org/D73130
- Loading branch information
1 parent
8a2b86b
commit 1246e86
Showing
19 changed files
with
100 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
file(GLOB globbed *.c *.cpp) | ||
add_llvm_library(MLIRIR | ||
add_mlir_library(MLIRIR | ||
${globbed} | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
add_llvm_library(MLIRParser | ||
add_mlir_library(MLIRParser | ||
Lexer.cpp | ||
Parser.cpp | ||
Token.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
add_llvm_library(MLIRTranslation | ||
add_mlir_library(MLIRTranslation | ||
Translation.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ set(LLVM_OPTIONAL_SOURCES | |
|
||
set(LIB_LIBS | ||
MLIRAnalysis | ||
MLIRIR | ||
MLIRLLVMIR | ||
MLIROptLib | ||
MLIRParser | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Building libmlir-cpp.so fails if LLVM_ENABLE_PIC=Off | ||
if (NOT LLVM_ENABLE_PIC) | ||
return() | ||
endif() | ||
|
||
# Building libmlir-cpp.so may not work on MSVC | ||
if (MSVC) | ||
return() | ||
endif() | ||
|
||
get_property(mlir_libs GLOBAL PROPERTY MLIR_ALL_LIBS) | ||
list(REMOVE_DUPLICATES mlir_libs) | ||
|
||
foreach (lib ${mlir_libs}) | ||
if(XCODE) | ||
# Xcode doesn't support object libraries, so we have to trick it into | ||
# linking the static libraries instead. | ||
list(APPEND _DEPS "-force_load" ${lib}) | ||
else() | ||
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>) | ||
endif() | ||
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>) | ||
endforeach () | ||
|
||
if(MLIR_LINK_MLIR_DYLIB) | ||
set(INSTALL_WITH_TOOLCHAIN INSTALL_WITH_TOOLCHAIN) | ||
endif() | ||
|
||
# libMLIR.so depends on LLVM components. To avoid multiple | ||
# copies of those LLVM components, libMLIR.so depends on libLLVM.so. | ||
# This probably won't work if some LLVM components are not included | ||
# in libLLVM.so. | ||
if(LLVM_BUILD_LLVM_DYLIB) | ||
add_llvm_library(MLIR | ||
SHARED | ||
${INSTALL_WITH_TOOLCHAIN} | ||
|
||
mlir-shlib.cpp | ||
) | ||
target_link_libraries(MLIR PRIVATE LLVM ${LLVM_PTHREAD_LIB}) | ||
whole_archive_link(MLIR ${mlir_libs}) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Intentionally empty source file to make CMake happy |