add_dependencies(mlir-doc ${output_file}DocGen)
endfunction()
-# Declare a library which can be compiled in libMLIR.so
-macro(add_mlir_library name)
- set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
- add_llvm_library(${ARGV})
-endmacro(add_mlir_library)
+# 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;EXCLUDE_FROM_LIBMLIR"
+ ""
+ "ADDITIONAL_HEADERS;DEPENDS;LINK_COMPONENTS;LINK_LIBS"
+ ${ARGN})
+ set(srcs)
+ if(MSVC_IDE OR XCODE)
+ # Add public headers
+ file(RELATIVE_PATH lib_path
+ ${MLIR_SOURCE_DIR}/lib/
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+ if(NOT lib_path MATCHES "^[.][.]")
+ file( GLOB_RECURSE headers
+ ${MLIR_SOURCE_DIR}/include/mlir/${lib_path}/*.h
+ ${MLIR_SOURCE_DIR}/include/mlir/${lib_path}/*.def
+ )
+ set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
+
+ file( GLOB_RECURSE tds
+ ${MLIR_SOURCE_DIR}/include/mlir/${lib_path}/*.td
+ )
+ source_group("TableGen descriptions" FILES ${tds})
+ set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON)
+
+ if(headers OR tds)
+ set(srcs ${headers} ${tds})
+ endif()
+ endif()
+ endif(MSVC_IDE OR XCODE)
+ if(srcs OR ARG_ADDITIONAL_HEADERS)
+ set(srcs
+ ADDITIONAL_HEADERS
+ ${srcs}
+ ${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
+ )
+ endif()
+ if(ARG_SHARED)
+ set(LIBTYPE SHARED)
+ else()
+ # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
+ # so we need to handle it here.
+ if(BUILD_SHARED_LIBS)
+ set(LIBTYPE SHARED)
+ else()
+ set(LIBTYPE STATIC)
+ endif()
+ if(NOT XCODE)
+ # The Xcode generator doesn't handle object libraries correctly.
+ list(APPEND LIBTYPE OBJECT)
+ endif()
+ # 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()
+
+ # 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})
+
+ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+ set(export_to_mlirtargets)
+ if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+ "mlir-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
+ NOT LLVM_DISTRIBUTION_COMPONENTS)
+ set(export_to_mlirtargets EXPORT MLIRTargets)
+ set_property(GLOBAL PROPERTY MLIR_HAS_EXPORTS True)
+ endif()
+
+ install(TARGETS ${name}
+ COMPONENT ${name}
+ ${export_to_mlirtargets}
+ LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ RUNTIME DESTINATION bin)
+
+ if (NOT LLVM_ENABLE_IDE)
+ add_llvm_install_targets(install-${name}
+ DEPENDS ${name}
+ COMPONENT ${name})
+ endif()
+ set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
+ endif()
+ set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name})
+ else()
+ # Add empty "phony" target
+ add_custom_target(${name})
+ endif()
+ set_target_properties(${name} PROPERTIES FOLDER "MLIR libraries")
+endfunction(add_mlir_library)
# Declare the library associated with a dialect.
function(add_mlir_dialect_library name)
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)
set_property(GLOBAL PROPERTY MLIR_CONVERSION_LIBS "@MLIR_CONVERSION_LIBS@")
# Provide all our library targets to users.
-if(EXISTS @MLIR_CONFIG_EXPORTS_FILE@)
- include("@MLIR_CONFIG_EXPORTS_FILE@")
-endif()
+include("@MLIR_CONFIG_EXPORTS_FILE@")
# By creating these targets here, subprojects that depend on MLIR's
# tablegen-generated headers can always depend on these targets whether building
set(LLVM_LINK_COMPONENTS
Core
Support
+ nativecodegen
+ OrcJIT
)
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
set(LLVM_LINK_COMPONENTS
Core
Support
+ nativecodegen
+ OrcJIT
)
set(LLVM_TARGET_DEFINITIONS mlir/ToyCombine.td)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Analysis
- DEPENDS
- mlir-generic-headers
- )
-
-target_link_libraries(MLIRAnalysis
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRCallInterfaces
MLIRControlFlowInterfaces
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Analysis
- DEPENDS
- mlir-generic-headers
- )
-
-target_link_libraries(MLIRLoopAnalysis
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRCallInterfaces
MLIRControlFlowInterfaces
MLIRInferTypeOpInterface
- MLIRLoopOps)
+ MLIRLoopOps
+ )
DEPENDS
MLIRConversionPassIncGen
-)
-target_link_libraries(MLIRAVX512ToLLVM
- PUBLIC
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRAVX512
MLIRLLVMAVX512
MLIRLLVMIR
MLIRStandardToLLVM
MLIRTransforms
- LLVMCore
- LLVMSupport
)
DEPENDS
MLIRConversionPassIncGen
-)
-target_link_libraries(
- MLIRAffineToStandard
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRLoopOps
MLIRPass
MLIRStandardOps
MLIRTransforms
MLIRIR
- LLVMCore
- LLVMSupport
)
if (MLIR_CUDA_CONVERSIONS_ENABLED)
list(APPEND SOURCES "ConvertKernelFuncToCubin.cpp")
set(NVPTX_LIBS
- LLVMNVPTXCodeGen
- LLVMNVPTXDesc
- LLVMNVPTXInfo
+ NVPTXCodeGen
+ NVPTXDesc
+ NVPTXInfo
)
endif()
DEPENDS
MLIRConversionPassIncGen
intrinsics_gen
-)
-target_link_libraries(MLIRGPUtoCUDATransforms
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+ MC
${NVPTX_LIBS}
- LLVMCore
- LLVMMC
- LLVMSupport
+
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRIR
MLIRLLVMIR
DEPENDS
MLIRConversionPassIncGen
MLIRGPUToNVVMIncGen
- )
-target_link_libraries(MLIRGPUtoNVVMTransforms
- PUBLIC
- LLVMSupport
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRLLVMIR
MLIRNVVMIR
DEPENDS
MLIRConversionPassIncGen
MLIRGPUToROCDLIncGen
- )
-target_link_libraries(MLIRGPUtoROCDLTransforms
- PUBLIC
- LLVMSupport
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRLLVMIR
MLIRROCDLIR
DEPENDS
MLIRConversionPassIncGen
MLIRGPUToSPIRVIncGen
- )
-target_link_libraries(MLIRGPUtoSPIRVTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRIR
MLIRPass
DEPENDS
MLIRConversionPassIncGen
- )
-target_link_libraries(MLIRGPUtoVulkanTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRIR
MLIRLLVMIR
MLIRSupport
MLIRTransforms
MLIRTranslation
- LLVMSupport
)
DEPENDS
MLIRConversionPassIncGen
intrinsics_gen
- )
-target_link_libraries(MLIRLinalgToLLVM
- PUBLIC
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRAffineToStandard
MLIREDSC
MLIRIR
MLIRVectorToLLVM
MLIRVectorToLoops
MLIRTransforms
- LLVMCore
- LLVMSupport
)
DEPENDS
MLIRConversionPassIncGen
- )
-target_link_libraries(MLIRLinalgToSPIRVTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRIR
MLIRLinalgOps
MLIRLinalgUtils
DEPENDS
MLIRConversionPassIncGen
-)
-target_link_libraries(
- MLIRLoopToStandard
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRLoopOps
MLIRTransforms
- LLVMCore
- LLVMSupport
)
DEPENDS
MLIRConversionPassIncGen
-)
-target_link_libraries(MLIRLoopsToGPU
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRAffineToStandard
MLIRGPU
MLIRStandardOps
MLIRSupport
MLIRTransforms
- LLVMSupport
)
DEPENDS
MLIRConversionPassIncGen
intrinsics_gen
- )
-target_link_libraries(
- MLIRStandardToLLVM
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRLLVMIR
MLIRTransforms
- LLVMCore
- LLVMSupport
)
DEPENDS
MLIRConversionPassIncGen
- )
-target_link_libraries(MLIRStandardToSPIRVTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRIR
MLIRPass
MLIRSPIRV
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/StandardToStandard
- )
-target_link_libraries(MLIRStandardToStandard
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRPass
MLIRStandardOps
DEPENDS
MLIRConversionPassIncGen
intrinsics_gen
- )
-target_link_libraries(MLIRVectorToLLVM
- PUBLIC
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRLLVMIR
MLIRStandardToLLVM
MLIRVector
MLIRTransforms
- LLVMCore
- LLVMSupport
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Conversion/VectorToLoops
-)
-target_link_libraries(MLIRVectorToLoops
- PUBLIC
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIREDSC
MLIRAffineEDSC
MLIRLLVMIR
MLIRTransforms
- LLVMCore
- LLVMSupport
)
DEPENDS
MLIRAVX512IncGen
- )
-target_link_libraries(MLIRAVX512
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRSideEffects
MLIRVectorToLLVM
- LLVMSupport
)
DEPENDS
MLIRAffineOpsIncGen
- )
-target_link_libraries(MLIRAffineEDSC
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIREDSC
MLIRIR
DEPENDS
MLIRAffineOpsIncGen
- )
-target_link_libraries(MLIRAffineOps
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIREDSC
MLIRIR
MLIRLoopLikeInterface
MLIRAffineOpsIncGen
MLIRAffinePassIncGen
MLIRLoopLikeInterfaceIncGen
- )
-target_link_libraries(MLIRAffineTransforms
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIREDSC
MLIRIR
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Affine
- )
-target_link_libraries(MLIRAffineUtils
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRTransformUtils
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect
- )
-target_link_libraries(MLIRDialect
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
MLIRGPUPassIncGen
MLIRParallelLoopMapperAttrGen
MLIRParallelLoopMapperEnumsGen
- )
-target_link_libraries(MLIRGPU
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIREDSC
MLIRIR
MLIRLLVMIR
MLIRStandardOps
MLIRSupport
MLIRTransformUtils
- LLVMSupport
)
MLIRLLVMOpsIncGen
MLIRLLVMConversionsIncGen
intrinsics_gen
- )
-target_link_libraries(MLIRLLVMIR
- PUBLIC
- LLVMAsmParser
- LLVMBitReader
- LLVMBitWriter
- LLVMCore
- LLVMSupport
- LLVMFrontendOpenMP
+
+ LINK_COMPONENTS
+ AsmParser
+ BitReader
+ BitWriter
+ Core
+ FrontendOpenMP
+
+ LINK_LIBS PUBLIC
MLIRCallInterfaces
MLIRControlFlowInterfaces
MLIROpenMP
MLIRLLVMAVX512IncGen
MLIRLLVMAVX512ConversionsIncGen
intrinsics_gen
- )
-target_link_libraries(MLIRLLVMAVX512
- PUBLIC
- LLVMAsmParser
+
+ LINK_COMPONENTS
+ AsmParser
+ Core
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRLLVMIR
MLIRSideEffects
- LLVMSupport
- LLVMCore
)
add_mlir_dialect_library(MLIRNVVMIR
MLIRNVVMOpsIncGen
MLIRNVVMConversionsIncGen
intrinsics_gen
- )
-target_link_libraries(MLIRNVVMIR
- PUBLIC
- LLVMAsmParser
+
+ LINK_COMPONENTS
+ AsmParser
+ Core
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRLLVMIR
MLIRSideEffects
- LLVMSupport
- LLVMCore
)
add_mlir_dialect_library(MLIRROCDLIR
MLIRROCDLOpsIncGen
MLIRROCDLConversionsIncGen
intrinsics_gen
- )
-target_link_libraries(MLIRROCDLIR
- PUBLIC
- LLVMAsmParser
- LLVMCore
- LLVMSupport
+
+ LINK_COMPONENTS
+ AsmParser
+ Core
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRSideEffects
MLIRVectorToLLVM
DEPENDS
MLIRLLVMPassIncGen
- )
-target_link_libraries(MLIRLLVMIRTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRIR
MLIRLLVMIR
MLIRPass
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Linalg
- )
-target_link_libraries(MLIRLinalgAnalysis
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRIR
MLIRLinalgOps
MLIRStandardOps
- LLVMSupport
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Linalg
- )
-target_link_libraries(MLIRLinalgEDSC
- PUBLIC
+ LINK_LIBS PUBLIC
MLIREDSC
MLIRIR
MLIRAffineOps
MLIRLinalgOps
MLIRLoopOps
MLIRStandardOps
- LLVMSupport
)
MLIRLinalgOpsIncGen
MLIRLinalgStructuredOpsIncGen
MLIRLinalgStructuredOpsInterfaceIncGen
- )
-target_link_libraries(MLIRLinalgOps
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRSideEffects
MLIRViewLikeInterface
DEPENDS
MLIRLinalgPassIncGen
- )
-target_link_libraries(MLIRLinalgTransforms
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRAnalysis
MLIREDSC
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Linalg
- )
-target_link_libraries(MLIRLinalgUtils
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIREDSC
MLIRIR
DEPENDS
MLIRLoopOpsIncGen
- )
-target_link_libraries(MLIRLoopOps
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIREDSC
MLIRIR
MLIRLoopLikeInterface
MLIRSideEffects
MLIRStandardOps
- LLVMSupport
)
add_subdirectory(Transforms)
DEPENDS
MLIRLoopPassIncGen
- )
-target_link_libraries(MLIRLoopOpsTransforms
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRIR
MLIRPass
MLIRLoopOps
MLIRStandardOps
MLIRSupport
- LLVMSupport
)
DEPENDS
MLIROpenMPOpsIncGen
- )
-target_link_libraries(MLIROpenMP
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRQuantOpsIncGen
MLIRQuantPassIncGen
- )
-target_link_libraries(MLIRQuant
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRPass
MLIRSideEffects
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SDBM
-)
-target_link_libraries(MLIRSDBM
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
MLIRSPIRVOpsIncGen
MLIRSPIRVOpUtilsGen
MLIRSPIRVTargetAndABIIncGen
- )
-target_link_libraries(MLIRSPIRV
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRControlFlowInterfaces
MLIRIR
MLIRParser
DEPENDS
MLIRSPIRVSerializationGen
- )
-target_link_libraries(MLIRSPIRVSerialization
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRSPIRV
MLIRSupport
DEPENDS
MLIRSPIRVPassIncGen
- )
-target_link_libraries(MLIRSPIRVTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRPass
MLIRSPIRV
)
DEPENDS
MLIRShapeOpsIncGen
- )
-target_link_libraries(MLIRShape
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRDialect
MLIRInferTypeOpInterface
MLIRIR
MLIRSideEffects
- LLVMSupport
)
DEPENDS
MLIRStandardOpsIncGen
- )
-target_link_libraries(MLIRStandardOps
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRCallInterfaces
MLIRControlFlowInterfaces
MLIREDSC
MLIRIR
MLIRSideEffects
MLIRViewLikeInterface
- LLVMSupport
)
DEPENDS
MLIRVectorOpsIncGen
MLIRVectorTransformPatternsIncGen
- )
-target_link_libraries(MLIRVector
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIREDSC
MLIRIR
MLIRStandardOps
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/EDSC
- )
-target_link_libraries(MLIREDSC
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRIR
MLIRSupport
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/EDSC
- )
-target_link_libraries(MLIREDSCInterface
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRSupport
MLIRParser
+# Exclude these from libMLIR.so because the JIT infrastructure
+# is a big dependency which most don't need.
+
set(LLVM_OPTIONAL_SOURCES
CRunnerUtils.cpp
ExecutionEngine.cpp
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
DEPENDS
intrinsics_gen
- )
-target_link_libraries(MLIRExecutionEngine
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+ ExecutionEngine
+ Object
+ OrcJIT
+ JITLink
+ Analysis
+ AggressiveInstCombine
+ InstCombine
+ MC
+ ScalarOpts
+ Target
+ Vectorize
+ TransformUtils
+ nativecodegen
+ IPO
+
+ LINK_LIBS 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)
-target_link_libraries(mlir_runner_utils
- PUBLIC
+add_mlir_library(mlir_runner_utils
+ SHARED
+ RunnerUtils.cpp
+
+ EXCLUDE_FROM_LIBMLIR
+
+ LINK_LIBS PUBLIC
mlir_c_runner_utils_static
)
target_compile_definitions(mlir_runner_utils PRIVATE mlir_runner_utils_EXPORTS)
MLIRCallInterfacesIncGen
MLIROpAsmInterfacesIncGen
MLIRSymbolInterfacesIncGen
- )
-target_link_libraries(MLIRIR
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRSupport
LLVMSupport
)
DEPENDS
MLIRCallInterfacesIncGen
- )
-target_link_libraries(MLIRCallInterfaces
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRControlFlowInterfacesIncGen
- )
-target_link_libraries(MLIRControlFlowInterfaces
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRDerivedAttributeOpInterfaceIncGen
- )
-target_link_libraries(MLIRDerivedAttributeOpInterface
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRInferTypeOpInterfaceIncGen
- )
-target_link_libraries(MLIRInferTypeOpInterface
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRLoopLikeInterfaceIncGen
- )
-target_link_libraries(MLIRLoopLikeInterface
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRSideEffectOpInterfacesIncGen
- )
-target_link_libraries(MLIRSideEffects
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
DEPENDS
MLIRViewLikeInterfaceIncGen
- )
-target_link_libraries(MLIRViewLikeInterface
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Parser
- DEPENDS
- mlir-generic-headers
- )
-target_link_libraries(MLIRParser
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRIR
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Pass
- )
-target_link_libraries(MLIRPass
- PUBLIC
+
+ DEPENDS
+ mlir-generic-headers
+
+ LINK_LIBS PUBLIC
MLIRAnalysis
MLIRIR
- LLVMSupport)
+ )
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Support
- )
-target_link_libraries(MLIRSupport
- PUBLIC
- LLVMSupport
+
+ LINK_COMPONENTS
+ Support
+
+ LINK_LIBS PUBLIC
${LLVM_PTHREAD_LIB})
add_mlir_library(MLIROptLib
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Support
- )
-target_link_libraries(MLIROptLib
- PUBLIC
+
+ LINK_COMPONENTS
+ Support
+
+ LINK_LIBS PUBLIC
MLIRPass
MLIRParser
- LLVMSupport
MLIRSupport
)
-add_llvm_library(MLIRJitRunner
+# Exclude from libMLIR.so because the JIT infrastructure
+# is a big dependency which most don't need.
+add_mlir_library(MLIRJitRunner
JitRunner.cpp
DEPENDS
intrinsics_gen
-)
-target_link_libraries(MLIRJitRunner
- PUBLIC
+
+ EXCLUDE_FROM_LIBMLIR
+
+ LINK_COMPONENTS
+ Core
+ OrcJIT
+ JITLink
+ Support
+
+ LINK_LIBS PUBLIC
MLIRExecutionEngine
MLIRIR
MLIRParser
MLIRTransforms
MLIRStandardToLLVM
MLIRSupport
- LLVMCore
- LLVMSupport
)
-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
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)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
+
DEPENDS
intrinsics_gen
- )
-target_link_libraries(MLIRTargetLLVMIRModuleTranslation
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+ FrontendOpenMP
+ TransformUtils
+
+ LINK_LIBS PUBLIC
MLIRLLVMIR
MLIRLLVMIRTransforms
- LLVMCore
- LLVMIRReader
- LLVMSupport
- LLVMTransformUtils
MLIRTranslation
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
+
DEPENDS
MLIRLLVMAVX512ConversionsIncGen
- )
-target_link_libraries(MLIRTargetAVX512
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRLLVMAVX512
MLIRLLVMIR
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
- )
-target_link_libraries(MLIRTargetLLVMIR
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+ IRReader
+
+ LINK_LIBS PUBLIC
MLIRTargetLLVMIRModuleTranslation
)
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
+
DEPENDS
intrinsics_gen
- )
-target_link_libraries(MLIRTargetNVVMIR
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRIR
MLIRLLVMIR
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Target/LLVMIR
+
DEPENDS
intrinsics_gen
- )
-target_link_libraries(MLIRTargetROCDLIR
- PUBLIC
+
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRGPU
MLIRIR
MLIRLLVMIR
DEPENDS
MLIRStandardOpsIncGen
MLIRTransformsPassIncGen
- )
-target_link_libraries(MLIRTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRAnalysis
MLIRLoopLikeInterface
DEPENDS
MLIRStandardOpsIncGen
- )
-target_link_libraries(MLIRTransformUtils
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRAnalysis
MLIRLoopAnalysis
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Translation
- )
-target_link_libraries(MLIRTranslation
- PUBLIC
- LLVMSupport
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRParser
)
+set(LLVM_LINK_COMPONENTS
+ Core
+ Support
+ )
add_llvm_executable(mlir-edsc-builder-api-test
builder-api-test.cpp
)
MLIRStandardOps
MLIRTransforms
MLIRVector
- LLVMCore
- LLVMSupport
-)
+ )
target_include_directories(mlir-edsc-builder-api-test PRIVATE ..)
+set(LLVM_LINK_COMPONENTS
+ Core
+ Support
+ )
+
add_llvm_executable(mlir-sdbm-api-test
sdbm-api-test.cpp
)
MLIRIR
MLIRSDBM
MLIRSupport
- LLVMCore
- LLVMSupport
)
target_include_directories(mlir-sdbm-api-test PRIVATE ..)
-add_llvm_library(MLIRAffineTransformsTestPasses
+# Exclude tests from libMLIR.so
+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
- )
-target_link_libraries(MLIRAffineTransformsTestPasses PRIVATE
+ LINK_COMPONENTS
+ Core
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRPass
MLIRAffineTransforms
-add_llvm_library(MLIRSPIRVTestPasses
+# Exclude tests from libMLIR.so
+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
- )
-target_link_libraries(MLIRSPIRVTestPasses PRIVATE
+ LINK_LIBS PUBLIC
MLIRIR
MLIRPass
MLIRSPIRV
mlir_tablegen(TestPatterns.inc -gen-rewriters)
add_public_tablegen_target(MLIRTestOpsIncGen)
-add_llvm_library(MLIRTestDialect
+# Exclude tests from libMLIR.so
+add_mlir_library(MLIRTestDialect
TestDialect.cpp
TestPatterns.cpp
+ EXCLUDE_FROM_LIBMLIR
+
DEPENDS
MLIRTestOpsIncGen
-)
-target_link_libraries(MLIRTestDialect
- PUBLIC
- LLVMSupport
+
+ LINK_LIBS PUBLIC
MLIRControlFlowInterfaces
MLIRDerivedAttributeOpInterface
MLIRDialect
-add_llvm_library(MLIRTestIR
+# Exclude tests from libMLIR.so
+add_mlir_library(MLIRTestIR
TestFunc.cpp
TestMatchers.cpp
TestSideEffects.cpp
TestSymbolUses.cpp
- ADDITIONAL_HEADER_DIRS
- )
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Dialect/Test)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/../Dialect/Test)
+ EXCLUDE_FROM_LIBMLIR
-target_link_libraries(MLIRTestIR
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRPass
MLIRTestDialect
)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Dialect/Test)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/../Dialect/Test)
-add_llvm_library(MLIRTestPass
+# Exclude tests from libMLIR.so
+add_mlir_library(MLIRTestPass
TestPassManager.cpp
+ EXCLUDE_FROM_LIBMLIR
+
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Pass
- )
-target_link_libraries(MLIRTestPass
- PUBLIC
+
+ LINK_LIBS PUBLIC
MLIRIR
MLIRPass
)
-add_llvm_library(MLIRTestTransforms
+# Exclude tests from libMLIR.so
+add_mlir_library(MLIRTestTransforms
TestAllReduceLowering.cpp
TestBufferPlacement.cpp
TestCallGraph.cpp
TestVectorToLoopsConversion.cpp
TestVectorTransforms.cpp
+ EXCLUDE_FROM_LIBMLIR
+
ADDITIONAL_HEADER_DIRS
${MLIR_MAIN_INCLUDE_DIR}/mlir/Transforms
DEPENDS
MLIRStandardOpsIncGen
MLIRTestVectorTransformPatternsIncGen
-)
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Dialect/Test)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/../Dialect/Test)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../DeclarativeTransforms)
-include_directories(${CMAKE_CURRENT_BINARY_DIR}/../DeclarativeTransforms)
-target_link_libraries(MLIRTestTransforms
- PUBLIC
+ LINK_LIBS PUBLIC
MLIRAffineOps
MLIRAnalysis
MLIREDSC
MLIRVectorToLoops
MLIRVector
)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Dialect/Test)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/../Dialect/Test)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../DeclarativeTransforms)
+include_directories(${CMAKE_CURRENT_BINARY_DIR}/../DeclarativeTransforms)
+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
MLIRParser
MLIRTargetLLVMIR
MLIRSupport
- LLVMCore
- LLVMSupport
)
+set(LLVM_LINK_COMPONENTS
+ Core
+ Support
+ )
add_llvm_tool(mlir-linalg-ods-gen
mlir-linalg-ods-gen.cpp
)
target_link_libraries(mlir-linalg-ods-gen PRIVATE
MLIRParser
MLIRSupport
- LLVMCore
- LLVMSupport
)
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}
MLIRSupport
MLIRIR
MLIROptLib
- LLVMSupport
- LLVMCore
- LLVMAsmParser
)
-add_llvm_library(MLIRMlirOptMain
+# Exclude from libMLIR.so because this has static options intended for
+# opt-like tools only.
+add_mlir_library(MLIRMlirOptMain
mlir-opt.cpp
-)
-target_link_libraries(MLIRMlirOptMain
- PUBLIC
+
+ EXCLUDE_FROM_LIBMLIR
+
+ LINK_LIBS
${LIBS}
-)
+ )
add_llvm_tool(mlir-opt
- mlir-opt.cpp
-)
+ mlir-opt.cpp
+ DEPENDS
+ ${LIBS}
+ )
+target_link_libraries(mlir-opt PRIVATE ${LIBS})
llvm_update_compile_flags(mlir-opt)
-target_link_libraries(mlir-opt PRIVATE ${LIBS} ${targets_to_link})
+
+mlir_check_link_libraries(mlir-opt)
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)
else()
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
endif()
- list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>)
+ # libClang needs this, but it causes problems for MLIR (probably
+ # because we use public library dependencies within MLIR.)
+ # 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
+ add_mlir_library(
+ MLIR
SHARED
${INSTALL_WITH_TOOLCHAIN}
-
mlir-shlib.cpp
- )
- target_link_libraries(MLIR PRIVATE LLVM ${LLVM_PTHREAD_LIB})
+ ${_OBJECTS}
+ LINK_LIBS
+ ${_DEPS}
+
+ LINK_COMPONENTS
+ ${mlir_llvm_link_components}
+ )
+ 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)
set(LLVM_LINK_COMPONENTS
- MLIRTableGen
+ Demangle
Support
+ TableGen
)
add_tablegen(mlir-tblgen MLIR
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)
+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)