[mlir][Pass] Only enable/disable CrashRecovery once

This prevents potential problems that occur when multiple pass managers register crash recovery contexts.
This commit is contained in:
River Riddle 2020-11-18 18:49:23 -08:00
parent c0958b7b4c
commit bd106d7469
1 changed files with 4 additions and 2 deletions

View File

@ -670,6 +670,8 @@ RecoveryReproducerContext::RecoveryReproducerContext(
// Make sure that the handler is registered, and update the current context.
llvm::sys::SmartScopedLock<true> producerLock(*reproducerMutex);
if (reproducerSet->empty())
llvm::CrashRecoveryContext::Enable();
registerSignalHandler();
reproducerSet->insert(this);
}
@ -677,6 +679,8 @@ RecoveryReproducerContext::RecoveryReproducerContext(
RecoveryReproducerContext::~RecoveryReproducerContext() {
llvm::sys::SmartScopedLock<true> producerLock(*reproducerMutex);
reproducerSet->remove(this);
if (reproducerSet->empty())
llvm::CrashRecoveryContext::Disable();
}
LogicalResult RecoveryReproducerContext::generate(std::string &error) {
@ -745,7 +749,6 @@ PassManager::runWithCrashRecovery(MutableArrayRef<std::unique_ptr<Pass>> 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<std::unique_ptr<Pass>> passes,
return;
passManagerResult = success();
});
llvm::CrashRecoveryContext::Disable();
if (succeeded(passManagerResult))
return success();