Skip to content

Commit 57a9bcc

Browse files
committed
[MLIR] Fix checks for native arch
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
1 parent 7ce321e commit 57a9bcc

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

mlir/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,16 @@ set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
8686
add_dependencies(mlir-headers mlir-generic-headers)
8787
add_custom_target(mlir-doc)
8888

89+
# Only enable execution engine if the native target is available.
90+
if(${LLVM_NATIVE_ARCH} IN_LIST LLVM_TARGETS_TO_BUILD)
91+
set(MLIR_ENABLE_EXECUTION_ENGINE 1)
92+
else()
93+
set(MLIR_ENABLE_EXECUTION_ENGINE 0)
94+
endif()
95+
8996
# Build the CUDA conversions and run according tests if the NVPTX backend
9097
# is available
91-
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
98+
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD AND MLIR_ENABLE_EXECUTION_ENGINE)
9299
set(MLIR_ENABLE_CUDA_CONVERSIONS 1)
93100
else()
94101
set(MLIR_ENABLE_CUDA_CONVERSIONS 0)
@@ -97,8 +104,8 @@ endif()
97104
add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_ENABLE_CUDA_CONVERSIONS})
98105

99106
# Build the ROCm conversions and run according tests if the AMDGPU backend
100-
# is available
101-
if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
107+
# is available.
108+
if ("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD AND MLIR_ENABLE_EXECUTION_ENGINE)
102109
set(MLIR_ENABLE_ROCM_CONVERSIONS 1)
103110
else()
104111
set(MLIR_ENABLE_ROCM_CONVERSIONS 0)

mlir/lib/CAPI/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ add_subdirectory(IR)
1515
add_subdirectory(RegisterEverything)
1616
add_subdirectory(Transforms)
1717

18-
# Only enable the ExecutionEngine if the native target is configured in.
19-
if(TARGET ${LLVM_NATIVE_ARCH})
18+
if(MLIR_ENABLE_EXECUTION_ENGINE)
2019
add_subdirectory(ExecutionEngine)
2120
endif()
2221

mlir/lib/ExecutionEngine/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ add_mlir_library(MLIRExecutionEngineUtils
3939
Passes
4040
)
4141

42-
# Only enable the ExecutionEngine if the native target is configured in.
43-
if(NOT TARGET ${LLVM_NATIVE_ARCH})
42+
if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
4443
return()
4544
endif()
4645

mlir/python/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
363363
MLIRCAPIAsync
364364
)
365365

366-
# Only enable the ExecutionEngine if the native target is configured in.
367-
if(TARGET ${LLVM_NATIVE_ARCH})
366+
if(MLIR_ENABLE_EXECUTION_ENGINE)
368367
declare_mlir_python_extension(MLIRPythonExtension.ExecutionEngine
369368
MODULE_NAME _mlirExecutionEngine
370369
ADD_TO_PARENT MLIRPythonSources.ExecutionEngine

mlir/test/CAPI/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ function(_add_capi_test_executable name)
1919
endif()
2020
endfunction(_add_capi_test_executable)
2121

22-
# Only enable the ExecutionEngine if the native target is configured in.
23-
if(TARGET ${LLVM_NATIVE_ARCH})
22+
if(MLIR_ENABLE_EXECUTION_ENGINE)
2423
_add_capi_test_executable(mlir-capi-execution-engine-test
2524
execution_engine.c
2625
LINK_LIBS PRIVATE

mlir/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (MLIR_INCLUDE_INTEGRATION_TESTS)
4040

4141

4242
# The native target may not be enabled when cross compiling, raise an error.
43-
if(NOT TARGET ${LLVM_NATIVE_ARCH})
43+
if(NOT MLIR_ENABLE_EXECUTION_ENGINE)
4444
message(FATAL_ERROR "MLIR_INCLUDE_INTEGRATION_TESTS requires a native target")
4545
endif()
4646

mlir/tools/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ add_subdirectory(mlir-translate)
99
add_subdirectory(mlir-vulkan-runner)
1010
add_subdirectory(tblgen-lsp-server)
1111

12-
# mlir-cpu-runner requires ExecutionEngine which is only built
13-
# when the native target is configured in.
14-
if(TARGET ${LLVM_NATIVE_ARCH})
12+
# mlir-cpu-runner requires ExecutionEngine.
13+
if(MLIR_ENABLE_EXECUTION_ENGINE)
1514
add_subdirectory(mlir-cpu-runner)
1615
endif()

mlir/unittests/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_subdirectory(Rewrite)
1616
add_subdirectory(TableGen)
1717
add_subdirectory(Transforms)
1818

19-
# The native target may not be enabled when cross compiling.
20-
if(TARGET ${LLVM_NATIVE_ARCH})
19+
if(MLIR_ENABLE_EXECUTION_ENGINE)
2120
add_subdirectory(ExecutionEngine)
2221
endif()

0 commit comments

Comments
 (0)