From 570e4c977e83c46f8a9c74cefcc9057d571780fe Mon Sep 17 00:00:00 2001 From: Hongbin Zheng Date: Tue, 19 Sep 2017 04:59:27 +0000 Subject: [PATCH] [LLVM] [RegionInfo] Introduce getExitingBlocks to get all predecessors of Exit in the current region. This function will return true if all predecessors of Exit are in the current region, false otherwise. Differential Revision: https://reviews.llvm.org/D36210 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313611 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/RegionInfo.h | 5 +++++ include/llvm/Analysis/RegionInfoImpl.h | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index 8e633cc3c86..71962235994 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -407,6 +407,11 @@ public: /// else NULL. BlockT *getExitingBlock() const; + /// @brief Collect all blocks of this region's single exit edge, if existing. + /// + /// @return True if this region contains all the predecessors of the exit. + bool getExitingBlocks(SmallVectorImpl &Exitings) const; + /// @brief Is this a simple region? /// /// A region is simple if it has exactly one exit and one entry edge. diff --git a/include/llvm/Analysis/RegionInfoImpl.h b/include/llvm/Analysis/RegionInfoImpl.h index cd4ec0a03a9..6e522354dd9 100644 --- a/include/llvm/Analysis/RegionInfoImpl.h +++ b/include/llvm/Analysis/RegionInfoImpl.h @@ -177,6 +177,29 @@ typename RegionBase::BlockT *RegionBase::getEnteringBlock() const { return enteringBlock; } +template +bool RegionBase::getExitingBlocks( + SmallVectorImpl &Exitings) const { + bool CoverAll = true; + + if (!exit) + return CoverAll; + + for (PredIterTy PI = InvBlockTraits::child_begin(exit), + PE = InvBlockTraits::child_end(exit); + PI != PE; ++PI) { + BlockT *Pred = *PI; + if (contains(Pred)) { + Exitings.push_back(Pred); + continue; + } + + CoverAll = false; + } + + return CoverAll; +} + template typename RegionBase::BlockT *RegionBase::getExitingBlock() const { BlockT *exit = getExit(); -- 2.40.0