[PATCH] D11872: [RegionInfo] Verify getRegionFor

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 8 11:49:21 PDT 2015


Meinersbur created this revision.
Meinersbur added a reviewer: grosser.
Meinersbur added a subscriber: llvm-commits.
Meinersbur set the repository for this revision to rL LLVM.

Check the contents of BBtoRegion during analysis verification.

Repository:
  rL LLVM

http://reviews.llvm.org/D11872

Files:
  include/llvm/Analysis/RegionInfo.h
  include/llvm/Analysis/RegionInfoImpl.h

Index: include/llvm/Analysis/RegionInfoImpl.h
===================================================================
--- include/llvm/Analysis/RegionInfoImpl.h
+++ include/llvm/Analysis/RegionInfoImpl.h
@@ -236,23 +236,25 @@
 template <class Tr>
 void RegionBase<Tr>::verifyBBInRegion(BlockT *BB) const {
   if (!contains(BB))
-    llvm_unreachable("Broken region found!");
+    llvm_unreachable("Broken region found: enumerated BB not in region!");
 
   BlockT *entry = getEntry(), *exit = getExit();
 
   for (SuccIterTy SI = BlockTraits::child_begin(BB),
                   SE = BlockTraits::child_end(BB);
        SI != SE; ++SI) {
     if (!contains(*SI) && exit != *SI)
-      llvm_unreachable("Broken region found!");
+      llvm_unreachable("Broken region found: edges leaving the region must go "
+                       "to the exit node!");
   }
 
   if (entry != BB) {
     for (PredIterTy SI = InvBlockTraits::child_begin(BB),
                     SE = InvBlockTraits::child_end(BB);
          SI != SE; ++SI) {
       if (!contains(*SI))
-        llvm_unreachable("Broken region found!");
+        llvm_unreachable("Broken region found: edges entering the region must "
+                         "go to the entry node!");
     }
   }
 }
@@ -542,6 +544,21 @@
 }
 
 template <class Tr>
+void RegionInfoBase<Tr>::verifyBBMap(const RegionT *R) const {
+  assert(R && "Re must be non-null");
+  for (auto I = R->element_begin(), E = R->element_end(); I != E; ++I) {
+    if (I->isSubRegion()) {
+      const RegionT *SR = I->template getNodeAs<RegionT>();
+      verifyBBMap(SR);
+    } else {
+      BlockT *BB = I->template getNodeAs<BlockT>();
+      if (getRegionFor(BB) != R)
+        llvm_unreachable("BB map does not match region nesting");
+    }
+  }
+}
+
+template <class Tr>
 bool RegionInfoBase<Tr>::isCommonDomFrontier(BlockT *BB, BlockT *entry,
                                              BlockT *exit) const {
   for (PredIterTy PI = InvBlockTraits::child_begin(BB),
@@ -786,7 +803,14 @@
 
 template <class Tr>
 void RegionInfoBase<Tr>::verifyAnalysis() const {
+  // Do only verify regions if explicitely activated using XDEBUG or
+  // -verify-region-info
+  if (!RegionInfoBase<Tr>::VerifyRegionInfo)
+    return;
+
   TopLevelRegion->verifyRegionNest();
+
+  verifyBBMap(TopLevelRegion);
 }
 
 // Region pass manager support.
Index: include/llvm/Analysis/RegionInfo.h
===================================================================
--- include/llvm/Analysis/RegionInfo.h
+++ include/llvm/Analysis/RegionInfo.h
@@ -688,6 +688,11 @@
   /// Map every BB to the smallest region, that contains BB.
   BBtoRegionMap BBtoRegion;
 
+  // verifyBBMap - Check whether the entries of BBtoRegion for the BBs of region
+  // SR are correct. Triggers an assertion if not. Calls itself recursively for
+  // subregions.
+  void verifyBBMap(const RegionT *SR) const;
+
   // isCommonDomFrontier - Returns true if BB is in the dominance frontier of
   // entry, because it was inherited from exit. In the other case there is an
   // edge going from entry to BB without passing exit.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11872.31591.patch
Type: text/x-patch
Size: 3098 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150808/e06ae77c/attachment.bin>


More information about the llvm-commits mailing list