37 #ifndef LLVM_ANALYSIS_REGIONINFO_H
38 #define LLVM_ANALYSIS_REGIONINFO_H
55 template <
class FuncT_>
62 typedef typename FuncT_::UnknownRegionTypeError
BrokenT;
72 template <
class RegionTr>
76 template <
class RegionTr>
106 template <
class GraphType>
177 template <
class T>
inline T *
getNodeAs()
const;
249 class RegionBase :
public RegionNodeBase<Tr> {
250 typedef typename Tr::FuncT FuncT;
251 typedef typename Tr::BlockT BlockT;
252 typedef typename Tr::RegionInfoT RegionInfoT;
253 typedef typename Tr::RegionT RegionT;
254 typedef typename Tr::RegionNodeT RegionNodeT;
255 typedef typename Tr::DomTreeT DomTreeT;
256 typedef typename Tr::LoopT LoopT;
257 typedef typename Tr::LoopInfoT LoopInfoT;
258 typedef typename Tr::InstT InstT;
260 typedef GraphTraits<BlockT *> BlockTraits;
261 typedef GraphTraits<Inverse<BlockT *>> InvBlockTraits;
262 typedef typename BlockTraits::ChildIteratorType SuccIterTy;
263 typedef typename InvBlockTraits::ChildIteratorType PredIterTy;
277 typedef std::vector<std::unique_ptr<RegionT>> RegionSet;
282 typedef std::map<BlockT *, std::unique_ptr<RegionNodeT>> BBNodeMapT;
285 mutable BBNodeMapT BBNodeMap;
289 void verifyBBInRegion(
BlockT *BB)
const;
294 void verifyWalk(
BlockT *BB, std::set<BlockT *> *visitedBB)
const;
297 void verifyRegionNest()
const;
365 return const_cast<RegionNodeT *
>(
366 reinterpret_cast<const RegionNodeT *
>(
this));
428 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
437 bool contains(
const BlockT *BB)
const;
448 return contains(SubRegion->getEntry()) &&
450 SubRegion->getExit() ==
getExit());
502 RegionNodeT *
getNode(BlockT *BB)
const;
508 RegionNodeT *
getBBNode(BlockT *BB)
const;
515 void addSubRegion(RegionT *SubRegion,
bool moveChildren =
false);
562 template <
bool IsConst>
565 typename std::conditional<IsConst, const BlockT, BlockT>::type *> {
567 typename std::conditional<IsConst, const BlockT, BlockT>::type *>
super;
654 inline raw_ostream &operator<<(raw_ostream &OS, const RegionNodeBase<Tr> &Node);
663 class RegionInfoBase {
664 typedef typename Tr::BlockT BlockT;
665 typedef typename Tr::FuncT FuncT;
666 typedef typename Tr::RegionT RegionT;
667 typedef typename Tr::RegionInfoT RegionInfoT;
668 typedef typename Tr::DomTreeT DomTreeT;
669 typedef typename Tr::DomTreeNodeT DomTreeNodeT;
670 typedef typename Tr::PostDomTreeT PostDomTreeT;
671 typedef typename Tr::DomFrontierT DomFrontierT;
672 typedef GraphTraits<BlockT *> BlockTraits;
673 typedef GraphTraits<Inverse<BlockT *>> InvBlockTraits;
674 typedef typename BlockTraits::ChildIteratorType SuccIterTy;
675 typedef typename InvBlockTraits::ChildIteratorType PredIterTy;
689 : DT(std::move(Arg.DT)), PDT(std::move(Arg.PDT)), DF(std::move(Arg.DF)),
690 TopLevelRegion(std::move(Arg.TopLevelRegion)),
691 BBtoRegion(std::move(Arg.BBtoRegion)) {
695 DT = std::move(RHS.DT);
696 PDT = std::move(RHS.PDT);
697 DF = std::move(RHS.DF);
698 TopLevelRegion = std::move(RHS.TopLevelRegion);
699 BBtoRegion = std::move(RHS.BBtoRegion);
709 RegionT *TopLevelRegion;
713 BBtoRegionMap BBtoRegion;
723 TopLevelRegion =
nullptr;
730 void verifyBBMap(
const RegionT *SR)
const;
735 bool isCommonDomFrontier(BlockT *BB, BlockT *entry, BlockT *exit)
const;
739 bool isRegion(BlockT *entry, BlockT *exit)
const;
743 void insertShortCut(BlockT *entry, BlockT *exit, BBtoBBMap *ShortCut)
const;
747 DomTreeNodeT *getNextPostDom(DomTreeNodeT *
N, BBtoBBMap *ShortCut)
const;
750 bool isTrivialRegion(BlockT *entry, BlockT *exit)
const;
753 RegionT *createRegion(BlockT *entry, BlockT *exit);
756 void findRegionsWithEntry(BlockT *entry, BBtoBBMap *ShortCut);
759 void scanForRegions(FuncT &
F, BBtoBBMap *ShortCut);
762 RegionT *getTopMostParent(RegionT *region);
765 void buildRegionsTree(DomTreeNodeT *
N, RegionT *region);
768 virtual void updateStatistics(RegionT *R) = 0;
771 void calculate(FuncT &
F);
778 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
845 TopLevelRegion->clearNodeCache();
859 return this ==
reinterpret_cast<const RegionNode *
>(&
RN);
866 Region *Parent =
nullptr);
870 return &RN ==
reinterpret_cast<const RegionNode *
>(
this);
883 :
Base(std::move(static_cast<
Base &>(Arg))) {}
885 Base::operator=(std::move(static_cast<Base &>(RHS)));
962 assert(!isSubRegion() &&
"This is not a BasicBlock RegionNode!");
970 assert(isSubRegion() &&
"This is not a subregion RegionNode!");
972 return reinterpret_cast<Region *
>(Unconst);
978 typedef typename Tr::BlockT BlockT;
979 typedef typename Tr::RegionT RegionT;
982 return OS << Node.template getNodeAs<RegionT>()->getNameStr();
984 return OS << Node.template getNodeAs<BlockT>()->
getName();
987 extern template class RegionBase<RegionTraits<Function>>;
988 extern template class RegionNodeBase<RegionTraits<Function>>;
989 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.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
block_iterator_wrapper< false > block_iterator
block_iterator_wrapper(value_type Entry, value_type Exit)
RegionNodeT * getNode() const
Get the RegionNode representing the current Region.
iterator_range< element_iterator > elements()
bool isSimple() const
Is this a simple region?
A Module instance is used to store all the information related to an LLVM module. ...
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.
block_iterator_wrapper(super I)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
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.
RegionInfo & operator=(RegionInfo &&RHS)
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.
void view()
Opens a viewer to show the GraphViz visualization of the regions.
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...
RegionInfoPrinterPass(raw_ostream &OS)
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
PointerTy getPointer() const
Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo *RI, DominatorTree *DT, Region *Parent=nullptr)
A CRTP mix-in to automatically provide informational APIs needed for passes.
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.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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
RegionT * getParent() const
Get the parent Region of this RegionNode.
Verifier pass for the RegionInfo.
A set of analyses that are preserved following a run of a transformation pass.
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()
A CRTP mix-in that provides informational APIs needed for analysis passes.
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.
RegionInfo run(Function &F, FunctionAnalysisManager &AM)
void viewOnly()
Opens a viewer to show the GraphViz visualization of this region without instructions in the BasicBlo...
void transferChildrenTo(RegionT *To)
Move all direct child nodes of this Region to another Region.
iterator_range< block_iterator > block_range
df_iterator< RegionNodeT *, df_iterator_default_set< RegionNodeT * >, false, GraphTraits< RegionNodeT * > > element_iterator
const_block_range blocks() const
Returns a range view of the basic blocks in the region.
iterator_range< const_element_iterator > elements() const
block_iterator_wrapper< IsConst > Self
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
RegionInfo(RegionInfo &&Arg)
~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.
Analysis pass that exposes the RegionInfo for a function.
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()
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
FuncT_::UnknownRegionTypeError BrokenT
df_iterator< const RegionNodeT *, df_iterator_default_set< const RegionNodeT * >, false, GraphTraits< const RegionNodeT * > > const_element_iterator
block_iterator block_begin()
super::value_type value_type
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.
Represents a single loop in the control flow graph.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
const NodeRef & operator*() const
RegionInfoBase< RegionTraits< Function > > Base
A container for analyses that lazily runs them and caches their results.
RegionT * removeSubRegion(RegionT *SubRegion)
Remove a subregion from this Region.
This header defines various interfaces for pass management in LLVM.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
Printer pass for the RegionInfo.
A special type used by analysis passes to provide an address that identifies that particular analysis...
static unsigned getNumSuccessors(BasicBlock *BB)
bool isTopLevelRegion() const
Check if a Region is the TopLevel region.