Home | History | Annotate | Download | only in Analysis

Lines Matching defs:Region

1 //===- RegionInfo.cpp - SESE region detection analysis --------------------===//
22 #define DEBUG_TYPE "region"
38 VerifyRegionInfoX("verify-region-info", cl::location(VerifyRegionInfo),
39 cl::desc("Verify region info (time consuming)"));
44 static cl::opt<enum Region::PrintStyle> printStyle("print-region-style",
48 clEnumValN(Region::PrintNone, "none", "print no details"),
49 clEnumValN(Region::PrintBB, "bb",
51 clEnumValN(Region::PrintRN, "rn",
55 /// Region Implementation
56 Region::Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo* RInfo,
57 DominatorTree *dt, Region *Parent)
60 Region::~Region() {
66 // Only clean the cache for this Region. Caches of child Regions will be
74 void Region::replaceEntry(BasicBlock *BB) {
78 void Region::replaceExit(BasicBlock *BB) {
83 bool Region::contains(const BasicBlock *B) const {
90 // Toplevel region.
98 bool Region::contains(const Loop *L) const {
100 // described by the NULL pointer. This loop is not part of any region,
101 // except if the region describes the whole function.
119 Loop *Region::outermostLoopInRegion(Loop *L) const {
130 Loop *Region::outermostLoopInRegion(LoopInfo *LI, BasicBlock* BB) const {
136 BasicBlock *Region::getEnteringBlock() const {
155 BasicBlock *Region::getExitingBlock() const {
177 bool Region::isSimple() const {
181 std::string Region::getNameStr() const {
207 void Region::verifyBBInRegion(BasicBlock *BB) const {
209 llvm_unreachable("Broken region found!");
215 llvm_unreachable("Broken region found!");
220 llvm_unreachable("Broken region found!");
223 void Region::verifyWalk(BasicBlock *BB, std::set<BasicBlock*> *visited) const {
235 void Region::verifyRegion() const {
244 void Region::verifyRegionNest() const {
245 for (Region::const_iterator RI = begin(), RE = end(); RI != RE; ++RI)
251 Region::block_iterator Region::block_begin() {
252 return GraphTraits<FlatIt<Region*> >::nodes_begin(this);
255 Region::block_iterator Region::block_end() {
256 return GraphTraits<FlatIt<Region*> >::nodes_end(this);
259 Region::const_block_iterator Region::block_begin() const {
260 return GraphTraits<FlatIt<const Region*> >::nodes_begin(this);
263 Region::const_block_iterator Region::block_end() const {
264 return GraphTraits<FlatIt<const Region*> >::nodes_end(this);
267 Region::element_iterator Region::element_begin() {
268 return GraphTraits<Region*>::nodes_begin(this);
271 Region::element_iterator Region::element_end() {
272 return GraphTraits<Region*>::nodes_end(this);
275 Region::const_element_iterator Region::element_begin() const {
276 return GraphTraits<const Region*>::nodes_begin(this);
279 Region::const_element_iterator Region::element_end() const {
280 return GraphTraits<const Region*>::nodes_end(this);
283 Region* Region::getSubRegionNode(BasicBlock *BB) const {
284 Region *R = RI->getRegionFor(BB);
289 // If we pass the BB out of this region, that means our code is broken.
290 assert(contains(R) && "BB not in current region!");
301 RegionNode* Region::getBBNode(BasicBlock *BB) const {
302 assert(contains(BB) && "Can get BB node out of this region!");
309 RegionNode *NewNode = new RegionNode(const_cast<Region*>(this), BB);
314 RegionNode* Region::getNode(BasicBlock *BB) const {
315 assert(contains(BB) && "Can get BB node out of this region!");
316 if (Region* Child = getSubRegionNode(BB))
322 void Region::transferChildrenTo(Region *To) {
330 void Region::addSubRegion(Region *SubRegion, bool moveChildren) {
352 std::vector<Region*> Keep;
365 Region *Region::removeSubRegion(Region *Child) {
366 assert(Child->parent == this && "Child is not a child of this region!");
369 assert(I != children.end() && "Region does not exit. Unable to remove.");
374 unsigned Region::getDepth() const {
377 for (Region *R = parent; R != 0; R = R->parent)
383 Region *Region::getExpandedRegion() const {
394 Region *R = RI->getRegionFor(exit);
398 return new Region(getEntry(), *succ_begin(exit), RI, DT);
412 return new Region(getEntry(), R->getExit(), RI, DT);
415 void Region::print(raw_ostream &OS, bool print_tree, unsigned level,
448 void Region::dump() const {
452 void Region::clearNodeCache() {
459 for (Region::iterator RI = begin(), RE = end(); RI != RE; ++RI)
496 // Do not allow edges leaving the region.
507 // Do not allow edges pointing into the region.
524 // No further region at exit available.
527 // We found a region e that starts at exit. Therefore (entry, e->second)
528 // is also a region, that is larger than (entry, exit). Insert the
556 void RegionInfo::updateStatistics(Region *R) {
563 Region *RegionInfo::createRegion(BasicBlock *entry, BasicBlock *exit) {
569 Region *region = new Region(entry, exit, this, DT);
570 BBtoRegion.insert(std::make_pair(entry, region));
573 region->verifyRegion();
575 DEBUG(region->verifyRegion());
578 updateStatistics(region);
579 return region;
590 Region *lastRegion= 0;
593 // As only a BasicBlock that postdominates entry can finish a region, walk the
602 Region *newRegion = createRegion(entry, exit);
611 // This can never be a region, so stop the search.
636 Region *RegionInfo::getTopMostParent(Region *region) {
637 while (region->parent)
638 region = region->getParent();
640 return region;
643 void RegionInfo::buildRegionsTree(DomTreeNode *N, Region *region) {
646 // Passed region exit
647 while (BB == region->getExit())
648 region = region->getParent();
652 // This basic block is a start block of a region. It is already in the
655 Region *newRegion = it->second;;
656 region->addSubRegion(getTopMostParent(newRegion));
657 region = newRegion;
659 BBtoRegion[BB] = region;
663 buildRegionsTree(*CI, region);
683 // ShortCut a function where for every BB the exit of the largest region
700 TopLevelRegion = new Region(&F.getEntryBlock(), 0, this, DT, 0);
716 OS << "Region tree:\n";
718 OS << "End region tree\n";
730 // Region pass manager support.
731 Region *RegionInfo::getRegionFor(BasicBlock *BB) const {
737 void RegionInfo::setRegionFor(BasicBlock *BB, Region *R) {
741 Region *RegionInfo::operator[](BasicBlock *BB) const {
749 // Get largest region that starts at BB.
750 Region *R = getRegionFor(BB);
762 // Get largest region that starts at Exit.
763 Region *ExitR = getRegionFor(Exit);
783 Region*
784 RegionInfo::getCommonRegion(Region *A, Region *B) const {
795 Region*
796 RegionInfo::getCommonRegion(SmallVectorImpl<Region*> &Regions) const {
797 Region* ret = Regions.back();
800 for (SmallVectorImpl<Region*>::const_iterator I = Regions.begin(),
807 Region*
809 Region* ret = getRegionFor(BBs.back());
821 Region *R = getRegionFor(OldBB);