summaryrefslogtreecommitdiff
path: root/lib/Analysis/RegionInfo.cpp
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2010-07-27 08:39:43 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2010-07-27 08:39:43 +0000
commit0e6fcf4be360f5d73685c213e3b4af1bb9ce2b5d (patch)
tree32292954d18407ee71186d4be76b92d184a9d875 /lib/Analysis/RegionInfo.cpp
parent2c11046fa186a4489bfd562cd81ff8a4883cb223 (diff)
downloadllvm-0e6fcf4be360f5d73685c213e3b4af1bb9ce2b5d.tar.gz
llvm-0e6fcf4be360f5d73685c213e3b4af1bb9ce2b5d.tar.bz2
llvm-0e6fcf4be360f5d73685c213e3b4af1bb9ce2b5d.tar.xz
RegionInfo: Add getMaxRegionExit()
getMaxRegionExit returns the exit of the maximal refined region starting at a specific basic block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109496 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/RegionInfo.cpp')
-rw-r--r--lib/Analysis/RegionInfo.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/Analysis/RegionInfo.cpp b/lib/Analysis/RegionInfo.cpp
index 0ea92cb012..ac660e72f0 100644
--- a/lib/Analysis/RegionInfo.cpp
+++ b/lib/Analysis/RegionInfo.cpp
@@ -651,6 +651,45 @@ Region *RegionInfo::operator[](BasicBlock *BB) const {
return getRegionFor(BB);
}
+
+BasicBlock *RegionInfo::getMaxRegionExit(BasicBlock *BB) const {
+ BasicBlock *Exit = NULL;
+
+ while (true) {
+ // Get largest region that starts at BB.
+ Region *R = getRegionFor(BB);
+ while (R && R->getParent() && R->getParent()->getEntry() == BB)
+ R = R->getParent();
+
+ // Get the single exit of BB.
+ if (R && R->getEntry() == BB)
+ Exit = R->getExit();
+ else if (++succ_begin(BB) == succ_end(BB))
+ Exit = *succ_begin(BB);
+ else // No single exit exists.
+ return Exit;
+
+ // Get largest region that starts at Exit.
+ Region *ExitR = getRegionFor(Exit);
+ while (ExitR && ExitR->getParent()
+ && ExitR->getParent()->getEntry() == Exit)
+ ExitR = ExitR->getParent();
+
+ for (pred_iterator PI = pred_begin(Exit), PE = pred_end(Exit); PI != PE;
+ ++PI)
+ if (!R->contains(*PI) && !ExitR->contains(*PI))
+ break;
+
+ // This stops infinite cycles.
+ if (DT->dominates(Exit, BB))
+ break;
+
+ BB = Exit;
+ }
+
+ return Exit;
+}
+
Region*
RegionInfo::getCommonRegion(Region *A, Region *B) const {
assert (A && B && "One of the Regions is NULL");