From 58cee9e869103f4d8ee4c453274f2cfbd316a624 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Tue, 11 Aug 2015 15:16:43 +0000 Subject: [PATCH] [RegionInfo] Verify getRegionFor Summary: Check the contents of BBtoRegion during analysis verification. It only takes place if -verify-region-info is passed or LLVM is compiled with XDEBUG. RegionBase::verifyRegion() also checks the RegionInfoBase::VerifyRegionInfo flag, which is redundant, but verifyRegion() is public API and might be invoked from other sites. In order to avoid behavioral change, this check is not removed. In any case, no region will be verified unless VerifyRegionInfo is set. Reviewers: grosser Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D11872 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244611 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/RegionInfo.h | 5 +++++ include/llvm/Analysis/RegionInfoImpl.h | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index 57219fe0f41..8d1739a679b 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -687,6 +687,11 @@ private: /// 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. diff --git a/include/llvm/Analysis/RegionInfoImpl.h b/include/llvm/Analysis/RegionInfoImpl.h index 38bc365b8b9..a5157a92cf4 100644 --- a/include/llvm/Analysis/RegionInfoImpl.h +++ b/include/llvm/Analysis/RegionInfoImpl.h @@ -544,6 +544,21 @@ RegionInfoBase::~RegionInfoBase() { } 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 @@ void RegionInfoBase::releaseMemory() { 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. -- 2.11.0