Skip to content

[mlir] Add support for MLIR_LINK_MLIR_DYLIB #119408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ set(MLIR_INSTALL_AGGREGATE_OBJECTS 1 CACHE BOOL

set(MLIR_BUILD_MLIR_C_DYLIB 0 CACHE BOOL "Builds libMLIR-C shared library.")

set(MLIR_LINK_MLIR_DYLIB ${LLVM_LINK_LLVM_DYLIB} CACHE BOOL
"Link tools against libMLIR.so")

configure_file(
${MLIR_MAIN_INCLUDE_DIR}/mlir/Config/mlir-config.h.cmake
${MLIR_INCLUDE_DIR}/mlir/Config/mlir-config.h)
Expand Down
20 changes: 20 additions & 0 deletions mlir/cmake/modules/AddMLIR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,23 @@ function(mlir_check_all_link_libraries name)
endforeach()
endif()
endfunction(mlir_check_all_link_libraries)

# Link target against a list of MLIR libraries. If MLIR_LINK_MLIR_DYLIB is
# enabled, this will link against the MLIR dylib instead of the static
# libraries.
#
# This function should be used instead of target_link_libraries() when linking
# MLIR libraries that are part of the MLIR dylib. For libraries that are not
# part of the dylib (like test libraries), target_link_libraries() should be
# used.
function(mlir_target_link_libraries target type)
Copy link
Collaborator

@joker-eph joker-eph Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document this? (why it is there and when/how it should be used?)

My concern isn't really in the context of this PR, but for people who have to read the cmake code later and try to figure out what's going on.

if (TARGET obj.${target})
target_link_libraries(obj.${target} ${ARGN})
endif()

