Using if (TARGET ${LLVM_NATIVE_ARCH}) only works if MLIR is built
together with LLVM, but not for standalone builds of MLIR. The
correct way to check this is
if (${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD), as the
LLVM build system exports LLVM_TARGETS_TO_BUILD.
To avoid repeating the same check many times, add a
MLIR_ENABLE_EXECUTION_ENGINE variable.
Differential Revision: https://reviews.llvm.org/
D131071
(cherry picked from commit
57a9bccec7dea036dbfa1a78f1ec5e73ecf7a33c)
add_dependencies(mlir-headers mlir-generic-headers)
add_custom_target(mlir-doc)
+# Only enable execution engine if the native target is available.
+if(${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD)
+ set(MLIR_ENABLE_EXECUTION_ENGINE 1)
+else()
+ set(MLIR_ENABLE_EXECUTION_ENGINE 0)
+endif()
+
# Build the CUDA conversions and run according tests if the NVPTX backend
# is available
-if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
+if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD AND MLIR_ENABLE_EXECUTION_ENGINE)
set(MLIR_ENABLE_CUDA_CONVERSIONS 1)
else()
set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})
# Build the ROCm conversions and run according tests if the AMDGPU backend
-# is available
-if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
+# is available.
+if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD AND MLIR_ENABLE_EXECUTION_ENGINE)
set(MLIR_ENABLE_ROCM_CONVERSIONS 1)
else()
set(MLIR_ENABLE_ROCM_CONVERSIONS 0)
add_subdirectory(RegisterEverything)
add_subdirectory(Transforms)
-# Only enable the ExecutionEngine if the native target is configured in.
-if(TARGET ${LLVM_NATIVE_ARCH})
+if(MLIR_ENABLE_EXECUTION_ENGINE)
add_subdirectory(ExecutionEngine)
endif()
Passes
)
-# Only enable the ExecutionEngine if the native target is configured in.
-if(NOT TARGET ${LLVM_NATIVE_ARCH})
+if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
return()
endif()
MLIRCAPIAsync
)
-# Only enable the ExecutionEngine if the native target is configured in.
-if(TARGET ${LLVM_NATIVE_ARCH})
+if(MLIR_ENABLE_EXECUTION_ENGINE)
declare_mlir_python_extension(MLIRPythonExtension.ExecutionEngine
MODULE_NAME _mlirExecutionEngine
ADD_TO_PARENT MLIRPythonSources.ExecutionEngine
endif()
endfunction(_add_capi_test_executable)
-# Only enable the ExecutionEngine if the native target is configured in.
-if(TARGET ${LLVM_NATIVE_ARCH})
+if(MLIR_ENABLE_EXECUTION_ENGINE)
_add_capi_test_executable(mlir-capi-execution-engine-test
execution_engine.c
LINK_LIBS PRIVATE
# The native target may not be enabled when cross compiling, raise an error.
- if(NOT TARGET ${LLVM_NATIVE_ARCH})
+ if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
message(FATAL_ERROR "MLIR_INCLUDE_INTEGRATION_TESTS requires a native target")
endif()
add_subdirectory(mlir-vulkan-runner)
add_subdirectory(tblgen-lsp-server)
-# mlir-cpu-runner requires ExecutionEngine which is only built
-# when the native target is configured in.
-if(TARGET ${LLVM_NATIVE_ARCH})
+# mlir-cpu-runner requires ExecutionEngine.
+if(MLIR_ENABLE_EXECUTION_ENGINE)
add_subdirectory(mlir-cpu-runner)
endif()
add_subdirectory(TableGen)
add_subdirectory(Transforms)
-# The native target may not be enabled when cross compiling.
-if(TARGET ${LLVM_NATIVE_ARCH})
+if(MLIR_ENABLE_EXECUTION_ENGINE)
add_subdirectory(ExecutionEngine)
endif()