[llvm-commits] [llvm] r109496 - in /llvm/trunk: include/llvm/Analysis/RegionInfo.h lib/Analysis/RegionInfo.cpp
Tobias Grosser
grosser at fim.uni-passau.de
Tue Jul 27 01:39:43 PDT 2010
Author: grosser
Date: Tue Jul 27 03:39:43 2010
New Revision: 109496
URL: http://llvm.org/viewvc/llvm-project?rev=109496&view=rev
Log:
RegionInfo: Add getMaxRegionExit()
getMaxRegionExit returns the exit of the maximal refined region starting
at a specific basic block.
Modified:
llvm/trunk/include/llvm/Analysis/RegionInfo.h
llvm/trunk/lib/Analysis/RegionInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/RegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/RegionInfo.h?rev=109496&r1=109495&r2=109496&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/RegionInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/RegionInfo.h Tue Jul 27 03:39:43 2010
@@ -572,6 +572,12 @@
/// region containing BB.
Region *operator[](BasicBlock *BB) const;
+ /// @brief Return the exit of the maximal refined region, that starts at a
+ /// BasicBlock.
+ ///
+ /// @param BB The BasicBlock the refined region starts.
+ BasicBlock *getMaxRegionExit(BasicBlock *BB) const;
+
/// @brief Find the smallest region that contains two regions.
///
/// @param A The first region.
Modified: llvm/trunk/lib/Analysis/RegionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionInfo.cpp?rev=109496&r1=109495&r2=109496&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionInfo.cpp Tue Jul 27 03:39:43 2010
@@ -651,6 +651,45 @@
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");
More information about the llvm-commits
mailing list