2019-10-30 01:57:56 +08:00
|
|
|
# Path to LLVM source folder.
|
2020-01-07 04:59:19 +08:00
|
|
|
if(DEFINED ENV{LLVM_PROJ_SRC})
|
|
|
|
set(LLVM_PROJ_SRC $ENV{LLVM_PROJ_SRC})
|
|
|
|
if(EXISTS ${LLVM_PROJ_SRC})
|
|
|
|
message(STATUS "LLVM_PROJ_SRC " ${LLVM_PROJ_SRC})
|
2019-10-09 07:25:59 +08:00
|
|
|
else()
|
2020-01-07 04:59:19 +08:00
|
|
|
message(FATAL_ERROR "The path specified by LLVM_PROJ_SRC does not exist: "
|
|
|
|
${LLVM_PROJ_SRC})
|
2019-10-09 07:25:59 +08:00
|
|
|
endif()
|
|
|
|
else()
|
2020-01-07 04:59:19 +08:00
|
|
|
message(FATAL_ERROR "env variable LLVM_PROJ_SRC not set")
|
2019-10-09 07:25:59 +08:00
|
|
|
endif()
|
|
|
|
|
2019-10-30 01:57:56 +08:00
|
|
|
# Path to LLVM build folder
|
2020-01-07 04:59:19 +08:00
|
|
|
if(DEFINED ENV{LLVM_PROJ_BUILD})
|
|
|
|
set(LLVM_PROJ_BUILD $ENV{LLVM_PROJ_BUILD})
|
|
|
|
if(EXISTS ${LLVM_PROJ_BUILD})
|
|
|
|
message(STATUS "LLVM_PROJ_BUILD " ${LLVM_PROJ_BUILD})
|
2019-10-30 01:57:56 +08:00
|
|
|
else()
|
2020-01-07 04:59:19 +08:00
|
|
|
message(FATAL_ERROR "The path specified by LLVM_PROJ_BUILD does not exist: "
|
|
|
|
${LLVM_PROJ_BUILD})
|
2019-10-30 01:57:56 +08:00
|
|
|
endif()
|
2019-10-09 07:25:59 +08:00
|
|
|
else()
|
2020-01-07 04:59:19 +08:00
|
|
|
message(FATAL_ERROR "env variable LLVM_PROJ_BUILD not set")
|
2019-10-09 07:25:59 +08:00
|
|
|
endif()
|
|
|
|
|
2019-10-30 01:57:56 +08:00
|
|
|
# LLVM project lib folder
|
2020-01-07 04:59:19 +08:00
|
|
|
set(LLVM_PROJECT_LIB ${LLVM_PROJ_BUILD}/lib)
|
2019-10-30 01:57:56 +08:00
|
|
|
|
|
|
|
# Include paths for MLIR
|
2020-01-07 04:59:19 +08:00
|
|
|
set(LLVM_SRC_INCLUDE_PATH ${LLVM_PROJ_SRC}/llvm/include)
|
|
|
|
set(LLVM_BIN_INCLUDE_PATH ${LLVM_PROJ_BUILD}/include)
|
|
|
|
set(MLIR_SRC_INCLUDE_PATH ${LLVM_PROJ_SRC}/mlir/include)
|
|
|
|
set(MLIR_BIN_INCLUDE_PATH ${LLVM_PROJ_BUILD}/tools/mlir/include)
|
|
|
|
set(MLIR_TOOLS_DIR ${LLVM_PROJ_BUILD}/bin)
|
2019-11-19 08:37:58 +08:00
|
|
|
|
2019-12-22 13:25:02 +08:00
|
|
|
set(ONNF_TOOLS_DIR ${ONNF_BIN_ROOT}/bin)
|
2019-11-19 08:37:58 +08:00
|
|
|
set(ONNF_LIT_TEST_SRC_DIR ${CMAKE_SOURCE_DIR}/test/mlir)
|
|
|
|
set(ONNF_LIT_TEST_BUILD_DIR ${CMAKE_BINARY_DIR}/test/mlir)
|
2019-10-09 07:25:59 +08:00
|
|
|
|
2019-11-19 08:37:58 +08:00
|
|
|
set(
|
2019-11-28 11:56:34 +08:00
|
|
|
MLIR_INCLUDE_PATHS
|
|
|
|
${LLVM_SRC_INCLUDE_PATH};${LLVM_BIN_INCLUDE_PATH};${MLIR_SRC_INCLUDE_PATH};${MLIR_BIN_INCLUDE_PATH}
|
|
|
|
)
|
2019-10-09 07:25:59 +08:00
|
|
|
include_directories(${MLIR_INCLUDE_PATHS})
|
|
|
|
|
2019-11-04 23:58:48 +08:00
|
|
|
# Threading libraries required due to parallel pass execution.
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
2019-11-27 02:55:44 +08:00
|
|
|
function(find_mlir_lib lib)
|
|
|
|
find_library(${lib}
|
2019-11-28 11:56:34 +08:00
|
|
|
NAMES ${lib}
|
|
|
|
PATHS ${LLVM_PROJECT_LIB}
|
|
|
|
NO_DEFAULT_PATH)
|
2019-11-27 02:55:44 +08:00
|
|
|
endfunction(find_mlir_lib)
|
|
|
|
|
|
|
|
find_mlir_lib(MLIRAffineOps)
|
|
|
|
find_mlir_lib(MLIRAffineToStandard)
|
|
|
|
find_mlir_lib(MLIRAnalysis)
|
2019-12-20 00:28:06 +08:00
|
|
|
find_mlir_lib(MLIRDialect)
|
2019-11-27 02:55:44 +08:00
|
|
|
find_mlir_lib(MLIRExecutionEngine)
|
|
|
|
find_mlir_lib(MLIRIR)
|
|
|
|
find_mlir_lib(MLIRLLVMIR)
|
|
|
|
find_mlir_lib(MLIRLoopToStandard)
|
2019-12-23 09:33:33 +08:00
|
|
|
find_mlir_lib(MLIRLoopOps)
|
2019-11-27 02:55:44 +08:00
|
|
|
find_mlir_lib(MLIRParser)
|
|
|
|
find_mlir_lib(MLIRPass)
|
|
|
|
find_mlir_lib(MLIRStandardOps)
|
|
|
|
find_mlir_lib(MLIRStandardToLLVM)
|
|
|
|
find_mlir_lib(MLIRTargetLLVMIR)
|
|
|
|
find_mlir_lib(MLIRTransforms)
|
|
|
|
find_mlir_lib(MLIRTransformUtils)
|
|
|
|
find_mlir_lib(MLIRSupport)
|
|
|
|
find_mlir_lib(MLIROptMain)
|
2019-11-28 11:56:34 +08:00
|
|
|
find_mlir_lib(MLIRTargetLLVMIRModuleTranslation)
|
|
|
|
find_mlir_lib(MLIRTargetLLVMIR)
|
|
|
|
find_mlir_lib(MLIRTransformUtils)
|
|
|
|
find_mlir_lib(MLIRTranslation)
|
2019-11-27 08:29:18 +08:00
|
|
|
find_mlir_lib(MLIRVectorOps)
|
2019-11-27 02:55:44 +08:00
|
|
|
|
|
|
|
find_mlir_lib(LLVMCore)
|
|
|
|
find_mlir_lib(LLVMSupport)
|
|
|
|
find_mlir_lib(LLVMAsmParser)
|
|
|
|
find_mlir_lib(LLVMBinaryFormat)
|
|
|
|
find_mlir_lib(LLVMRemarks)
|
|
|
|
find_mlir_lib(LLVMIRReader)
|
|
|
|
find_mlir_lib(LLVMTransformUtils)
|
|
|
|
find_mlir_lib(LLVMBitstreamReader)
|
2019-11-28 11:56:34 +08:00
|
|
|
find_mlir_lib(LLVMAnalysis)
|
|
|
|
find_mlir_lib(LLVMBitWriter)
|
|
|
|
find_mlir_lib(LLVMBitReader)
|
|
|
|
find_mlir_lib(LLVMMC)
|
|
|
|
find_mlir_lib(LLVMMCParser)
|
|
|
|
find_mlir_lib(LLVMObject)
|
|
|
|
find_mlir_lib(LLVMProfileData)
|
|
|
|
find_mlir_lib(LLVMDemangle)
|
|
|
|
|
2019-11-27 02:55:44 +08:00
|
|
|
|
|
|
|
set(MLIRLibsOnce
|
2019-12-23 09:33:33 +08:00
|
|
|
${LLVMAnalysis}
|
|
|
|
${LLVMAsmParser}
|
|
|
|
${LLVMBinaryFormat}
|
|
|
|
${LLVMBitReader}
|
|
|
|
${LLVMBitstreamReader}
|
|
|
|
${LLVMBitWriter}
|
|
|
|
${LLVMCore}
|
|
|
|
${LLVMIRReader}
|
|
|
|
${LLVMMC}
|
|
|
|
${LLVMMCParser}
|
|
|
|
${LLVMObject}
|
|
|
|
${LLVMRemarks}
|
|
|
|
${LLVMSupport}
|
|
|
|
${LLVMTransformUtils}
|
|
|
|
${LLVMProfileData}
|
|
|
|
${LLVMDemangle}
|
|
|
|
${MLIRAffineOps}
|
|
|
|
${MLIRAffineToStandard}
|
|
|
|
${MLIRAnalysis}
|
|
|
|
${MLIRDialect}
|
|
|
|
${MLIRExecutionEngine}
|
|
|
|
${MLIRIR}
|
|
|
|
${MLIRLLVMIR}
|
|
|
|
${MLIRLoopToStandard}
|
|
|
|
${MLIRLoopOps}
|
|
|
|
${MLIROptMain}
|
|
|
|
${MLIRParser}
|
|
|
|
${MLIRPass}
|
|
|
|
${MLIRStandardOps}
|
|
|
|
${MLIRStandardToLLVM}
|
|
|
|
${MLIRSupport}
|
|
|
|
${MLIRTargetLLVMIR}
|
|
|
|
${MLIRTargetLLVMIRModuleTranslation}
|
|
|
|
${MLIRTransforms}
|
|
|
|
${MLIRTransformUtils}
|
|
|
|
${MLIRTranslation})
|
2019-11-27 02:55:44 +08:00
|
|
|
|
|
|
|
set(MLIRLibs
|
|
|
|
${MLIRLibsOnce}
|
|
|
|
${MLIRLibsOnce}
|
|
|
|
Threads::Threads)
|
|
|
|
|
|
|
|
set(MLIRWholeArchiveLibs
|
2019-12-24 00:40:15 +08:00
|
|
|
MLIRAffineToStandard
|
|
|
|
MLIRAffineOps
|
|
|
|
MLIRLLVMIR
|
|
|
|
MLIRStandardOps
|
|
|
|
MLIRStandardToLLVM
|
|
|
|
MLIRTransforms
|
|
|
|
MLIRLoopToStandard
|
|
|
|
MLIRVectorOps
|
|
|
|
MLIRLoopOps)
|
2019-10-09 07:25:59 +08:00
|
|
|
|
2019-11-19 08:37:58 +08:00
|
|
|
function(whole_archive_link target lib_dir)
|
|
|
|
get_property(link_flags TARGET ${target} PROPERTY LINK_FLAGS)
|
2019-11-13 02:37:46 +08:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
2019-12-23 15:09:11 +08:00
|
|
|
set(link_flags "${link_flags} -L${lib_dir} ")
|
2019-11-19 08:37:58 +08:00
|
|
|
foreach(LIB ${ARGN})
|
|
|
|
string(CONCAT link_flags ${link_flags}
|
2019-12-24 00:40:15 +08:00
|
|
|
"-Wl,-force_load, ${lib_dir}/lib${LIB}.a ")
|
2019-11-19 08:37:58 +08:00
|
|
|
endforeach(LIB)
|
2019-11-13 02:37:46 +08:00
|
|
|
elseif(MSVC)
|
2019-11-19 08:37:58 +08:00
|
|
|
foreach(LIB ${ARGN})
|
2019-11-13 02:37:46 +08:00
|
|
|
string(CONCAT link_flags ${link_flags} "/WHOLEARCHIVE:${LIB} ")
|
2019-11-19 08:37:58 +08:00
|
|
|
endforeach(LIB)
|
2019-11-13 02:37:46 +08:00
|
|
|
else()
|
2019-11-19 08:37:58 +08:00
|
|
|
set(link_flags "${link_flags} -L${lib_dir} -Wl,--whole-archive,")
|
|
|
|
foreach(LIB ${ARGN})
|
2019-11-13 02:37:46 +08:00
|
|
|
string(CONCAT link_flags ${link_flags} "-l${LIB},")
|
2019-11-19 08:37:58 +08:00
|
|
|
endforeach(LIB)
|
2019-11-13 02:37:46 +08:00
|
|
|
string(CONCAT link_flags ${link_flags} "--no-whole-archive")
|
|
|
|
endif()
|
|
|
|
set_target_properties(${target} PROPERTIES LINK_FLAGS ${link_flags})
|
|
|
|
endfunction(whole_archive_link)
|
|
|
|
|
2019-11-19 08:37:58 +08:00
|
|
|
function(whole_archive_link_mlir target)
|
2020-01-07 04:59:19 +08:00
|
|
|
whole_archive_link(${target} ${LLVM_PROJ_BUILD}/lib ${ARGN})
|
2019-11-19 08:37:58 +08:00
|
|
|
endfunction(whole_archive_link_mlir)
|
|
|
|
|
|
|
|
function(whole_archive_link_onnf target)
|
2019-12-24 00:40:15 +08:00
|
|
|
foreach(lib_target ${ARGN})
|
|
|
|
add_dependencies(${target} ${lib_target})
|
|
|
|
endforeach(lib_target)
|
2019-11-19 08:37:58 +08:00
|
|
|
whole_archive_link(${target} ${CMAKE_BINARY_DIR}/lib ${ARGN})
|
|
|
|
endfunction(whole_archive_link_onnf)
|
|
|
|
|
|
|
|
set(LLVM_CMAKE_DIR
|
2020-01-07 04:59:19 +08:00
|
|
|
"${LLVM_PROJ_BUILD}/lib/cmake/llvm"
|
2019-11-28 11:56:34 +08:00
|
|
|
CACHE PATH "Path to LLVM cmake modules")
|
2019-11-19 08:37:58 +08:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
|
|
|
|
include(AddLLVM)
|
|
|
|
include(TableGen)
|
2019-10-09 07:25:59 +08:00
|
|
|
|
|
|
|
function(onnf_tablegen ofn)
|
|
|
|
tablegen(MLIR
|
2019-11-28 11:56:34 +08:00
|
|
|
${ARGV}
|
|
|
|
"-I${MLIR_SRC_INCLUDE_PATH}"
|
|
|
|
"-I${MLIR_BIN_INCLUDE_PATH}")
|
2019-10-09 07:25:59 +08:00
|
|
|
set(TABLEGEN_OUTPUT
|
2019-11-28 11:56:34 +08:00
|
|
|
${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
|
|
|
|
PARENT_SCOPE)
|
2019-10-09 07:25:59 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Import the pre-built mlir TableGen as an imported exetuable. It is required by
|
|
|
|
# the LLVM TableGen command to have the TableGen target so that changes to the
|
|
|
|
# table gen utility itself can be detected and cause re-compilation of .td file.
|
|
|
|
add_executable(mlir-tblgen IMPORTED)
|
|
|
|
set_property(TARGET mlir-tblgen
|
2020-01-07 04:59:19 +08:00
|
|
|
PROPERTY IMPORTED_LOCATION ${LLVM_PROJ_BUILD}/bin/mlir-tblgen)
|
2019-10-09 07:25:59 +08:00
|
|
|
set(MLIR_TABLEGEN_EXE mlir-tblgen)
|