[llvm] r179157 - RegionInfo: Add helpers to replace entry/exit recursively
Tobias Grosser
grosser at fim.uni-passau.de
Tue Apr 9 23:54:49 PDT 2013
Author: grosser
Date: Wed Apr 10 01:54:49 2013
New Revision: 179157
URL: http://llvm.org/viewvc/llvm-project?rev=179157&view=rev
Log:
RegionInfo: Add helpers to replace entry/exit recursively
Contributed by: Star Tan <tanmx_star at yeah.net>
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=179157&r1=179156&r2=179157&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/RegionInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/RegionInfo.h Wed Apr 10 01:54:49 2013
@@ -266,6 +266,24 @@ public:
/// @param BB The new exit basic block of the region.
void replaceExit(BasicBlock *BB);
+ /// @brief Recursively replace the entry basic block of the region.
+ ///
+ /// This function replaces the entry basic block with a new basic block. It
+ /// also updates all child regions that have the same entry basic block as
+ /// this region.
+ ///
+ /// @param NewEntry The new entry basic block.
+ void replaceEntryRecursive(BasicBlock *NewEntry);
+
+ /// @brief Recursively replace the exit basic block of the region.
+ ///
+ /// This function replaces the exit basic block with a new basic block. It
+ /// also updates all child regions that have the same exit basic block as
+ /// this region.
+ ///
+ /// @param NewExit The new exit basic block.
+ void replaceExitRecursive(BasicBlock *NewExit);
+
/// @brief Get the exit BasicBlock of the Region.
/// @return The exit BasicBlock of the Region, NULL if this is the TopLevel
/// Region.
Modified: llvm/trunk/lib/Analysis/RegionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/RegionInfo.cpp?rev=179157&r1=179156&r2=179157&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/RegionInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/RegionInfo.cpp Wed Apr 10 01:54:49 2013
@@ -79,6 +79,38 @@ void Region::replaceExit(BasicBlock *BB)
exit = BB;
}
+void Region::replaceEntryRecursive(BasicBlock *NewEntry) {
+ std::vector<Region *> RegionQueue;
+ BasicBlock *OldEntry = getEntry();
+
+ RegionQueue.push_back(this);
+ while (!RegionQueue.empty()) {
+ Region *R = RegionQueue.back();
+ RegionQueue.pop_back();
+
+ R->replaceEntry(NewEntry);
+ for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI)
+ if ((*RI)->getEntry() == OldEntry)
+ RegionQueue.push_back(*RI);
+ }
+}
+
+void Region::replaceExitRecursive(BasicBlock *NewExit) {
+ std::vector<Region *> RegionQueue;
+ BasicBlock *OldExit = getExit();
+
+ RegionQueue.push_back(this);
+ while (!RegionQueue.empty()) {
+ Region *R = RegionQueue.back();
+ RegionQueue.pop_back();
+
+ R->replaceExit(NewExit);
+ for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI)
+ if ((*RI)->getExit() == OldExit)
+ RegionQueue.push_back(*RI);
+ }
+}
+
bool Region::contains(const BasicBlock *B) const {
BasicBlock *BB = const_cast<BasicBlock*>(B);
More information about the llvm-commits
mailing list