[mlir] Clear running passes in crashreporter
authorJacques Pienaar <jpienaar@google.com>
Wed, 21 Dec 2022 19:43:03 +0000 (11:43 -0800)
committerJacques Pienaar <jpienaar@google.com>
Wed, 21 Dec 2022 19:43:03 +0000 (11:43 -0800)
Clear active contexts and running passes whenever finalizing crash
report message. Ran into segfault where a failure in dynamic pipeline
resulted in querying a pass whose passmanager had already been destroyed
come time for creating summary of running passes. Conservatively clear
both running states as I don't think there is recovery intended from
pass pipeline failure.

Additionally restrict to one reproducer per report - else we end up
clobbering the same reproducer file over and over again. So instead of
ending with last reproducer we now end up with the first reproducer
while not creating and clobbering reproducers over and over again.

Differential Revision: https://reviews.llvm.org/D140488

mlir/lib/Pass/PassCrashRecovery.cpp

index a98a1f1..67e4047 100644 (file)
@@ -258,6 +258,8 @@ void PassCrashReproducerGenerator::finalize(Operation *rootOp,
                             formatPassOpReproducerMessage(note, value);
                           });
     note << "]: " << description;
+    impl->runningPasses.clear();
+    impl->activeContexts.clear();
     return;
   }
 
@@ -278,6 +280,7 @@ void PassCrashReproducerGenerator::finalize(Operation *rootOp,
   note << ": " << description;
 
   impl->activeContexts.clear();
+  impl->runningPasses.clear();
 }
 
 void PassCrashReproducerGenerator::prepareReproducerFor(Pass *pass,
@@ -359,12 +362,18 @@ struct CrashReproducerInstrumentation : public PassInstrumentation {
   }
 
   void runAfterPassFailed(Pass *pass, Operation *op) override {
+    // Only generate one reproducer per crash reproducer instrumentation.
+    if (alreadyFailed)
+      return;
+
+    alreadyFailed = true;
     generator.finalize(op, /*executionResult=*/failure());
   }
 
 private:
   /// The generator used to create crash reproducers.
   PassCrashReproducerGenerator &generator;
+  bool alreadyFailed = false;
 };
 } // namespace