diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -55,6 +55,7 @@ # MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included # from another directory like tools add_subdirectory(tools/mlir-tblgen) +add_subdirectory(tools/mlir-linalg-ods-gen) add_subdirectory(include/mlir) add_subdirectory(lib) diff --git a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt --- a/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt +++ b/mlir/include/mlir/Dialect/Linalg/IR/CMakeLists.txt @@ -11,17 +11,17 @@ PROPERTIES GENERATED TRUE) add_custom_command( OUTPUT ${GEN_ODS_FILE} ${GEN_CPP_FILE} - COMMAND mlir-linalg-ods-gen -gen-ods-decl ${TC_SOURCE} > ${GEN_ODS_FILE} - COMMAND mlir-linalg-ods-gen -gen-impl ${TC_SOURCE} > ${GEN_CPP_FILE} + COMMAND ${MLIR_LINALG_ODS_GEN_EXE} -gen-ods-decl ${TC_SOURCE} > ${GEN_ODS_FILE} + COMMAND ${MLIR_LINALG_ODS_GEN_EXE} -gen-impl ${TC_SOURCE} > ${GEN_CPP_FILE} MAIN_DEPENDENCY ${TC_SOURCE} DEPENDS - mlir-linalg-ods-gen + ${MLIR_LINALG_ODS_GEN_TARGET} VERBATIM) add_custom_target( MLIR${output_file}IncGen DEPENDS - mlir-linalg-ods-gen + ${MLIR_LINALG_ODS_GEN_TARGET} ${GEN_ODS_FILE} ${GEN_CPP_FILE}) endfunction() diff --git a/mlir/tools/CMakeLists.txt b/mlir/tools/CMakeLists.txt --- a/mlir/tools/CMakeLists.txt +++ b/mlir/tools/CMakeLists.txt @@ -1,6 +1,5 @@ add_subdirectory(mlir-cuda-runner) add_subdirectory(mlir-cpu-runner) -add_subdirectory(mlir-linalg-ods-gen) add_subdirectory(mlir-opt) add_subdirectory(mlir-rocm-runner) add_subdirectory(mlir-translate) diff --git a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt --- a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt +++ b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt @@ -10,3 +10,29 @@ MLIRParser MLIRSupport ) + + +set(MLIR_LINALG_ODS_GEN "mlir-linalg-ods-gen" CACHE + STRING "Native mlir-linalg-ods-gen executable. Saves building one when cross-compiling.") + +set(MLIR_LINALG_ODS_GEN_EXE "${MLIR_LINALG_ODS_GEN}" PARENT_SCOPE) +set(MLIR_LINALG_ODS_GEN_TARGET "${MLIR_LINALG_ODS_GEN}" PARENT_SCOPE) + +if(LLVM_USE_HOST_TOOLS) + if( "${MLIR_LINALG_ODS_GEN}" STREQUAL "${target}" ) + # The NATIVE executable *must* depend on the current target one + # otherwise the native one won't get rebuilt when the sources + # change, and we end up with incorrect builds. + build_native_tool(mlir-linalg-ods-gen MLIR_LINALG_ODS_GEN_EXE DEPENDS mlir-linalg-ods-gen) + set(MLIR_LINALG_ODS_GEN_EXE ${MLIR_LINALG_ODS_GEN_EXE} PARENT_SCOPE) + + add_custom_target(mlir-linalg-ods-gen-host DEPENDS ${MLIR_LINALG_ODS_GEN_EXE}) + set(MLIR_LINALG_ODS_GEN_TARGET mlir-linalg-ods-gen-host PARENT_SCOPE) + + # If we're using the host tool, and utils were not requested, we have no + # need to build this tool. + if ( NOT LLVM_BUILD_UTILS ) + set_target_properties(mlir-linalg-ods-gen PROPERTIES EXCLUDE_FROM_ALL ON) + endif() + endif() +endif()