]> granicus.if.org Git - llvm/commitdiff
[LLVM] [RegionInfo] Introduce getExitingBlocks to get all predecessors of Exit in...
authorHongbin Zheng <etherzhhb@gmail.com>
Tue, 19 Sep 2017 04:59:27 +0000 (04:59 +0000)
committerHongbin Zheng <etherzhhb@gmail.com>
Tue, 19 Sep 2017 04:59:27 +0000 (04:59 +0000)
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
include/llvm/Analysis/RegionInfoImpl.h

index 8e633cc3c867f9255ca3bf33ddc5ddc7d732739f..71962235994949f26ec4843a95e54089fcd2dafe 100644 (file)
@@ -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<BlockT *> &Exitings) const;
+
   /// @brief Is this a simple region?
   ///
   /// A region is simple if it has exactly one exit and one entry edge.
index cd4ec0a03a9ee22b5b8a213e2ed49e896a0e011f..6e522354dd9b48e3f214de17debe1df7db86c63d 100644 (file)
@@ -177,6 +177,29 @@ typename RegionBase<Tr>::BlockT *RegionBase<Tr>::getEnteringBlock() const {
   return enteringBlock;
 }
 
+template <class Tr>
+bool RegionBase<Tr>::getExitingBlocks(
+    SmallVectorImpl<BlockT *> &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 <class Tr>
 typename RegionBase<Tr>::BlockT *RegionBase<Tr>::getExitingBlock() const {
   BlockT *exit = getExit();