[PATCH] D35279: [Dominators] Improve reachability verification

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 16:31:56 PDT 2017


kuhar created this revision.

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.


https://reviews.llvm.org/D35279

Files:
  include/llvm/Support/GenericDomTree.h
  include/llvm/Support/GenericDomTreeConstruction.h


Index: include/llvm/Support/GenericDomTreeConstruction.h
===================================================================
--- include/llvm/Support/GenericDomTreeConstruction.h
+++ include/llvm/Support/GenericDomTreeConstruction.h
@@ -298,9 +298,11 @@
     for (auto &NodeToTN : DT.DomTreeNodes) {
       const TreeNodePtr TN = NodeToTN.second.get();
       const NodePtr BB = TN->getBlock();
-      if (!BB) continue;
 
-      if (NodeToInfo.count(BB) == 0) {
+      // Virtual root doesn't have a corresponding CFG node.
+      if (DT.isVirtualRoot(TN)) continue;
+
+      if (!BB || NodeToInfo.count(BB) == 0) {
         errs() << "DomTree node ";
         PrintBlockOrNullptr(errs(), BB);
         errs() << " not found by DFS walk!\n";
@@ -310,6 +312,17 @@
       }
     }
 
+    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;
   }
 
@@ -363,7 +376,7 @@
       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:";
Index: include/llvm/Support/GenericDomTree.h
===================================================================
--- include/llvm/Support/GenericDomTree.h
+++ include/llvm/Support/GenericDomTree.h
@@ -443,6 +443,10 @@
                                       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...


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35279.106113.patch
Type: text/x-patch
Size: 2063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170711/7c286a54/attachment.bin>


More information about the llvm-commits mailing list