From: Chris Lattner Date: Mon, 14 Jun 2021 17:31:00 +0000 (-0700) Subject: [PassManager] Save compile time by not running the verifier unnecessarily. NFC X-Git-Tag: llvmorg-14-init~3993 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a490ca8e014acac9c2df7bd7f0aff6c7422d850a;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 28309e4..bae1722 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(pass) && + !pass->passState->preservedAnalyses.isAll(); +#endif + if (runVerifierNow) + passFailed = failed(verify(op)); + } // Instrument after the pass has run. if (pi) {