36#ifndef LLVM_ANALYSIS_REGIONINFO_H
37#define LLVM_ANALYSIS_REGIONINFO_H
44#include "llvm/Config/llvm-config.h"
60class DominanceFrontier;
63class PostDominatorTree;
65template <
class RegionTr>
class RegionBase;
67template <
class RegionTr>
class RegionInfoBase;
74template <
class FuncT_>
81 using BrokenT =
typename FuncT_::UnknownRegionTypeError;
111template <
class GraphType>
257 using FuncT =
typename Tr::FuncT;
258 using BlockT =
typename Tr::BlockT;
259 using RegionInfoT =
typename Tr::RegionInfoT;
260 using RegionT =
typename Tr::RegionT;
261 using RegionNodeT =
typename Tr::RegionNodeT;
262 using DomTreeT =
typename Tr::DomTreeT;
263 using LoopT =
typename Tr::LoopT;
264 using LoopInfoT =
typename Tr::LoopInfoT;
265 using InstT =
typename Tr::InstT;
269 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
270 using PredIterTy =
typename InvBlockTraits::ChildIteratorType;
280 using RegionSet = std::vector<std::unique_ptr<RegionT>>;
285 using BBNodeMapT = std::map<BlockT *, std::unique_ptr<RegionNodeT>>;
288 mutable BBNodeMapT BBNodeMap;
292 void verifyBBInRegion(BlockT *BB)
const;
297 void verifyWalk(BlockT *BB, std::set<BlockT *> *visitedBB)
const;
300 void verifyRegionNest()
const;
311 RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT,
312 RegionT *Parent =
nullptr);
371 return const_cast<RegionNodeT *
>(
372 reinterpret_cast<const RegionNodeT *
>(
this));
439#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
448 bool contains(
const BlockT *BB)
const;
459 return contains(SubRegion->getEntry()) &&
461 SubRegion->getExit() ==
getExit());
478 bool contains(
const LoopT *L)
const;
513 RegionNodeT *
getNode(BlockT *BB)
const;
519 RegionNodeT *
getBBNode(BlockT *BB)
const;
526 void addSubRegion(RegionT *SubRegion,
bool moveChildren =
false);
573 template <
bool IsConst>
576 std::conditional_t<IsConst, const BlockT, BlockT> *> {
665inline raw_ostream &
operator<<(raw_ostream &
OS,
const RegionNodeBase<Tr> &
Node);
678 using BlockT =
typename Tr::BlockT;
679 using FuncT =
typename Tr::FuncT;
680 using RegionT =
typename Tr::RegionT;
681 using RegionInfoT =
typename Tr::RegionInfoT;
682 using DomTreeT =
typename Tr::DomTreeT;
683 using DomTreeNodeT =
typename Tr::DomTreeNodeT;
684 using PostDomTreeT =
typename Tr::PostDomTreeT;
685 using DomFrontierT =
typename Tr::DomFrontierT;
688 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
689 using PredIterTy =
typename InvBlockTraits::ChildIteratorType;
698 TopLevelRegion(
std::
move(
Arg.TopLevelRegion)),
704 DT = std::move(
RHS.DT);
705 PDT = std::move(
RHS.PDT);
706 DF = std::move(
RHS.DF);
707 TopLevelRegion = std::move(
RHS.TopLevelRegion);
708 BBtoRegion = std::move(
RHS.BBtoRegion);
713 virtual ~RegionInfoBase();
720 RegionT *TopLevelRegion =
nullptr;
723 BBtoRegionMap BBtoRegion;
730 template<
typename TheRegionT>
735 for (
auto &SubR : *R)
748 TopLevelRegion =
nullptr;
755 void verifyBBMap(
const RegionT *SR)
const;
760 bool isCommonDomFrontier(BlockT *BB, BlockT *
entry, BlockT *exit)
const;
764 bool isRegion(BlockT *
entry, BlockT *exit)
const;
768 void insertShortCut(BlockT *
entry, BlockT *exit, BBtoBBMap *ShortCut)
const;
772 DomTreeNodeT *getNextPostDom(DomTreeNodeT *
N, BBtoBBMap *ShortCut)
const;
775 bool isTrivialRegion(BlockT *
entry, BlockT *exit)
const;
778 RegionT *createRegion(BlockT *
entry, BlockT *exit);
781 void findRegionsWithEntry(BlockT *
entry, BBtoBBMap *ShortCut);
784 void scanForRegions(FuncT &
F, BBtoBBMap *ShortCut);
787 RegionT *getTopMostParent(RegionT *region);
790 void buildRegionsTree(DomTreeNodeT *
N, RegionT *region);
793 virtual void updateStatistics(RegionT *R) = 0;
796 void calculate(FuncT &
F);
806#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
873 TopLevelRegion->clearNodeCache();
885 return this ==
reinterpret_cast<const RegionNode *
>(&RN);
892 Region *Parent =
nullptr);
896 return &RN ==
reinterpret_cast<const RegionNode *
>(
this);
911 Base::operator=(std::move(
static_cast<Base &
>(
RHS)));
997 assert(!isSubRegion() &&
"This is not a BasicBlock RegionNode!");
1005 assert(isSubRegion() &&
"This is not a subregion RegionNode!");
1007 return reinterpret_cast<Region *
>(Unconst);
1013 using BlockT =
typename Tr::BlockT;
1014 using RegionT =
typename Tr::RegionT;
1016 if (
Node.isSubRegion())
1017 return OS <<
Node.template getNodeAs<RegionT>()->getNameStr();
1019 return OS <<
Node.template getNodeAs<BlockT>()->getName();
1022extern template class RegionBase<RegionTraits<Function>>;
1023extern template class RegionNodeBase<RegionTraits<Function>>;
1024extern template class RegionInfoBase<RegionTraits<Function>>;
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
This file defines the DenseMap class.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
print Instructions which execute on loop entry
This header defines various interfaces for pass management in LLVM.
This file defines the PointerIntPair class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Marker class to iterate over the elements of a Region in flat mode.
FunctionPass class - This class is used to implement most global optimizations.
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
Represents a single loop in the control flow graph.
A Module instance is used to store all the information related to an LLVM module.
PointerIntPair - This class implements a pair of a pointer and small integer.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
A set of analyses that are preserved following a run of a transformation pass.
typename super::value_type value_type
BlockT * operator*() const
block_iterator_wrapper(super I)
block_iterator_wrapper(value_type Entry, value_type Exit)
A single entry single exit Region.
void replaceExit(BlockT *BB)
Replace the exit basic block of the region with the new basic block.
void clearNodeCache()
Clear the cache for BB RegionNodes.
std::string getNameStr() const
Returns the name of the Region.
block_range blocks()
Returns a range view of the basic blocks in the region.
BlockT * getExit() const
Get the exit BasicBlock of the Region.
void transferChildrenTo(RegionT *To)
Move all direct child nodes of this Region to another Region.
RegionNodeT * getBBNode(BlockT *BB) const
Get the BasicBlock RegionNode for a BasicBlock.
block_iterator_wrapper< true > const_block_iterator
block_iterator block_begin()
bool getExitingBlocks(SmallVectorImpl< BlockT * > &Exitings) const
Collect all blocks of this region's single exit edge, if existing.
RegionNodeT * getNode() const
Get the RegionNode representing the current Region.
iterator_range< element_iterator > elements()
block_iterator_wrapper< false > block_iterator
const_iterator end() const
const_block_iterator block_end() const
LoopT * outermostLoopInRegion(LoopT *L) const
Get the outermost loop in the region that contains a loop.
unsigned getDepth() const
Get the nesting level of this Region.
const_block_iterator block_begin() const
void replaceEntry(BlockT *BB)
Replace the entry basic block of the region with the new basic block.
void dump() const
Print the region to stderr.
block_iterator block_end()
void replaceEntryRecursive(BlockT *NewEntry)
Recursively replace the entry basic block of the region.
bool contains(const BlockT *BB) const
Check if the region contains a BasicBlock.
element_iterator element_begin()
void replaceExitRecursive(BlockT *NewExit)
Recursively replace the exit basic block of the region.
void verifyRegion() const
Verify if the region is a correct region.
RegionBase & operator=(const RegionBase &)=delete
RegionT * getParent() const
Get the parent of the Region.
RegionInfoT * getRegionInfo() const
Return the RegionInfo object, that belongs to this Region.
BlockT * getEntry() const
Get the entry BasicBlock of the Region.
void addSubRegion(RegionT *SubRegion, bool moveChildren=false)
Add a new subregion to this Region.
RegionBase(const RegionBase &)=delete
const_iterator begin() const
bool contains(const InstT *Inst) const
Check if the region contains an Instruction.
typename RegionSet::iterator iterator
element_iterator element_end()
df_iterator< const RegionNodeT *, df_iterator_default_set< const RegionNodeT * >, false, GraphTraits< const RegionNodeT * > > const_element_iterator
bool isSimple() const
Is this a simple region?
bool isTopLevelRegion() const
Check if a Region is the TopLevel region.
bool contains(const RegionT *SubRegion) const
Check if the region contains another region.
BlockT * getExitingBlock() const
Return the first block of this region's single exit edge, if existing.
~RegionBase()
Delete the Region and all its subregions.
iterator_range< const_block_iterator > const_block_range
iterator_range< const_element_iterator > elements() const
PrintStyle
PrintStyle - Print region in difference ways.
const_block_range blocks() const
Returns a range view of the basic blocks in the region.
RegionT * removeSubRegion(RegionT *SubRegion)
Remove a subregion from this Region.
typename RegionSet::const_iterator const_iterator
BlockT * getEnteringBlock() const
Return the first block of this region's single entry edge, if existing.
RegionT * getExpandedRegion() const
Return a new (non-canonical) region, that is obtained by joining this region with its predecessors.
void print(raw_ostream &OS, bool printTree=true, unsigned level=0, PrintStyle Style=PrintNone) const
Print the region.
RegionT * getSubRegionNode(BlockT *BB) const
Get the subregion that starts at a BasicBlock.
iterator_range< block_iterator > block_range
Analysis pass that exposes the RegionInfo for a function.
RegionInfo run(Function &F, FunctionAnalysisManager &AM)
Analysis that detects all canonical Regions.
RegionT * getCommonRegion(BlockT *A, BlockT *B) const
Find the smallest region that contains two basic blocks.
void updateRegionTree(RegionInfoT &RI, TheRegionT *R)
Update refences to a RegionInfoT held by the RegionT managed here.
void clearNodeCache()
Clear the Node Cache for all Regions.
BlockT * getMaxRegionExit(BlockT *BB) const
Return the exit of the maximal refined region, that starts at a BasicBlock.
static bool VerifyRegionInfo
void print(raw_ostream &OS) const
RegionT * getTopLevelRegion() const
RegionT * getRegionFor(BlockT *BB) const
Get the smallest region that contains a BasicBlock.
static RegionT::PrintStyle printStyle
RegionInfoBase & operator=(const RegionInfoBase &)=delete
void verifyAnalysis() const
void setRegionFor(BlockT *BB, RegionT *R)
Set the smallest region that surrounds a basic block.
RegionT * operator[](BlockT *BB) const
A shortcut for getRegionFor().
RegionInfoBase(const RegionInfoBase &)=delete
RegionT * getCommonRegion(RegionT *A, RegionT *B) const
Find the smallest region that contains two regions.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
~RegionInfoPass() override
RegionInfo & getRegionInfo()
const RegionInfo & getRegionInfo() const
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Printer pass for the RegionInfo.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
RegionInfo(RegionInfo &&Arg)
void view()
Opens a viewer to show the GraphViz visualization of the regions.
void viewOnly()
Opens a viewer to show the GraphViz visualization of this region without instructions in the BasicBlo...
void recalculate(Function &F, DominatorTree *DT, PostDominatorTree *PDT, DominanceFrontier *DF)
RegionInfo & operator=(RegionInfo &&RHS)
void updateStatistics(Region *R) final
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
typename Tr::RegionT RegionT
RegionNodeBase & operator=(const RegionNodeBase &)=delete
RegionNodeBase(RegionT *Parent, BlockT *Entry, bool isSubRegion=false)
Create a RegionNode.
bool isSubRegion() const
Is this RegionNode a subregion?
RegionT * getParent() const
Get the parent Region of this RegionNode.
T * getNodeAs() const
Get the content of this RegionNode.
RegionNodeBase(const RegionNodeBase &)=delete
typename Tr::BlockT BlockT
BlockT * getEntry() const
Get the entry BasicBlock of this RegionNode.
RegionNode(Region *Parent, BasicBlock *Entry, bool isSubRegion=false)
bool operator==(const Region &RN) const
bool operator==(const RegionNode &RN) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference operator*() const
typename GT::NodeRef value_type
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
df_iterator< T > df_begin(const T &G)
DomTreeNodeBase< BasicBlock > DomTreeNode
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
df_iterator< T > df_end(const T &G)
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
A CRTP mix-in to automatically provide informational APIs needed for passes.
Verifier pass for the RegionInfo.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
static unsigned getNumSuccessors(BasicBlock *BB)
typename FuncT_::UnknownRegionTypeError BrokenT