[Mlir-commits] [mlir] [mlir] Skip uniquer locks when a context starts without threading (PR #235294)

Arseniy Obolenskiy llvmlistbot at llvm.org
Sat Oct 24 06:28:08 PDT 2026


https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/235294

Only disableMultithreading() turned these locks off before

Context that was created without threading still took a lock on every type and attribute lookup

>From 0a9803955817f19aa88787c650b345a667c0ce70 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Sat, 24 Oct 2026 15:27:05 +0200
Subject: [PATCH] [mlir] Skip uniquer locks when a context starts without
 threading

Only disableMultithreading() turned these locks off before

Context that was created without threading still took a lock on every type and attribute lookup
---
 mlir/lib/IR/MLIRContext.cpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index c5d66c27557c50..350680692a6e0f 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -286,8 +286,16 @@ class MLIRContextImpl {
     if (threadingIsEnabled) {
       ownedThreadPool = std::make_unique<llvm::DefaultThreadPool>();
       threadPool = ownedThreadPool.get();
+    } else {
+      disableUniquerMultithreading(true);
     }
   }
+  /// Update the threading mode for each of the uniquers.
+  void disableUniquerMultithreading(bool disable) {
+    affineUniquer.disableMultithreading(disable);
+    attributeUniquer.disableMultithreading(disable);
+    typeUniquer.disableMultithreading(disable);
+  }
   ~MLIRContextImpl() {
     for (auto typeMapping : registeredTypes)
       typeMapping.second->~AbstractType();
@@ -624,10 +632,7 @@ void MLIRContext::disableMultithreading(bool disable) {
 
   impl->threadingIsEnabled = !disable;
 
-  // Update the threading mode for each of the uniquers.
-  impl->affineUniquer.disableMultithreading(disable);
-  impl->attributeUniquer.disableMultithreading(disable);
-  impl->typeUniquer.disableMultithreading(disable);
+  impl->disableUniquerMultithreading(disable);
 
   // Destroy thread pool (stop all threads) if it is no longer needed, or create
   // a new one if multithreading was re-enabled.



More information about the Mlir-commits mailing list