[Mlir-commits] [mlir] [mlir] Avoid parallel code in single-threaded builds (PR #229794)
Anutosh Bhat
llvmlistbot at llvm.org
Wed Oct 7 21:11:21 PDT 2026
https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/229794
>From a56f3d2e9861dae549bef5ee73d34bcc5243afad Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Wed, 7 Oct 2026 20:46:07 +0530
Subject: [PATCH 1/2] [mlir] Inline the threading query when threads are
disabled
---
mlir/include/mlir/IR/MLIRContext.h | 5 +++++
mlir/lib/IR/MLIRContext.cpp | 4 +++-
2 files changed, 8 insertions(+), 1 deletion(-)
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..68589d8c4c192 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -608,9 +608,11 @@ void MLIRContext::allowUnregisteredDialects(bool allowing) {
}
/// Return true if multi-threading is enabled by the context.
+#if LLVM_ENABLE_THREADS
bool MLIRContext::isMultithreadingEnabled() {
- return impl->threadingIsEnabled && llvm::llvm_is_multithreaded();
+ return impl->threadingIsEnabled;
}
+#endif
/// Set the flag specifying if multi-threading is disabled by the context.
void MLIRContext::disableMultithreading(bool disable) {
>From 2cce64961b141b411e2ba58205436a76dae140c7 Mon Sep 17 00:00:00 2001
From: Anutosh Bhat <andersonbhat491 at gmail.com>
Date: Thu, 8 Oct 2026 09:41:10 +0530
Subject: [PATCH 2/2] formatting
---
mlir/lib/IR/MLIRContext.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 68589d8c4c192..c5d66c27557c5 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -609,9 +609,7 @@ void MLIRContext::allowUnregisteredDialects(bool allowing) {
/// Return true if multi-threading is enabled by the context.
#if LLVM_ENABLE_THREADS
-bool MLIRContext::isMultithreadingEnabled() {
- return impl->threadingIsEnabled;
-}
+bool MLIRContext::isMultithreadingEnabled() { return impl->threadingIsEnabled; }
#endif
/// Set the flag specifying if multi-threading is disabled by the context.
More information about the Mlir-commits
mailing list