[Mlir-commits] [mlir] a490ca8 - [PassManager] Save compile time by not running the verifier unnecessarily. NFC

Chris Lattner llvmlistbot at llvm.org
Mon Jun 14 11:44:11 PDT 2021


Author: Chris Lattner
Date: 2021-06-14T11:43:52-07:00
New Revision: a490ca8e014acac9c2df7bd7f0aff6c7422d850a

URL: https://github.com/llvm/llvm-project/commit/a490ca8e014acac9c2df7bd7f0aff6c7422d850a
DIFF: https://github.com/llvm/llvm-project/commit/a490ca8e014acac9c2df7bd7f0aff6c7422d850a.diff

LOG: [PassManager] Save compile time by not running the verifier unnecessarily. NFC

This changes the pass manager to not rerun the verifier when a pass says it
didn't change anything or after an OpToOpPassAdaptor, since neither of those
cases need verification (and if the pass lied, then there will be much larger
semantic problems than will be caught by the verifier).

This maintains behavior in EXPENSIVE_CHECKS mode.

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

Added: 
    

Modified: 
    mlir/lib/Pass/Pass.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp
index 28309e462ea6b..bae172200a764 100644
--- a/mlir/lib/Pass/Pass.cpp
+++ b/mlir/lib/Pass/Pass.cpp
@@ -387,9 +387,27 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
   // Invalidate any non preserved analyses.
   am.invalidate(pass->passState->preservedAnalyses);
 
-  // Run the verifier if this pass didn't fail already.
-  if (!passFailed && verifyPasses)
-    passFailed = failed(verify(op));
+  // When verifyPasses is specified, we run the verifier (unless the pass
+  // failed).
+  if (!passFailed && verifyPasses) {
+    bool runVerifierNow = true;
+    // Reduce compile time by avoiding running the verifier if the pass didn't
+    // change the IR since the last time the verifier was run:
+    //
+    //  1) If the pass said that it preserved all analyses then it can't have
+    //     permuted the IR.
+    //  2) If we just ran an OpToOpPassAdaptor (e.g. to run function passes
+    //     within a module) then each sub-unit will have been verified on the
+    //     subunit (and those passes aren't allowed to modify the parent).
+    //
+    // We run these checks in EXPENSIVE_CHECKS mode out of caution.
+#ifndef EXPENSIVE_CHECKS
+    runVerifierNow = !isa<OpToOpPassAdaptor>(pass) &&
+                     !pass->passState->preservedAnalyses.isAll();
+#endif
+    if (runVerifierNow)
+      passFailed = failed(verify(op));
+  }
 
   // Instrument after the pass has run.
   if (pi) {


        


More information about the Mlir-commits mailing list