if (MLIR_LINK_MLIR_DYLIB)
target_link_libraries(${target} ${type} MLIR)
else()
target_link_libraries(${target} ${type} ${ARGN})
endif()
endfunction()
8 changes: 5 additions & 3 deletions mlir/tools/mlir-cpu-runner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ add_mlir_tool(mlir-cpu-runner
EXPORT_SYMBOLS
)
llvm_update_compile_flags(mlir-cpu-runner)
target_link_libraries(mlir-cpu-runner PRIVATE
mlir_target_link_libraries(mlir-cpu-runner PRIVATE
MLIRAnalysis
MLIRBuiltinToLLVMIRTranslation
MLIRExecutionEngine
MLIRIR
MLIRJitRunner
MLIRLLVMDialect
MLIRLLVMToLLVMIRTranslation
MLIRToLLVMIRTranslationRegistration
MLIRParser
MLIRTargetLLVMIRExport
MLIRSupport
)
target_link_libraries(mlir-cpu-runner PRIVATE
MLIRExecutionEngine
MLIRJitRunner
)
7 changes: 2 additions & 5 deletions mlir/tools/mlir-lsp-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ set(LIBS
${conversion_libs}
${dialect_libs}
${extension_libs}
${test_libs}

MLIRAffineAnalysis
MLIRAnalysis
Expand All @@ -56,11 +55,9 @@ set(LIBS

add_mlir_tool(mlir-lsp-server
mlir-lsp-server.cpp

DEPENDS
${LIBS}
)
target_link_libraries(mlir-lsp-server PRIVATE ${LIBS})
mlir_target_link_libraries(mlir-lsp-server PRIVATE ${LIBS})
target_link_libraries(mlir-lsp-server PRIVATE ${test_libs})
llvm_update_compile_flags(mlir-lsp-server)

mlir_check_all_link_libraries(mlir-lsp-server)
7 changes: 3 additions & 4 deletions mlir/tools/mlir-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if(MLIR_INCLUDE_TESTS)
MLIRTestReducer
MLIRTestTransforms
MLIRTilingInterfaceTestPasses
MLIRTosaTestPasses
MLIRVectorTestPasses
MLIRTestVectorToSPIRV
MLIRLLVMTestPasses
Expand All @@ -66,7 +67,6 @@ set(LIBS
${dialect_libs}
${conversion_libs}
${extension_libs}
${test_libs}

MLIRAffineAnalysis
MLIRAnalysis
Expand Down Expand Up @@ -99,11 +99,10 @@ add_mlir_library(MLIRMlirOptMain
add_mlir_tool(mlir-opt
mlir-opt.cpp

DEPENDS
${LIBS}
SUPPORT_PLUGINS
)
target_link_libraries(mlir-opt PRIVATE ${LIBS})
mlir_target_link_libraries(mlir-opt PRIVATE ${LIBS})
target_link_libraries(mlir-opt PRIVATE ${test_libs})
llvm_update_compile_flags(mlir-opt)

mlir_check_all_link_libraries(mlir-opt)
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-parser-fuzzer/bytecode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_llvm_fuzzer(mlir-bytecode-parser-fuzzer
mlir-bytecode-parser-fuzzer.cpp
DUMMY_MAIN DummyParserFuzzer.cpp
)
target_link_libraries(mlir-bytecode-parser-fuzzer
mlir_target_link_libraries(mlir-bytecode-parser-fuzzer
PUBLIC
MLIRIR
MLIRParser
Expand Down
2 changes: 1 addition & 1 deletion mlir/tools/mlir-parser-fuzzer/text/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_llvm_fuzzer(mlir-text-parser-fuzzer
mlir-text-parser-fuzzer.cpp
DUMMY_MAIN DummyParserFuzzer.cpp
)
target_link_libraries(mlir-text-parser-fuzzer
mlir_target_link_libraries(mlir-text-parser-fuzzer
PUBLIC
MLIRIR
MLIRParser
Expand Down
4 changes: 2 additions & 2 deletions mlir/tools/mlir-query/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ add_mlir_tool(mlir-query
mlir-query.cpp
)
llvm_update_compile_flags(mlir-query)
target_link_libraries(mlir-query
mlir_target_link_libraries(mlir-query
PRIVATE
${dialect_libs}
${test_libs}
MLIRQueryLib
)
target_link_libraries(mlir-query PRIVATE ${test_libs})

mlir_check_link_libraries(mlir-query)
7 changes: 2 additions & 5 deletions mlir/tools/mlir-reduce/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ endif()
set(LIBS
${conversion_libs}
${dialect_libs}
${test_libs}
MLIRDialect
MLIRIR
MLIRPass
Expand All @@ -19,12 +18,10 @@ set(LIBS

add_mlir_tool(mlir-reduce
mlir-reduce.cpp

DEPENDS
${LIBS}
)

target_link_libraries(mlir-reduce PRIVATE ${LIBS})
mlir_target_link_libraries(mlir-reduce PRIVATE ${LIBS})
target_link_libraries(mlir-reduce PRIVATE ${test_libs})
llvm_update_compile_flags(mlir-reduce)

mlir_check_all_link_libraries(mlir-reduce)
5 changes: 1 addition & 4 deletions mlir/tools/mlir-rewrite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ set(LLVM_LINK_COMPONENTS

set(LIBS
${dialect_libs}
${test_libs}

MLIRAffineAnalysis
MLIRAnalysis
Expand All @@ -24,11 +23,9 @@ include_directories(../../../clang/include)
add_mlir_tool(mlir-rewrite
mlir-rewrite.cpp

DEPENDS
${LIBS}
SUPPORT_PLUGINS
)
target_link_libraries(mlir-rewrite PRIVATE ${LIBS})
mlir_target_link_libraries(mlir-rewrite PRIVATE ${LIBS})
llvm_update_compile_flags(mlir-rewrite)

mlir_check_all_link_libraries(mlir-rewrite)
Expand Down
9 changes: 6 additions & 3 deletions mlir/tools/mlir-translate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ add_mlir_tool(mlir-translate
mlir-translate.cpp
)
llvm_update_compile_flags(mlir-translate)
target_link_libraries(mlir-translate
mlir_target_link_libraries(mlir-translate
PRIVATE
${dialect_libs}
${translation_libs}
${test_libs}
MLIRIR
MLIRParser
MLIRPass
MLIRSPIRVDialect
MLIRTranslateLib
MLIRSupport
)
target_link_libraries(mlir-translate
PRIVATE
${translation_libs}
${test_libs}
)

mlir_check_link_libraries(mlir-translate)
Loading