1 //===- RegionInfo.h - SESE region analysis ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Calculate a program structure tree built out of single entry single exit
12 // The basic ideas are taken from "The Program Structure Tree - Richard Johnson,
13 // David Pearson, Keshav Pingali - 1994", however enriched with ideas from "The
14 // Refined Process Structure Tree - Jussi Vanhatalo, Hagen Voelyer, Jana
16 // The algorithm to calculate these data structures however is completely
17 // different, as it takes advantage of existing information already available
18 // in (Post)dominace tree and dominance frontier passes. This leads to a simpler
19 // and in practice hopefully better performing algorithm. The runtime of the
20 // algorithms described in the papers above are both linear in graph size,
21 // O(V+E), whereas this algorithm is not, as the dominance frontier information
22 // itself is not, but in practice runtime seems to be in the order of magnitude
23 // of dominance tree calculation.
25 //===----------------------------------------------------------------------===//
27 #ifndef LLVM_ANALYSIS_REGIONINFO_H
28 #define LLVM_ANALYSIS_REGIONINFO_H
30 #include "llvm/ADT/PointerIntPair.h"
31 #include "llvm/ADT/iterator_range.h"
32 #include "llvm/Analysis/DominanceFrontier.h"
33 #include "llvm/Analysis/PostDominators.h"
34 #include "llvm/Support/Allocator.h"
46 /// @brief Marker class to iterate over the elements of a Region in flat mode.
48 /// The class is used to either iterate in Flat mode or by not using it to not
49 /// iterate in Flat mode. During a Flat mode iteration all Regions are entered
50 /// and the iteration returns every BasicBlock. If the Flat mode is not
51 /// selected for SubRegions just one RegionNode containing the subregion is
53 template <class GraphType>
56 /// @brief A RegionNode represents a subregion or a BasicBlock that is part of a
59 RegionNode(const RegionNode &) LLVM_DELETED_FUNCTION;
60 const RegionNode &operator=(const RegionNode &) LLVM_DELETED_FUNCTION;
63 /// This is the entry basic block that starts this region node. If this is a
64 /// BasicBlock RegionNode, then entry is just the basic block, that this
65 /// RegionNode represents. Otherwise it is the entry of this (Sub)RegionNode.
67 /// In the BBtoRegionNode map of the parent of this node, BB will always map
68 /// to this node no matter which kind of node this one is.
70 /// The node can hold either a Region or a BasicBlock.
71 /// Use one bit to save, if this RegionNode is a subregion or BasicBlock
73 PointerIntPair<BasicBlock*, 1, bool> entry;
75 /// @brief The parent Region of this RegionNode.
80 /// @brief Create a RegionNode.
82 /// @param Parent The parent of this RegionNode.
83 /// @param Entry The entry BasicBlock of the RegionNode. If this
84 /// RegionNode represents a BasicBlock, this is the
85 /// BasicBlock itself. If it represents a subregion, this
86 /// is the entry BasicBlock of the subregion.
87 /// @param isSubRegion If this RegionNode represents a SubRegion.
88 inline RegionNode(Region* Parent, BasicBlock* Entry, bool isSubRegion = 0)
89 : entry(Entry, isSubRegion), parent(Parent) {}
91 /// @brief Get the parent Region of this RegionNode.
93 /// The parent Region is the Region this RegionNode belongs to. If for
94 /// example a BasicBlock is element of two Regions, there exist two
95 /// RegionNodes for this BasicBlock. Each with the getParent() function
96 /// pointing to the Region this RegionNode belongs to.
98 /// @return Get the parent Region of this RegionNode.
99 inline Region* getParent() const { return parent; }
101 /// @brief Get the entry BasicBlock of this RegionNode.
103 /// If this RegionNode represents a BasicBlock this is just the BasicBlock
104 /// itself, otherwise we return the entry BasicBlock of the Subregion
106 /// @return The entry BasicBlock of this RegionNode.
107 inline BasicBlock* getEntry() const { return entry.getPointer(); }
109 /// @brief Get the content of this RegionNode.
111 /// This can be either a BasicBlock or a subregion. Before calling getNodeAs()
112 /// check the type of the content with the isSubRegion() function call.
114 /// @return The content of this RegionNode.
116 inline T* getNodeAs() const;
118 /// @brief Is this RegionNode a subregion?
120 /// @return True if it contains a subregion. False if it contains a
122 inline bool isSubRegion() const {
123 return entry.getInt();
127 /// Print a RegionNode.
128 inline raw_ostream &operator<<(raw_ostream &OS, const RegionNode &Node);
131 inline BasicBlock* RegionNode::getNodeAs<BasicBlock>() const {
132 assert(!isSubRegion() && "This is not a BasicBlock RegionNode!");
137 inline Region* RegionNode::getNodeAs<Region>() const {
138 assert(isSubRegion() && "This is not a subregion RegionNode!");
139 return reinterpret_cast<Region*>(const_cast<RegionNode*>(this));
142 //===----------------------------------------------------------------------===//
143 /// @brief A single entry single exit Region.
145 /// A Region is a connected subgraph of a control flow graph that has exactly
146 /// two connections to the remaining graph. It can be used to analyze or
147 /// optimize parts of the control flow graph.
149 /// A <em> simple Region </em> is connected to the remaining graph by just two
150 /// edges. One edge entering the Region and another one leaving the Region.
152 /// An <em> extended Region </em> (or just Region) is a subgraph that can be
153 /// transform into a simple Region. The transformation is done by adding
154 /// BasicBlocks that merge several entry or exit edges so that after the merge
155 /// just one entry and one exit edge exists.
157 /// The \e Entry of a Region is the first BasicBlock that is passed after
158 /// entering the Region. It is an element of the Region. The entry BasicBlock
159 /// dominates all BasicBlocks in the Region.
161 /// The \e Exit of a Region is the first BasicBlock that is passed after
162 /// leaving the Region. It is not an element of the Region. The exit BasicBlock,
163 /// postdominates all BasicBlocks in the Region.
165 /// A <em> canonical Region </em> cannot be constructed by combining smaller
168 /// Region A is the \e parent of Region B, if B is completely contained in A.
170 /// Two canonical Regions either do not intersect at all or one is
171 /// the parent of the other.
173 /// The <em> Program Structure Tree</em> is a graph (V, E) where V is the set of
174 /// Regions in the control flow graph and E is the \e parent relation of these
180 /// A simple control flow graph, that contains two regions.
190 /// \ |/ Region A: 1 -> 9 {1,2,3,4,5,6,7,8}
191 /// 9 Region B: 2 -> 9 {2,4,5,6,7}
194 /// You can obtain more examples by either calling
196 /// <tt> "opt -regions -analyze anyprogram.ll" </tt>
198 /// <tt> "opt -view-regions-only anyprogram.ll" </tt>
200 /// on any LLVM file you are interested in.
202 /// The first call returns a textual representation of the program structure
203 /// tree, the second one creates a graphical representation using graphviz.
204 class Region : public RegionNode {
205 friend class RegionInfo;
206 Region(const Region &) LLVM_DELETED_FUNCTION;
207 const Region &operator=(const Region &) LLVM_DELETED_FUNCTION;
209 // Information necessary to manage this Region.
213 // The exit BasicBlock of this region.
214 // (The entry BasicBlock is part of RegionNode)
217 typedef std::vector<std::unique_ptr<Region>> RegionSet;
219 // The subregions of this region.
222 typedef std::map<BasicBlock*, RegionNode*> BBNodeMapT;
224 // Save the BasicBlock RegionNodes that are element of this Region.
225 mutable BBNodeMapT BBNodeMap;
227 /// verifyBBInRegion - Check if a BB is in this Region. This check also works
228 /// if the region is incorrectly built. (EXPENSIVE!)
229 void verifyBBInRegion(BasicBlock* BB) const;
231 /// verifyWalk - Walk over all the BBs of the region starting from BB and
232 /// verify that all reachable basic blocks are elements of the region.
234 void verifyWalk(BasicBlock* BB, std::set<BasicBlock*>* visitedBB) const;
236 /// verifyRegionNest - Verify if the region and its children are valid
237 /// regions (EXPENSIVE!)
238 void verifyRegionNest() const;
241 /// @brief Create a new region.
243 /// @param Entry The entry basic block of the region.
244 /// @param Exit The exit basic block of the region.
245 /// @param RI The region info object that is managing this region.
246 /// @param DT The dominator tree of the current function.
247 /// @param Parent The surrounding region or NULL if this is a top level
249 Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo* RI,
250 DominatorTree *DT, Region *Parent = nullptr);
252 /// Delete the Region and all its subregions.
255 /// @brief Get the entry BasicBlock of the Region.
256 /// @return The entry BasicBlock of the region.
257 BasicBlock *getEntry() const { return RegionNode::getEntry(); }
259 /// @brief Replace the entry basic block of the region with the new basic
262 /// @param BB The new entry basic block of the region.
263 void replaceEntry(BasicBlock *BB);
265 /// @brief Replace the exit basic block of the region with the new basic
268 /// @param BB The new exit basic block of the region.
269 void replaceExit(BasicBlock *BB);
271 /// @brief Recursively replace the entry basic block of the region.
273 /// This function replaces the entry basic block with a new basic block. It
274 /// also updates all child regions that have the same entry basic block as
277 /// @param NewEntry The new entry basic block.
278 void replaceEntryRecursive(BasicBlock *NewEntry);
280 /// @brief Recursively replace the exit basic block of the region.
282 /// This function replaces the exit basic block with a new basic block. It
283 /// also updates all child regions that have the same exit basic block as
286 /// @param NewExit The new exit basic block.
287 void replaceExitRecursive(BasicBlock *NewExit);
289 /// @brief Get the exit BasicBlock of the Region.
290 /// @return The exit BasicBlock of the Region, NULL if this is the TopLevel
292 BasicBlock *getExit() const { return exit; }
294 /// @brief Get the parent of the Region.
295 /// @return The parent of the Region or NULL if this is a top level
297 Region *getParent() const { return RegionNode::getParent(); }
299 /// @brief Get the RegionNode representing the current Region.
300 /// @return The RegionNode representing the current Region.
301 RegionNode* getNode() const {
302 return const_cast<RegionNode*>(reinterpret_cast<const RegionNode*>(this));
305 /// @brief Get the nesting level of this Region.
307 /// An toplevel Region has depth 0.
309 /// @return The depth of the region.
310 unsigned getDepth() const;
312 /// @brief Check if a Region is the TopLevel region.
314 /// The toplevel region represents the whole function.
315 bool isTopLevelRegion() const { return exit == nullptr; }
317 /// @brief Return a new (non-canonical) region, that is obtained by joining
318 /// this region with its predecessors.
320 /// @return A region also starting at getEntry(), but reaching to the next
321 /// basic block that forms with getEntry() a (non-canonical) region.
322 /// NULL if such a basic block does not exist.
323 Region *getExpandedRegion() const;
325 /// @brief Return the first block of this region's single entry edge,
328 /// @return The BasicBlock starting this region's single entry edge,
330 BasicBlock *getEnteringBlock() const;
332 /// @brief Return the first block of this region's single exit edge,
335 /// @return The BasicBlock starting this region's single exit edge,
337 BasicBlock *getExitingBlock() const;
339 /// @brief Is this a simple region?
341 /// A region is simple if it has exactly one exit and one entry edge.
343 /// @return True if the Region is simple.
344 bool isSimple() const;
346 /// @brief Returns the name of the Region.
347 /// @return The Name of the Region.
348 std::string getNameStr() const;
350 /// @brief Return the RegionInfo object, that belongs to this Region.
351 RegionInfo *getRegionInfo() const {
355 /// PrintStyle - Print region in difference ways.
356 enum PrintStyle { PrintNone, PrintBB, PrintRN };
358 /// @brief Print the region.
360 /// @param OS The output stream the Region is printed to.
361 /// @param printTree Print also the tree of subregions.
362 /// @param level The indentation level used for printing.
363 void print(raw_ostream& OS, bool printTree = true, unsigned level = 0,
364 enum PrintStyle Style = PrintNone) const;
366 /// @brief Print the region to stderr.
369 /// @brief Check if the region contains a BasicBlock.
371 /// @param BB The BasicBlock that might be contained in this Region.
372 /// @return True if the block is contained in the region otherwise false.
373 bool contains(const BasicBlock *BB) const;
375 /// @brief Check if the region contains another region.
377 /// @param SubRegion The region that might be contained in this Region.
378 /// @return True if SubRegion is contained in the region otherwise false.
379 bool contains(const Region *SubRegion) const {
384 return contains(SubRegion->getEntry())
385 && (contains(SubRegion->getExit()) || SubRegion->getExit() == getExit());
388 /// @brief Check if the region contains an Instruction.
390 /// @param Inst The Instruction that might be contained in this region.
391 /// @return True if the Instruction is contained in the region otherwise false.
392 bool contains(const Instruction *Inst) const {
393 return contains(Inst->getParent());
396 /// @brief Check if the region contains a loop.
398 /// @param L The loop that might be contained in this region.
399 /// @return True if the loop is contained in the region otherwise false.
400 /// In case a NULL pointer is passed to this function the result
401 /// is false, except for the region that describes the whole function.
402 /// In that case true is returned.
403 bool contains(const Loop *L) const;
405 /// @brief Get the outermost loop in the region that contains a loop.
407 /// Find for a Loop L the outermost loop OuterL that is a parent loop of L
408 /// and is itself contained in the region.
410 /// @param L The loop the lookup is started.
411 /// @return The outermost loop in the region, NULL if such a loop does not
412 /// exist or if the region describes the whole function.
413 Loop *outermostLoopInRegion(Loop *L) const;
415 /// @brief Get the outermost loop in the region that contains a basic block.
417 /// Find for a basic block BB the outermost loop L that contains BB and is
418 /// itself contained in the region.
420 /// @param LI A pointer to a LoopInfo analysis.
421 /// @param BB The basic block surrounded by the loop.
422 /// @return The outermost loop in the region, NULL if such a loop does not
423 /// exist or if the region describes the whole function.
424 Loop *outermostLoopInRegion(LoopInfo *LI, BasicBlock* BB) const;
426 /// @brief Get the subregion that starts at a BasicBlock
428 /// @param BB The BasicBlock the subregion should start.
429 /// @return The Subregion if available, otherwise NULL.
430 Region* getSubRegionNode(BasicBlock *BB) const;
432 /// @brief Get the RegionNode for a BasicBlock
434 /// @param BB The BasicBlock at which the RegionNode should start.
435 /// @return If available, the RegionNode that represents the subregion
436 /// starting at BB. If no subregion starts at BB, the RegionNode
438 RegionNode* getNode(BasicBlock *BB) const;
440 /// @brief Get the BasicBlock RegionNode for a BasicBlock
442 /// @param BB The BasicBlock for which the RegionNode is requested.
443 /// @return The RegionNode representing the BB.
444 RegionNode* getBBNode(BasicBlock *BB) const;
446 /// @brief Add a new subregion to this Region.
448 /// @param SubRegion The new subregion that will be added.
449 /// @param moveChildren Move the children of this region, that are also
450 /// contained in SubRegion into SubRegion.
451 void addSubRegion(Region *SubRegion, bool moveChildren = false);
453 /// @brief Remove a subregion from this Region.
455 /// The subregion is not deleted, as it will probably be inserted into another
457 /// @param SubRegion The SubRegion that will be removed.
458 Region *removeSubRegion(Region *SubRegion);
460 /// @brief Move all direct child nodes of this Region to another Region.
462 /// @param To The Region the child nodes will be transferred to.
463 void transferChildrenTo(Region *To);
465 /// @brief Verify if the region is a correct region.
467 /// Check if this is a correctly build Region. This is an expensive check, as
468 /// the complete CFG of the Region will be walked.
469 void verifyRegion() const;
471 /// @brief Clear the cache for BB RegionNodes.
473 /// After calling this function the BasicBlock RegionNodes will be stored at
474 /// different memory locations. RegionNodes obtained before this function is
475 /// called are therefore not comparable to RegionNodes abtained afterwords.
476 void clearNodeCache();
478 /// @name Subregion Iterators
480 /// These iterators iterator over all subregions of this Region.
482 typedef RegionSet::iterator iterator;
483 typedef RegionSet::const_iterator const_iterator;
485 iterator begin() { return children.begin(); }
486 iterator end() { return children.end(); }
488 const_iterator begin() const { return children.begin(); }
489 const_iterator end() const { return children.end(); }
492 /// @name BasicBlock Iterators
494 /// These iterators iterate over all BasicBlocks that are contained in this
495 /// Region. The iterator also iterates over BasicBlocks that are elements of
496 /// a subregion of this Region. It is therefore called a flat iterator.
498 template <bool IsConst>
499 class block_iterator_wrapper
500 : public df_iterator<typename std::conditional<IsConst, const BasicBlock,
501 BasicBlock>::type *> {
502 typedef df_iterator<typename std::conditional<IsConst, const BasicBlock,
503 BasicBlock>::type *> super;
506 typedef block_iterator_wrapper<IsConst> Self;
507 typedef typename super::pointer pointer;
509 // Construct the begin iterator.
510 block_iterator_wrapper(pointer Entry, pointer Exit) : super(df_begin(Entry))
512 // Mark the exit of the region as visited, so that the children of the
513 // exit and the exit itself, i.e. the block outside the region will never
515 super::Visited.insert(Exit);
518 // Construct the end iterator.
519 block_iterator_wrapper() : super(df_end<pointer>((BasicBlock *)nullptr)) {}
521 /*implicit*/ block_iterator_wrapper(super I) : super(I) {}
523 // FIXME: Even a const_iterator returns a non-const BasicBlock pointer.
524 // This was introduced for backwards compatibility, but should
525 // be removed as soon as all users are fixed.
526 BasicBlock *operator*() const {
527 return const_cast<BasicBlock*>(super::operator*());
531 typedef block_iterator_wrapper<false> block_iterator;
532 typedef block_iterator_wrapper<true> const_block_iterator;
534 block_iterator block_begin() {
535 return block_iterator(getEntry(), getExit());
538 block_iterator block_end() {
539 return block_iterator();
542 const_block_iterator block_begin() const {
543 return const_block_iterator(getEntry(), getExit());
545 const_block_iterator block_end() const {
546 return const_block_iterator();
549 typedef iterator_range<block_iterator> block_range;
550 typedef iterator_range<const_block_iterator> const_block_range;
552 /// @brief Returns a range view of the basic blocks in the region.
553 inline block_range blocks() {
554 return block_range(block_begin(), block_end());
557 /// @brief Returns a range view of the basic blocks in the region.
559 /// This is the 'const' version of the range view.
560 inline const_block_range blocks() const {
561 return const_block_range(block_begin(), block_end());
565 /// @name Element Iterators
567 /// These iterators iterate over all BasicBlock and subregion RegionNodes that
568 /// are direct children of this Region. It does not iterate over any
569 /// RegionNodes that are also element of a subregion of this Region.
571 typedef df_iterator<RegionNode*, SmallPtrSet<RegionNode*, 8>, false,
572 GraphTraits<RegionNode*> > element_iterator;
574 typedef df_iterator<const RegionNode*, SmallPtrSet<const RegionNode*, 8>,
575 false, GraphTraits<const RegionNode*> >
576 const_element_iterator;
578 element_iterator element_begin();
579 element_iterator element_end();
581 const_element_iterator element_begin() const;
582 const_element_iterator element_end() const;
586 //===----------------------------------------------------------------------===//
587 /// @brief Analysis that detects all canonical Regions.
589 /// The RegionInfo pass detects all canonical regions in a function. The Regions
590 /// are connected using the parent relation. This builds a Program Structure
592 class RegionInfo : public FunctionPass {
593 typedef DenseMap<BasicBlock*,BasicBlock*> BBtoBBMap;
594 typedef DenseMap<BasicBlock*, Region*> BBtoRegionMap;
595 typedef SmallPtrSet<Region*, 4> RegionSet;
597 RegionInfo(const RegionInfo &) LLVM_DELETED_FUNCTION;
598 const RegionInfo &operator=(const RegionInfo &) LLVM_DELETED_FUNCTION;
601 PostDominatorTree *PDT;
602 DominanceFrontier *DF;
604 /// The top level region.
605 Region *TopLevelRegion;
607 /// Map every BB to the smallest region, that contains BB.
608 BBtoRegionMap BBtoRegion;
610 // isCommonDomFrontier - Returns true if BB is in the dominance frontier of
611 // entry, because it was inherited from exit. In the other case there is an
612 // edge going from entry to BB without passing exit.
613 bool isCommonDomFrontier(BasicBlock* BB, BasicBlock* entry,
614 BasicBlock* exit) const;
616 // isRegion - Check if entry and exit surround a valid region, based on
617 // dominance tree and dominance frontier.
618 bool isRegion(BasicBlock* entry, BasicBlock* exit) const;
620 // insertShortCut - Saves a shortcut pointing from entry to exit.
621 // This function may extend this shortcut if possible.
622 void insertShortCut(BasicBlock* entry, BasicBlock* exit,
623 BBtoBBMap* ShortCut) const;
625 // getNextPostDom - Returns the next BB that postdominates N, while skipping
626 // all post dominators that cannot finish a canonical region.
627 DomTreeNode *getNextPostDom(DomTreeNode* N, BBtoBBMap *ShortCut) const;
629 // isTrivialRegion - A region is trivial, if it contains only one BB.
630 bool isTrivialRegion(BasicBlock *entry, BasicBlock *exit) const;
632 // createRegion - Creates a single entry single exit region.
633 Region *createRegion(BasicBlock *entry, BasicBlock *exit);
635 // findRegionsWithEntry - Detect all regions starting with bb 'entry'.
636 void findRegionsWithEntry(BasicBlock *entry, BBtoBBMap *ShortCut);
638 // scanForRegions - Detects regions in F.
639 void scanForRegions(Function &F, BBtoBBMap *ShortCut);
641 // getTopMostParent - Get the top most parent with the same entry block.
642 Region *getTopMostParent(Region *region);
644 // buildRegionsTree - build the region hierarchy after all region detected.
645 void buildRegionsTree(DomTreeNode *N, Region *region);
647 // Calculate - detecte all regions in function and build the region tree.
648 void Calculate(Function& F);
650 void releaseMemory() override;
652 // updateStatistics - Update statistic about created regions.
653 void updateStatistics(Region *R);
655 // isSimple - Check if a region is a simple region with exactly one entry
656 // edge and exactly one exit edge.
657 bool isSimple(Region* R) const;
661 explicit RegionInfo();
665 /// @name FunctionPass interface
667 bool runOnFunction(Function &F) override;
668 void getAnalysisUsage(AnalysisUsage &AU) const override;
669 void print(raw_ostream &OS, const Module *) const override;
670 void verifyAnalysis() const override;
673 /// @brief Get the smallest region that contains a BasicBlock.
675 /// @param BB The basic block.
676 /// @return The smallest region, that contains BB or NULL, if there is no
677 /// region containing BB.
678 Region *getRegionFor(BasicBlock *BB) const;
680 /// @brief Set the smallest region that surrounds a basic block.
682 /// @param BB The basic block surrounded by a region.
683 /// @param R The smallest region that surrounds BB.
684 void setRegionFor(BasicBlock *BB, Region *R);
686 /// @brief A shortcut for getRegionFor().
688 /// @param BB The basic block.
689 /// @return The smallest region, that contains BB or NULL, if there is no
690 /// region containing BB.
691 Region *operator[](BasicBlock *BB) const;
693 /// @brief Return the exit of the maximal refined region, that starts at a
696 /// @param BB The BasicBlock the refined region starts.
697 BasicBlock *getMaxRegionExit(BasicBlock *BB) const;
699 /// @brief Find the smallest region that contains two regions.
701 /// @param A The first region.
702 /// @param B The second region.
703 /// @return The smallest region containing A and B.
704 Region *getCommonRegion(Region* A, Region *B) const;
706 /// @brief Find the smallest region that contains two basic blocks.
708 /// @param A The first basic block.
709 /// @param B The second basic block.
710 /// @return The smallest region that contains A and B.
711 Region* getCommonRegion(BasicBlock* A, BasicBlock *B) const {
712 return getCommonRegion(getRegionFor(A), getRegionFor(B));
715 /// @brief Find the smallest region that contains a set of regions.
717 /// @param Regions A vector of regions.
718 /// @return The smallest region that contains all regions in Regions.
719 Region* getCommonRegion(SmallVectorImpl<Region*> &Regions) const;
721 /// @brief Find the smallest region that contains a set of basic blocks.
723 /// @param BBs A vector of basic blocks.
724 /// @return The smallest region that contains all basic blocks in BBS.
725 Region* getCommonRegion(SmallVectorImpl<BasicBlock*> &BBs) const;
727 Region *getTopLevelRegion() const {
728 return TopLevelRegion;
731 /// @brief Update RegionInfo after a basic block was split.
733 /// @param NewBB The basic block that was created before OldBB.
734 /// @param OldBB The old basic block.
735 void splitBlock(BasicBlock* NewBB, BasicBlock *OldBB);
737 /// @brief Clear the Node Cache for all Regions.
739 /// @see Region::clearNodeCache()
740 void clearNodeCache() {
742 TopLevelRegion->clearNodeCache();
746 inline raw_ostream &operator<<(raw_ostream &OS, const RegionNode &Node) {
747 if (Node.isSubRegion())
748 return OS << Node.getNodeAs<Region>()->getNameStr();
750 return OS << Node.getNodeAs<BasicBlock>()->getName();
752 } // End llvm namespace