[PATCH] D41298: [PDT] Add verifyDomTree and verifyAnalysis for Post Dom Trees
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 09:22:47 PST 2017
dmgreen created this revision.
This will allow checking of post dom trees it the same way we check domtrees and machine domtrees.
https://reviews.llvm.org/D41298
Files:
include/llvm/Analysis/PostDominators.h
lib/Analysis/PostDominators.cpp
lib/IR/Dominators.cpp
Index: lib/IR/Dominators.cpp
===================================================================
--- lib/IR/Dominators.cpp
+++ lib/IR/Dominators.cpp
@@ -381,8 +381,8 @@
}
void DominatorTreeWrapperPass::verifyAnalysis() const {
- if (VerifyDomInfo)
- DT.verifyDomTree();
+ if (VerifyDomInfo)
+ DT.verifyDomTree();
}
void DominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
Index: lib/Analysis/PostDominators.cpp
===================================================================
--- lib/Analysis/PostDominators.cpp
+++ lib/Analysis/PostDominators.cpp
@@ -39,11 +39,42 @@
PAC.preservedSet<CFGAnalyses>());
}
+void PostDominatorTree::verifyDomTree() const {
+ // Perform the expensive checks only when VerifyDomInfo is set.
+ if (VerifyDomInfo && !verify()) {
+ errs() << "\n~~~~~~~~~~~\n\t\tDomTree verification failed!\n~~~~~~~~~~~\n";
+ print(errs());
+ abort();
+ }
+
+ assert(getRoots().size() >= 1);
+ Function &F = *getRoots()[0]->getParent();
+
+ PostDominatorTree OtherDT;
+ OtherDT.recalculate(F);
+ if (compare(OtherDT)) {
+ errs() << "PostDominatorTree for function " << F.getName()
+ << " is not up to date!\nExisting:\n";
+ print(errs());
+ errs() << "\nRecalculated:\n";
+ OtherDT.print(errs());
+ errs() << "\nCFG:\n";
+ F.print(errs());
+ errs().flush();
+ abort();
+ }
+}
+
bool PostDominatorTreeWrapperPass::runOnFunction(Function &F) {
DT.recalculate(F);
return false;
}
+void PostDominatorTreeWrapperPass::verifyAnalysis() const {
+ if (VerifyDomInfo)
+ DT.verifyDomTree();
+}
+
void PostDominatorTreeWrapperPass::print(raw_ostream &OS, const Module *) const {
DT.print(OS);
}
Index: include/llvm/Analysis/PostDominators.h
===================================================================
--- include/llvm/Analysis/PostDominators.h
+++ include/llvm/Analysis/PostDominators.h
@@ -32,6 +32,12 @@
/// Handle invalidation explicitly.
bool invalidate(Function &F, const PreservedAnalyses &PA,
FunctionAnalysisManager::Invalidator &);
+
+ /// \brief Verify the correctness of the domtree by re-computing it.
+ ///
+ /// This should only be used for debugging as it aborts the program if the
+ /// verification fails.
+ void verifyDomTree() const;
};
/// \brief Analysis pass which computes a \c PostDominatorTree.
@@ -75,6 +81,8 @@
bool runOnFunction(Function &F) override;
+ void verifyAnalysis() const override;
+
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41298.127141.patch
Type: text/x-patch
Size: 2593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/30293067/attachment.bin>
More information about the llvm-commits
mailing list