Skip to content

Commit 6f2c610

Browse files
authored
[CGSCC] Verify that call graph is valid after iteration (#94692)
Only in expensive checks, to match other LazyCallGraph verification. Is helpful for verifying LazyCallGraph updates. Many issues only surface when we reuse the LazyCallGraph.
1 parent f9ae07b commit 6f2c610

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

llvm/include/llvm/Analysis/LazyCallGraph.h

+5
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,11 @@ class LazyCallGraph {
943943
LazyCallGraph(LazyCallGraph &&G);
944944
LazyCallGraph &operator=(LazyCallGraph &&RHS);
945945

946+
#if !defined(NDEBUG) || defined(EXPENSIVE_CHECKS)
947+
/// Verify that every RefSCC is valid.
948+
void verify();
949+
#endif
950+
946951
bool invalidate(Module &, const PreservedAnalyses &PA,
947952
ModuleAnalysisManager::Invalidator &);
948953

llvm/lib/Analysis/CGSCCPassManager.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ ModuleToPostOrderCGSCCPassAdaptor::run(Module &M, ModuleAnalysisManager &AM) {
340340
} while (!RCWorklist.empty());
341341
}
342342

343+
#if defined(EXPENSIVE_CHECKS)
344+
// Verify that the call graph is still valid.
345+
CG.verify();
346+
#endif
347+
343348
// By definition we preserve the call garph, all SCC analyses, and the
344349
// analysis proxies by handling them above and in any nested pass managers.
345350
PA.preserveSet<AllAnalysesOn<LazyCallGraph::SCC>>();

llvm/lib/Analysis/LazyCallGraph.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ LazyCallGraph::LazyCallGraph(LazyCallGraph &&G)
211211
updateGraphPtrs();
212212
}
213213

214+
#if !defined(NDEBUG) || defined(EXPENSIVE_CHECKS)
215+
void LazyCallGraph::verify() {
216+
for (RefSCC &RC : postorder_ref_sccs()) {
217+
RC.verify();
218+
}
219+
}
220+
#endif
221+
214222
bool LazyCallGraph::invalidate(Module &, const PreservedAnalyses &PA,
215223
ModuleAnalysisManager::Invalidator &) {
216224
// Check whether the analysis, all analyses on functions, or the function's

0 commit comments

Comments
 (0)