RegionInfo: Free the RegionNodes in cache.
[oota-llvm.git] / lib / Analysis / RegionInfo.cpp
1 //===- RegionInfo.cpp - SESE region detection analysis --------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Detects single entry single exit regions in the control flow graph.
10 //===----------------------------------------------------------------------===//
11
12 #include "llvm/Analysis/RegionInfo.h"
13 #include "llvm/Analysis/RegionIterator.h"
14
15 #include "llvm/ADT/PostOrderIterator.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/Analysis/LoopInfo.h"
21
22 #define DEBUG_TYPE "region"
23 #include "llvm/Support/Debug.h"
24
25 #include <set>
26 #include <algorithm>
27
28 using namespace llvm;
29
30 // Always verify if expensive checking is enabled.
31 #ifdef XDEBUG
32 static bool VerifyRegionInfo = true;
33 #else
34 static bool VerifyRegionInfo = false;
35 #endif
36
37 static cl::opt<bool,true>
38 VerifyRegionInfoX("verify-region-info", cl::location(VerifyRegionInfo),
39                 cl::desc("Verify region info (time consuming)"));
40
41 STATISTIC(numRegions,       "The # of regions");
42 STATISTIC(numSimpleRegions, "The # of simple regions");
43
44 //===----------------------------------------------------------------------===//
45 /// PrintStyle - Print region in difference ways.
46 enum PrintStyle { PrintNone, PrintBB, PrintRN  };
47
48 cl::opt<enum PrintStyle> printStyle("print-region-style", cl::Hidden,
49   cl::desc("style of printing regions"),
50   cl::values(
51     clEnumValN(PrintNone, "none",  "print no details"),
52     clEnumValN(PrintBB, "bb",  "print regions in detail with block_iterator"),
53     clEnumValN(PrintRN, "rn",  "print regions in detail with element_iterator"),
54     clEnumValEnd));
55 //===----------------------------------------------------------------------===//
56 /// Region Implementation
57 Region::Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo* RInfo,
58                DominatorTree *dt, Region *Parent)
59                : RegionNode(Parent, Entry, 1), RI(RInfo), DT(dt), exit(Exit) {}
60
61 Region::~Region() {
62   // Free the cached nodes.
63   for (BBNodeMapT::iterator it = BBNodeMap.begin(),
64          ie = BBNodeMap.end(); it != ie; ++it)
65     delete it->second;
66
67   // Only clean the cache for this Region. Caches of child Regions will be
68   // cleaned when the child Regions are deleted.
69   BBNodeMap.clear();
70
71   for (iterator I = begin(), E = end(); I != E; ++I)
72     delete *I;
73 }
74
75 bool Region::contains(const BasicBlock *B) const {
76   BasicBlock *BB = const_cast<BasicBlock*>(B);
77
78   assert(DT->getNode(BB) && "BB not part of the dominance tree");
79
80   BasicBlock *entry = getEntry(), *exit = getExit();
81
82   // Toplevel region.
83   if (!exit)
84     return true;
85
86   return (DT->dominates(entry, BB)
87     && !(DT->dominates(exit, BB) && DT->dominates(entry, exit)));
88 }
89
90 bool Region::contains(const Loop *L) const {
91   // BBs that are not part of any loop are element of the Loop
92   // described by the NULL pointer. This loop is not part of any region,
93   // except if the region describes the whole function.
94   if (L == 0)
95     return getExit() == 0;
96
97   if (!contains(L->getHeader()))
98     return false;
99
100   SmallVector<BasicBlock *, 8> ExitingBlocks;
101   L->getExitingBlocks(ExitingBlocks);
102
103   for (SmallVectorImpl<BasicBlock*>::iterator BI = ExitingBlocks.begin(),
104        BE = ExitingBlocks.end(); BI != BE; ++BI)
105     if (!contains(*BI))
106       return false;
107
108   return true;
109 }
110
111 Loop *Region::outermostLoopInRegion(Loop *L) const {
112   if (!contains(L))
113     return 0;
114
115   while (L && contains(L->getParentLoop())) {
116     L = L->getParentLoop();
117   }
118
119   return L;
120 }
121
122 Loop *Region::outermostLoopInRegion(LoopInfo *LI, BasicBlock* BB) const {
123   assert(LI && BB && "LI and BB cannot be null!");
124   Loop *L = LI->getLoopFor(BB);
125   return outermostLoopInRegion(L);
126 }
127
128 bool Region::isSimple() const {
129   bool isSimple = true;
130   bool found = false;
131
132   BasicBlock *entry = getEntry(), *exit = getExit();
133
134   // TopLevelRegion
135   if (!exit)
136     return false;
137
138   for (pred_iterator PI = pred_begin(entry), PE = pred_end(entry); PI != PE;
139        ++PI) {
140     BasicBlock *Pred = *PI;
141     if (DT->getNode(Pred) && !contains(Pred)) {
142       if (found) {
143         isSimple = false;
144         break;
145       }
146       found = true;
147     }
148   }
149
150   found = false;
151
152   for (pred_iterator PI = pred_begin(exit), PE = pred_end(exit); PI != PE;
153        ++PI)
154     if (contains(*PI)) {
155       if (found) {
156         isSimple = false;
157         break;
158       }
159       found = true;
160     }
161
162   return isSimple;
163 }
164
165 std::string Region::getNameStr() const {
166   std::string exitName;
167   std::string entryName;
168
169   if (getEntry()->getName().empty()) {
170     raw_string_ostream OS(entryName);
171
172     WriteAsOperand(OS, getEntry(), false);
173     entryName = OS.str();
174   } else
175     entryName = getEntry()->getNameStr();
176
177   if (getExit()) {
178     if (getExit()->getName().empty()) {
179       raw_string_ostream OS(exitName);
180
181       WriteAsOperand(OS, getExit(), false);
182       exitName = OS.str();
183     } else
184       exitName = getExit()->getNameStr();
185   } else
186     exitName = "<Function Return>";
187
188   return entryName + " => " + exitName;
189 }
190
191 void Region::verifyBBInRegion(BasicBlock *BB) const {
192   if (!contains(BB))
193     llvm_unreachable("Broken region found!");
194
195   BasicBlock *entry = getEntry(), *exit = getExit();
196
197   for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
198     if (!contains(*SI) && exit != *SI)
199       llvm_unreachable("Broken region found!");
200
201   if (entry != BB)
202     for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB); SI != SE; ++SI)
203       if (!contains(*SI))
204         llvm_unreachable("Broken region found!");
205 }
206
207 void Region::verifyWalk(BasicBlock *BB, std::set<BasicBlock*> *visited) const {
208   BasicBlock *exit = getExit();
209
210   visited->insert(BB);
211
212   verifyBBInRegion(BB);
213
214   for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB); SI != SE; ++SI)
215     if (*SI != exit && visited->find(*SI) == visited->end())
216         verifyWalk(*SI, visited);
217 }
218
219 void Region::verifyRegion() const {
220   // Only do verification when user wants to, otherwise this expensive
221   // check will be invoked by PassManager.
222   if (!VerifyRegionInfo) return;
223
224   std::set<BasicBlock*> visited;
225   verifyWalk(getEntry(), &visited);
226 }
227
228 void Region::verifyRegionNest() const {
229   for (Region::const_iterator RI = begin(), RE = end(); RI != RE; ++RI)
230     (*RI)->verifyRegionNest();
231
232   verifyRegion();
233 }
234
235 Region::block_iterator Region::block_begin() {
236   return GraphTraits<FlatIt<Region*> >::nodes_begin(this);
237 }
238
239 Region::block_iterator Region::block_end() {
240   return GraphTraits<FlatIt<Region*> >::nodes_end(this);
241 }
242
243 Region::const_block_iterator Region::block_begin() const {
244   return GraphTraits<FlatIt<const Region*> >::nodes_begin(this);
245 }
246
247 Region::const_block_iterator Region::block_end() const {
248   return GraphTraits<FlatIt<const Region*> >::nodes_end(this);
249 }
250
251 Region::element_iterator Region::element_begin() {
252   return GraphTraits<Region*>::nodes_begin(this);
253 }
254
255 Region::element_iterator Region::element_end() {
256   return GraphTraits<Region*>::nodes_end(this);
257 }
258
259 Region::const_element_iterator Region::element_begin() const {
260   return GraphTraits<const Region*>::nodes_begin(this);
261 }
262
263 Region::const_element_iterator Region::element_end() const {
264   return GraphTraits<const Region*>::nodes_end(this);
265 }
266
267 Region* Region::getSubRegionNode(BasicBlock *BB) const {
268   Region *R = RI->getRegionFor(BB);
269
270   if (!R || R == this)
271     return 0;
272
273   // If we pass the BB out of this region, that means our code is broken.
274   assert(contains(R) && "BB not in current region!");
275
276   while (contains(R->getParent()) && R->getParent() != this)
277     R = R->getParent();
278
279   if (R->getEntry() != BB)
280     return 0;
281
282   return R;
283 }
284
285 RegionNode* Region::getBBNode(BasicBlock *BB) const {
286   assert(contains(BB) && "Can get BB node out of this region!");
287
288   BBNodeMapT::const_iterator at = BBNodeMap.find(BB);
289
290   if (at != BBNodeMap.end())
291     return at->second;
292
293   RegionNode *NewNode = new RegionNode(const_cast<Region*>(this), BB);
294   BBNodeMap.insert(std::make_pair(BB, NewNode));
295   return NewNode;
296 }
297
298 RegionNode* Region::getNode(BasicBlock *BB) const {
299   assert(contains(BB) && "Can get BB node out of this region!");
300   if (Region* Child = getSubRegionNode(BB))
301     return Child->getNode();
302
303   return getBBNode(BB);
304 }
305
306 void Region::transferChildrenTo(Region *To) {
307   for (iterator I = begin(), E = end(); I != E; ++I) {
308     (*I)->parent = To;
309     To->children.push_back(*I);
310   }
311   children.clear();
312 }
313
314 void Region::addSubRegion(Region *SubRegion) {
315   assert(SubRegion->parent == 0 && "SubRegion already has a parent!");
316   SubRegion->parent = this;
317   // Set up the region node.
318   assert(std::find(children.begin(), children.end(), SubRegion) == children.end()
319          && "Node already exist!");
320   children.push_back(SubRegion);
321 }
322
323
324 Region *Region::removeSubRegion(Region *Child) {
325   assert(Child->parent == this && "Child is not a child of this region!");
326   Child->parent = 0;
327   RegionSet::iterator I = std::find(children.begin(), children.end(), Child);
328   assert(I != children.end() && "Region does not exit. Unable to remove.");
329   children.erase(children.begin()+(I-begin()));
330   return Child;
331 }
332
333 unsigned Region::getDepth() const {
334   unsigned Depth = 0;
335
336   for (Region *R = parent; R != 0; R = R->parent)
337     ++Depth;
338
339   return Depth;
340 }
341
342 void Region::print(raw_ostream &OS, bool print_tree, unsigned level) const {
343   if (print_tree)
344     OS.indent(level*2) << "[" << level << "] " << getNameStr();
345   else
346     OS.indent(level*2) << getNameStr();
347
348   OS << "\n";
349
350
351   if (printStyle != PrintNone) {
352     OS.indent(level*2) << "{\n";
353     OS.indent(level*2 + 2);
354
355     if (printStyle == PrintBB) {
356       for (const_block_iterator I = block_begin(), E = block_end(); I!=E; ++I)
357         OS << **I << ", "; // TODO: remove the last ","
358     } else if (printStyle == PrintRN) {
359       for (const_element_iterator I = element_begin(), E = element_end(); I!=E; ++I)
360         OS << **I << ", "; // TODO: remove the last ",
361     }
362
363     OS << "\n";
364   }
365
366   if (print_tree)
367     for (const_iterator RI = begin(), RE = end(); RI != RE; ++RI)
368       (*RI)->print(OS, print_tree, level+1);
369
370   if (printStyle != PrintNone)
371     OS.indent(level*2) << "} \n";
372 }
373
374 void Region::dump() const {
375   print(dbgs(), true, getDepth());
376 }
377
378 void Region::clearNodeCache() {
379   // Free the cached nodes.
380   for (BBNodeMapT::iterator I = BBNodeMap.begin(),
381        IE = BBNodeMap.end(); I != IE; ++IE)
382     delete I->second;
383
384   BBNodeMap.clear();
385   for (Region::iterator RI = begin(), RE = end(); RI != RE; ++RI)
386     (*RI)->clearNodeCache();
387 }
388
389 //===----------------------------------------------------------------------===//
390 // RegionInfo implementation
391 //
392
393 bool RegionInfo::isCommonDomFrontier(BasicBlock *BB, BasicBlock *entry,
394                                      BasicBlock *exit) const {
395   for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
396     BasicBlock *P = *PI;
397     if (DT->dominates(entry, P) && !DT->dominates(exit, P))
398       return false;
399   }
400   return true;
401 }
402
403 bool RegionInfo::isRegion(BasicBlock *entry, BasicBlock *exit) const {
404   assert(entry && exit && "entry and exit must not be null!");
405   typedef DominanceFrontier::DomSetType DST;
406
407   DST *entrySuccs = &DF->find(entry)->second;
408
409   // Exit is the header of a loop that contains the entry. In this case,
410   // the dominance frontier must only contain the exit.
411   if (!DT->dominates(entry, exit)) {
412     for (DST::iterator SI = entrySuccs->begin(), SE = entrySuccs->end();
413          SI != SE; ++SI)
414       if (*SI != exit && *SI != entry)
415         return false;
416
417     return true;
418   }
419
420   DST *exitSuccs = &DF->find(exit)->second;
421
422   // Do not allow edges leaving the region.
423   for (DST::iterator SI = entrySuccs->begin(), SE = entrySuccs->end();
424        SI != SE; ++SI) {
425     if (*SI == exit || *SI == entry)
426       continue;
427     if (exitSuccs->find(*SI) == exitSuccs->end())
428       return false;
429     if (!isCommonDomFrontier(*SI, entry, exit))
430       return false;
431   }
432
433   // Do not allow edges pointing into the region.
434   for (DST::iterator SI = exitSuccs->begin(), SE = exitSuccs->end();
435        SI != SE; ++SI)
436     if (DT->properlyDominates(entry, *SI) && *SI != exit)
437       return false;
438
439
440   return true;
441 }
442
443 void RegionInfo::insertShortCut(BasicBlock *entry, BasicBlock *exit,
444                              BBtoBBMap *ShortCut) const {
445   assert(entry && exit && "entry and exit must not be null!");
446
447   BBtoBBMap::iterator e = ShortCut->find(exit);
448
449   if (e == ShortCut->end())
450     // No further region at exit available.
451     (*ShortCut)[entry] = exit;
452   else {
453     // We found a region e that starts at exit. Therefore (entry, e->second)
454     // is also a region, that is larger than (entry, exit). Insert the
455     // larger one.
456     BasicBlock *BB = e->second;
457     (*ShortCut)[entry] = BB;
458   }
459 }
460
461 DomTreeNode* RegionInfo::getNextPostDom(DomTreeNode* N,
462                                         BBtoBBMap *ShortCut) const {
463   BBtoBBMap::iterator e = ShortCut->find(N->getBlock());
464
465   if (e == ShortCut->end())
466     return N->getIDom();
467
468   return PDT->getNode(e->second)->getIDom();
469 }
470
471 bool RegionInfo::isTrivialRegion(BasicBlock *entry, BasicBlock *exit) const {
472   assert(entry && exit && "entry and exit must not be null!");
473
474   unsigned num_successors = succ_end(entry) - succ_begin(entry);
475
476   if (num_successors <= 1 && exit == *(succ_begin(entry)))
477     return true;
478
479   return false;
480 }
481
482 void RegionInfo::updateStatistics(Region *R) {
483   ++numRegions;
484
485   // TODO: Slow. Should only be enabled if -stats is used.
486   if (R->isSimple()) ++numSimpleRegions;
487 }
488
489 Region *RegionInfo::createRegion(BasicBlock *entry, BasicBlock *exit) {
490   assert(entry && exit && "entry and exit must not be null!");
491
492   if (isTrivialRegion(entry, exit))
493     return 0;
494
495   Region *region = new Region(entry, exit, this, DT);
496   BBtoRegion.insert(std::make_pair(entry, region));
497
498  #ifdef XDEBUG
499     region->verifyRegion();
500  #else
501     DEBUG(region->verifyRegion());
502  #endif
503
504   updateStatistics(region);
505   return region;
506 }
507
508 void RegionInfo::findRegionsWithEntry(BasicBlock *entry, BBtoBBMap *ShortCut) {
509   assert(entry);
510
511   DomTreeNode *N = PDT->getNode(entry);
512
513   if (!N)
514     return;
515
516   Region *lastRegion= 0;
517   BasicBlock *lastExit = entry;
518
519   // As only a BasicBlock that postdominates entry can finish a region, walk the
520   // post dominance tree upwards.
521   while ((N = getNextPostDom(N, ShortCut))) {
522     BasicBlock *exit = N->getBlock();
523
524     if (!exit)
525       break;
526
527     if (isRegion(entry, exit)) {
528       Region *newRegion = createRegion(entry, exit);
529
530       if (lastRegion)
531         newRegion->addSubRegion(lastRegion);
532
533       lastRegion = newRegion;
534       lastExit = exit;
535     }
536
537     // This can never be a region, so stop the search.
538     if (!DT->dominates(entry, exit))
539       break;
540   }
541
542   // Tried to create regions from entry to lastExit.  Next time take a
543   // shortcut from entry to lastExit.
544   if (lastExit != entry)
545     insertShortCut(entry, lastExit, ShortCut);
546 }
547
548 void RegionInfo::scanForRegions(Function &F, BBtoBBMap *ShortCut) {
549   BasicBlock *entry = &(F.getEntryBlock());
550   DomTreeNode *N = DT->getNode(entry);
551
552   // Iterate over the dominance tree in post order to start with the small
553   // regions from the bottom of the dominance tree.  If the small regions are
554   // detected first, detection of bigger regions is faster, as we can jump
555   // over the small regions.
556   for (po_iterator<DomTreeNode*> FI = po_begin(N), FE = po_end(N); FI != FE;
557     ++FI) {
558     findRegionsWithEntry(FI->getBlock(), ShortCut);
559   }
560 }
561
562 Region *RegionInfo::getTopMostParent(Region *region) {
563   while (region->parent)
564     region = region->getParent();
565
566   return region;
567 }
568
569 void RegionInfo::buildRegionsTree(DomTreeNode *N, Region *region) {
570   BasicBlock *BB = N->getBlock();
571
572   // Passed region exit
573   while (BB == region->getExit())
574     region = region->getParent();
575
576   BBtoRegionMap::iterator it = BBtoRegion.find(BB);
577
578   // This basic block is a start block of a region. It is already in the
579   // BBtoRegion relation. Only the child basic blocks have to be updated.
580   if (it != BBtoRegion.end()) {
581     Region *newRegion = it->second;;
582     region->addSubRegion(getTopMostParent(newRegion));
583     region = newRegion;
584   } else {
585     BBtoRegion[BB] = region;
586   }
587
588   for (DomTreeNode::iterator CI = N->begin(), CE = N->end(); CI != CE; ++CI)
589     buildRegionsTree(*CI, region);
590 }
591
592 void RegionInfo::releaseMemory() {
593   BBtoRegion.clear();
594   if (TopLevelRegion)
595     delete TopLevelRegion;
596   TopLevelRegion = 0;
597 }
598
599 RegionInfo::RegionInfo() : FunctionPass(ID) {
600   TopLevelRegion = 0;
601 }
602
603 RegionInfo::~RegionInfo() {
604   releaseMemory();
605 }
606
607 void RegionInfo::Calculate(Function &F) {
608   // ShortCut a function where for every BB the exit of the largest region
609   // starting with BB is stored. These regions can be threated as single BBS.
610   // This improves performance on linear CFGs.
611   BBtoBBMap ShortCut;
612
613   scanForRegions(F, &ShortCut);
614   BasicBlock *BB = &F.getEntryBlock();
615   buildRegionsTree(DT->getNode(BB), TopLevelRegion);
616 }
617
618 bool RegionInfo::runOnFunction(Function &F) {
619   releaseMemory();
620
621   DT = &getAnalysis<DominatorTree>();
622   PDT = &getAnalysis<PostDominatorTree>();
623   DF = &getAnalysis<DominanceFrontier>();
624
625   TopLevelRegion = new Region(&F.getEntryBlock(), 0, this, DT, 0);
626   updateStatistics(TopLevelRegion);
627
628   Calculate(F);
629
630   return false;
631 }
632
633 void RegionInfo::getAnalysisUsage(AnalysisUsage &AU) const {
634   AU.setPreservesAll();
635   AU.addRequiredTransitive<DominatorTree>();
636   AU.addRequired<PostDominatorTree>();
637   AU.addRequired<DominanceFrontier>();
638 }
639
640 void RegionInfo::print(raw_ostream &OS, const Module *) const {
641   OS << "Region tree:\n";
642   TopLevelRegion->print(OS, true, 0);
643   OS << "End region tree\n";
644 }
645
646 void RegionInfo::verifyAnalysis() const {
647   // Only do verification when user wants to, otherwise this expensive check
648   // will be invoked by PMDataManager::verifyPreservedAnalysis when
649   // a regionpass (marked PreservedAll) finish.
650   if (!VerifyRegionInfo) return;
651
652   TopLevelRegion->verifyRegionNest();
653 }
654
655 // Region pass manager support.
656 Region *RegionInfo::getRegionFor(BasicBlock *BB) const {
657   BBtoRegionMap::const_iterator I=
658     BBtoRegion.find(BB);
659   return I != BBtoRegion.end() ? I->second : 0;
660 }
661
662 Region *RegionInfo::operator[](BasicBlock *BB) const {
663   return getRegionFor(BB);
664 }
665
666
667 BasicBlock *RegionInfo::getMaxRegionExit(BasicBlock *BB) const {
668   BasicBlock *Exit = NULL;
669
670   while (true) {
671     // Get largest region that starts at BB.
672     Region *R = getRegionFor(BB);
673     while (R && R->getParent() && R->getParent()->getEntry() == BB)
674       R = R->getParent();
675
676     // Get the single exit of BB.
677     if (R && R->getEntry() == BB)
678       Exit = R->getExit();
679     else if (++succ_begin(BB) == succ_end(BB))
680       Exit = *succ_begin(BB);
681     else // No single exit exists.
682       return Exit;
683
684     // Get largest region that starts at Exit.
685     Region *ExitR = getRegionFor(Exit);
686     while (ExitR && ExitR->getParent()
687            && ExitR->getParent()->getEntry() == Exit)
688       ExitR = ExitR->getParent();
689
690     for (pred_iterator PI = pred_begin(Exit), PE = pred_end(Exit); PI != PE;
691          ++PI)
692       if (!R->contains(*PI) && !ExitR->contains(*PI))
693         break;
694
695     // This stops infinite cycles.
696     if (DT->dominates(Exit, BB))
697       break;
698
699     BB = Exit;
700   }
701
702   return Exit;
703 }
704
705 Region*
706 RegionInfo::getCommonRegion(Region *A, Region *B) const {
707   assert (A && B && "One of the Regions is NULL");
708
709   if (A->contains(B)) return A;
710
711   while (!B->contains(A))
712     B = B->getParent();
713
714   return B;
715 }
716
717 Region*
718 RegionInfo::getCommonRegion(SmallVectorImpl<Region*> &Regions) const {
719   Region* ret = Regions.back();
720   Regions.pop_back();
721
722   for (SmallVectorImpl<Region*>::const_iterator I = Regions.begin(),
723        E = Regions.end(); I != E; ++I)
724       ret = getCommonRegion(ret, *I);
725
726   return ret;
727 }
728
729 Region*
730 RegionInfo::getCommonRegion(SmallVectorImpl<BasicBlock*> &BBs) const {
731   Region* ret = getRegionFor(BBs.back());
732   BBs.pop_back();
733
734   for (SmallVectorImpl<BasicBlock*>::const_iterator I = BBs.begin(),
735        E = BBs.end(); I != E; ++I)
736       ret = getCommonRegion(ret, getRegionFor(*I));
737
738   return ret;
739 }
740
741 char RegionInfo::ID = 0;
742 INITIALIZE_PASS_BEGIN(RegionInfo, "regions",
743                 "Detect single entry single exit regions", true, true)
744 INITIALIZE_PASS_DEPENDENCY(DominatorTree)
745 INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
746 INITIALIZE_PASS_DEPENDENCY(DominanceFrontier)
747 INITIALIZE_PASS_END(RegionInfo, "regions",
748                 "Detect single entry single exit regions", true, true)
749
750 // Create methods available outside of this file, to use them
751 // "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by
752 // the link time optimization.
753
754 namespace llvm {
755   FunctionPass *createRegionInfoPass() {
756     return new RegionInfo();
757   }
758 }
759