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

Tobias Gysi llvmlistbot at llvm.org
Sat Mar 1 05:54:08 PST 2025


================
@@ -414,6 +414,19 @@ struct FileReproducerStream : public mlir::ReproducerStream {
 
 LogicalResult PassManager::runWithCrashRecovery(Operation *op,
                                                 AnalysisManager am) {
+  // Notify the context to disable the use of thread-local storage while the
+  // pass manager is running in a crash recovery context thread. This RAII guard
+  // will re-enable thread local storage use upon function exit.
+  class ScopedThreadLocalStorageDisable {
+    MLIRContext *const ctx;
+
+  public:
+    ScopedThreadLocalStorageDisable(MLIRContext *ctx) : ctx(ctx) {
+      ctx->disableThreadLocalStorage();
+    }
+    ~ScopedThreadLocalStorageDisable() { ctx->enableThreadLocalStorage(); }
+  };
+  ScopedThreadLocalStorageDisable raii(this->getContext());
----------------
gysit wrote:

LLVM already has some raii helper for that:
```
  ctx->disableThreadLocalStorage();
  auto guard = llvm::make_scope_exit(
      [&]() { ctx->enableThreadLocalStorage(); });
```
Should do the job.

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


More information about the Mlir-commits mailing list