[NewPM] Only verify loop for nonskipped user loop pass

No verification for pass mangers since it is not needed.
No verification for skipped loop pass since the asserted condition is not used.

Add a BeforeNonSkippedPass callback for this. The callback needs more
inputs than its parameters to work so the callback is added on-the-fly.

Reviewed By: aeubanks, asbirlea

Differential Revision: https://reviews.llvm.org/D84977
This commit is contained in:
Yuanfang Chen 2020-08-07 09:22:51 -07:00
parent 382df1c674
commit 954bd9c861
4 changed files with 31 additions and 13 deletions

View File

@ -243,6 +243,16 @@ public:
ExtraArgsT...) {
return false;
}
template <typename CallableT>
void pushBeforeNonSkippedPassCallback(CallableT C) {
if (Callbacks)
Callbacks->BeforeNonSkippedPassCallbacks.emplace_back(std::move(C));
}
void popBeforeNonSkippedPassCallback() {
if (Callbacks)
Callbacks->BeforeNonSkippedPassCallbacks.pop_back();
}
};
bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials);

View File

@ -50,6 +50,7 @@
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/PassInstrumentation.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Transforms/Utils/LCSSA.h"
#include "llvm/Transforms/Utils/LoopSimplify.h"
@ -296,6 +297,21 @@ public:
// declaration.
appendLoopsToWorklist(LI, Worklist);
#ifndef NDEBUG
PI.pushBeforeNonSkippedPassCallback([&LAR, &LI](StringRef PassID, Any IR) {
if (isSpecialPass(PassID, {"PassManager"}))
return;
assert(any_isa<const Loop *>(IR));
const Loop *L = any_cast<const Loop *>(IR);
assert(L && "Loop should be valid for printing");
// Verify the loop structure and LCSSA form before visiting the loop.
L->verifyLoop();
assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
"Loops must remain in LCSSA form!");
});
#endif
do {
Loop *L = Worklist.pop_back_val();
@ -306,11 +322,6 @@ public:
#ifndef NDEBUG
// Save a parent loop pointer for asserts.
Updater.ParentL = L->getParentLoop();
// Verify the loop structure and LCSSA form before visiting the loop.
L->verifyLoop();
assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
"Loops must remain in LCSSA form!");
#endif
// Check the PassInstrumentation's BeforePass callbacks before running the
// pass, skip its execution completely if asked to (callback returns
@ -345,6 +356,10 @@ public:
PA.intersect(std::move(PassPA));
} while (!Worklist.empty());
#ifndef NDEBUG
PI.popBeforeNonSkippedPassCallback();
#endif
// By definition we preserve the proxy. We also preserve all analyses on
// Loops. This precludes *any* invalidation of loop analyses by the proxy,
// but that's OK because we've taken care to invalidate analyses in the

View File

@ -57,13 +57,6 @@ PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
break;
}
#ifndef NDEBUG
// Verify the loop structure and LCSSA form before visiting the loop.
L.verifyLoop();
assert(L.isRecursivelyLCSSAForm(AR.DT, AR.LI) &&
"Loops must remain in LCSSA form!");
#endif
// Update the analysis manager as each pass runs and potentially
// invalidates analyses.
AM.invalidate(L, PassPA);

View File

@ -34,7 +34,7 @@ while.body: ; preds = %while.cond
br label %while.cond
while.end: ; preds = %while.cond
ret i32 0
ret i32 %dec
}
attributes #0 = { optnone noinline }