[Mlir-commits] [mlir] [mlir] Add `MLIRContext::executeCriticalSection` and `Pass::getOpDependentDialects` methods. (PR #98953)

Fabian Mora llvmlistbot at llvm.org
Mon Jul 15 16:03:16 PDT 2024


================
@@ -703,6 +706,24 @@ bool MLIRContext::isOperationRegistered(StringRef name) {
   return RegisteredOperationName::lookup(name, this).has_value();
 }
 
+void MLIRContext::executeCriticalSection(function_ref<void()> function) {
+  if (!function)
+    return;
+  llvm::sys::SmartScopedLock<true> lock(impl->criticalSectionMutex);
+#ifndef NDEBUG
+  // Temporarily disable `multiThreadedExecutionContext` so the context is aware
+  // only a single thread is running.
----------------
fabianmcg wrote:

I don't think it's fully safe. This function only protects modifying the context, not reading from it. However, given the storage uniquer also has some internal mutexes I was unsure if it was fully unsafe. That's why I added the disclaimer, I should have been more explicit on the PR.

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


More information about the Mlir-commits mailing list