2019-03-30 05:10:12 +00:00
|
|
|
# MLIR project.
|
2021-02-02 19:09:45 +00:00
|
|
|
|
|
|
|
# Check if MLIR is built as a standalone project.
|
|
|
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
project(mlir)
|
|
|
|
cmake_minimum_required(VERSION 3.13.4)
|
|
|
|
|
|
|
|
find_package(LLVM CONFIG REQUIRED)
|
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR})
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
include(AddLLVM)
|
|
|
|
include(TableGen)
|
|
|
|
|
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
|
|
|
|
set(LLVM_MAIN_SRC_DIR ${CMAKE_SOURCE_DIR}/../llvm CACHE PATH
|
|
|
|
"Path to LLVM source tree")
|
|
|
|
set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
|
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h)
|
|
|
|
add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
|
|
|
|
endif()
|
|
|
|
|
2020-04-12 06:29:07 +00:00
|
|
|
set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} )
|
|
|
|
set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include )
|
2019-03-30 05:10:12 +00:00
|
|
|
|
2020-04-12 06:29:07 +00:00
|
|
|
set(MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(MLIR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
|
2021-02-02 19:09:45 +00:00
|
|
|
set(MLIR_TOOLS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
2019-03-30 05:10:12 +00:00
|
|
|
|
2022-01-03 02:25:06 +00:00
|
|
|
if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
|
|
|
|
set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Make sure that our source directory is on the current cmake module path so
|
|
|
|
# that we can include cmake files from this directory.
|
|
|
|
list(INSERT CMAKE_MODULE_PATH 0
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
|
|
|
|
"${LLVM_COMMON_CMAKE_UTILS}/Modules"
|
|
|
|
)
|
2019-03-30 05:10:12 +00:00
|
|
|
|
2020-01-22 00:44:17 +00:00
|
|
|
include(AddMLIR)
|
|
|
|
|
2021-09-25 17:24:55 +00:00
|
|
|
# -BSymbolic is incompatible with TypeID
|
|
|
|
if("${CMAKE_SHARED_LINKER_FLAGS}" MATCHES "-Bsymbolic[^-]")
|
|
|
|
message(FATAL_ERROR " MLIR does not support `-Bsymbolic` (see http://llvm.org/pr51420 ),"
|
|
|
|
" try `-Bsymbolic-functions` instead.")
|
|
|
|
endif()
|
|
|
|
|
2020-11-04 00:06:28 +00:00
|
|
|
# Forbid implicit function declaration: this may lead to subtle bugs and we
|
|
|
|
# don't have a reason to support this.
|
2020-11-05 02:33:51 +00:00
|
|
|
check_c_compiler_flag("-Werror=implicit-function-declaration" C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION)
|
|
|
|
append_if(C_SUPPORTS_WERROR_IMPLICIT_FUNCTION_DECLARATION "-Werror=implicit-function-declaration" CMAKE_C_FLAGS)
|
2020-11-04 00:06:28 +00:00
|
|
|
|
2021-12-08 05:14:01 +00:00
|
|
|
# Forbid mismatch between declaration and definition for class vs struct. This is
|
|
|
|
# harmless on Unix systems, but it'll be a ticking bomb for MSVC/Windows systems
|
|
|
|
# where it creeps into the ABI.
|
|
|
|
check_c_compiler_flag("-Werror=mismatched-tags" C_SUPPORTS_WERROR_MISMATCHED_TAGS)
|
|
|
|
append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_C_FLAGS)
|
|
|
|
append_if(C_SUPPORTS_WERROR_MISMATCHED_TAGS "-Werror=mismatched-tags" CMAKE_CXX_FLAGS)
|
|
|
|
|
Add missing mlir-headers target and add tablegen'd deps to it.
Summary:
Prior to this, "ninja install-mlir-headers" failed with an error indicating
the missing target. Verified that from a clean build, the installed
headers include generated files.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72045
2020-01-01 00:32:41 +00:00
|
|
|
# Installing the headers and docs needs to depend on generating any public
|
|
|
|
# tablegen'd targets.
|
2020-04-24 23:42:07 +00:00
|
|
|
# mlir-generic-headers are dialect-independent.
|
|
|
|
add_custom_target(mlir-generic-headers)
|
|
|
|
set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc")
|
|
|
|
# mlir-headers may be dialect-dependent.
|
Add missing mlir-headers target and add tablegen'd deps to it.
Summary:
Prior to this, "ninja install-mlir-headers" failed with an error indicating
the missing target. Verified that from a clean build, the installed
headers include generated files.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D72045
2020-01-01 00:32:41 +00:00
|
|
|
add_custom_target(mlir-headers)
|
|
|
|
set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
|
2020-04-24 23:42:07 +00:00
|
|
|
add_dependencies(mlir-headers mlir-generic-headers)
|
2019-12-02 17:17:51 +00:00
|
|
|
add_custom_target(mlir-doc)
|
|
|
|
|
2019-06-26 12:16:11 +00:00
|
|
|
# Build the CUDA conversions and run according tests if the NVPTX backend
|
|
|
|
# is available
|
|
|
|
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
|
2021-05-22 14:25:38 +00:00
|
|
|
set(MLIR_ENABLE_CUDA_CONVERSIONS 1)
|
2019-06-26 12:16:11 +00:00
|
|
|
else()
|
2021-05-22 14:25:38 +00:00
|
|
|
set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
|
2019-06-26 12:16:11 +00:00
|
|
|
endif()
|
2020-02-14 09:12:41 +00:00
|
|
|
# TODO: we should use a config.h file like LLVM does
|
2021-05-22 14:25:38 +00:00
|
|
|
add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})
|
2019-06-26 12:16:11 +00:00
|
|
|
|
2020-05-22 21:25:00 +00:00
|
|
|
# Build the ROCm conversions and run according tests if the AMDGPU backend
|
|
|
|
# is available
|
|
|
|
if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
|
2021-05-22 14:25:38 +00:00
|
|
|
set(MLIR_ENABLE_ROCM_CONVERSIONS 1)
|
2020-05-22 21:25:00 +00:00
|
|
|
else()
|
2021-05-22 14:25:38 +00:00
|
|
|
set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
|
2020-05-22 21:25:00 +00:00
|
|
|
endif()
|
2021-05-22 14:25:38 +00:00
|
|
|
add_definitions(-DMLIR_ROCM_CONVERSIONS_ENABLED=${MLIR_ENABLE_ROCM_CONVERSIONS})
|
2020-05-22 21:25:00 +00:00
|
|
|
|
2021-05-24 03:20:17 +00:00
|
|
|
set(MLIR_ENABLE_CUDA_RUNNER 0 CACHE BOOL "Enable building the mlir CUDA runner")
|
2021-05-22 14:25:38 +00:00
|
|
|
set(MLIR_ENABLE_ROCM_RUNNER 0 CACHE BOOL "Enable building the mlir ROCm runner")
|
|
|
|
set(MLIR_ENABLE_SPIRV_CPU_RUNNER 0 CACHE BOOL "Enable building the mlir SPIR-V cpu runner")
|
|
|
|
set(MLIR_ENABLE_VULKAN_RUNNER 0 CACHE BOOL "Enable building the mlir Vulkan runner")
|
2019-07-04 14:49:52 +00:00
|
|
|
|
2020-10-04 22:17:34 +00:00
|
|
|
option(MLIR_INCLUDE_TESTS
|
|
|
|
"Generate build targets for the MLIR unit tests."
|
|
|
|
${LLVM_INCLUDE_TESTS})
|
|
|
|
|
|
|
|
option(MLIR_INCLUDE_INTEGRATION_TESTS
|
|
|
|
"Generate build targets for the MLIR integration tests.")
|
|
|
|
|
2021-10-19 19:22:56 +00:00
|
|
|
set(MLIR_INSTALL_AGGREGATE_OBJECTS 1 CACHE BOOL
|
|
|
|
"Installs object files needed for add_mlir_aggregate to work out of \
|
|
|
|
tree. Package maintainers can disable this to exclude these assets if \
|
|
|
|
not desired. Enabling this will result in object files being written \
|
|
|
|
under lib/objects-{CMAKE_BUILD_TYPE}.")
|
|
|
|
|
[mlir] Add MLIR-C dylib.
Per discussion on discord and various feature requests across bindings (Haskell and Rust bindings authors have asked me directly), we should be building a link-ready MLIR-C dylib which exports the C API and can be used without linking to anything else.
This patch:
* Adds a new MLIR-C aggregate shared library (libMLIR-C.so), which is similar in name and function to libLLVM-C.so.
* It is guarded by the new CMake option MLIR_BUILD_MLIR_C_DYLIB, which has a similar purpose/name to the LLVM_BUILD_LLVM_C_DYLIB option.
* On all platforms, this will work with both static, BUILD_SHARED_LIBS, and libMLIR builds, if supported:
* In static builds: libMLIR-C.so will export the CAPI symbols and statically link all dependencies into itself.
* In BUILD_SHARED_LIBS: libMLIR-C.so will export the CAPI symbols and have dynamic dependencies on implementation shared libraries.
* In libMLIR.so mode: same as static. libMLIR.so was not finished for actual linking use within the project. An eventual relayering so that libMLIR-C.so depends on libMLIR.so is possible but requires first re-engineering the latter to use the aggregate facility.
* On Linux, exported symbols are filtered to only the CAPI. On others (MacOS, Windows), all symbols are exported. A CMake status is printed unless if global visibility is hidden indicating that this has not yet been implemented. The library should still work, but it will be larger and more likely to conflict until fixed. Someone should look at lifting the corresponding support from libLLVM-C.so and adapting. Or, for special uses, just build with `-DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_C_VISIBILITY_PRESET=hidden`.
* Includes fixes to execution engine symbol export macros to enable default visibility. Without this, the advice to use hidden visibility would have resulted in test failures and unusable execution engine support libraries.
Differential Revision: https://reviews.llvm.org/D113731
2021-11-12 05:18:16 +00:00
|
|
|
set(MLIR_BUILD_MLIR_C_DYLIB 0 CACHE BOOL "Builds libMLIR-C shared library.")
|
|
|
|
|
Initial boiler-plate for python bindings.
Summary:
* Native '_mlir' extension module.
* Python mlir/__init__.py trampoline module.
* Lit test that checks a message.
* Uses some cmake configurations that have worked for me in the past but likely needs further elaboration.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D83279
2020-07-07 06:05:46 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Python Bindings Configuration
|
|
|
|
# Requires:
|
|
|
|
# The pybind11 library can be found (set with -DPYBIND_DIR=...)
|
2020-11-24 17:50:18 +00:00
|
|
|
# The python executable is correct (set with -DPython3_EXECUTABLE=...)
|
Initial boiler-plate for python bindings.
Summary:
* Native '_mlir' extension module.
* Python mlir/__init__.py trampoline module.
* Lit test that checks a message.
* Uses some cmake configurations that have worked for me in the past but likely needs further elaboration.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D83279
2020-07-07 06:05:46 +00:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
2021-05-24 03:20:17 +00:00
|
|
|
set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
|
Initial boiler-plate for python bindings.
Summary:
* Native '_mlir' extension module.
* Python mlir/__init__.py trampoline module.
* Lit test that checks a message.
* Uses some cmake configurations that have worked for me in the past but likely needs further elaboration.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D83279
2020-07-07 06:05:46 +00:00
|
|
|
"Enables building of Python bindings.")
|
2021-05-22 14:25:38 +00:00
|
|
|
if(MLIR_ENABLE_BINDINGS_PYTHON)
|
2020-11-21 01:57:46 +00:00
|
|
|
include(MLIRDetectPythonEnv)
|
2021-10-13 02:32:48 +00:00
|
|
|
mlir_configure_python_dev_packages()
|
Initial boiler-plate for python bindings.
Summary:
* Native '_mlir' extension module.
* Python mlir/__init__.py trampoline module.
* Lit test that checks a message.
* Uses some cmake configurations that have worked for me in the past but likely needs further elaboration.
Subscribers: mgorny, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, stephenneuendorffer, Joonsoo, grosul1, Kayjukh, jurahul, msifontes
Tags: #mlir
Differential Revision: https://reviews.llvm.org/D83279
2020-07-07 06:05:46 +00:00
|
|
|
endif()
|
|
|
|
|
2019-03-30 05:10:12 +00:00
|
|
|
include_directories( "include")
|
|
|
|
include_directories( ${MLIR_INCLUDE_DIR})
|
|
|
|
|
2020-03-14 18:41:12 +00:00
|
|
|
# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
|
|
|
|
# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
|
|
|
|
# from another directory like tools
|
2020-10-04 22:17:34 +00:00
|
|
|
add_subdirectory(tools/mlir-tblgen)
|
2021-01-18 10:54:06 +00:00
|
|
|
add_subdirectory(tools/mlir-linalg-ods-gen)
|
2020-03-14 18:41:12 +00:00
|
|
|
|
2019-03-30 05:10:12 +00:00
|
|
|
add_subdirectory(include/mlir)
|
|
|
|
add_subdirectory(lib)
|
2020-08-05 12:36:16 +00:00
|
|
|
# C API needs all dialects for registration, but should be built before tests.
|
|
|
|
add_subdirectory(lib/CAPI)
|
2021-10-14 15:18:28 +00:00
|
|
|
|
2020-05-18 16:44:26 +00:00
|
|
|
if (MLIR_INCLUDE_TESTS)
|
2020-10-04 22:17:34 +00:00
|
|
|
add_definitions(-DMLIR_INCLUDE_TESTS)
|
2021-02-11 01:17:24 +00:00
|
|
|
add_custom_target(MLIRUnitTests)
|
2021-02-04 01:59:08 +00:00
|
|
|
if (EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
|
2021-02-02 19:09:45 +00:00
|
|
|
add_subdirectory(unittests)
|
|
|
|
else()
|
|
|
|
message(WARNING "gtest not found, unittests will not be available")
|
|
|
|
endif()
|
2020-05-18 16:44:26 +00:00
|
|
|
add_subdirectory(test)
|
|
|
|
endif()
|
2020-02-09 03:27:54 +00:00
|
|
|
# Tools needs to come late to ensure that MLIR_ALL_LIBS is populated.
|
|
|
|
# Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
|
2020-10-04 22:17:34 +00:00
|
|
|
add_subdirectory(tools)
|
2021-04-28 20:04:17 +00:00
|
|
|
|
2021-05-22 14:25:38 +00:00
|
|
|
if(MLIR_ENABLE_BINDINGS_PYTHON)
|
2021-04-28 20:04:17 +00:00
|
|
|
# Python sources: built extensions come in via lib/Bindings/Python
|
|
|
|
add_subdirectory(python)
|
|
|
|
endif()
|
2019-04-02 17:02:07 +00:00
|
|
|
|
2020-10-04 22:17:34 +00:00
|
|
|
if( LLVM_INCLUDE_EXAMPLES )
|
2019-04-02 17:02:07 +00:00
|
|
|
add_subdirectory(examples)
|
|
|
|
endif()
|
2019-11-20 05:04:45 +00:00
|
|
|
|
2020-10-04 22:17:34 +00:00
|
|
|
option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs."
|
|
|
|
${LLVM_INCLUDE_DOCS})
|
2020-01-25 17:17:31 +00:00
|
|
|
if (MLIR_INCLUDE_DOCS)
|
|
|
|
add_subdirectory(docs)
|
|
|
|
endif()
|
|
|
|
|
2020-10-04 22:17:34 +00:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
2019-11-20 05:04:45 +00:00
|
|
|
install(DIRECTORY include/mlir include/mlir-c
|
2022-01-16 05:48:30 +00:00
|
|
|
DESTINATION include
|
2019-11-20 05:04:45 +00:00
|
|
|
COMPONENT mlir-headers
|
|
|
|
FILES_MATCHING
|
2020-01-06 09:01:59 +00:00
|
|
|
PATTERN "*.def"
|
2019-11-20 05:04:45 +00:00
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN "*.inc"
|
2019-12-29 17:04:09 +00:00
|
|
|
PATTERN "*.td"
|
2019-11-20 05:04:45 +00:00
|
|
|
PATTERN "LICENSE.TXT"
|
|
|
|
)
|
|
|
|
|
|
|
|
install(DIRECTORY ${MLIR_INCLUDE_DIR}/mlir ${MLIR_INCLUDE_DIR}/mlir-c
|
2022-01-16 05:48:30 +00:00
|
|
|
DESTINATION include
|
2019-11-20 05:04:45 +00:00
|
|
|
COMPONENT mlir-headers
|
|
|
|
FILES_MATCHING
|
2020-01-22 00:44:17 +00:00
|
|
|
PATTERN "*.def"
|
2019-11-20 05:04:45 +00:00
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN "*.gen"
|
|
|
|
PATTERN "*.inc"
|
2020-01-22 00:44:17 +00:00
|
|
|
PATTERN "*.td"
|
2019-11-20 05:04:45 +00:00
|
|
|
PATTERN "CMakeFiles" EXCLUDE
|
|
|
|
PATTERN "config.h" EXCLUDE
|
|
|
|
)
|
|
|
|
|
|
|
|
if (NOT LLVM_ENABLE_IDE)
|
|
|
|
add_llvm_install_targets(install-mlir-headers
|
|
|
|
DEPENDS mlir-headers
|
|
|
|
COMPONENT mlir-headers)
|
|
|
|
endif()
|
|
|
|
endif()
|
2020-01-22 00:44:17 +00:00
|
|
|
|
|
|
|
add_subdirectory(cmake/modules)
|