[Mlir-commits] [mlir] 8fc70c5 - [mlir] Avoid parallel code in single-threaded builds (#229794)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 8 01:48:25 PDT 2026
Author: Anutosh Bhat
Date: 2026-10-08T08:48:19Z
New Revision: 8fc70c50df98e271030db77b838d5ffbcf400078
URL: https://github.com/llvm/llvm-project/commit/8fc70c50df98e271030db77b838d5ffbcf400078
DIFF: https://github.com/llvm/llvm-project/commit/8fc70c50df98e271030db77b838d5ffbcf400078.diff
LOG: [mlir] Avoid parallel code in single-threaded builds (#229794)
We hit this while building MLIR 23.1.2 for wasm32 and wasm64 in
emscripten-forge (this is an effort towards
[RFC](https://discourse.llvm.org/t/rfc-bringing-interactive-mlir-compilation-and-execution-to-webassembly/91566/3))
with `LLVM_ENABLE_THREADS=OFF`. `libMLIRIR.a` still retained
`pthread_create` and `pthread_setspecific` references from libc++ async
machinery, causing our package checks to fail.
`failableParallelForEach` only checks whether threading is enabled at
runtime, so the unused thread-pool code still reaches code generation.
We also need to check `LLVM_ENABLE_THREADS`, allowing the compiler to
discard that path in single-threaded builds !
Added:
Modified:
mlir/include/mlir/IR/MLIRContext.h
mlir/lib/IR/MLIRContext.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h
index ce195518066d9..d63c863de6544 100644
--- a/mlir/include/mlir/IR/MLIRContext.h
+++ b/mlir/include/mlir/IR/MLIRContext.h
@@ -12,6 +12,7 @@
#include "mlir/Support/LLVM.h"
#include "mlir/Support/TypeID.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Config/llvm-config.h"
#include <functional>
#include <memory>
#include <vector>
@@ -189,7 +190,11 @@ class MLIRContext {
};
/// Return true if multi-threading is enabled by the context.
+#if LLVM_ENABLE_THREADS
bool isMultithreadingEnabled();
+#else
+ bool isMultithreadingEnabled() { return false; }
+#endif
/// Set the flag specifying if multi-threading is disabled by the context.
/// The command line debugging flag `--mlir-disable-threading` is overriding
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 94cf420070131..c5d66c27557c5 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -608,9 +608,9 @@ void MLIRContext::allowUnregisteredDialects(bool allowing) {
}
/// Return true if multi-threading is enabled by the context.
-bool MLIRContext::isMultithreadingEnabled() {
- return impl->threadingIsEnabled && llvm::llvm_is_multithreaded();
-}
+#if LLVM_ENABLE_THREADS
+bool MLIRContext::isMultithreadingEnabled() { return impl->threadingIsEnabled; }
+#endif
/// Set the flag specifying if multi-threading is disabled by the context.
void MLIRContext::disableMultithreading(bool disable) {
More information about the Mlir-commits
mailing list