Skip to content

Commit d7cbef2

Browse files
[MLIR] Fixes for shared library dependencies.
Summary: This patch is a step towards enabling BUILD_SHARED_LIBS=on, which builds most libraries as DLLs instead of statically linked libraries. The main effect of this is that incremental 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) A separate issue is that in cmake, dependencies between static libraries are automatically included in dependencies. In the above example, if MLIBlib1 depends on MLIRlib2, then it is sufficient to have only MLIRlib1 in the target_link_libraries. When compiling with shared libraries, it is necessary to have both MLIRlib1 and MLIRlib2 specified if MLIRfoo uses symbols from both. Reviewers: mravishankar, antiagainst, nicolasvasilache, vchuravy, inouehrs, mehdi_amini, jdoerfert Reviewed By: nicolasvasilache, mehdi_amini Subscribers: Joonsoo, merge_guards_bot, jholewinski, mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, herhut, aartbik, liufengdb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73653
1 parent 6d07802 commit d7cbef2

File tree

28 files changed

+113
-26
lines changed

28 files changed

+113
-26
lines changed

mlir/cmake/modules/AddMLIR.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ endfunction()
77
# TODO: This is to handle the current static registration, but should be
88
# factored out a bit.
99
function(whole_archive_link target)
10+
add_dependencies(${target} ${ARGN})
1011
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
1112
set(link_flags "-L${CMAKE_BINARY_DIR}/lib ")
1213
FOREACH(LIB ${ARGN})

mlir/lib/Analysis/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@ add_dependencies(MLIRAnalysis
2323
MLIRCallOpInterfacesIncGen
2424
MLIRTypeInferOpInterfaceIncGen
2525
MLIRLoopOps
26-
MLIRVectorOps
2726
)
28-
target_link_libraries(MLIRAnalysis MLIRAffineOps MLIRLoopOps MLIRVectorOps)
27+
target_link_libraries(MLIRAnalysis MLIRAffineOps MLIRLoopOps)

