[llvm] 39e3e3a - [NewPM] Redesign of PreserveCFG Checker
Yevgeny Rouban via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 5 22:37:02 PDT 2021
Author: Yevgeny Rouban
Date: 2021-04-06T12:35:49+07:00
New Revision: 39e3e3aa51d628722637c1bfa507f9ec2c532120
URL: https://github.com/llvm/llvm-project/commit/39e3e3aa51d628722637c1bfa507f9ec2c532120
DIFF: https://github.com/llvm/llvm-project/commit/39e3e3aa51d628722637c1bfa507f9ec2c532120.diff
LOG: [NewPM] Redesign of PreserveCFG Checker
The reason for the NewPM redesign is described in the commit
cba3e783389a: [NewPM] Disable PreservedCFGChecker ...
The checker introduces an internal custom CFG analysis that tracks
current up-to date CFG snapshot. The analysis is invalidated along
any other CFG related analysis (the key is CFGAnalyses). If the CFG
analysis is not invalidated at a functional pass exit then the checker
asserts that the CFG snapshot taken from this analysis is equals to
a snapshot of the current CFG.
Along the way:
- the function CFG::printDiff() is simplified by removing function
name calculation. The name is printed by the caller;
- fixed CFG invalidated condition (see CFG::invalidate());
- StandardInstrumentations::registerCallbacks() gets additional
optional parameter of type FunctionAnalysisManager*, which is
needed by the checker to get the custom CFG analysis;
- several PM related tests updated to explicitly set
-verify-cfg-preserved=1 as they need.
This patch is safe to land as the CFGChecker is left switched off
(the options -verify-cfg-preserved is false by default). It will be
switched on by a separate patch to minimize possible reverts.
Reviewed By: skatkov, kuhar
Differential Revision: https://reviews.llvm.org/D91327
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Passes/StandardInstrumentations.h
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/StandardInstrumentations.cpp
llvm/test/Other/new-pass-manager.ll
llvm/test/Other/new-pm-defaults.ll
llvm/tools/opt/NewPMDriver.cpp
llvm/unittests/IR/PassManagerTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 00d92e7beadd4..7edca6fb30730 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1268,9 +1268,14 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
PTO.Coroutines = LangOpts.Coroutines;
+ LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
+ FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
+ CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
+ ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
+
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
- SI.registerCallbacks(PIC);
+ SI.registerCallbacks(PIC, &FAM);
PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, &PIC);
// Attempt to load pass plugins and register their callbacks with PB.
@@ -1287,11 +1292,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"
- LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
- FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
- CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
- ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
-
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); });
diff --git a/llvm/include/llvm/Passes/StandardInstrumentations.h b/llvm/include/llvm/Passes/StandardInstrumentations.h
index d24f3fbbf2e54..6953d0cd1b0a1 100644
--- a/llvm/include/llvm/Passes/StandardInstrumentations.h
+++ b/llvm/include/llvm/Passes/StandardInstrumentations.h
@@ -91,7 +91,16 @@ class PrintPassInstrumentation {
};
class PreservedCFGCheckerInstrumentation {
-private:
+public:
+ // Keeps sticky poisoned flag for the given basic block once it has been
+ // deleted or RAUWed.
+ struct BBGuard final : public CallbackVH {
+ BBGuard(const BasicBlock *BB) : CallbackVH(BB) {}
+ void deleted() override { CallbackVH::deleted(); }
+ void allUsesReplacedWith(Value *) override { CallbackVH::deleted(); }
+ bool isPoisoned() const { return !getValPtr(); }
+ };
+
// CFG is a map BB -> {(Succ, Multiplicity)}, where BB is a non-leaf basic
// block, {(Succ, Multiplicity)} set of all pairs of the block's successors
// and the multiplicity of the edge (BB->Succ). As the mapped sets are
@@ -101,40 +110,34 @@ class PreservedCFGCheckerInstrumentation {
// in the Graph (BBGuard). That is if any of the block is deleted or RAUWed
// then the CFG is treated poisoned and no block pointer of the Graph is used.
struct CFG {
- struct BBGuard final : public CallbackVH {
- BBGuard(const BasicBlock *BB) : CallbackVH(BB) {}
- void deleted() override { CallbackVH::deleted(); }
- void allUsesReplacedWith(Value *) override { CallbackVH::deleted(); }
- bool isPoisoned() const { return !getValPtr(); }
- };
-
Optional<DenseMap<intptr_t, BBGuard>> BBGuards;
DenseMap<const BasicBlock *, DenseMap<const BasicBlock *, unsigned>> Graph;
- CFG(const Function *F, bool TrackBBLifetime = false);
+ CFG(const Function *F, bool TrackBBLifetime);
bool operator==(const CFG &G) const {
return !isPoisoned() && !G.isPoisoned() && Graph == G.Graph;
}
bool isPoisoned() const {
- if (BBGuards)
- for (auto &BB : *BBGuards) {
- if (BB.second.isPoisoned())
- return true;
- }
- return false;
+ return BBGuards &&
+ std::any_of(BBGuards->begin(), BBGuards->end(),
+ [](const auto &BB) { return BB.second.isPoisoned(); });
}
static void printDiff(raw_ostream &out, const CFG &Before,
const CFG &After);
+ bool invalidate(Function &F, const PreservedAnalyses &PA,
+ FunctionAnalysisManager::Invalidator &);
};
- SmallVector<std::pair<StringRef, Optional<CFG>>, 8> GraphStackBefore;
+#ifndef NDEBUG
+ SmallVector<StringRef, 8> PassStack;
+#endif
-public:
static cl::opt<bool> VerifyPreservedCFG;
- void registerCallbacks(PassInstrumentationCallbacks &PIC);
+ void registerCallbacks(PassInstrumentationCallbacks &PIC,
+ FunctionAnalysisManager &FAM);
};
// Base class for classes that report changes to the IR.
@@ -412,7 +415,10 @@ class StandardInstrumentations {
public:
StandardInstrumentations(bool DebugLogging, bool VerifyEach = false);
- void registerCallbacks(PassInstrumentationCallbacks &PIC);
+ // Register all the standard instrumentation callbacks. If \p FAM is nullptr
+ // then PreservedCFGChecker is not enabled.
+ void registerCallbacks(PassInstrumentationCallbacks &PIC,
+ FunctionAnalysisManager *FAM = nullptr);
TimePassesHandler &getTimePasses() { return TimePasses; }
};
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index c81f08d04925e..34d1c9317e095 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -220,18 +220,18 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
PGOOptions::IRUse, PGOOptions::CSIRUse);
}
+ LoopAnalysisManager LAM(Conf.DebugPassManager);
+ FunctionAnalysisManager FAM(Conf.DebugPassManager);
+ CGSCCAnalysisManager CGAM(Conf.DebugPassManager);
+ ModuleAnalysisManager MAM(Conf.DebugPassManager);
+
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(Conf.DebugPassManager);
- SI.registerCallbacks(PIC);
+ SI.registerCallbacks(PIC, &FAM);
PassBuilder PB(Conf.DebugPassManager, TM, Conf.PTO, PGOOpt, &PIC);
RegisterPassPlugins(Conf.PassPlugins, PB);
- LoopAnalysisManager LAM(Conf.DebugPassManager);
- FunctionAnalysisManager FAM(Conf.DebugPassManager);
- CGSCCAnalysisManager CGAM(Conf.DebugPassManager);
- ModuleAnalysisManager MAM(Conf.DebugPassManager);
-
std::unique_ptr<TargetLibraryInfoImpl> TLII(
new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
if (Conf.Freestanding)
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 1cf17972cc2fd..bd1db0c003942 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -22,6 +22,7 @@
#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassInstrumentation.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/IR/PrintPasses.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
@@ -958,18 +959,6 @@ void PreservedCFGCheckerInstrumentation::CFG::printDiff(raw_ostream &out,
const CFG &Before,
const CFG &After) {
assert(!After.isPoisoned());
-
- // Print function name.
- const CFG *FuncGraph = nullptr;
- if (!After.Graph.empty())
- FuncGraph = &After;
- else if (!Before.isPoisoned() && !Before.Graph.empty())
- FuncGraph = &Before;
-
- if (FuncGraph)
- out << "In function @"
- << FuncGraph->Graph.begin()->first->getParent()->getName() << "\n";
-
if (Before.isPoisoned()) {
out << "Some blocks were deleted\n";
return;
@@ -1025,46 +1014,96 @@ void PreservedCFGCheckerInstrumentation::CFG::printDiff(raw_ostream &out,
}
}
+// PreservedCFGCheckerInstrumentation uses PreservedCFGCheckerAnalysis to check
+// passes, that reported they kept CFG analyses up-to-date, did not actually
+// change CFG. This check is done as follows. Before every functional pass in
+// BeforeNonSkippedPassCallback a CFG snapshot (an instance of
+// PreservedCFGCheckerInstrumentation::CFG) is requested from
+// FunctionAnalysisManager as a result of PreservedCFGCheckerAnalysis. When the
+// functional pass finishes and reports that CFGAnalyses or AllAnalyses are
+// up-to-date then the cached result of PreservedCFGCheckerAnalysis (if
+// available) is checked to be equal to a freshly created CFG snapshot.
+struct PreservedCFGCheckerAnalysis
+ : public AnalysisInfoMixin<PreservedCFGCheckerAnalysis> {
+ friend AnalysisInfoMixin<PreservedCFGCheckerAnalysis>;
+
+ static AnalysisKey Key;
+
+public:
+ /// Provide the result type for this analysis pass.
+ using Result = PreservedCFGCheckerInstrumentation::CFG;
+
+ /// Run the analysis pass over a function and produce CFG.
+ Result run(Function &F, FunctionAnalysisManager &FAM) {
+ return Result(&F, /* TrackBBLifetime */ true);
+ }
+};
+
+AnalysisKey PreservedCFGCheckerAnalysis::Key;
+
+bool PreservedCFGCheckerInstrumentation::CFG::invalidate(
+ Function &F, const PreservedAnalyses &PA,
+ FunctionAnalysisManager::Invalidator &) {
+ auto PAC = PA.getChecker<PreservedCFGCheckerAnalysis>();
+ return !(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() ||
+ PAC.preservedSet<CFGAnalyses>());
+}
+
void PreservedCFGCheckerInstrumentation::registerCallbacks(
- PassInstrumentationCallbacks &PIC) {
+ PassInstrumentationCallbacks &PIC, FunctionAnalysisManager &FAM) {
if (!VerifyPreservedCFG)
return;
- PIC.registerBeforeNonSkippedPassCallback([this](StringRef P, Any IR) {
- if (any_isa<const Function *>(IR))
- GraphStackBefore.emplace_back(P, CFG(any_cast<const Function *>(IR)));
- else
- GraphStackBefore.emplace_back(P, None);
- });
+ FAM.registerPass([&] { return PreservedCFGCheckerAnalysis(); });
+
+ auto checkCFG = [](StringRef Pass, StringRef FuncName, const CFG &GraphBefore,
+ const CFG &GraphAfter) {
+ if (GraphAfter == GraphBefore)
+ return;
+
+ dbgs() << "Error: " << Pass
+ << " does not invalidate CFG analyses but CFG changes detected in "
+ "function @"
+ << FuncName << ":\n";
+ CFG::printDiff(dbgs(), GraphBefore, GraphAfter);
+ report_fatal_error(Twine("CFG unexpectedly changed by ", Pass));
+ };
+
+ PIC.registerBeforeNonSkippedPassCallback(
+ [this, &FAM, checkCFG](StringRef P, Any IR) {
+ assert(&PassStack.emplace_back(P));
+ if (!any_isa<const Function *>(IR))
+ return;
+
+ const auto *F = any_cast<const Function *>(IR);
+ // Make sure a fresh CFG snapshot is available before the pass.
+ FAM.getResult<PreservedCFGCheckerAnalysis>(*const_cast<Function *>(F));
+ });
PIC.registerAfterPassInvalidatedCallback(
[this](StringRef P, const PreservedAnalyses &PassPA) {
- auto Before = GraphStackBefore.pop_back_val();
- assert(Before.first == P &&
+ assert(PassStack.pop_back_val() == P &&
"Before and After callbacks must correspond");
- (void)Before;
});
- PIC.registerAfterPassCallback([this](StringRef P, Any IR,
- const PreservedAnalyses &PassPA) {
- auto Before = GraphStackBefore.pop_back_val();
- assert(Before.first == P && "Before and After callbacks must correspond");
- auto &GraphBefore = Before.second;
+ PIC.registerAfterPassCallback([this, &FAM,
+ checkCFG](StringRef P, Any IR,
+ const PreservedAnalyses &PassPA) {
+ assert(PassStack.pop_back_val() == P &&
+ "Before and After callbacks must correspond");
- if (!PassPA.allAnalysesInSetPreserved<CFGAnalyses>())
+ if (!any_isa<const Function *>(IR))
return;
- if (any_isa<const Function *>(IR)) {
- assert(GraphBefore && "Must be built in BeforePassCallback");
- CFG GraphAfter(any_cast<const Function *>(IR), false /* NeedsGuard */);
- if (GraphAfter == *GraphBefore)
- return;
+ if (!PassPA.allAnalysesInSetPreserved<CFGAnalyses>() &&
+ !PassPA.allAnalysesInSetPreserved<AllAnalysesOn<Function>>())
+ return;
- dbgs() << "Error: " << P
- << " reported it preserved CFG, but changes detected:\n";
- CFG::printDiff(dbgs(), *GraphBefore, GraphAfter);
- report_fatal_error(Twine("Preserved CFG changed by ", P));
- }
+ const auto *F = any_cast<const Function *>(IR);
+ if (auto *GraphBefore = FAM.getCachedResult<PreservedCFGCheckerAnalysis>(
+ *const_cast<Function *>(F)))
+ checkCFG(P, F->getName(), *GraphBefore,
+ CFG(F, /* TrackBBLifetime */ false));
});
}
@@ -1169,13 +1208,14 @@ StandardInstrumentations::StandardInstrumentations(bool DebugLogging,
Verify(DebugLogging), VerifyEach(VerifyEach) {}
void StandardInstrumentations::registerCallbacks(
- PassInstrumentationCallbacks &PIC) {
+ PassInstrumentationCallbacks &PIC, FunctionAnalysisManager *FAM) {
PrintIR.registerCallbacks(PIC);
PrintPass.registerCallbacks(PIC);
TimePasses.registerCallbacks(PIC);
OptNone.registerCallbacks(PIC);
OptBisect.registerCallbacks(PIC);
- PreservedCFGChecker.registerCallbacks(PIC);
+ if (FAM)
+ PreservedCFGChecker.registerCallbacks(PIC, *FAM);
PrintChangedIR.registerCallbacks(PIC);
PseudoProbeVerification.registerCallbacks(PIC);
if (VerifyEach)
diff --git a/llvm/test/Other/new-pass-manager.ll b/llvm/test/Other/new-pass-manager.ll
index dec7a8e3018f6..0b083271be9ff 100644
--- a/llvm/test/Other/new-pass-manager.ll
+++ b/llvm/test/Other/new-pass-manager.ll
@@ -5,17 +5,17 @@
; files, but for now this is just going to step the new process through its
; paces.
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes=no-op-module %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-MODULE-PASS
; CHECK-MODULE-PASS: Starting llvm::Module pass manager run
; CHECK-MODULE-PASS-NEXT: Running pass: NoOpModulePass
; CHECK-MODULE-PASS-NEXT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes=no-op-cgscc %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-CGSCC-PASS
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='cgscc(no-op-cgscc)' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-CGSCC-PASS
; CHECK-CGSCC-PASS: Starting llvm::Module pass manager run
@@ -30,14 +30,15 @@
; CHECK-CGSCC-PASS-NEXT: Finished CGSCC pass manager run
; CHECK-CGSCC-PASS-NEXT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes=no-op-function %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-FUNCTION-PASS
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='function(no-op-function)' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-FUNCTION-PASS
; CHECK-FUNCTION-PASS: Starting llvm::Module pass manager run
; CHECK-FUNCTION-PASS-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}>
+; CHECK-FUNCTION-PASS-NEXT: Running analysis: PreservedCFGCheckerAnalysis on foo
; CHECK-FUNCTION-PASS-NEXT: Starting llvm::Function pass manager run
; CHECK-FUNCTION-PASS-NEXT: Running pass: NoOpFunctionPass
; CHECK-FUNCTION-PASS-NEXT: Finished llvm::Function pass manager run
@@ -53,7 +54,7 @@
; CHECK-MODULE-PRINT: Running pass: VerifierPass
; CHECK-MODULE-PRINT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -debug-pass-manager -disable-verify -passes='print,verify' %s 2>&1 \
+; RUN: opt -disable-output -debug-pass-manager -disable-verify -verify-cfg-preserved=1 -passes='print,verify' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-MODULE-VERIFY
; CHECK-MODULE-VERIFY: Starting llvm::Module pass manager run
; CHECK-MODULE-VERIFY: Running pass: PrintModulePass
@@ -75,7 +76,7 @@
; CHECK-FUNCTION-PRINT: Running pass: VerifierPass
; CHECK-FUNCTION-PRINT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -debug-pass-manager -disable-verify -passes='function(print,verify)' %s 2>&1 \
+; RUN: opt -disable-output -debug-pass-manager -disable-verify -verify-cfg-preserved=1 -passes='function(print,verify)' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-FUNCTION-VERIFY
; CHECK-FUNCTION-VERIFY: Starting llvm::Module pass manager run
; CHECK-FUNCTION-VERIFY: Starting llvm::Function pass manager run
@@ -104,7 +105,7 @@
; RUN: | llvm-dis \
; RUN: | FileCheck %s --check-prefix=CHECK-NOOP
-; RUN: opt -disable-output -debug-pass-manager -disable-verify -passes='no-op-module,function(no-op-function)' %s 2>&1 \
+; RUN: opt -disable-output -debug-pass-manager -disable-verify -verify-cfg-preserved=1 -passes='no-op-module,function(no-op-function)' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-NO-VERIFY
; CHECK-NO-VERIFY: Starting llvm::Module pass manager run
; CHECK-NO-VERIFY-NOT: VerifierPass
@@ -188,7 +189,7 @@
; CHECK-DO-INVALIDATE-FUNCTION-ANALYSIS-RESULTS: Invalidating analysis: NoOpFunctionAnalysis
; CHECK-DO-INVALIDATE-FUNCTION-ANALYSIS-RESULTS: Running analysis: NoOpFunctionAnalysis
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='require<no-op-module>,module(require<no-op-module>,function(require<no-op-function>,invalidate<all>,require<no-op-function>),require<no-op-module>),require<no-op-module>' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-INVALIDATE-ALL
; CHECK-INVALIDATE-ALL: Starting llvm::Module pass manager run
@@ -212,7 +213,7 @@
; CHECK-INVALIDATE-ALL-NOT: Running analysis: NoOpModuleAnalysis
; CHECK-INVALIDATE-ALL: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='require<no-op-module>,module(require<no-op-module>,cgscc(require<no-op-cgscc>,function(require<no-op-function>,invalidate<all>,require<no-op-function>),require<no-op-cgscc>),require<no-op-module>),require<no-op-module>' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-INVALIDATE-ALL-CG
; CHECK-INVALIDATE-ALL-CG: Starting llvm::Module pass manager run
@@ -245,7 +246,7 @@
; CHECK-INVALIDATE-ALL-CG-NOT: Running analysis: NoOpModuleAnalysis
; CHECK-INVALIDATE-ALL-CG: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<targetlibinfo>,invalidate<all>,require<targetlibinfo>' \
; RUN: | FileCheck %s --check-prefix=CHECK-TLI
; CHECK-TLI: Starting llvm::Module pass manager run
@@ -257,7 +258,7 @@
; CHECK-TLI-NOT: Running analysis: TargetLibraryAnalysis
; CHECK-TLI: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<targetir>,invalidate<all>,require<targetir>' \
; RUN: | FileCheck %s --check-prefix=CHECK-TIRA
; CHECK-TIRA: Starting llvm::Module pass manager run
@@ -269,7 +270,7 @@
; CHECK-TIRA-NOT: Running analysis: TargetIRAnalysis
; CHECK-TIRA: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<domtree>' \
; RUN: | FileCheck %s --check-prefix=CHECK-DT
; CHECK-DT: Starting llvm::Module pass manager run
@@ -277,7 +278,7 @@
; CHECK-DT: Running analysis: DominatorTreeAnalysis
; CHECK-DT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<basic-aa>' \
; RUN: | FileCheck %s --check-prefix=CHECK-BASIC-AA
; CHECK-BASIC-AA: Starting llvm::Module pass manager run
@@ -285,7 +286,7 @@
; CHECK-BASIC-AA: Running analysis: BasicAA
; CHECK-BASIC-AA: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<aa>' -aa-pipeline='basic-aa' \
; RUN: | FileCheck %s --check-prefix=CHECK-AA
; CHECK-AA: Starting llvm::Module pass manager run
@@ -294,7 +295,7 @@
; CHECK-AA: Running analysis: BasicAA
; CHECK-AA: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<aa>' -aa-pipeline='default' \
; RUN: | FileCheck %s --check-prefix=CHECK-AA-DEFAULT
; CHECK-AA-DEFAULT: Starting llvm::Module pass manager run
@@ -305,7 +306,7 @@
; CHECK-AA-DEFAULT: Running analysis: TypeBasedAA
; CHECK-AA-DEFAULT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<aa>,invalidate<domtree>,aa-eval' -aa-pipeline='basic-aa' \
; RUN: | FileCheck %s --check-prefix=CHECK-AA-FUNCTION-INVALIDATE
; CHECK-AA-FUNCTION-INVALIDATE: Starting llvm::Function pass manager run
@@ -321,7 +322,7 @@
; CHECK-AA-FUNCTION-INVALIDATE: Running analysis: BasicAA
; CHECK-AA-FUNCTION-INVALIDATE: Finished llvm::Function pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<globals-aa>,function(require<aa>),invalidate<globals-aa>,require<globals-aa>,function(aa-eval)' -aa-pipeline='globals-aa' \
; RUN: | FileCheck %s --check-prefix=CHECK-AA-MODULE-INVALIDATE
; CHECK-AA-MODULE-INVALIDATE: Starting llvm::Module pass manager run
@@ -340,7 +341,7 @@
; CHECK-AA-MODULE-INVALIDATE: Finished llvm::Function pass manager run
; CHECK-AA-MODULE-INVALIDATE: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<memdep>' \
; RUN: | FileCheck %s --check-prefix=CHECK-MEMDEP
; CHECK-MEMDEP: Starting llvm::Module pass manager run
@@ -348,7 +349,7 @@
; CHECK-MEMDEP: Running analysis: MemoryDependenceAnalysis
; CHECK-MEMDEP: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager %s 2>&1 \
; RUN: -passes='require<callgraph>' \
; RUN: | FileCheck %s --check-prefix=CHECK-CALLGRAPH
; CHECK-CALLGRAPH: Starting llvm::Module pass manager run
@@ -356,7 +357,7 @@
; CHECK-CALLGRAPH: Running analysis: CallGraphAnalysis
; CHECK-CALLGRAPH: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='default<O0>' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-O0 --check-prefix=%llvmcheckext
; CHECK-O0: Starting llvm::Module pass manager run
@@ -371,7 +372,7 @@
; CHECK-NOEXT: {{.*}}
; CHECK-O0-NEXT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='repeat<3>(no-op-module)' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-REPEAT-MODULE-PASS
; CHECK-REPEAT-MODULE-PASS: Starting llvm::Module pass manager run
@@ -387,7 +388,7 @@
; CHECK-REPEAT-MODULE-PASS-NEXT: Finished llvm::Module pass manager run
; CHECK-REPEAT-MODULE-PASS-NEXT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='cgscc(repeat<3>(no-op-cgscc))' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-REPEAT-CGSCC-PASS
; CHECK-REPEAT-CGSCC-PASS: Starting llvm::Module pass manager run
@@ -411,11 +412,12 @@
; CHECK-REPEAT-CGSCC-PASS-NEXT: Finished CGSCC pass manager run
; CHECK-REPEAT-CGSCC-PASS-NEXT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='function(repeat<3>(no-op-function))' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-REPEAT-FUNCTION-PASS
; CHECK-REPEAT-FUNCTION-PASS: Starting llvm::Module pass manager run
; CHECK-REPEAT-FUNCTION-PASS-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}>
+; CHECK-REPEAT-FUNCTION-PASS-NEXT: Running analysis: PreservedCFGCheckerAnalysis on foo
; CHECK-REPEAT-FUNCTION-PASS-NEXT: Starting llvm::Function pass manager run
; CHECK-REPEAT-FUNCTION-PASS-NEXT: Running pass: RepeatedPass
; CHECK-REPEAT-FUNCTION-PASS-NEXT: Starting llvm::Function pass manager run
@@ -430,18 +432,21 @@
; CHECK-REPEAT-FUNCTION-PASS-NEXT: Finished llvm::Function pass manager run
; CHECK-REPEAT-FUNCTION-PASS-NEXT: Finished llvm::Module pass manager run
-; RUN: opt -disable-output -disable-verify -debug-pass-manager \
+; RUN: opt -disable-output -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='loop(repeat<3>(no-op-loop))' %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-REPEAT-LOOP-PASS
; CHECK-REPEAT-LOOP-PASS: Starting llvm::Module pass manager run
; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: InnerAnalysisManagerProxy<{{.*}}>
+; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: PreservedCFGCheckerAnalysis on foo
; CHECK-REPEAT-LOOP-PASS-NEXT: Starting llvm::Function pass manager run
; CHECK-REPEAT-LOOP-PASS-NEXT: Starting llvm::Function pass manager run
; CHECK-REPEAT-LOOP-PASS-NEXT: Running pass: LoopSimplify
; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: LoopAnalysis
; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: DominatorTreeAnalysis
; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: AssumptionAnalysis
+; CHECK-REPEAT-LOOP-PASS-NEXT: Invalidating analysis: PreservedCFGCheckerAnalysis on foo
; CHECK-REPEAT-LOOP-PASS-NEXT: Running pass: LCSSAPass
+; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: PreservedCFGCheckerAnalysis on foo
; CHECK-REPEAT-LOOP-PASS-NEXT: Finished llvm::Function pass manager run
; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: AAManager
; CHECK-REPEAT-LOOP-PASS-NEXT: Running analysis: TargetLibraryAnalysis
diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll
index 337a0857701cf..8dc54e4ccb84e 100644
--- a/llvm/test/Other/new-pm-defaults.ll
+++ b/llvm/test/Other/new-pm-defaults.ll
@@ -7,62 +7,62 @@
; Any invalidation that shows up here is a bug, unless we started modifying
; the IR, in which case we need to make it immutable harder.
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='default<O1>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O1,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='default<O2>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O2,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='default<Os>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-Os,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='default<Oz>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-Oz,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes='lto-pre-link<O2>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O2,CHECK-O23SZ,%llvmcheckext
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-peephole='no-op-function' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PEEPHOLE,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-late-loop-optimizations='no-op-loop' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-LATE,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-loop-optimizer-end='no-op-loop' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-LOOP-END,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-scalar-optimizer-late='no-op-function' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-SCALAR-LATE,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-cgscc-optimizer-late='no-op-cgscc' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-CGSCC-LATE,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-vectorizer-start='no-op-function' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-VECTORIZER-START,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-pipeline-start='no-op-module' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-pipeline-early-simplification='no-op-module' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-pipeline-start='no-op-module' \
; RUN: -passes='lto-pre-link<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-LTO,CHECK-O3,%llvmcheckext,CHECK-EP-PIPELINE-START,CHECK-O23SZ
-; RUN: opt -disable-verify -debug-pass-manager \
+; RUN: opt -disable-verify -verify-cfg-preserved=1 -debug-pass-manager \
; RUN: -passes-ep-optimizer-last='no-op-function' \
; RUN: -passes='default<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-DEFAULT,CHECK-O3,%llvmcheckext,CHECK-EP-OPTIMIZER-LAST,CHECK-O23SZ
@@ -77,6 +77,7 @@
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
+; CHECK-O-NEXT: Running analysis: PreservedCFGCheckerAnalysis on foo
; CHECK-O-NEXT: Starting llvm::Function pass manager run.
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 1071cb6cb39b2..b41b61c3580a4 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -275,9 +275,14 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
P->CSAction = PGOOptions::CSIRUse;
}
}
+ LoopAnalysisManager LAM(DebugPM);
+ FunctionAnalysisManager FAM(DebugPM);
+ CGSCCAnalysisManager CGAM(DebugPM);
+ ModuleAnalysisManager MAM(DebugPM);
+
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(DebugPM, VerifyEachPass);
- SI.registerCallbacks(PIC);
+ SI.registerCallbacks(PIC, &FAM);
DebugifyEachInstrumentation Debugify;
if (DebugifyEach)
Debugify.registerCallbacks(PIC);
@@ -373,11 +378,6 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
}
}
- LoopAnalysisManager LAM(DebugPM);
- FunctionAnalysisManager FAM(DebugPM);
- CGSCCAnalysisManager CGAM(DebugPM);
- ModuleAnalysisManager MAM(DebugPM);
-
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });
// Register our TargetLibraryInfoImpl.
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp
index 5e24ae3e54108..a53a81e27a262 100644
--- a/llvm/unittests/IR/PassManagerTest.cpp
+++ b/llvm/unittests/IR/PassManagerTest.cpp
@@ -827,7 +827,7 @@ TEST_F(PassManagerTest, FunctionPassCFGChecker) {
FunctionPassManager FPM(/*DebugLogging*/ true);
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(/*DebugLogging*/ true);
- SI.registerCallbacks(PIC);
+ SI.registerCallbacks(PIC, &FAM);
FAM.registerPass([&] { return PassInstrumentationAnalysis(&PIC); });
FAM.registerPass([&] { return DominatorTreeAnalysis(); });
FAM.registerPass([&] { return AssumptionAnalysis(); });
@@ -873,7 +873,7 @@ TEST_F(PassManagerTest, FunctionPassCFGCheckerInvalidateAnalysis) {
FunctionPassManager FPM(/*DebugLogging*/ true);
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(/*DebugLogging*/ true);
- SI.registerCallbacks(PIC);
+ SI.registerCallbacks(PIC, &FAM);
FAM.registerPass([&] { return PassInstrumentationAnalysis(&PIC); });
FAM.registerPass([&] { return DominatorTreeAnalysis(); });
FAM.registerPass([&] { return AssumptionAnalysis(); });
@@ -938,7 +938,7 @@ TEST_F(PassManagerTest, FunctionPassCFGCheckerWrapped) {
FunctionPassManager FPM(/*DebugLogging*/ true);
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(/*DebugLogging*/ true);
- SI.registerCallbacks(PIC);
+ SI.registerCallbacks(PIC, &FAM);
FAM.registerPass([&] { return PassInstrumentationAnalysis(&PIC); });
FAM.registerPass([&] { return DominatorTreeAnalysis(); });
FAM.registerPass([&] { return AssumptionAnalysis(); });
More information about the llvm-commits
mailing list