37 #ifndef LLVM_ANALYSIS_REGIONINFO_H
38 #define LLVM_ANALYSIS_REGIONINFO_H
53 template <
class FuncT_>
60 typedef typename FuncT_::UnknownRegionTypeError
BrokenT;
70 template <
class RegionTr>
74 template <
class RegionTr>
104 template <
class GraphType>
175 template <
class T>
inline T *
getNodeAs()
const;
247 class RegionBase :
public RegionNodeBase<Tr> {
248 typedef typename Tr::FuncT FuncT;
249 typedef typename Tr::BlockT BlockT;
250 typedef typename Tr::RegionInfoT RegionInfoT;
251 typedef typename Tr::RegionT RegionT;
252 typedef typename Tr::RegionNodeT RegionNodeT;
253 typedef typename Tr::DomTreeT DomTreeT;
254 typedef typename Tr::LoopT LoopT;
255 typedef typename Tr::LoopInfoT LoopInfoT;
256 typedef typename Tr::InstT InstT;
258 typedef GraphTraits<BlockT *> BlockTraits;
259 typedef GraphTraits<Inverse<BlockT *>> InvBlockTraits;
260 typedef typename BlockTraits::ChildIteratorType SuccIterTy;
261 typedef typename InvBlockTraits::ChildIteratorType PredIterTy;
275 typedef std::vector<std::unique_ptr<RegionT>> RegionSet;
280 typedef std::map<BlockT *, RegionNodeT *> BBNodeMapT;
283 mutable BBNodeMapT BBNodeMap;
287 void verifyBBInRegion(BlockT *BB)
const;
292 void verifyWalk(BlockT *BB, std::set<BlockT *> *visitedBB)
const;
296 void verifyRegionNest()
const;
307 RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT,
364 return const_cast<RegionNodeT *
>(
365 reinterpret_cast<const RegionNodeT *
>(
this));
427 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
436 bool contains(
const BlockT *BB)
const;
447 return contains(SubRegion->getEntry()) &&
449 SubRegion->getExit() ==
getExit());
466 bool contains(
const LoopT *L)
const;
501 RegionNodeT *
getNode(BlockT *BB)
const;
507 RegionNodeT *
getBBNode(BlockT *BB)
const;
514 void addSubRegion(RegionT *SubRegion,
bool moveChildren =
false);
561 template <
bool IsConst>
564 typename std::conditional<IsConst, const BlockT, BlockT>::type *> {
566 typename std::conditional<IsConst, const BlockT, BlockT>::type *>
super;
645 inline raw_ostream &operator<<(raw_ostream &OS, const RegionNodeBase<Tr> &Node);
655 typedef typename Tr::BlockT BlockT;
656 typedef typename Tr::FuncT FuncT;
657 typedef typename Tr::RegionT RegionT;
658 typedef typename Tr::RegionInfoT RegionInfoT;
659 typedef typename Tr::DomTreeT DomTreeT;
660 typedef typename Tr::DomTreeNodeT DomTreeNodeT;
661 typedef typename Tr::PostDomTreeT PostDomTreeT;
662 typedef typename Tr::DomFrontierT DomFrontierT;
665 typedef typename BlockTraits::ChildIteratorType SuccIterTy;
666 typedef typename InvBlockTraits::ChildIteratorType PredIterTy;
685 RegionT *TopLevelRegion;
694 bool isCommonDomFrontier(BlockT *BB, BlockT *entry, BlockT *exit)
const;
698 bool isRegion(BlockT *entry, BlockT *exit)
const;
702 void insertShortCut(BlockT *entry, BlockT *exit,
BBtoBBMap *ShortCut)
const;
706 DomTreeNodeT *getNextPostDom(DomTreeNodeT *
N,
BBtoBBMap *ShortCut)
const;
709 bool isTrivialRegion(BlockT *entry, BlockT *exit)
const;
712 RegionT *createRegion(BlockT *entry, BlockT *exit);
715 void findRegionsWithEntry(BlockT *entry,
BBtoBBMap *ShortCut);
718 void scanForRegions(FuncT &
F,
BBtoBBMap *ShortCut);
721 RegionT *getTopMostParent(RegionT *region);
724 void buildRegionsTree(DomTreeNodeT *
N, RegionT *region);
727 virtual void updateStatistics(RegionT *R) = 0;
730 void calculate(FuncT &
F);
737 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
803 void splitBlock(BlockT *NewBB, BlockT *OldBB);
810 TopLevelRegion->clearNodeCache();
824 return this ==
reinterpret_cast<const RegionNode *
>(&
RN);
831 Region *Parent =
nullptr);
835 return &RN ==
reinterpret_cast<const RegionNode *
>(
this);
880 assert(!isSubRegion() &&
"This is not a BasicBlock RegionNode!");
888 assert(isSubRegion() &&
"This is not a subregion RegionNode!");
890 return reinterpret_cast<Region *
>(Unconst);
896 typedef typename Tr::BlockT BlockT;
897 typedef typename Tr::RegionT RegionT;
900 return OS << Node.template getNodeAs<RegionT>()->getNameStr();
902 return OS << Node.template getNodeAs<BlockT>()->
getName();
905 extern template class RegionBase<RegionTraits<Function>>;
906 extern template class RegionNodeBase<RegionTraits<Function>>;
907 extern template class RegionInfoBase<RegionTraits<Function>>;
RegionT * getCommonRegion(BlockT *A, BlockT *B) const
Find the smallest region that contains two basic blocks.
std::string getNameStr() const
Returns the name of the Region.
block_iterator_wrapper< false > block_iterator
RegionNodeT * getNode() const
Get the RegionNode representing the current Region.
bool isSimple() const
Is this a simple region?
A Module instance is used to store all the information related to an LLVM module. ...
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
static RegionT::PrintStyle printStyle
const RegionInfo & getRegionInfo() const
void print(raw_ostream &OS, bool printTree=true, unsigned level=0, PrintStyle Style=PrintNone) const
Print the region.
pointer operator*() const
block_iterator_wrapper(super I)
BlockT * getExitingBlock() const
Return the first block of this region's single exit edge, if existing.
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
RegionNodeBase(RegionT *Parent, BlockT *Entry, bool isSubRegion=false)
Create a RegionNode.
block_iterator_wrapper(pointer Entry, pointer Exit)
bool contains(const InstT *Inst) const
Check if the region contains an Instruction.
bool contains(const RegionT *SubRegion) const
Check if the region contains another region.
BlockT * getEntry() const
Get the entry BasicBlock of this RegionNode.
bool isSubRegion() const
Is this RegionNode a subregion?
void setRegionFor(BlockT *BB, RegionT *R)
Set the smallest region that surrounds a basic block.
RegionT * getTopLevelRegion() const
void recalculate(Function &F, DominatorTree *DT, PostDominatorTree *PDT, DominanceFrontier *DF)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
T * getNodeAs() const
Get the content of this RegionNode.
Analysis that detects all canonical Regions.
RegionT * getRegionFor(BlockT *BB) const
Get the smallest region that contains a BasicBlock.
RegionInfoT * getRegionInfo() const
Return the RegionInfo object, that belongs to this Region.
iterator_range< const_block_iterator > const_block_range
unsigned getDepth() const
Get the nesting level of this Region.
LoopT * outermostLoopInRegion(LoopT *L) const
Get the outermost loop in the region that contains a loop.
void clearNodeCache()
Clear the cache for BB RegionNodes.
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
block_iterator_wrapper< true > const_block_iterator
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
RegionT * getParent() const
Get the parent of the Region.
static StringRef getName(Value *V)
RegionInfo & getRegionInfo()
block_range blocks()
Returns a range view of the basic blocks in the region.
RegionNodeT * getBBNode(BlockT *BB) const
Get the BasicBlock RegionNode for a BasicBlock.
void print(raw_ostream &OS) const
BlockT * getMaxRegionExit(BlockT *BB) const
Return the exit of the maximal refined region, that starts at a BasicBlock.
PrintStyle
PrintStyle - Print region in difference ways.
void verifyAnalysis() const
RegionSet::iterator iterator
Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo *RI, DominatorTree *DT, Region *Parent=nullptr)
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
Base class for the actual dominator tree node.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
const_block_iterator block_begin() const
df_iterator< RegionNodeT *, SmallPtrSet< RegionNodeT *, 8 >, false, GraphTraits< RegionNodeT * > > element_iterator
RegionT * getParent() const
Get the parent Region of this RegionNode.
LLVM Basic Block Representation.
void dump() const
Print the region to stderr.
df_iterator< T > df_end(const T &G)
PostDominatorTree PostDomTreeT
void addSubRegion(RegionT *SubRegion, bool moveChildren=false)
Add a new subregion to this Region.
void replaceExit(BlockT *BB)
Replace the exit basic block of the region with the new basic block.
element_iterator element_end()
const_iterator begin() const
bool operator==(const RegionNode &RN) const
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
void transferChildrenTo(RegionT *To)
Move all direct child nodes of this Region to another Region.
iterator_range< block_iterator > block_range
const_block_range blocks() const
Returns a range view of the basic blocks in the region.
block_iterator_wrapper< IsConst > Self
PointerTy getPointer() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
df_iterator< const RegionNodeT *, SmallPtrSet< const RegionNodeT *, 8 >, false, GraphTraits< const RegionNodeT * > > const_element_iterator
~RegionInfoPass() override
void replaceEntryRecursive(BlockT *NewEntry)
Recursively replace the entry basic block of the region.
RegionT * getSubRegionNode(BlockT *BB) const
Get the subregion that starts at a BasicBlock.
RegionT * getExpandedRegion() const
Return a new (non-canonical) region, that is obtained by joining this region with its predecessors...
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
A single entry single exit Region.
void replaceEntry(BlockT *BB)
Replace the entry basic block of the region with the new basic block.
df_iterator< T > df_begin(const T &G)
A range adaptor for a pair of iterators.
element_iterator element_begin()
void splitBlock(BlockT *NewBB, BlockT *OldBB)
Update RegionInfo after a basic block was split.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
FuncT_::UnknownRegionTypeError BrokenT
block_iterator block_begin()
DominanceFrontier DomFrontierT
block_iterator block_end()
void replaceExitRecursive(BlockT *NewExit)
Recursively replace the exit basic block of the region.
BlockT * getEnteringBlock() const
Return the first block of this region's single entry edge, if existing.
bool operator==(const Region &RN) const
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
RegionNode(Region *Parent, BasicBlock *Entry, bool isSubRegion=false)
void verifyRegion() const
Verify if the region is a correct region.
Marker class to iterate over the elements of a Region in flat mode.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
RegionSet::const_iterator const_iterator
~RegionBase()
Delete the Region and all its subregions.
BlockT * getExit() const
Get the exit BasicBlock of the Region.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
RegionT * operator[](BlockT *BB) const
A shortcut for getRegionFor().
void clearNodeCache()
Clear the Node Cache for all Regions.
RegionT * getCommonRegion(RegionT *A, RegionT *B) const
Find the smallest region that contains two regions.
BlockT * getEntry() const
Get the entry BasicBlock of the Region.
bool contains(const BlockT *BB) const
Check if the region contains a BasicBlock.
const_block_iterator block_end() const
static bool VerifyRegionInfo
void updateStatistics(Region *R) final
This class implements an extremely fast bulk output stream that can only output to a stream...
const_iterator end() const
BlockT * operator*() const
RegionT * removeSubRegion(RegionT *SubRegion)
Remove a subregion from this Region.
static unsigned getNumSuccessors(BasicBlock *BB)
bool isTopLevelRegion() const
Check if a Region is the TopLevel region.