Skip to content

Commit

Permalink
[Dominators] Improve reachability verification
Browse files Browse the repository at this point in the history
Summary:
This patch improves verification by making `verifyReachablility` look for CFG not found in the DomTree.
It also makes the verification work with postdominators by handling virtual root.

Reviewers: dberlin, davide, grosser, sanjoy

Reviewed By: dberlin

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D35279

llvm-svn: 307936
  • Loading branch information
kuhar committed Jul 13, 2017
1 parent 89b2d7c commit 3064fae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions llvm/include/llvm/Support/GenericDomTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ template <class NodeT> class DominatorTreeBase {
const_cast<NodeT *>(B));
}

bool isVirtualRoot(const DomTreeNodeBase<NodeT> *A) const {
return isPostDominator() && !A->getBlock();
}

//===--------------------------------------------------------------------===//
// API to update (Post)DominatorTree information based on modifications to
// the CFG...
Expand Down
17 changes: 15 additions & 2 deletions llvm/include/llvm/Support/GenericDomTreeConstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ struct SemiNCAInfo {
for (auto &NodeToTN : DT.DomTreeNodes) {
const TreeNodePtr TN = NodeToTN.second.get();
const NodePtr BB = TN->getBlock();
if (!BB) continue;

// Virtual root has a corresponding virtual CFG node.
if (DT.isVirtualRoot(TN)) continue;

if (NodeToInfo.count(BB) == 0) {
errs() << "DomTree node ";
Expand All @@ -310,6 +312,17 @@ struct SemiNCAInfo {
}
}

for (const NodePtr N : NumToNode) {
if (N && !DT.getNode(N)) {
errs() << "CFG node ";
PrintBlockOrNullptr(errs(), N);
errs() << " not found in the DomTree!\n";
errs().flush();

return false;
}
}

return true;
}

Expand Down Expand Up @@ -363,7 +376,7 @@ struct SemiNCAInfo {
assert(ToTN);

const NodePtr NCD = DT.findNearestCommonDominator(From, To);
const TreeNodePtr NCDTN = NCD ? DT.getNode(NCD) : nullptr;
const TreeNodePtr NCDTN = DT.getNode(NCD);
const TreeNodePtr ToIDom = ToTN->getIDom();
if (NCDTN != ToTN && NCDTN != ToIDom) {
errs() << "NearestCommonDominator verification failed:\n\tNCD(From:";
Expand Down

0 comments on commit 3064fae

Please sign in to comment.