2020-01-22 08:44:17 +08:00
|
|
|
function(mlir_tablegen ofn)
|
|
|
|
tablegen(MLIR ${ARGV} "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}")
|
|
|
|
set(TABLEGEN_OUTPUT ${TABLEGEN_OUTPUT} ${CMAKE_CURRENT_BINARY_DIR}/${ofn}
|
|
|
|
PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# TODO: This is to handle the current static registration, but should be
|
|
|
|
# factored out a bit.
|
|
|
|
function(whole_archive_link target)
|
[MLIR] Fixes for shared library dependencies.
Summary:
This patch is a step towards enabling BUILD_SHARED_LIBS=on, which
builds most libraries as DLLs instead of statically linked libraries.
The main effect of this is that incremental build times are greatly
reduced, since usually only one library need be relinked in response
to isolated code changes.
The bulk of this patch is fixing incorrect usage of cmake, where library
dependencies are listed under add_dependencies rather than under
target_link_libraries or under the LINK_LIBS tag. Correct usage should be
like this:
add_dependencies(MLIRfoo MLIRfooIncGen)
target_link_libraries(MLIRfoo MLIRlib1 MLIRlib2)
A separate issue is that in cmake, dependencies between static libraries
are automatically included in dependencies. In the above example, if MLIBlib1
depends on MLIRlib2, then it is sufficient to have only MLIRlib1 in the
target_link_libraries. When compiling with shared libraries, it is necessary
to have both MLIRlib1 and MLIRlib2 specified if MLIRfoo uses symbols from both.
Reviewers: mravishankar, antiagainst, nicolasvasilache, vchuravy, inouehrs, mehdi_amini, jdoerfert
Reviewed By: nicolasvasilache, mehdi_amini
Subscribers: Joonsoo, merge_guards_bot, jholewinski, mgorny, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, csigg, arpith-jacob, mgester, lucyrfox, herhut, aartbik, liufengdb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73653
2020-01-01 09:23:01 +08:00
|
|
|
add_dependencies(${target} ${ARGN})
|
2020-01-22 08:44:17 +08:00
|
|
|
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
|
|
|
|
set(link_flags "-L${CMAKE_BINARY_DIR}/lib ")
|
|
|
|
FOREACH(LIB ${ARGN})
|
|
|
|
string(CONCAT link_flags ${link_flags} "-Wl,-force_load ${CMAKE_BINARY_DIR}/lib/lib${LIB}.a ")
|
|
|
|
ENDFOREACH(LIB)
|
|
|
|
elseif(MSVC)
|
|
|
|
FOREACH(LIB ${ARGN})
|
2020-01-26 01:52:46 +08:00
|
|
|
string(CONCAT link_flags ${link_flags} "/WHOLEARCHIVE:${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${LIB}.lib ")
|
2020-01-22 08:44:17 +08:00
|
|
|
ENDFOREACH(LIB)
|
|
|
|
else()
|
|
|
|
set(link_flags "-L${CMAKE_BINARY_DIR}/lib -Wl,--whole-archive,")
|
|
|
|
FOREACH(LIB ${ARGN})
|
|
|
|
string(CONCAT link_flags ${link_flags} "-l${LIB},")
|
|
|
|
ENDFOREACH(LIB)
|
|
|
|
string(CONCAT link_flags ${link_flags} "--no-whole-archive")
|
|
|
|
endif()
|
|
|
|
set_target_properties(${target} PROPERTIES LINK_FLAGS ${link_flags})
|
|
|
|
endfunction(whole_archive_link)
|
2020-02-27 03:50:03 +08:00
|
|
|
|
|
|
|
# Declare a dialect in the include directory
|
|
|
|
function(add_mlir_dialect dialect dialect_doc_filename)
|
|
|
|
set(LLVM_TARGET_DEFINITIONS ${dialect}.td)
|
|
|
|
mlir_tablegen(${dialect}.h.inc -gen-op-decls)
|
|
|
|
mlir_tablegen(${dialect}.cpp.inc -gen-op-defs)
|
|
|
|
add_public_tablegen_target(MLIR${dialect}IncGen)
|
|
|
|
add_dependencies(mlir-headers MLIR${dialect}IncGen)
|
|
|
|
|
|
|
|
# Generate Dialect Documentation
|
|
|
|
set(LLVM_TARGET_DEFINITIONS ${dialect_doc_filename}.td)
|
|
|
|
tablegen(MLIR ${dialect_doc_filename}.md -gen-op-doc "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}")
|
|
|
|
set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/Dialects/${dialect_doc_filename}.md)
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${GEN_DOC_FILE}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/${dialect_doc_filename}.md
|
|
|
|
${GEN_DOC_FILE}
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${dialect_doc_filename}.md)
|
|
|
|
add_custom_target(${dialect_doc_filename}DocGen DEPENDS ${GEN_DOC_FILE})
|
|
|
|
add_dependencies(mlir-doc ${dialect_doc_filename}DocGen)
|
|
|
|
endfunction()
|
|
|
|
|
2020-02-09 11:27:54 +08:00
|
|
|
# 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)
|
|
|
|
|
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-02-09 11:27:54 +08:00
|
|
|
add_mlir_library(${ARGV})
|
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-02-09 11:27:54 +08:00
|
|
|
add_mlir_library(${ARGV})
|
2020-02-27 08:31:14 +08:00
|
|
|
endfunction(add_mlir_conversion_library)
|