[llvm] [LegacyPassManager] Verify all available analyses (PR #98314)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 06:12:37 PDT 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/98314
After a pass that setPreservesAll(), verify all available analyses.
Previously we would only verify analyses that were explicitly preserved
with addPreserved().
In my Release+Asserts build this makes check-llvm-codegen measurably
*faster* because although it verifies more analyses, it involves fewer
calls to the slow function findAnalysisPass.
>From c9814c57d68fbe4b4f4af878b5a14c0914917ff7 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Wed, 10 Jul 2024 13:58:33 +0100
Subject: [PATCH] [LegacyPassManager] Verify all available analyses
After a pass that setPreservesAll(), verify all available analyses.
Previously we would only verify analyses that were explicitly preserved
with addPreserved().
In my Release+Asserts build this makes check-llvm-codegen measurably
*faster* because although it verifies more analyses, it involves fewer
calls to the slow function findAnalysisPass.
---
llvm/include/llvm/Analysis/RegionInfoImpl.h | 2 +-
llvm/include/llvm/IR/LegacyPassManagers.h | 4 ++--
llvm/lib/Analysis/CallGraphSCCPass.cpp | 2 +-
llvm/lib/Analysis/LoopPass.cpp | 4 +---
llvm/lib/Analysis/RegionPass.cpp | 4 +---
llvm/lib/CodeGen/MachineRegionInfo.cpp | 2 +-
llvm/lib/IR/LegacyPassManager.cpp | 21 ++++++++-------------
7 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Analysis/RegionInfoImpl.h b/llvm/include/llvm/Analysis/RegionInfoImpl.h
index c5e8821858fd2..ea53a1438cf0f 100644
--- a/llvm/include/llvm/Analysis/RegionInfoImpl.h
+++ b/llvm/include/llvm/Analysis/RegionInfoImpl.h
@@ -272,7 +272,7 @@ void RegionBase<Tr>::verifyWalk(BlockT *BB, std::set<BlockT *> *visited) const {
template <class Tr>
void RegionBase<Tr>::verifyRegion() const {
// Only do verification when user wants to, otherwise this expensive check
- // will be invoked by PMDataManager::verifyPreservedAnalysis when
+ // will be invoked by PMDataManager::verifyAvailableAnalyses when
// a regionpass (marked PreservedAll) finish.
if (!RegionInfoBase<Tr>::VerifyRegionInfo)
return;
diff --git a/llvm/include/llvm/IR/LegacyPassManagers.h b/llvm/include/llvm/IR/LegacyPassManagers.h
index 6c490791fda4b..b43e1e2bee9da 100644
--- a/llvm/include/llvm/IR/LegacyPassManagers.h
+++ b/llvm/include/llvm/IR/LegacyPassManagers.h
@@ -303,8 +303,8 @@ class PMDataManager {
/// Augment AvailableAnalysis by adding analysis made available by pass P.
void recordAvailableAnalysis(Pass *P);
- /// verifyPreservedAnalysis -- Verify analysis presreved by pass P.
- void verifyPreservedAnalysis(Pass *P);
+ /// verifyAvailableAnalyses -- Verify all available analyses.
+ void verifyAvailableAnalyses();
/// Remove Analysis that is not preserved by the pass
void removeNotPreservedAnalysis(Pass *P);
diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp
index ccba8b3831c8f..3f4f98397a2ad 100644
--- a/llvm/lib/Analysis/CallGraphSCCPass.cpp
+++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp
@@ -482,9 +482,9 @@ bool CGPassManager::RunAllPassesOnSCC(CallGraphSCC &CurSCC, CallGraph &CG,
dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, "");
dumpPreservedSet(P);
- verifyPreservedAnalysis(P);
if (LocalChanged)
removeNotPreservedAnalysis(P);
+ verifyAvailableAnalyses();
recordAvailableAnalysis(P);
removeDeadPasses(P, "", ON_CG_MSG);
}
diff --git a/llvm/lib/Analysis/LoopPass.cpp b/llvm/lib/Analysis/LoopPass.cpp
index 3dc9e75b6168f..64bb2827a0f26 100644
--- a/llvm/lib/Analysis/LoopPass.cpp
+++ b/llvm/lib/Analysis/LoopPass.cpp
@@ -246,14 +246,12 @@ bool LPPassManager::runOnFunction(Function &F) {
assert(CurrentLoop->isRecursivelyLCSSAForm(*DT, *LI));
#endif
- // Then call the regular verifyAnalysis functions.
- verifyPreservedAnalysis(P);
-
F.getContext().yield();
}
if (LocalChanged)
removeNotPreservedAnalysis(P);
+ verifyAvailableAnalyses();
recordAvailableAnalysis(P);
removeDeadPasses(P,
CurrentLoopDeleted ? "<deleted>"
diff --git a/llvm/lib/Analysis/RegionPass.cpp b/llvm/lib/Analysis/RegionPass.cpp
index 9ea7d711918f5..fba3f220b13ac 100644
--- a/llvm/lib/Analysis/RegionPass.cpp
+++ b/llvm/lib/Analysis/RegionPass.cpp
@@ -127,11 +127,9 @@ bool RGPassManager::runOnFunction(Function &F) {
CurrentRegion->verifyRegion();
}
- // Then call the regular verifyAnalysis functions.
- verifyPreservedAnalysis(P);
-
if (LocalChanged)
removeNotPreservedAnalysis(P);
+ verifyAvailableAnalyses();
recordAvailableAnalysis(P);
removeDeadPasses(P,
(!isPassDebuggingExecutionsOrMore())
diff --git a/llvm/lib/CodeGen/MachineRegionInfo.cpp b/llvm/lib/CodeGen/MachineRegionInfo.cpp
index f8268b8894ca3..e93a2f16da4c0 100644
--- a/llvm/lib/CodeGen/MachineRegionInfo.cpp
+++ b/llvm/lib/CodeGen/MachineRegionInfo.cpp
@@ -102,7 +102,7 @@ void MachineRegionInfoPass::releaseMemory() {
void MachineRegionInfoPass::verifyAnalysis() const {
// Only do verification when user wants to, otherwise this expensive check
- // will be invoked by PMDataManager::verifyPreservedAnalysis when
+ // will be invoked by PMDataManager::verifyAvailableAnalyses when
// a regionpass (marked PreservedAll) finish.
if (MachineRegionInfo::VerifyRegionInfo)
RI.verifyAnalysis();
diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp
index 01aaedcf7d547..bc23817cf1794 100644
--- a/llvm/lib/IR/LegacyPassManager.cpp
+++ b/llvm/lib/IR/LegacyPassManager.cpp
@@ -905,21 +905,16 @@ bool PMDataManager::preserveHigherLevelAnalysis(Pass *P) {
return true;
}
-/// verifyPreservedAnalysis -- Verify analysis preserved by pass P.
-void PMDataManager::verifyPreservedAnalysis(Pass *P) {
+/// verifyAvailableAnalyses -- Verify all available analyses.
+void PMDataManager::verifyAvailableAnalyses() {
// Don't do this unless assertions are enabled.
#ifdef NDEBUG
return;
#endif
- AnalysisUsage *AnUsage = TPM->findAnalysisUsage(P);
- const AnalysisUsage::VectorType &PreservedSet = AnUsage->getPreservedSet();
-
- // Verify preserved analysis
- for (AnalysisID AID : PreservedSet) {
- if (Pass *AP = findAnalysisPass(AID, true)) {
- TimeRegion PassTimer(getPassTimer(AP));
- AP->verifyAnalysis();
- }
+ for (auto AA : AvailableAnalysis) {
+ Pass *AP = AA.second;
+ TimeRegion PassTimer(getPassTimer(AP));
+ AP->verifyAnalysis();
}
}
@@ -1469,9 +1464,9 @@ bool FPPassManager::runOnFunction(Function &F) {
dumpPreservedSet(FP);
dumpUsedSet(FP);
- verifyPreservedAnalysis(FP);
if (LocalChanged)
removeNotPreservedAnalysis(FP);
+ verifyAvailableAnalyses();
recordAvailableAnalysis(FP);
removeDeadPasses(FP, Name, ON_FUNCTION_MSG);
}
@@ -1579,9 +1574,9 @@ MPPassManager::runOnModule(Module &M) {
dumpPreservedSet(MP);
dumpUsedSet(MP);
- verifyPreservedAnalysis(MP);
if (LocalChanged)
removeNotPreservedAnalysis(MP);
+ verifyAvailableAnalyses();
recordAvailableAnalysis(MP);
removeDeadPasses(MP, M.getModuleIdentifier(), ON_MODULE_MSG);
}
More information about the llvm-commits
mailing list