Skip to content

Commit

Permalink
RegionInfo: Add helpers to replace entry/exit recursively
Browse files Browse the repository at this point in the history
Contributed by: Star Tan <[email protected]>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179157 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tobiasgrosser committed Apr 10, 2013
1 parent 90dd7fd commit d03fdfb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
18 changes: 18 additions & 0 deletions include/llvm/Analysis/RegionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ class Region : public RegionNode {
/// @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.
Expand Down
32 changes: 32 additions & 0 deletions lib/Analysis/RegionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d03fdfb

Please sign in to comment.