Home | History | Annotate | Download | only in Analysis

Lines Matching defs:Region

1 //===- RegionInfo.cpp - SESE region detection analysis --------------------===//
21 #define DEBUG_TYPE "region"
37 VerifyRegionInfoX("verify-region-info", cl::location(VerifyRegionInfo),
38 cl::desc("Verify region info (time consuming)"));
43 static cl::opt<enum Region::PrintStyle> printStyle("print-region-style",
47 clEnumValN(Region::PrintNone, "none", "print no details"),
48 clEnumValN(Region::PrintBB, "bb",
50 clEnumValN(Region::PrintRN, "rn",
54 /// Region Implementation
55 Region::Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo* RInfo,
56 DominatorTree *dt, Region *Parent)
59 Region::~Region() {
65 // Only clean the cache for this Region. Caches of child Regions will be
73 void Region::replaceEntry(BasicBlock *BB) {
77 void Region::replaceExit(BasicBlock *BB) {
82 bool Region::contains(const BasicBlock *B) const {
89 // Toplevel region.
97 bool Region::contains(const Loop *L) const {
99 // described by the NULL pointer. This loop is not part of any region,
100 // except if the region describes the whole function.
118 Loop *Region::outermostLoopInRegion(Loop *L) const {
129 Loop *Region::outermostLoopInRegion(LoopInfo *LI, BasicBlock* BB) const {
135 BasicBlock *Region::getEnteringBlock() const {
154 BasicBlock *Region::getExitingBlock() const {
176 bool Region::isSimple() const {
180 std::string Region::getNameStr() const {
204 void Region::verifyBBInRegion(BasicBlock *BB) const {
206 llvm_unreachable("Broken region found!");
212 llvm_unreachable("Broken region found!");
217 llvm_unreachable("Broken region found!");
220 void Region::verifyWalk(BasicBlock *BB, std::set<BasicBlock*> *visited) const {
232 void Region::verifyRegion() const {
241 void Region::verifyRegionNest() const {
242 for (Region::const_iterator RI = begin(), RE = end(); RI != RE; ++RI)
248 Region::element_iterator Region::element_begin() {
249 return GraphTraits<Region*>::nodes_begin(this);
252 Region::element_iterator Region::element_end() {
253 return GraphTraits<Region*>::nodes_end(this);
256 Region::const_element_iterator Region::element_begin() const {
257 return GraphTraits<const Region*>::nodes_begin(this);
260 Region::const_element_iterator Region::element_end() const {
261 return GraphTraits<const Region*>::nodes_end(this);
264 Region* Region::getSubRegionNode(BasicBlock *BB) const {
265 Region *R = RI->getRegionFor(BB);
270 // If we pass the BB out of this region, that means our code is broken.
271 assert(contains(R) && "BB not in current region!");
282 RegionNode* Region::getBBNode(BasicBlock *BB) const {
283 assert(contains(BB) && "Can get BB node out of this region!");
290 RegionNode *NewNode = new RegionNode(const_cast<Region*>(this), BB);
295 RegionNode* Region::getNode(BasicBlock *BB) const {
296 assert(contains(BB) && "Can get BB node out of this region!");
297 if (Region* Child = getSubRegionNode(BB))
303 void Region::transferChildrenTo(Region *To) {
311 void Region::addSubRegion(Region *SubRegion, bool moveChildren) {
333 std::vector<Region*> Keep;
346 Region *Region::removeSubRegion(Region *Child) {
347 assert(Child->parent == this && "Child is not a child of this region!");
350 assert(I != children.end() && "Region does not exit. Unable to remove.");
355 unsigned Region::getDepth() const {
358 for (Region *R = parent; R != 0; R = R->parent)
364 Region *Region::getExpandedRegion() const {
375 Region *R = RI->getRegionFor(exit);
379 return new Region(getEntry(), *succ_begin(exit), RI, DT);
393 return new Region(getEntry(), R->getExit(), RI, DT);
396 void Region::print(raw_ostream &OS, bool print_tree, unsigned level,
430 void Region::dump() const {
435 void Region::clearNodeCache() {
442 for (Region::iterator RI = begin(), RE = end(); RI != RE; ++RI)
479 // Do not allow edges leaving the region.
490 // Do not allow edges pointing into the region.
507 // No further region at exit available.
510 // We found a region e that starts at exit. Therefore (entry, e->second)
511 // is also a region, that is larger than (entry, exit). Insert the
539 void RegionInfo::updateStatistics(Region *R) {
546 Region *RegionInfo::createRegion(BasicBlock *entry, BasicBlock *exit) {
552 Region *region = new Region(entry, exit, this, DT);
553 BBtoRegion.insert(std::make_pair(entry, region));
556 region->verifyRegion();
558 DEBUG(region->verifyRegion());
561 updateStatistics(region);
562 return region;
573 Region *lastRegion= 0;
576 // As only a BasicBlock that postdominates entry can finish a region, walk the
585 Region *newRegion = createRegion(entry, exit);
594 // This can never be a region, so stop the search.
619 Region *RegionInfo::getTopMostParent(Region *region) {
620 while (region->parent)
621 region = region->getParent();
623 return region;
626 void RegionInfo::buildRegionsTree(DomTreeNode *N, Region *region) {
629 // Passed region exit
630 while (BB == region->getExit())
631 region = region->getParent();
635 // This basic block is a start block of a region. It is already in the
638 Region *newRegion = it->second;
639 region->addSubRegion(getTopMostParent(newRegion));
640 region = newRegion;
642 BBtoRegion[BB] = region;
646 buildRegionsTree(*CI, region);
666 // ShortCut a function where for every BB the exit of the largest region
683 TopLevelRegion = new Region(&F.getEntryBlock(), 0, this, DT, 0);
699 OS << "Region tree:\n";
701 OS << "End region tree\n";
713 // Region pass manager support.
714 Region *RegionInfo::getRegionFor(BasicBlock *BB) const {
720 void RegionInfo::setRegionFor(BasicBlock *BB, Region *R) {
724 Region *RegionInfo::operator[](BasicBlock *BB) const {
732 // Get largest region that starts at BB.
733 Region *R = getRegionFor(BB);
745 // Get largest region that starts at Exit.
746 Region *ExitR = getRegionFor(Exit);
766 Region*
767 RegionInfo::getCommonRegion(Region *A, Region *B) const {
778 Region*
779 RegionInfo::getCommonRegion(SmallVectorImpl<Region*> &Regions) const {
780 Region* ret = Regions.back();
783 for (SmallVectorImpl<Region*>::const_iterator I = Regions.begin(),
790 Region*
792 Region* ret = getRegionFor(BBs.back());
804 Region *R = getRegionFor(OldBB);