X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FRegionInfo.cpp;h=6725cfd28fabbcff550aee75f182793840331a47;hb=c0362d5c6e0066c741bce056a65d8b4c026de19f;hp=75ca61f67c7346736acc96b1d272f59d231fb807;hpb=9649390e1fcb6d42e228364230f16409ad150fef;p=oota-llvm.git diff --git a/lib/Analysis/RegionInfo.cpp b/lib/Analysis/RegionInfo.cpp index 75ca61f67c7..6725cfd28fa 100644 --- a/lib/Analysis/RegionInfo.cpp +++ b/lib/Analysis/RegionInfo.cpp @@ -45,7 +45,7 @@ STATISTIC(numSimpleRegions, "The # of simple regions"); /// PrintStyle - Print region in difference ways. enum PrintStyle { PrintNone, PrintBB, PrintRN }; -cl::opt printStyle("print-region-style", cl::Hidden, +static cl::opt printStyle("print-region-style", cl::Hidden, cl::desc("style of printing regions"), cl::values( clEnumValN(PrintNone, "none", "print no details"), @@ -72,6 +72,15 @@ Region::~Region() { delete *I; } +void Region::replaceEntry(BasicBlock *BB) { + entry.setPointer(BB); +} + +void Region::replaceExit(BasicBlock *BB) { + assert(exit && "No exit to replace!"); + exit = BB; +} + bool Region::contains(const BasicBlock *B) const { BasicBlock *BB = const_cast(B); @@ -131,8 +140,7 @@ bool Region::isSimple() const { BasicBlock *entry = getEntry(), *exit = getExit(); - // TopLevelRegion - if (!exit) + if (isTopLevelRegion()) return false; for (pred_iterator PI = pred_begin(entry), PE = pred_end(entry); PI != PE; @@ -364,6 +372,38 @@ unsigned Region::getDepth() const { return Depth; } +Region *Region::getExpandedRegion() const { + unsigned NumSuccessors = exit->getTerminator()->getNumSuccessors(); + + if (NumSuccessors == 0) + return NULL; + + for (pred_iterator PI = pred_begin(getExit()), PE = pred_end(getExit()); + PI != PE; ++PI) + if (!DT->dominates(getEntry(), *PI)) + return NULL; + + Region *R = RI->getRegionFor(exit); + + if (R->getEntry() != exit) { + if (exit->getTerminator()->getNumSuccessors() == 1) + return new Region(getEntry(), *succ_begin(exit), RI, DT); + else + return NULL; + } + + while (R->getParent() && R->getParent()->getEntry() == exit) + R = R->getParent(); + + if (!DT->dominates(getEntry(), R->getExit())) + for (pred_iterator PI = pred_begin(getExit()), PE = pred_end(getExit()); + PI != PE; ++PI) + if (!DT->dominates(R->getExit(), *PI)) + return NULL; + + return new Region(getEntry(), R->getExit(), RI, DT); +} + void Region::print(raw_ostream &OS, bool print_tree, unsigned level) const { if (print_tree) OS.indent(level*2) << "[" << level << "] " << getNameStr(); @@ -403,7 +443,7 @@ void Region::dump() const { void Region::clearNodeCache() { // Free the cached nodes. for (BBNodeMapT::iterator I = BBNodeMap.begin(), - IE = BBNodeMap.end(); I != IE; ++IE) + IE = BBNodeMap.end(); I != IE; ++I) delete I->second; BBNodeMap.clear(); @@ -622,6 +662,7 @@ void RegionInfo::releaseMemory() { } RegionInfo::RegionInfo() : FunctionPass(ID) { + initializeRegionInfoPass(*PassRegistry::getPassRegistry()); TopLevelRegion = 0; } @@ -766,6 +807,20 @@ RegionInfo::getCommonRegion(SmallVectorImpl &BBs) const { return ret; } +void RegionInfo::splitBlock(BasicBlock* NewBB, BasicBlock *OldBB) +{ + Region *R = getRegionFor(OldBB); + + setRegionFor(NewBB, R); + + while (R->getEntry() == OldBB && !R->isTopLevelRegion()) { + R->replaceEntry(NewBB); + R = R->getParent(); + } + + setRegionFor(OldBB, R); +} + char RegionInfo::ID = 0; INITIALIZE_PASS_BEGIN(RegionInfo, "regions", "Detect single entry single exit regions", true, true)