Skip to content

Commit 954bd9c

Browse files
author
Yuanfang Chen
committed
[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
1 parent 382df1c commit 954bd9c

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

llvm/include/llvm/IR/PassInstrumentation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,16 @@ class PassInstrumentation {
243243
ExtraArgsT...) {
244244
return false;
245245
}
246+
247+
template <typename CallableT>
248+
void pushBeforeNonSkippedPassCallback(CallableT C) {
249+
if (Callbacks)
250+
Callbacks->BeforeNonSkippedPassCallbacks.emplace_back(std::move(C));
251+
}
252+
void popBeforeNonSkippedPassCallback() {
253+
if (Callbacks)
254+
Callbacks->BeforeNonSkippedPassCallbacks.pop_back();
255+
}
246256
};
247257

248258
bool isSpecialPass(StringRef PassID, const std::vector<StringRef> &Specials);

llvm/include/llvm/Transforms/Scalar/LoopPassManager.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/Analysis/TargetLibraryInfo.h"
5151
#include "llvm/Analysis/TargetTransformInfo.h"
5252
#include "llvm/IR/Dominators.h"
53+
#include "llvm/IR/PassInstrumentation.h"
5354
#include "llvm/IR/PassManager.h"
5455
#include "llvm/Transforms/Utils/LCSSA.h"
5556
#include "llvm/Transforms/Utils/LoopSimplify.h"
@@ -296,6 +297,21 @@ class FunctionToLoopPassAdaptor
296297
// declaration.
297298
appendLoopsToWorklist(LI, Worklist);
298299

300+
#ifndef NDEBUG
301+
PI.pushBeforeNonSkippedPassCallback([&LAR, &LI](StringRef PassID, Any IR) {
302+
if (isSpecialPass(PassID, {"PassManager"}))
303+
return;
304+
assert(any_isa<const Loop *>(IR));
305+
const Loop *L = any_cast<const Loop *>(IR);
306+
assert(L && "Loop should be valid for printing");
307+
308+
// Verify the loop structure and LCSSA form before visiting the loop.
309+
L->verifyLoop();
310+
assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
311+
"Loops must remain in LCSSA form!");
312+
});
313+
#endif
314+
299315
do {
300316
Loop *L = Worklist.pop_back_val();
301317

@@ -306,11 +322,6 @@ class FunctionToLoopPassAdaptor
306322
#ifndef NDEBUG
307323
// Save a parent loop pointer for asserts.
308324
Updater.ParentL = L->getParentLoop();
309-
310-
// Verify the loop structure and LCSSA form before visiting the loop.
311-
L->verifyLoop();
312-
assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
313-
"Loops must remain in LCSSA form!");
314325
#endif
315326
// Check the PassInstrumentation's BeforePass callbacks before running the
316327
// pass, skip its execution completely if asked to (callback returns
@@ -345,6 +356,10 @@ class FunctionToLoopPassAdaptor
345356
PA.intersect(std::move(PassPA));
346357
} while (!Worklist.empty());
347358

359+
#ifndef NDEBUG
360+
PI.popBeforeNonSkippedPassCallback();
361+
#endif
362+
348363
// By definition we preserve the proxy. We also preserve all analyses on
349364
// Loops. This precludes *any* invalidation of loop analyses by the proxy,
350365
// but that's OK because we've taken care to invalidate analyses in the

llvm/lib/Transforms/Scalar/LoopPassManager.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
5757
break;
5858
}
5959

60-
#ifndef NDEBUG
61-
// Verify the loop structure and LCSSA form before visiting the loop.
62-
L.verifyLoop();
63-
assert(L.isRecursivelyLCSSAForm(AR.DT, AR.LI) &&
64-
"Loops must remain in LCSSA form!");
65-
#endif
66-
6760
// Update the analysis manager as each pass runs and potentially
6861
// invalidates analyses.
6962
AM.invalidate(L, PassPA);

llvm/test/Feature/optnone-opt.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ while.body: ; preds = %while.cond
3434
br label %while.cond
3535

3636
while.end: ; preds = %while.cond
37-
ret i32 0
37+
ret i32 %dec
3838
}
3939

4040
attributes #0 = { optnone noinline }

0 commit comments

Comments
 (0)