[Mlir-commits] [mlir] [mlir] Use non thread-local allocator for DistinctAttr when threading is disabled (PR #128566)

Tobias Gysi llvmlistbot at llvm.org
Tue Mar 4 23:02:40 PST 2025


================
@@ -411,12 +414,51 @@ class DistinctAttributeAllocator {
   /// Allocates a distinct attribute storage using a thread local bump pointer
   /// allocator to enable synchronization free parallel allocations.
   DistinctAttrStorage *allocate(Attribute referencedAttr) {
-    return new (allocatorCache.get().Allocate<DistinctAttrStorage>())
-        DistinctAttrStorage(referencedAttr);
+    if (!useThreadLocalAllocator && threadingIsEnabled) {
+      std::scoped_lock<std::mutex> lock(allocatorMutex);
+      return allocateImpl(referencedAttr);
+    }
+    return allocateImpl(referencedAttr);
+  }
+
+  /// Sets flags to use thread local bump pointer allocators or a single
+  /// non-thread safe bump pointer allocator depending on if multi-threading is
+  /// enabled. Use this to disable the use of thread local storage and bypass
+  /// thread safety synchronization overhead.
+  void disableMultiThreading(bool disable = true) {
+    threadingIsEnabled = !disable;
+  }
+
+  /// Sets flags to disable using thread local bump pointer allocators and use a
+  /// single thread-safe allocator. Use this to persist allocated storage beyond
+  /// the lifetime of a child thread calling this function while ensuring
+  /// thread-safe allocation.
----------------
gysit wrote:

```suggestion
  /// Sets a flag to disable using thread local bump pointer allocators and use a
  /// single thread-safe allocator. Use this to persist allocated storage beyond
  /// the lifetime of a child thread calling this function while ensuring
  /// thread-safe allocation.
```
nit: comment update

https://github.com/llvm/llvm-project/pull/128566


More information about the Mlir-commits mailing list