diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake --- a/mlir/cmake/modules/AddMLIR.cmake +++ b/mlir/cmake/modules/AddMLIR.cmake @@ -29,12 +29,18 @@ add_dependencies(mlir-doc ${output_file}DocGen) endfunction() -# Declare a library which can be compiled in libMLIR.so -macro(add_mlir_library name) +# Declare an mlir library which can be compiled in libMLIR.so +# In addition to everything that llvm_add_librar accepts, this +# also has the following option: +# EXCLUDE_FROM_LIBMLIR +# Don't include this library in libMLIR.so. This option should be used +# for test libraries, executable-specific libraries, or rarely used libraries +# with large dependencies. +function(add_mlir_library name) cmake_parse_arguments(ARG - "SHARED;INSTALL_WITH_TOOLCHAIN" + "SHARED;INSTALL_WITH_TOOLCHAIN;EXCLUDE_FROM_LIBMLIR" "" - "ADDITIONAL_HEADERS" + "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS" ${ARGN}) set(srcs) if(MSVC_IDE OR XCODE) @@ -82,9 +88,18 @@ # The Xcode generator doesn't handle object libraries correctly. list(APPEND LIBTYPE OBJECT) endif() - set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name}) + # Test libraries and such shouldn't be include in libMLIR.so + if(NOT ARG_EXCLUDE_FROM_LIBMLIR) + set_property(GLOBAL APPEND PROPERTY MLIR_STATIC_LIBS ${name}) + set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS}) + set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) + endif() endif() - llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs}) + + # MLIR libraries uniformly depend on LLVMSupport. Just specify it once here. + list(APPEND ARG_LINK_COMPONENTS Support) + list(APPEND ARG_DEPENDS mlir-generic-headers) + llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs} DEPENDS ${ARG_DEPENDS} LINK_COMPONENTS ${ARG_LINK_COMPONENTS} LINK_LIBS ${ARG_LINK_LIBS}) if(TARGET ${name}) target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS}) @@ -110,7 +125,6 @@ DEPENDS ${name} COMPONENT ${name}) endif() - set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name}) endif() set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name}) @@ -119,7 +133,7 @@ add_custom_target(${name}) endif() set_target_properties(${name} PROPERTIES FOLDER "MLIR libraries") -endmacro(add_mlir_library) +endfunction(add_mlir_library) # Declare the library associated with a dialect. function(add_mlir_dialect_library name) @@ -138,3 +152,38 @@ set_property(GLOBAL APPEND PROPERTY MLIR_TRANSLATION_LIBS ${name}) add_mlir_library(${ARGV} DEPENDS mlir-headers) endfunction(add_mlir_translation_library) + + +# Verification tools to aid debugging. +function(mlir_check_link_libraries name) + if(TARGET ${name}) + get_target_property(libs ${name} LINK_LIBRARIES) + # message("${name} libs are: ${libs}") + set(linking_llvm 0) + foreach(lib ${libs}) + if(lib) + if(${lib} MATCHES "^LLVM$") + set(linking_llvm 1) + endif() + if((${lib} MATCHES "^LLVM.+") AND ${linking_llvm}) + # This will almost always cause execution problems, since the + # same symbol might be loaded from 2 separate libraries. This + # often comes from referring to an LLVM library target + # explicitly in target_link_libraries() + message("WARNING: ${l} links LLVM and ${lib}!") + endif() + endif() + endforeach() + endif() +endfunction(mlir_check_link_libraries) + +function(mlir_check_all_link_libraries name) + mlir_check_link_libraries(${name}) + if(TARGET ${name}) + get_target_property(libs ${name} LINK_LIBRARIES) + # message("${name} libs are: ${libs}") + foreach(lib ${libs}) + mlir_check_link_libraries(${lib}) + endforeach() + endif() +endfunction(mlir_check_all_link_libraries) diff --git a/mlir/examples/toy/Ch6/CMakeLists.txt b/mlir/examples/toy/Ch6/CMakeLists.txt --- a/mlir/examples/toy/Ch6/CMakeLists.txt +++ b/mlir/examples/toy/Ch6/CMakeLists.txt @@ -4,6 +4,8 @@ set(LLVM_LINK_COMPONENTS Core Support + nativecodegen + OrcJIT ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) diff --git a/mlir/examples/toy/Ch7/CMakeLists.txt b/mlir/examples/toy/Ch7/CMakeLists.txt --- a/mlir/examples/toy/Ch7/CMakeLists.txt +++ b/mlir/examples/toy/Ch7/CMakeLists.txt @@ -4,6 +4,8 @@ set(LLVM_LINK_COMPONENTS Core Support + nativecodegen + OrcJIT ) set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td) diff --git a/mlir/lib/Conversion/AVX512ToLLVM/CMakeLists.txt b/mlir/lib/Conversion/AVX512ToLLVM/CMakeLists.txt --- a/mlir/lib/Conversion/AVX512ToLLVM/CMakeLists.txt +++ b/mlir/lib/Conversion/AVX512ToLLVM/CMakeLists.txt @@ -6,7 +6,10 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + ) target_link_libraries(MLIRAVX512ToLLVM PUBLIC @@ -15,6 +18,4 @@ MLIRLLVMIR MLIRStandardToLLVM MLIRTransforms - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Conversion/AffineToStandard/CMakeLists.txt b/mlir/lib/Conversion/AffineToStandard/CMakeLists.txt --- a/mlir/lib/Conversion/AffineToStandard/CMakeLists.txt +++ b/mlir/lib/Conversion/AffineToStandard/CMakeLists.txt @@ -6,7 +6,10 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + ) target_link_libraries( MLIRAffineToStandard PUBLIC @@ -16,6 +19,4 @@ MLIRStandardOps MLIRTransforms MLIRIR - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Conversion/GPUToCUDA/CMakeLists.txt b/mlir/lib/Conversion/GPUToCUDA/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToCUDA/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToCUDA/CMakeLists.txt @@ -9,9 +9,9 @@ if (MLIR_CUDA_CONVERSIONS_ENABLED) list(APPEND SOURCES "ConvertKernelFuncToCubin.cpp") set(NVPTX_LIBS - LLVMNVPTXCodeGen - LLVMNVPTXDesc - LLVMNVPTXInfo + NVPTXCodeGen + NVPTXDesc + NVPTXInfo ) endif() @@ -20,13 +20,14 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + MC + ${NVPTX_LIBS} + ) target_link_libraries(MLIRGPUtoCUDATransforms PUBLIC - ${NVPTX_LIBS} - LLVMCore - LLVMMC - LLVMSupport MLIRGPU MLIRIR MLIRLLVMIR diff --git a/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt b/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt @@ -12,7 +12,6 @@ target_link_libraries(MLIRGPUtoNVVMTransforms PUBLIC - LLVMSupport MLIRGPU MLIRLLVMIR MLIRNVVMIR diff --git a/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt b/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt @@ -6,7 +6,6 @@ ) target_link_libraries(MLIRGPUtoROCDLTransforms PUBLIC - LLVMSupport MLIRGPU MLIRLLVMIR MLIRROCDLIR diff --git a/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt b/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToVulkan/CMakeLists.txt @@ -18,5 +18,4 @@ MLIRSupport MLIRTransforms MLIRTranslation - LLVMSupport ) diff --git a/mlir/lib/Conversion/LinalgToLLVM/CMakeLists.txt b/mlir/lib/Conversion/LinalgToLLVM/CMakeLists.txt --- a/mlir/lib/Conversion/LinalgToLLVM/CMakeLists.txt +++ b/mlir/lib/Conversion/LinalgToLLVM/CMakeLists.txt @@ -6,7 +6,10 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + ) target_link_libraries(MLIRLinalgToLLVM PUBLIC @@ -19,6 +22,4 @@ MLIRStandardToLLVM MLIRVectorToLLVM MLIRTransforms - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Conversion/LoopToStandard/CMakeLists.txt b/mlir/lib/Conversion/LoopToStandard/CMakeLists.txt --- a/mlir/lib/Conversion/LoopToStandard/CMakeLists.txt +++ b/mlir/lib/Conversion/LoopToStandard/CMakeLists.txt @@ -6,12 +6,13 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + ) target_link_libraries( MLIRLoopToStandard PUBLIC MLIRLoopOps MLIRTransforms - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Conversion/LoopsToGPU/CMakeLists.txt b/mlir/lib/Conversion/LoopsToGPU/CMakeLists.txt --- a/mlir/lib/Conversion/LoopsToGPU/CMakeLists.txt +++ b/mlir/lib/Conversion/LoopsToGPU/CMakeLists.txt @@ -19,5 +19,4 @@ MLIRStandardOps MLIRSupport MLIRTransforms - LLVMSupport ) diff --git a/mlir/lib/Conversion/StandardToLLVM/CMakeLists.txt b/mlir/lib/Conversion/StandardToLLVM/CMakeLists.txt --- a/mlir/lib/Conversion/StandardToLLVM/CMakeLists.txt +++ b/mlir/lib/Conversion/StandardToLLVM/CMakeLists.txt @@ -6,12 +6,13 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + ) target_link_libraries( MLIRStandardToLLVM PUBLIC MLIRLLVMIR MLIRTransforms - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt b/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt --- a/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt +++ b/mlir/lib/Conversion/VectorToLLVM/CMakeLists.txt @@ -6,7 +6,10 @@ DEPENDS MLIRConversionPassIncGen -) + + LINK_COMPONENTS + Core + ) target_link_libraries(MLIRVectorToLLVM PUBLIC @@ -14,6 +17,4 @@ MLIRStandardToLLVM MLIRVector MLIRTransforms - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Conversion/VectorToLoops/CMakeLists.txt b/mlir/lib/Conversion/VectorToLoops/CMakeLists.txt --- a/mlir/lib/Conversion/VectorToLoops/CMakeLists.txt +++ b/mlir/lib/Conversion/VectorToLoops/CMakeLists.txt @@ -3,7 +3,10 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/VectorToLoops -) + + LINK_COMPONENTS + Core + ) target_link_libraries(MLIRVectorToLoops PUBLIC @@ -11,6 +14,4 @@ MLIRAffineEDSC MLIRLLVMIR MLIRTransforms - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/Dialect/AVX512/CMakeLists.txt b/mlir/lib/Dialect/AVX512/CMakeLists.txt --- a/mlir/lib/Dialect/AVX512/CMakeLists.txt +++ b/mlir/lib/Dialect/AVX512/CMakeLists.txt @@ -12,5 +12,4 @@ MLIRIR MLIRSideEffects MLIRVectorToLLVM - LLVMSupport ) diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt --- a/mlir/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/lib/Dialect/GPU/CMakeLists.txt @@ -25,5 +25,4 @@ MLIRStandardOps MLIRSupport MLIRTransformUtils - LLVMSupport ) diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt --- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt +++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt @@ -9,15 +9,16 @@ DEPENDS MLIRLLVMOpsIncGen MLIRLLVMConversionsIncGen - ) + + LINK_COMPONENTS + AsmParser + BitReader + BitWriter + Core + FrontendOpenMP +) target_link_libraries(MLIRLLVMIR PUBLIC - LLVMAsmParser - LLVMBitReader - LLVMBitWriter - LLVMCore - LLVMSupport - LLVMFrontendOpenMP MLIRCallInterfaces MLIRControlFlowInterfaces MLIROpenMP @@ -35,15 +36,16 @@ DEPENDS MLIRLLVMAVX512IncGen MLIRLLVMAVX512ConversionsIncGen + + LINK_COMPONENTS + AsmParser + Core ) target_link_libraries(MLIRLLVMAVX512 PUBLIC - LLVMAsmParser MLIRIR MLIRLLVMIR MLIRSideEffects - LLVMSupport - LLVMCore ) add_mlir_dialect_library(MLIRNVVMIR @@ -55,15 +57,16 @@ DEPENDS MLIRNVVMOpsIncGen MLIRNVVMConversionsIncGen + + LINK_COMPONENTS + AsmParser + Core ) target_link_libraries(MLIRNVVMIR PUBLIC - LLVMAsmParser MLIRIR MLIRLLVMIR MLIRSideEffects - LLVMSupport - LLVMCore ) add_mlir_dialect_library(MLIRROCDLIR @@ -75,12 +78,13 @@ DEPENDS MLIRROCDLOpsIncGen MLIRROCDLConversionsIncGen + + LINK_COMPONENTS + AsmParser + Core ) target_link_libraries(MLIRROCDLIR PUBLIC - LLVMAsmParser - LLVMCore - LLVMSupport MLIRIR MLIRSideEffects ) diff --git a/mlir/lib/Dialect/Linalg/Analysis/CMakeLists.txt b/mlir/lib/Dialect/Linalg/Analysis/CMakeLists.txt --- a/mlir/lib/Dialect/Linalg/Analysis/CMakeLists.txt +++ b/mlir/lib/Dialect/Linalg/Analysis/CMakeLists.txt @@ -13,5 +13,4 @@ MLIRIR MLIRLinalgOps MLIRStandardOps - LLVMSupport ) diff --git a/mlir/lib/Dialect/Linalg/EDSC/CMakeLists.txt b/mlir/lib/Dialect/Linalg/EDSC/CMakeLists.txt --- a/mlir/lib/Dialect/Linalg/EDSC/CMakeLists.txt +++ b/mlir/lib/Dialect/Linalg/EDSC/CMakeLists.txt @@ -17,5 +17,4 @@ MLIRLinalgOps MLIRLoopOps MLIRStandardOps - LLVMSupport ) diff --git a/mlir/lib/Dialect/LoopOps/CMakeLists.txt b/mlir/lib/Dialect/LoopOps/CMakeLists.txt --- a/mlir/lib/Dialect/LoopOps/CMakeLists.txt +++ b/mlir/lib/Dialect/LoopOps/CMakeLists.txt @@ -16,7 +16,6 @@ MLIRLoopLikeInterface MLIRSideEffects MLIRStandardOps - LLVMSupport ) add_subdirectory(Transforms) diff --git a/mlir/lib/Dialect/LoopOps/Transforms/CMakeLists.txt b/mlir/lib/Dialect/LoopOps/Transforms/CMakeLists.txt --- a/mlir/lib/Dialect/LoopOps/Transforms/CMakeLists.txt +++ b/mlir/lib/Dialect/LoopOps/Transforms/CMakeLists.txt @@ -17,5 +17,4 @@ MLIRLoopOps MLIRStandardOps MLIRSupport - LLVMSupport ) diff --git a/mlir/lib/Dialect/Shape/CMakeLists.txt b/mlir/lib/Dialect/Shape/CMakeLists.txt --- a/mlir/lib/Dialect/Shape/CMakeLists.txt +++ b/mlir/lib/Dialect/Shape/CMakeLists.txt @@ -13,5 +13,4 @@ MLIRInferTypeOpInterface MLIRIR MLIRSideEffects - LLVMSupport ) diff --git a/mlir/lib/Dialect/StandardOps/CMakeLists.txt b/mlir/lib/Dialect/StandardOps/CMakeLists.txt --- a/mlir/lib/Dialect/StandardOps/CMakeLists.txt +++ b/mlir/lib/Dialect/StandardOps/CMakeLists.txt @@ -17,5 +17,4 @@ MLIRIR MLIRSideEffects MLIRViewLikeInterface - LLVMSupport ) diff --git a/mlir/lib/ExecutionEngine/CMakeLists.txt b/mlir/lib/ExecutionEngine/CMakeLists.txt --- a/mlir/lib/ExecutionEngine/CMakeLists.txt +++ b/mlir/lib/ExecutionEngine/CMakeLists.txt @@ -5,41 +5,56 @@ OptUtils.cpp ) -llvm_map_components_to_libnames(outlibs "nativecodegen" "IPO") add_mlir_library(MLIRExecutionEngine ExecutionEngine.cpp OptUtils.cpp + EXCLUDE_FROM_LIBMLIR + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/ExecutionEngine + + LINK_COMPONENTS + Core + ExecutionEngine + Object + OrcJIT + JITLink + Analysis + AggressiveInstCombine + InstCombine + MC + ScalarOpts + Target + Vectorize + TransformUtils + nativecodegen + IPO ) target_link_libraries(MLIRExecutionEngine PUBLIC MLIRLLVMIR MLIRTargetLLVMIR - LLVMExecutionEngine - LLVMObject - LLVMOrcJIT - LLVMJITLink - LLVMSupport - LLVMAnalysis - LLVMAggressiveInstCombine - LLVMInstCombine - LLVMMC - LLVMScalarOpts - LLVMTarget - LLVMVectorize - LLVMTransformUtils - - ${outlibs}) + ) -add_llvm_library(mlir_c_runner_utils SHARED CRunnerUtils.cpp) +add_mlir_library(mlir_c_runner_utils + SHARED + CRunnerUtils.cpp + EXCLUDE_FROM_LIBMLIR + ) set_property(TARGET mlir_c_runner_utils PROPERTY CXX_STANDARD 11) -add_llvm_library(mlir_c_runner_utils_static CRunnerUtils.cpp) + +add_mlir_library(mlir_c_runner_utils_static + CRunnerUtils.cpp + EXCLUDE_FROM_LIBMLIR + ) set_property(TARGET mlir_c_runner_utils_static PROPERTY CXX_STANDARD 11) target_compile_definitions(mlir_c_runner_utils PRIVATE mlir_c_runner_utils_EXPORTS) -add_llvm_library(mlir_runner_utils SHARED RunnerUtils.cpp) +add_mlir_library(mlir_runner_utils + SHARED + RunnerUtils.cpp + ) target_link_libraries(mlir_runner_utils PUBLIC mlir_c_runner_utils_static diff --git a/mlir/lib/Pass/CMakeLists.txt b/mlir/lib/Pass/CMakeLists.txt --- a/mlir/lib/Pass/CMakeLists.txt +++ b/mlir/lib/Pass/CMakeLists.txt @@ -9,4 +9,4 @@ PUBLIC MLIRAnalysis MLIRIR - LLVMSupport) + ) diff --git a/mlir/lib/Support/CMakeLists.txt b/mlir/lib/Support/CMakeLists.txt --- a/mlir/lib/Support/CMakeLists.txt +++ b/mlir/lib/Support/CMakeLists.txt @@ -13,10 +13,12 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Support + + LINK_COMPONENTS + Support ) target_link_libraries(MLIRSupport PUBLIC - LLVMSupport ${LLVM_PTHREAD_LIB}) add_mlir_library(MLIROptLib @@ -24,18 +26,28 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Support + + LINK_COMPONENTS + Support ) target_link_libraries(MLIROptLib PUBLIC MLIRPass MLIRParser - LLVMSupport MLIRSupport ) -add_llvm_library(MLIRJitRunner +add_mlir_library(MLIRJitRunner JitRunner.cpp -) + + EXCLUDE_FROM_LIBMLIR + + LINK_COMPONENTS + Core + OrcJIT + JITLink + Support + ) target_link_libraries(MLIRJitRunner PUBLIC MLIRExecutionEngine @@ -46,6 +58,4 @@ MLIRTransforms MLIRStandardToLLVM MLIRSupport - LLVMCore - LLVMSupport ) diff --git a/mlir/lib/TableGen/CMakeLists.txt b/mlir/lib/TableGen/CMakeLists.txt --- a/mlir/lib/TableGen/CMakeLists.txt +++ b/mlir/lib/TableGen/CMakeLists.txt @@ -1,4 +1,8 @@ -add_llvm_library(LLVMMLIRTableGen +# This library is unusual, since mlir-tblgen depends on it. +# For non-obvious reasons, linking mlir-tblgen fails with +# LLVM_BUILD_LLVM_DYLIB and LLVM_LINK_LLVM_DYLIB unless +# DISABLE_LLVM_LINK_LLVM_DYLIB is set. +llvm_add_library(LLVMMLIRTableGen STATIC Argument.cpp Attribute.cpp Constraint.cpp @@ -15,11 +19,15 @@ SideEffects.cpp Successor.cpp Type.cpp - + + DISABLE_LLVM_LINK_LLVM_DYLIB + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/TableGen + + LINK_COMPONENTS + TableGen + Demangle ) -target_link_libraries(LLVMMLIRTableGen - PUBLIC - LLVMSupport - LLVMTableGen) + +mlir_check_all_link_libraries(LLVMMLIRTableGen) diff --git a/mlir/lib/Target/CMakeLists.txt b/mlir/lib/Target/CMakeLists.txt --- a/mlir/lib/Target/CMakeLists.txt +++ b/mlir/lib/Target/CMakeLists.txt @@ -6,15 +6,16 @@ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR DEPENDS intrinsics_gen + + LINK_COMPONENTS + Core + FrontendOpenMP + TransformUtils ) target_link_libraries(MLIRTargetLLVMIRModuleTranslation PUBLIC MLIRLLVMIR MLIRLLVMIRTransforms - LLVMCore - LLVMIRReader - LLVMSupport - LLVMTransformUtils MLIRTranslation ) @@ -23,8 +24,12 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR + DEPENDS MLIRLLVMAVX512ConversionsIncGen + + LINK_COMPONENTS + Core ) target_link_libraries(MLIRTargetAVX512 PUBLIC @@ -40,6 +45,10 @@ ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR + + LINK_COMPONENTS + Core + IRReader ) target_link_libraries(MLIRTargetLLVMIR PUBLIC @@ -53,6 +62,9 @@ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR DEPENDS intrinsics_gen + + LINK_COMPONENTS + Core ) target_link_libraries(MLIRTargetNVVMIR PUBLIC @@ -70,6 +82,8 @@ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR DEPENDS intrinsics_gen + LINK_COMPONENTS + Core ) target_link_libraries(MLIRTargetROCDLIR PUBLIC diff --git a/mlir/lib/Translation/CMakeLists.txt b/mlir/lib/Translation/CMakeLists.txt --- a/mlir/lib/Translation/CMakeLists.txt +++ b/mlir/lib/Translation/CMakeLists.txt @@ -6,7 +6,6 @@ ) target_link_libraries(MLIRTranslation PUBLIC - LLVMSupport MLIRIR MLIRParser ) diff --git a/mlir/test/EDSC/CMakeLists.txt b/mlir/test/EDSC/CMakeLists.txt --- a/mlir/test/EDSC/CMakeLists.txt +++ b/mlir/test/EDSC/CMakeLists.txt @@ -1,3 +1,7 @@ +set(LLVM_LINK_COMPONENTS + Core + Support + ) add_llvm_executable(mlir-edsc-builder-api-test builder-api-test.cpp ) @@ -16,8 +20,6 @@ MLIRStandardOps MLIRTransforms MLIRVector - LLVMCore - LLVMSupport -) + ) target_include_directories(mlir-edsc-builder-api-test PRIVATE ..) diff --git a/mlir/test/SDBM/CMakeLists.txt b/mlir/test/SDBM/CMakeLists.txt --- a/mlir/test/SDBM/CMakeLists.txt +++ b/mlir/test/SDBM/CMakeLists.txt @@ -1,3 +1,8 @@ +set(LLVM_LINK_COMPONENTS + Core + Support + ) + add_llvm_executable(mlir-sdbm-api-test sdbm-api-test.cpp ) @@ -9,8 +14,6 @@ MLIRIR MLIRSDBM MLIRSupport - LLVMCore - LLVMSupport ) target_include_directories(mlir-sdbm-api-test PRIVATE ..) diff --git a/mlir/test/lib/Dialect/Affine/CMakeLists.txt b/mlir/test/lib/Dialect/Affine/CMakeLists.txt --- a/mlir/test/lib/Dialect/Affine/CMakeLists.txt +++ b/mlir/test/lib/Dialect/Affine/CMakeLists.txt @@ -1,13 +1,18 @@ -add_llvm_library(MLIRAffineTransformsTestPasses +add_mlir_library(MLIRAffineTransformsTestPasses TestAffineDataCopy.cpp TestAffineLoopUnswitching.cpp TestLoopPermutation.cpp TestParallelismDetection.cpp TestVectorizationUtils.cpp + EXCLUDE_FROM_LIBMLIR + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Affine ${MLIR_MAIN_INCLUDE_DIR}/mlir/IR + + LINK_COMPONENTS + Core ) target_link_libraries(MLIRAffineTransformsTestPasses PRIVATE diff --git a/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt b/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt --- a/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt +++ b/mlir/test/lib/Dialect/SPIRV/CMakeLists.txt @@ -1,6 +1,8 @@ -add_llvm_library(MLIRSPIRVTestPasses +add_mlir_library(MLIRSPIRVTestPasses TestAvailability.cpp + EXCLUDE_FROM_LIBMLIR + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SPIRV ${MLIR_MAIN_INCLUDE_DIR}/mlir/IR diff --git a/mlir/test/lib/Dialect/Test/CMakeLists.txt b/mlir/test/lib/Dialect/Test/CMakeLists.txt --- a/mlir/test/lib/Dialect/Test/CMakeLists.txt +++ b/mlir/test/lib/Dialect/Test/CMakeLists.txt @@ -12,16 +12,17 @@ mlir_tablegen(TestPatterns.inc -gen-rewriters) add_public_tablegen_target(MLIRTestOpsIncGen) -add_llvm_library(MLIRTestDialect +add_mlir_library(MLIRTestDialect TestDialect.cpp TestPatterns.cpp + EXCLUDE_FROM_LIBMLIR + DEPENDS MLIRTestOpsIncGen ) target_link_libraries(MLIRTestDialect PUBLIC - LLVMSupport MLIRControlFlowInterfaces MLIRDerivedAttributeOpInterface MLIRDialect diff --git a/mlir/test/lib/IR/CMakeLists.txt b/mlir/test/lib/IR/CMakeLists.txt --- a/mlir/test/lib/IR/CMakeLists.txt +++ b/mlir/test/lib/IR/CMakeLists.txt @@ -1,10 +1,10 @@ -add_llvm_library(MLIRTestIR +add_mlir_library(MLIRTestIR TestFunc.cpp TestMatchers.cpp TestSideEffects.cpp TestSymbolUses.cpp - ADDITIONAL_HEADER_DIRS + EXCLUDE_FROM_LIBMLIR ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Dialect/Test) include_directories(${CMAKE_CURRENT_BINARY_DIR}/../Dialect/Test) diff --git a/mlir/test/lib/Pass/CMakeLists.txt b/mlir/test/lib/Pass/CMakeLists.txt --- a/mlir/test/lib/Pass/CMakeLists.txt +++ b/mlir/test/lib/Pass/CMakeLists.txt @@ -1,6 +1,8 @@ -add_llvm_library(MLIRTestPass +add_mlir_library(MLIRTestPass TestPassManager.cpp + EXCLUDE_FROM_LIBMLIR + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Pass ) diff --git a/mlir/test/lib/Transforms/CMakeLists.txt b/mlir/test/lib/Transforms/CMakeLists.txt --- a/mlir/test/lib/Transforms/CMakeLists.txt +++ b/mlir/test/lib/Transforms/CMakeLists.txt @@ -1,4 +1,4 @@ -add_llvm_library(MLIRTestTransforms +add_mlir_library(MLIRTestTransforms TestAllReduceLowering.cpp TestCallGraph.cpp TestConstantFold.cpp @@ -20,6 +20,8 @@ TestVectorToLoopsConversion.cpp TestVectorTransforms.cpp + EXCLUDE_FROM_LIBMLIR + ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Transforms @@ -28,7 +30,7 @@ MLIRTestLinalgMatmulToVectorPatternsIncGen MLIRTestLinalgTransformPatternsIncGen MLIRTestVectorTransformPatternsIncGen -) + ) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Dialect/Test) include_directories(${CMAKE_CURRENT_BINARY_DIR}/../Dialect/Test) diff --git a/mlir/tools/mlir-cpu-runner/CMakeLists.txt b/mlir/tools/mlir-cpu-runner/CMakeLists.txt --- a/mlir/tools/mlir-cpu-runner/CMakeLists.txt +++ b/mlir/tools/mlir-cpu-runner/CMakeLists.txt @@ -1,6 +1,12 @@ +set(LLVM_LINK_COMPONENTS + Core + Support + nativecodegen + ) + add_llvm_tool(mlir-cpu-runner mlir-cpu-runner.cpp -) + ) llvm_update_compile_flags(mlir-cpu-runner) get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) target_link_libraries(mlir-cpu-runner PRIVATE @@ -14,6 +20,4 @@ MLIRParser MLIRTargetLLVMIR MLIRSupport - LLVMCore - LLVMSupport ) diff --git a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt --- a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt +++ b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt @@ -1,3 +1,7 @@ +set(LLVM_LINK_COMPONENTS + Core + Support + ) add_llvm_tool(mlir-linalg-ods-gen mlir-linalg-ods-gen.cpp ) @@ -5,6 +9,4 @@ target_link_libraries(mlir-linalg-ods-gen PRIVATE MLIRParser MLIRSupport - LLVMCore - LLVMSupport ) diff --git a/mlir/tools/mlir-opt/CMakeLists.txt b/mlir/tools/mlir-opt/CMakeLists.txt --- a/mlir/tools/mlir-opt/CMakeLists.txt +++ b/mlir/tools/mlir-opt/CMakeLists.txt @@ -4,6 +4,12 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +set(LLVM_LINK_COMPONENTS + Core + Support + AsmParser + ) + set(LIBS ${dialect_libs} ${conversion_libs} @@ -25,14 +31,13 @@ MLIRSupport MLIRIR MLIROptLib - LLVMSupport - LLVMCore - LLVMAsmParser ) -add_llvm_library(MLIRMlirOptMain +add_mlir_library(MLIRMlirOptMain mlir-opt.cpp -) + + EXCLUDE_FROM_LIBMLIR + ) target_link_libraries(MLIRMlirOptMain PUBLIC ${LIBS} @@ -44,3 +49,5 @@ llvm_update_compile_flags(mlir-opt) target_link_libraries(mlir-opt PRIVATE ${LIBS} ${targets_to_link}) + +mlir_check_link_libraries(mlir-opt) diff --git a/mlir/tools/mlir-shlib/CMakeLists.txt b/mlir/tools/mlir-shlib/CMakeLists.txt --- a/mlir/tools/mlir-shlib/CMakeLists.txt +++ b/mlir/tools/mlir-shlib/CMakeLists.txt @@ -8,8 +8,10 @@ return() endif() -get_property(mlir_libs GLOBAL PROPERTY MLIR_ALL_LIBS) +get_property(mlir_libs GLOBAL PROPERTY MLIR_STATIC_LIBS) +get_property(mlir_llvm_link_components GLOBAL PROPERTY MLIR_LLVM_LINK_COMPONENTS) list(REMOVE_DUPLICATES mlir_libs) +list(REMOVE_DUPLICATES mlir_llvm_link_components) foreach (lib ${mlir_libs}) if(XCODE) @@ -19,19 +21,17 @@ else() list(APPEND _OBJECTS $) endif() - list(APPEND _DEPS $) + # libClang needs this, but it causes problems for MLIR (probably + # because we use public library dependencies within MLIR.) + # list(APPEND _DEPS $) 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( + add_mlir_library( MLIR SHARED ${INSTALL_WITH_TOOLCHAIN} @@ -39,6 +39,14 @@ ${_OBJECTS} LINK_LIBS ${_DEPS} + + LINK_COMPONENTS + ${mlir_llvm_link_components} ) - target_link_libraries(MLIR PRIVATE LLVM ${LLVM_PTHREAD_LIB}) + target_link_libraries(MLIR PRIVATE ${LLVM_PTHREAD_LIB}) endif() + +#message("Libraries included in libMLIR.so: ${mlir_libs}") +#message("LLVM Components included in libMLIR.so: ${mlir_llvm_link_components}") + +mlir_check_all_link_libraries(MLIR) diff --git a/mlir/tools/mlir-tblgen/CMakeLists.txt b/mlir/tools/mlir-tblgen/CMakeLists.txt --- a/mlir/tools/mlir-tblgen/CMakeLists.txt +++ b/mlir/tools/mlir-tblgen/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_LINK_COMPONENTS - MLIRTableGen + Demangle Support + TableGen ) add_tablegen(mlir-tblgen MLIR @@ -19,4 +20,10 @@ SPIRVUtilsGen.cpp StructsGen.cpp ) + set_target_properties(mlir-tblgen PROPERTIES FOLDER "Tablegenning") +target_link_libraries(mlir-tblgen + PRIVATE + LLVMMLIRTableGen) + +mlir_check_all_link_libraries(mlir-tblgen) diff --git a/mlir/tools/mlir-translate/CMakeLists.txt b/mlir/tools/mlir-translate/CMakeLists.txt --- a/mlir/tools/mlir-translate/CMakeLists.txt +++ b/mlir/tools/mlir-translate/CMakeLists.txt @@ -1,16 +1,24 @@ +set(LLVM_LINK_COMPONENTS + Support + ) + get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) -set(LIBS + +add_llvm_tool(mlir-translate + mlir-translate.cpp + ) +llvm_update_compile_flags(mlir-translate) +target_link_libraries(mlir-translate + PRIVATE ${dialect_libs} ${translation_libs} + MLIRIR MLIRParser MLIRPass MLIRSPIRV MLIRTranslation MLIRSupport -) -add_llvm_tool(mlir-translate - mlir-translate.cpp -) -llvm_update_compile_flags(mlir-translate) -target_link_libraries(mlir-translate PRIVATE MLIRIR MLIRTranslation ${LIBS} LLVMSupport) + ) + +mlir_check_link_libraries(mlir-translate)