mlir/lib/Conversion/AffineToStandard/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ target_link_libraries(
1717
MLIRAffineToStandard
1818

1919
MLIRAffineOps
20+
MLIRLoopOps
21+
MLIRPass
2022
MLIRStandardOps
23+
MLIRTransforms
2124
MLIRIR
2225
LLVMCore
2326
LLVMSupport

mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ target_link_libraries(MLIRGPUtoNVVMTransforms
1515
MLIRLLVMIR
1616
MLIRNVVMIR
1717
MLIRPass
18+
MLIRStandardToLLVM
19+
MLIRTransformUtils
1820
)

mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ target_link_libraries(MLIRGPUtoROCDLTransforms
77
MLIRLLVMIR
88
MLIRROCDLIR
99
MLIRPass
10+
MLIRStandardToLLVM
1011
)

mlir/lib/Conversion/LinalgToLLVM/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ add_llvm_library(MLIRLinalgToLLVM
55
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/LinalgToLLVM
66
)
77
set(LIBS
8+
MLIRAffineToStandard
9+
MLIREDSC
10+
MLIRIR
811
MLIRLinalgOps
912
MLIRLLVMIR
13+
MLIRLoopToStandard
14+
MLIRStandardToLLVM
15+
MLIRVectorToLLVM
1016
MLIRTransforms
1117
LLVMCore
1218
LLVMSupport

mlir/lib/Conversion/LinalgToSPIRV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_llvm_library(MLIRLinalgToSPIRVTransforms
1010
target_link_libraries(MLIRLinalgToSPIRVTransforms
1111
MLIRIR
1212
MLIRLinalgOps
13+
MLIRLinalgUtils
1314
MLIRPass
1415
MLIRSPIRV
1516
MLIRSupport

mlir/lib/Conversion/LoopsToGPU/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(LIBS
22
MLIRAffineOps
3+
MLIRAffineToStandard
34
MLIRGPU
45
MLIRIR
56
MLIRLinalgOps

mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ add_llvm_library(MLIRVectorToLLVM
66
)
77
set(LIBS
88
MLIRLLVMIR
9+
MLIRStandardToLLVM
10+
MLIRVectorOps
911
MLIRTransforms
1012
LLVMCore
1113
LLVMSupport

mlir/lib/Conversion/VectorToLoops/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_llvm_library(MLIRVectorToLoops
55
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/VectorToLoops
66
)
77
set(LIBS
8+
MLIREDSC
89
MLIRLLVMIR
910
MLIRTransforms
1011
LLVMCore

mlir/lib/Dialect/FxpMathOps/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ add_llvm_library(MLIRFxpMathOps
66
ADDITIONAL_HEADER_DIRS
77
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/FxpMathOps
88
)
9+
10+
target_link_libraries(MLIRFxpMathOps
11+
MLIRQuantOps
12+
MLIRIR
13+
MLIRPass
14+
MLIRSupport
15+
MLIRStandardOps
16+
)
917
add_dependencies(MLIRFxpMathOps
1018
MLIRFxpMathOpsIncGen
1119
MLIRQuantOps

mlir/lib/Dialect/GPU/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ target_link_libraries(MLIRGPU
2222
MLIRIR
2323
MLIRLLVMIR
2424
MLIRLoopOps
25+
MLIRPass
26+
MLIRStandardOps
2527
MLIRSupport
2628
MLIRTransformUtils
2729
LLVMSupport)

mlir/lib/Dialect/LLVMIR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_llvm_library(MLIRNVVMIR
1414
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
1515
)
1616
add_dependencies(MLIRNVVMIR MLIRNVVMOpsIncGen MLIRNVVMConversionsIncGen LLVMAsmParser LLVMCore LLVMSupport)
17-
target_link_libraries(MLIRNVVMIR LLVMAsmParser LLVMCore LLVMSupport MLIRIR)
17+
target_link_libraries(MLIRNVVMIR LLVMAsmParser MLIRIR MLIRLLVMIR LLVMSupport LLVMCore)
1818

1919
add_llvm_library(MLIRROCDLIR
2020
IR/ROCDLDialect.cpp

mlir/lib/Dialect/Linalg/IR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(LIBS
22

33
MLIRIR
4+
MLIRStandardOps
45
)
56

67
add_llvm_library(MLIRLinalgOps

mlir/lib/Dialect/LoopOps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ add_llvm_library(MLIRLoopOps
66
${MLIR_MAIN_INCLUDE_DIR}/mlir/LoopOps
77
)
88
add_dependencies(MLIRLoopOps MLIRLoopLikeInterfaceIncGen MLIRLoopOpsIncGen MLIRStandardOps LLVMSupport)
9-
target_link_libraries(MLIRLoopOps LLVMSupport)
9+
target_link_libraries(MLIRLoopOps MLIRStandardOps LLVMSupport MLIRIR)

mlir/lib/Dialect/OpenMP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ add_llvm_library(MLIROpenMP
66
)
77

88
add_dependencies(MLIROpenMP MLIROpenMPOpsIncGen)
9+
target_link_libraries(MLIROpenMP MLIRIR)

mlir/lib/Dialect/QuantOps/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ add_dependencies(MLIRQuantOps
1919
MLIRQuantOpsIncGen
2020
MLIRSupport
2121
MLIRStandardOps)
22+
23+
target_link_libraries(MLIRQuantOps
24+
MLIRIR
25+
MLIRPass
26+
MLIRSupport
27+
MLIRStandardOps
28+
MLIRTransformUtils
29+
)

mlir/lib/Dialect/SPIRV/Serialization/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ add_dependencies(MLIRSPIRVSerialization
1414
target_link_libraries(MLIRSPIRVSerialization
1515
MLIRIR
1616
MLIRSPIRV
17-
MLIRSupport)
17+
MLIRSupport
18+
MLIRTranslation)

mlir/lib/Dialect/VectorOps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ add_llvm_library(MLIRVectorOps
1111
add_dependencies(MLIRVectorOps MLIRVectorOpsIncGen)
1212
add_dependencies(MLIRVectorOps MLIRVectorTransformPatternsIncGen)
1313

14-
target_link_libraries(MLIRVectorOps MLIRIR)
14+
target_link_libraries(MLIRVectorOps MLIRAnalysis MLIRIR MLIRStandardOps MLIRAffineOps MLIRLoopOps)

mlir/lib/EDSC/CMakeLists.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ add_llvm_library(MLIREDSC
1515
)
1616
target_link_libraries(MLIREDSC
1717
PUBLIC
18-
MLIRAffineOps
19-
MLIRLoopOps
20-
MLIRStandardOps
21-
MLIRTransformUtils
22-
MLIRVectorOps
23-
)
18+
MLIRAffineOps
19+
MLIRIR
20+
MLIRLoopOps
21+
MLIRStandardOps
22+
MLIRSupport
23+
MLIRTransformUtils
24+
MLIRVectorOps
25+
)
2426

2527
add_llvm_library(MLIREDSCInterface
2628
CoreAPIs.cpp
@@ -29,9 +31,9 @@ add_llvm_library(MLIREDSCInterface
2931
${MLIR_MAIN_INCLUDE_DIR}/mlir/EDSC
3032
)
3133
add_dependencies(MLIREDSCInterface MLIRIR)
32-
target_link_libraries(MLIREDSC
34+
target_link_libraries(MLIREDSCInterface
3335
PUBLIC
34-
MLIRIR
35-
MLIRSupport
36-
MLIRParser
37-
)
36+
MLIRIR
37+
MLIRSupport
38+
MLIRParser
39+
)

mlir/lib/ExecutionEngine/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ target_link_libraries(MLIRExecutionEngine
1414
LLVMBitWriter
1515
LLVMExecutionEngine
1616
LLVMOrcJIT
17+
LLVMJITLink
1718
LLVMSupport
19+
LLVMAnalysis
20+
LLVMAggressiveInstCombine
21+
LLVMInstCombine
22+
LLVMMC
23+
LLVMScalarOpts
24+
LLVMTarget
25+
LLVMVectorize
1826
LLVMTransformUtils
1927

2028
${outlibs})

mlir/lib/Quantizer/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,36 @@ add_llvm_library(MLIRQuantizerSupport
1010

1111
ADDITIONAL_HEADER_DIRS
1212
)
13+
1314
add_dependencies(MLIRQuantizerSupport
1415
MLIRIR
1516
MLIRQuantOps
1617
MLIRSupport
1718
MLIRStandardOps)
19+
target_link_libraries(MLIRQuantizerSupport
20+
MLIRIR
21+
MLIRQuantOps
22+
MLIRSupport
23+
MLIRStandardOps
24+
LLVMSupport
25+
)
1826

1927
# Configurations.
2028
add_llvm_library(MLIRQuantizerFxpMathConfig
2129
Configurations/FxpMathConfig.cpp
2230

2331
ADDITIONAL_HEADER_DIRS
2432
)
33+
2534
add_dependencies(MLIRQuantizerFxpMathConfig
2635
MLIRFxpMathOpsIncGen
2736
MLIRQuantizerSupport)
37+
target_link_libraries(MLIRQuantizerFxpMathConfig
38+
MLIRIR
39+
MLIRFxpMathOps
40+
MLIRQuantOps
41+
MLIRQuantizerSupport
42+
)
2843

2944
# Transforms.
3045
add_llvm_library(MLIRQuantizerTransforms
@@ -39,6 +54,10 @@ add_dependencies(MLIRQuantizerTransforms
3954
MLIRQuantizerSupport
4055
MLIRPass)
4156
target_link_libraries(MLIRQuantizerTransforms
57+
MLIRIR
4258
MLIRQuantizerFxpMathConfig
4359
MLIRQuantizerSupport
44-
MLIRPass)
60+
MLIRQuantOps
61+
MLIRPass
62+
LLVMSupport
63+
)

mlir/lib/Support/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_llvm_library(MLIROptMain
2525
)
2626
target_link_libraries(MLIROptMain
2727
MLIRPass
28+
MLIRParser
2829
LLVMSupport
2930
MLIRSupport
3031
)
@@ -35,7 +36,7 @@ add_llvm_library(MLIRTranslateClParser
3536
ADDITIONAL_HEADER_DIRS
3637
${MLIR_MAIN_INCLUDE_DIR}/mlir/Support
3738
)
38-
target_link_libraries(MLIRTranslateClParser LLVMSupport)
39+
target_link_libraries(MLIRTranslateClParser LLVMSupport MLIRIR MLIRTranslation MLIRParser)
3940

4041
add_llvm_library(MLIRJitRunner
4142
JitRunner.cpp

mlir/test/Dialect/SPIRV/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_llvm_library(MLIRSPIRVTestPasses
66
${MLIR_MAIN_INCLUDE_DIR}/mlir/IR
77
)
88

9-
target_link_libraries(MLIRSPIRVTestPasses
9+
target_link_libraries(MLIRSPIRVTestPasses PRIVATE
1010
MLIRIR
1111
MLIRPass
1212
MLIRSPIRV

mlir/test/lib/IR/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../TestDialect)
99
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../TestDialect)
1010
add_dependencies(MLIRTestIR
1111
MLIRTestDialect
12-
)
12+
)
1313
target_link_libraries(MLIRTestIR
1414
MLIRPass
1515
)

mlir/test/lib/TestDialect/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ add_llvm_library(MLIRTestDialect
1717
)
1818
add_dependencies(MLIRTestDialect
1919
MLIRTestOpsIncGen
20-
MLIRIR
21-
LLVMSupport
2220
MLIRTypeInferOpInterfaceIncGen
2321
)
2422
target_link_libraries(MLIRTestDialect
2523
MLIRDialect
2624
MLIRIR
25+
MLIRLinalgTransforms
26+
MLIRPass
27+
MLIRTransforms
28+
MLIRTransformUtils
2729
LLVMSupport
2830
)

mlir/test/lib/Transforms/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ add_llvm_library(MLIRTestTransforms
1717

1818
ADDITIONAL_HEADER_DIRS
1919
${MLIR_MAIN_INCLUDE_DIR}/mlir/Transforms
20-
)
20+
)
21+
2122
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../TestDialect)
2223
include_directories(${CMAKE_CURRENT_BINARY_DIR}/../TestDialect)
2324
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../DeclarativeTransforms)
@@ -36,5 +37,7 @@ target_link_libraries(MLIRTestTransforms
3637
MLIRGPU
3738
MLIRPass
3839
MLIRTestDialect
40+
MLIRTransformUtils
41+
MLIRVectorToLoops
3942
MLIRVectorOps
4043
)

mlir/tools/mlir-opt/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(LLVM_OPTIONAL_SOURCES
55
set(LIB_LIBS
66
MLIRAnalysis
77
MLIRLLVMIR
8+
MLIROptMain
89
MLIRParser
910
MLIRPass
1011
MLIRTransforms
@@ -13,12 +14,15 @@ set(LIB_LIBS
1314
add_llvm_library(MLIRMlirOptLib
1415
mlir-opt.cpp
1516
)
16-
target_link_libraries(MLIRMlirOptLib ${LIB_LIBS})
17+
target_link_libraries(MLIRMlirOptLib
18+
${LIB_LIBS}
19+
)
1720

1821
set(LIBS
1922
MLIRAnalysis
2023
MLIRAffineOps
2124
MLIRAffineToStandard
25+
MLIRDialect
2226
MLIRLoopsToGPU
2327
MLIRLinalgToLLVM
2428

@@ -30,13 +34,19 @@ set(LIBS
3034
MLIRGPUtoROCDLTransforms
3135
MLIRGPUtoSPIRVTransforms
3236
MLIRLinalgOps
37+
MLIRLinalgAnalysis
38+
MLIRLinalgEDSC
39+
MLIRLinalgTransforms
40+
MLIRLinalgUtils
3341
MLIRLLVMIR
3442
MLIRLoopOps
3543
MLIRNVVMIR
3644
MLIROpenMP
3745
MLIROptMain
3846
MLIRParser
3947
MLIRPass
48+
MLIRQuantizerFxpMathConfig
49+
MLIRQuantizerSupport
4050
MLIRQuantizerTransforms
4151
MLIRQuantOps
4252
MLIRROCDLIR
@@ -48,6 +58,7 @@ set(LIBS
4858
MLIRStandardOps
4959
MLIRStandardToLLVM
5060
MLIRTransforms
61+
MLIRTransformUtils
5162
MLIRTestDialect
5263
MLIRTestIR
5364
MLIRTestPass
@@ -66,5 +77,8 @@ add_llvm_tool(mlir-opt
6677
mlir-opt.cpp
6778
)
6879
llvm_update_compile_flags(mlir-opt)
80+
# It is necessary to use whole_archive_link to ensure that all static
81+
# initializers are called. However, whole_archive_link libraries cannot
82+
# also be target_link_libraries
6983
whole_archive_link(mlir-opt ${LIBS})
70-
target_link_libraries(mlir-opt PRIVATE MLIRIR MLIRMlirOptLib ${LIBS} LLVMSupport)
84+
target_link_libraries(mlir-opt PRIVATE MLIRIR MLIROptMain LLVMSupport LLVMCore LLVMAsmParser)

0 commit comments

Comments
 (0)