[MLIR] Fix checks for native arch
authorNikita Popov <npopov@redhat.com>
Wed, 3 Aug 2022 13:28:49 +0000 (15:28 +0200)
committerTom Stellard <tstellar@redhat.com>
Mon, 8 Aug 2022 19:18:21 +0000 (12:18 -0700)
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)

mlir/CMakeLists.txt
mlir/lib/CAPI/CMakeLists.txt
mlir/lib/ExecutionEngine/CMakeLists.txt
mlir/python/CMakeLists.txt
mlir/test/CAPI/CMakeLists.txt
mlir/test/CMakeLists.txt
mlir/tools/CMakeLists.txt
mlir/unittests/CMakeLists.txt

index 3ea0be3e6b05c2436dabd09be51a12dd5db515ab..088aec88fff96a52b7cbf8674c3a701a2222170a 100644 (file)
@@ -86,9 +86,16 @@ set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
 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)
@@ -97,8 +104,8 @@ endif()
 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)
index ffb04c2878994c68ca84ac85d09d891d24765eac..052eff327c7326468860b725438d433676add4ff 100644 (file)
@@ -15,8 +15,7 @@ add_subdirectory(IR)
 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()
 
index 22ac4f846215b72c9e7a9df34bafd4ab3f644fab..bf627805986a0e96e043ecc585beb711b5cc1b24 100644 (file)
@@ -39,8 +39,7 @@ add_mlir_library(MLIRExecutionEngineUtils
   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()
 
index 1fbbadf2645a838de761b95404cd45c91bf3368c..7eb6e05e427ca7e53fb510ab703b115286155b01 100644 (file)
@@ -363,8 +363,7 @@ declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses
     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
index b089a374b4d2aad420ee3bf436ce070288caf698..2992b137c58f72f743c6e0733cae99daa5d7ddff 100644 (file)
@@ -19,8 +19,7 @@ function(_add_capi_test_executable name)
   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
index c203f2217ec5336ef872d606e86c326d238a1c15..74f805865d2d31b2016a42ea165445026a3c8e1e 100644 (file)
@@ -40,7 +40,7 @@ if (MLIR_INCLUDE_INTEGRATION_TESTS)
 
 
   # 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()
 
index 86003b735947796575f2c2a1a8c681bff5d27dd7..e9a1e4d6251722ef57dbe30043abed90537ddd94 100644 (file)
@@ -9,8 +9,7 @@ add_subdirectory(mlir-translate)
 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()
index 25f40d0317196a9e4157a215fb183e410530bf8c..78a0f99c5e3c9249dceb80990629446cf3564c01 100644 (file)
@@ -16,7 +16,6 @@ add_subdirectory(Rewrite)
 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()