diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index ae10d1059d83..ac236bbcc4a8 100644 --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -670,6 +670,8 @@ RecoveryReproducerContext::RecoveryReproducerContext( // Make sure that the handler is registered, and update the current context. llvm::sys::SmartScopedLock producerLock(*reproducerMutex); + if (reproducerSet->empty()) + llvm::CrashRecoveryContext::Enable(); registerSignalHandler(); reproducerSet->insert(this); } @@ -677,6 +679,8 @@ RecoveryReproducerContext::RecoveryReproducerContext( RecoveryReproducerContext::~RecoveryReproducerContext() { llvm::sys::SmartScopedLock producerLock(*reproducerMutex); reproducerSet->remove(this); + if (reproducerSet->empty()) + llvm::CrashRecoveryContext::Disable(); } LogicalResult RecoveryReproducerContext::generate(std::string &error) { @@ -745,7 +749,6 @@ PassManager::runWithCrashRecovery(MutableArrayRef> passes, verifyPasses); // Safely invoke the passes within a recovery context. - llvm::CrashRecoveryContext::Enable(); LogicalResult passManagerResult = failure(); llvm::CrashRecoveryContext recoveryContext; recoveryContext.RunSafelyOnThread([&] { @@ -754,7 +757,6 @@ PassManager::runWithCrashRecovery(MutableArrayRef> passes, return; passManagerResult = success(); }); - llvm::CrashRecoveryContext::Disable(); if (succeeded(passManagerResult)) return success();