2020-10-02 05:35:28 +08:00
|
|
|
include(LLVMDistributionSupport)
|
|
|
|
|
2020-01-22 08:44:17 +08:00
|
|
|
function(mlir_tablegen ofn)
|
2020-04-01 02:45:59 +08:00
|
|
|
tablegen(MLIR ${ARGV})
|
2020-01-22 08:44:17 +08:00
|
|
|
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
|
|
|
|
PARENT_SCOPE)
|
2021-02-03 03:09:45 +08:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
2020-01-22 08:44:17 +08:00
|
|
|
endfunction()
|
|
|
|
|
2020-02-27 03:50:03 +08:00
|
|
|
# Declare a dialect in the include directory
|
2020-03-25 02:57:13 +08:00
|
|
|
function(add_mlir_dialect dialect dialect_namespace)
|
2020-02-27 03:50:03 +08:00
|
|
|
set(LLVM_TARGET_DEFINITIONS ${dialect}.td)
|
|
|
|
mlir_tablegen(${dialect}.h.inc -gen-op-decls)
|
|
|
|
mlir_tablegen(${dialect}.cpp.inc -gen-op-defs)
|
2020-10-14 06:07:27 +08:00
|
|
|
mlir_tablegen(${dialect}Types.h.inc -gen-typedef-decls)
|
|
|
|
mlir_tablegen(${dialect}Types.cpp.inc -gen-typedef-defs)
|
2020-03-15 11:33:53 +08:00
|
|
|
mlir_tablegen(${dialect}Dialect.h.inc -gen-dialect-decls -dialect=${dialect_namespace})
|
2021-06-29 06:54:11 +08:00
|
|
|
mlir_tablegen(${dialect}Dialect.cpp.inc -gen-dialect-defs -dialect=${dialect_namespace})
|
2020-02-27 03:50:03 +08:00
|
|
|
add_public_tablegen_target(MLIR${dialect}IncGen)
|
|
|
|
add_dependencies(mlir-headers MLIR${dialect}IncGen)
|
2020-03-25 02:57:13 +08:00
|
|
|
endfunction()
|
2020-02-27 03:50:03 +08:00
|
|
|
|
2020-05-13 14:37:23 +08:00
|
|
|
# Declare a dialect in the include directory
|
|
|
|
function(add_mlir_interface interface)
|
|
|
|
set(LLVM_TARGET_DEFINITIONS ${interface}.td)
|
|
|
|
mlir_tablegen(${interface}.h.inc -gen-op-interface-decls)
|
|
|
|
mlir_tablegen(${interface}.cpp.inc -gen-op-interface-defs)
|
|
|
|
add_public_tablegen_target(MLIR${interface}IncGen)
|
|
|
|
add_dependencies(mlir-generic-headers MLIR${interface}IncGen)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
|
2020-10-05 06:17:34 +08:00
|
|
|
# Generate Documentation
|
2021-04-15 09:04:59 +08:00
|
|
|
function(add_mlir_doc doc_filename output_file output_directory command)
|
2020-03-25 02:57:13 +08:00
|
|
|
set(LLVM_TARGET_DEFINITIONS ${doc_filename}.td)
|
2021-04-15 09:04:59 +08:00
|
|
|
tablegen(MLIR ${output_file}.md ${command} ${ARGN})
|
2020-03-25 02:57:13 +08:00
|
|
|
set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/${output_directory}${output_file}.md)
|
2020-02-27 03:50:03 +08:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_DOC_FILE}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
2020-03-25 02:57:13 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${output_file}.md
|
2020-02-27 03:50:03 +08:00
|
|
|
${GEN_DOC_FILE}
|
2020-03-25 02:57:13 +08:00
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${output_file}.md)
|
|
|
|
add_custom_target(${output_file}DocGen DEPENDS ${GEN_DOC_FILE})
|
|
|
|
add_dependencies(mlir-doc ${output_file}DocGen)
|
2020-02-27 03:50:03 +08:00
|
|
|
endfunction()
|
|
|
|
|
2020-05-05 03:41:43 +08:00
|
|
|
# Declare an mlir library which can be compiled in libMLIR.so
|
2020-10-05 06:17:34 +08:00
|
|
|
# In addition to everything that llvm_add_librar accepts, this
|
2020-05-05 03:41:43 +08:00
|
|
|
# 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
|
2021-07-23 03:57:41 +08:00
|
|
|
"SHARED;INSTALL_WITH_TOOLCHAIN;EXCLUDE_FROM_LIBMLIR;DISABLE_INSTALL"
|
2020-05-05 03:41:43 +08:00
|
|
|
""
|
|
|
|
"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)
|
2020-05-18 14:09:41 +08:00
|
|
|
|
|
|
|
# LINK_COMPONENTS is necessary to allow libLLVM.so to be properly
|
|
|
|
# substituted for individual library dependencies if LLVM_LINK_LLVM_DYLIB
|
|
|
|
# Perhaps this should be in llvm_add_library instead? However, it fails
|
|
|
|
# on libclang-cpp.so
|
|
|
|
get_property(llvm_component_libs GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
|
|
|
|
foreach(lib ${ARG_LINK_LIBS})
|
|
|
|
if(${lib} IN_LIST llvm_component_libs)
|
|
|
|
message(SEND_ERROR "${name} specifies LINK_LIBS ${lib}, but LINK_LIBS cannot be used for LLVM libraries. Please use LINK_COMPONENTS instead.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2020-05-05 03:41:43 +08:00
|
|
|
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})
|
2021-07-23 03:57:41 +08:00
|
|
|
if(NOT ARG_DISABLE_INSTALL)
|
|
|
|
add_mlir_library_install(${name})
|
|
|
|
endif()
|
2020-05-05 03:41:43 +08:00
|
|
|
else()
|
|
|
|
# Add empty "phony" target
|
|
|
|
add_custom_target(${name})
|
|
|
|
endif()
|
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "MLIR libraries")
|
|
|
|
endfunction(add_mlir_library)
|
2020-02-09 11:27:54 +08:00
|
|
|
|
Install the MLIRTableGen static library.
Summary: * This library is special because of its dependencies so seems to have been inadvertently left out of installs.
Reviewers: antiagainst
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81693
2020-06-12 05:01:52 +08:00
|
|
|
# Adds an MLIR library target for installation.
|
|
|
|
# This is usually done as part of add_mlir_library but is broken out for cases
|
|
|
|
# where non-standard library builds can be installed.
|
|
|
|
function(add_mlir_library_install name)
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
2020-10-02 05:35:28 +08:00
|
|
|
get_target_export_arg(${name} MLIR export_to_mlirtargets UMBRELLA mlir-libraries)
|
Install the MLIRTableGen static library.
Summary: * This library is special because of its dependencies so seems to have been inadvertently left out of installs.
Reviewers: antiagainst
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, frgossen, Kayjukh, jurahul, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D81693
2020-06-12 05:01:52 +08:00
|
|
|
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})
|
|
|
|
endfunction()
|
|
|
|
|
2021-07-21 06:53:15 +08:00
|
|
|
# Declare an mlir library which is part of the public C-API.
|
2020-11-09 08:49:36 +08:00
|
|
|
function(add_mlir_public_c_api_library name)
|
|
|
|
add_mlir_library(${name}
|
|
|
|
${ARGN}
|
|
|
|
# NOTE: Generates obj.${name} which is used for shared library building.
|
|
|
|
OBJECT
|
|
|
|
EXCLUDE_FROM_LIBMLIR
|
|
|
|
ADDITIONAL_HEADER_DIRS
|
|
|
|
${MLIR_MAIN_INCLUDE_DIR}/mlir-c
|
|
|
|
)
|
|
|
|
# API libraries compile with hidden visibility and macros that enable
|
|
|
|
# exporting from the DLL. Only apply to the obj lib, which only affects
|
|
|
|
# the exports via a shared library.
|
|
|
|
set_target_properties(obj.${name}
|
|
|
|
PROPERTIES
|
|
|
|
CXX_VISIBILITY_PRESET hidden
|
|
|
|
)
|
|
|
|
target_compile_definitions(obj.${name}
|
|
|
|
PRIVATE
|
|
|
|
-DMLIR_CAPI_BUILDING_LIBRARY=1
|
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
2020-02-27 03:50:03 +08:00
|
|
|
# Declare the library associated with a dialect.
|
|
|
|
function(add_mlir_dialect_library name)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
|
2020-04-25 07:42:07 +08:00
|
|
|
add_mlir_library(${ARGV} DEPENDS mlir-headers)
|
2020-02-27 03:50:03 +08:00
|
|
|
endfunction(add_mlir_dialect_library)
|
2020-02-27 08:31:14 +08:00
|
|
|
|
|
|
|
# Declare the library associated with a conversion.
|
|
|
|
function(add_mlir_conversion_library name)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name})
|
2020-04-25 07:42:07 +08:00
|
|
|
add_mlir_library(${ARGV} DEPENDS mlir-headers)
|
2020-02-27 08:31:14 +08:00
|
|
|
endfunction(add_mlir_conversion_library)
|
2020-04-11 07:58:39 +08:00
|
|
|
|
|
|
|
# Declare the library associated with a translation.
|
|
|
|
function(add_mlir_translation_library name)
|
|
|
|
set_property(GLOBAL APPEND PROPERTY MLIR_TRANSLATION_LIBS ${name})
|
2020-04-25 07:42:07 +08:00
|
|
|
add_mlir_library(${ARGV} DEPENDS mlir-headers)
|
2020-04-11 07:58:39 +08:00
|
|
|
endfunction(add_mlir_translation_library)
|
2020-05-05 03:41:43 +08:00
|
|
|
|
|
|
|
# Verification tools to aid debugging.
|
|
|
|
function(mlir_check_link_libraries name)
|
|
|
|
if(TARGET ${name})
|
2020-08-14 14:28:01 +08:00
|
|
|
get_target_property(type ${name} TYPE)
|
|
|
|
if (${type} STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
get_target_property(libs ${name} INTERFACE_LINK_LIBRARIES)
|
|
|
|
else()
|
|
|
|
get_target_property(libs ${name} LINK_LIBRARIES)
|
|
|
|
endif()
|
2020-05-05 03:41:43 +08:00
|
|
|
# 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()
|
2020-05-17 13:46:57 +08:00
|
|
|
message("WARNING: ${name} links LLVM and ${lib}!")
|
2020-05-05 03:41:43 +08:00
|
|
|
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)
|