Index: include/llvm/Analysis/RegionInfo.h =================================================================== --- include/llvm/Analysis/RegionInfo.h +++ include/llvm/Analysis/RegionInfo.h @@ -687,6 +687,11 @@ /// Map every BB to the smallest region, that contains BB. BBtoRegionMap BBtoRegion; + // 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; + // 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. Index: include/llvm/Analysis/RegionInfoImpl.h =================================================================== --- include/llvm/Analysis/RegionInfoImpl.h +++ include/llvm/Analysis/RegionInfoImpl.h @@ -544,6 +544,21 @@ } template +void RegionInfoBase::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(); + verifyBBMap(SR); + } else { + BlockT *BB = I->template getNodeAs(); + if (getRegionFor(BB) != R) + llvm_unreachable("BB map does not match region nesting"); + } + } +} + +template bool RegionInfoBase::isCommonDomFrontier(BlockT *BB, BlockT *entry, BlockT *exit) const { for (PredIterTy PI = InvBlockTraits::child_begin(BB), @@ -788,7 +803,14 @@ template void RegionInfoBase::verifyAnalysis() const { + // Do only verify regions if explicitely activated using XDEBUG or + // -verify-region-info + if (!RegionInfoBase::VerifyRegionInfo) + return; + TopLevelRegion->verifyRegionNest(); + + verifyBBMap(TopLevelRegion); } // Region pass manager support.