37 #ifndef LLVM_ANALYSIS_REGIONINFO_H 38 #define LLVM_ANALYSIS_REGIONINFO_H 45 #include "llvm/Config/llvm-config.h" 57 #include <type_traits> 62 class DominanceFrontier;
66 class PostDominatorTree;
76 template <
class FuncT_>
83 using BrokenT =
typename FuncT_::UnknownRegionTypeError;
113 template <
class GraphType>
124 using RegionT =
typename Tr::RegionT;
153 bool isSubRegion =
false)
154 : entry(Entry, isSubRegion), parent(Parent) {}
184 template <
class T>
inline T *getNodeAs()
const;
259 using FuncT =
typename Tr::FuncT;
260 using BlockT =
typename Tr::BlockT;
261 using RegionInfoT =
typename Tr::RegionInfoT;
262 using RegionT =
typename Tr::RegionT;
263 using RegionNodeT =
typename Tr::RegionNodeT;
264 using DomTreeT =
typename Tr::DomTreeT;
265 using LoopT =
typename Tr::LoopT;
266 using LoopInfoT =
typename Tr::LoopInfoT;
267 using InstT =
typename Tr::InstT;
271 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
272 using PredIterTy =
typename InvBlockTraits::ChildIteratorType;
282 using RegionSet = std::vector<std::unique_ptr<RegionT>>;
287 using BBNodeMapT = std::map<BlockT *, std::unique_ptr<RegionNodeT>>;
290 mutable BBNodeMapT BBNodeMap;
294 void verifyBBInRegion(BlockT *BB)
const;
299 void verifyWalk(BlockT *BB, std::set<BlockT *> *visitedBB)
const;
302 void verifyRegionNest()
const;
313 RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT,
314 RegionT *Parent =
nullptr);
332 void replaceEntry(BlockT *BB);
338 void replaceExit(BlockT *BB);
347 void replaceEntryRecursive(BlockT *NewEntry);
356 void replaceExitRecursive(BlockT *NewExit);
373 return const_cast<RegionNodeT *
>(
374 reinterpret_cast<const RegionNodeT *
>(
this));
382 unsigned getDepth()
const;
395 RegionT *getExpandedRegion()
const;
402 BlockT *getEnteringBlock()
const;
409 BlockT *getExitingBlock()
const;
425 std::string getNameStr()
const;
441 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 450 bool contains(
const BlockT *BB)
const;
461 return contains(SubRegion->getEntry()) &&
463 SubRegion->getExit() == getExit());
480 bool contains(
const LoopT *L)
const;
490 LoopT *outermostLoopInRegion(LoopT *L)
const;
501 LoopT *outermostLoopInRegion(LoopInfoT *LI, BlockT *BB)
const;
507 RegionT *getSubRegionNode(BlockT *BB)
const;
515 RegionNodeT *getNode(BlockT *BB)
const;
521 RegionNodeT *getBBNode(BlockT *BB)
const;
528 void addSubRegion(RegionT *SubRegion,
bool moveChildren =
false);
535 RegionT *removeSubRegion(RegionT *SubRegion);
540 void transferChildrenTo(RegionT *To);
553 void clearNodeCache();
575 template <
bool IsConst>
578 typename std::conditional<IsConst, const BlockT, BlockT>::type *> {
581 typename std::conditional<IsConst, const BlockT, BlockT>::type *>;
593 super::Visited.insert(Exit);
655 return make_range(element_begin(), element_end());
661 return make_range(element_begin(), element_end());
668 inline raw_ostream &operator<<(raw_ostream &OS, const RegionNodeBase<Tr> &Node);
681 using BlockT =
typename Tr::BlockT;
682 using FuncT =
typename Tr::FuncT;
683 using RegionT =
typename Tr::RegionT;
684 using RegionInfoT =
typename Tr::RegionInfoT;
685 using DomTreeT =
typename Tr::DomTreeT;
686 using DomTreeNodeT =
typename Tr::DomTreeNodeT;
687 using PostDomTreeT =
typename Tr::PostDomTreeT;
688 using DomFrontierT =
typename Tr::DomFrontierT;
691 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
692 using PredIterTy =
typename InvBlockTraits::ChildIteratorType;
701 TopLevelRegion(
std::move(
Arg.TopLevelRegion)),
702 BBtoRegion(
std::move(
Arg.BBtoRegion)) {
707 DT = std::move(RHS.DT);
708 PDT = std::move(RHS.PDT);
709 DF = std::move(RHS.DF);
710 TopLevelRegion = std::move(RHS.TopLevelRegion);
711 BBtoRegion = std::move(RHS.BBtoRegion);
723 RegionT *TopLevelRegion =
nullptr;
733 template<
typename TheRegionT>
738 for (
auto &SubR : *R)
739 updateRegionTree(RI, SubR.get());
751 TopLevelRegion =
nullptr;
758 void verifyBBMap(
const RegionT *SR)
const;
763 bool isCommonDomFrontier(BlockT *BB, BlockT *
entry, BlockT *exit)
const;
767 bool isRegion(BlockT *entry, BlockT *exit)
const;
771 void insertShortCut(BlockT *entry, BlockT *exit,
BBtoBBMap *ShortCut)
const;
775 DomTreeNodeT *getNextPostDom(DomTreeNodeT *
N,
BBtoBBMap *ShortCut)
const;
778 bool isTrivialRegion(BlockT *entry, BlockT *exit)
const;
781 RegionT *createRegion(BlockT *entry, BlockT *exit);
784 void findRegionsWithEntry(BlockT *entry,
BBtoBBMap *ShortCut);
787 void scanForRegions(FuncT &
F,
BBtoBBMap *ShortCut);
790 RegionT *getTopMostParent(RegionT *region);
793 void buildRegionsTree(DomTreeNodeT *N, RegionT *region);
796 virtual void updateStatistics(RegionT *
R) = 0;
799 void calculate(FuncT &F);
809 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 813 void releaseMemory();
820 RegionT *getRegionFor(BlockT *BB)
const;
826 void setRegionFor(BlockT *BB, RegionT *R);
833 RegionT *operator[](BlockT *BB)
const;
839 BlockT *getMaxRegionExit(BlockT *BB)
const;
846 RegionT *getCommonRegion(RegionT *
A, RegionT *
B)
const;
854 return getCommonRegion(getRegionFor(A), getRegionFor(B));
876 TopLevelRegion->clearNodeCache();
879 void verifyAnalysis()
const;
890 return this ==
reinterpret_cast<const RegionNode *
>(&
RN);
897 Region *Parent =
nullptr);
901 return &RN ==
reinterpret_cast<const RegionNode *
>(
this);
912 updateRegionTree(*
this, TopLevelRegion);
916 Base::operator=(std::move(static_cast<Base &>(RHS)));
917 updateRegionTree(*
this, TopLevelRegion);
928 void updateStatistics(
Region *R)
final;
963 void releaseMemory()
override;
964 void verifyAnalysis()
const override;
1002 assert(!isSubRegion() &&
"This is not a BasicBlock RegionNode!");
1010 assert(isSubRegion() &&
"This is not a subregion RegionNode!");
1012 return reinterpret_cast<Region *
>(Unconst);
1018 using BlockT =
typename Tr::BlockT;
1019 using RegionT =
typename Tr::RegionT;
1022 return OS << Node.template getNodeAs<RegionT>()->getNameStr();
1024 return OS << Node.template getNodeAs<BlockT>()->
getName();
1033 #endif // LLVM_ANALYSIS_REGIONINFO_H
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
bool contains(const InstT *Inst) const
Check if the region contains an Instruction.
This class represents lattice values for constants.
PointerTy getPointer() const
block_iterator block_begin()
A Module instance is used to store all the information related to an LLVM module. ...
static RegionT::PrintStyle printStyle
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
block_iterator_wrapper< true > const_block_iterator
RegionNodeBase(RegionT *Parent, BlockT *Entry, bool isSubRegion=false)
Create a RegionNode.
RegionInfo & operator=(RegionInfo &&RHS)
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...
RegionT * getCommonRegion(BlockT *A, BlockT *B) const
Find the smallest region that contains two basic blocks.
typename super::value_type value_type
BlockT * getExit() const
Get the exit BasicBlock of the Region.
bool isSubRegion() const
Is this RegionNode a subregion?
Analysis that detects all canonical Regions.
const_block_iterator block_end() const
return AArch64::GPR64RegClass contains(Reg)
static void verifyRegion(const VPRegionBlock *Region)
Verify the CFG invariants of VPRegionBlock Region and its nested VPBlockBases.
bool contains(const RegionT *SubRegion) const
Check if the region contains another region.
RegionNodeT * getNode() const
Get the RegionNode representing the current Region.
A RegionNode represents a subregion or a BasicBlock that is part of a Region.
static StringRef getName(Value *V)
RegionInfo & getRegionInfo()
APInt operator*(APInt a, uint64_t RHS)
PrintStyle
PrintStyle - Print region in difference ways.
static bool isSimple(Instruction *I)
RegionT * getTopLevelRegion() const
RegionT * getParent() const
Get the parent Region of this RegionNode.
block_range blocks()
Returns a range view of the basic blocks in the region.
bool operator==(const RegionNode &RN) const
BlockT * getEntry() const
Get the entry BasicBlock of this RegionNode.
A CRTP mix-in to automatically provide informational APIs needed for passes.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
static bool runOnFunction(Function &F, bool PostInlining)
Verifier pass for the RegionInfo.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
A set of analyses that are preserved following a run of a transformation pass.
LLVM Basic Block Representation.
df_iterator< T > df_end(const T &G)
block_iterator_wrapper(value_type Entry, value_type Exit)
A CRTP mix-in that provides informational APIs needed for analysis passes.
typename RegionTraits< Function > ::BlockT BlockT
Represent the analysis usage information of a pass.
void updateRegionTree(RegionInfoT &RI, TheRegionT *R)
Update refences to a RegionInfoT held by the RegionT managed here.
FunctionPass class - This class is used to implement most global optimizations.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool operator==(const Region &RN) const
typename RegionSet::iterator iterator
bool isTopLevelRegion() const
Check if a Region is the TopLevel region.
typename RegionSet::const_iterator const_iterator
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
RegionInfo(RegionInfo &&Arg)
const_block_iterator block_begin() const
BlockT * getEntry() const
Get the entry BasicBlock of the Region.
block_iterator block_end()
RegionInfoT * getRegionInfo() const
Return the RegionInfo object, that belongs to this Region.
A single entry single exit Region.
Analysis pass that exposes the RegionInfo for a function.
iterator_range< const_element_iterator > elements() const
df_iterator< T > df_begin(const T &G)
A range adaptor for a pair of iterators.
const_block_range blocks() const
Returns a range view of the basic blocks in the region.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
amdgpu Simplify well known AMD library false Value Value * Arg
const_iterator end() const
Represents a single loop in the control flow graph.
const_iterator begin() const
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
BlockT * operator*() const
const RegionInfo & getRegionInfo() const
RegionNode(Region *Parent, BasicBlock *Entry, bool isSubRegion=false)
typename FuncT_::UnknownRegionTypeError BrokenT
block_iterator_wrapper< false > block_iterator
Marker class to iterate over the elements of a Region in flat mode.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
API to communicate dependencies between analyses during invalidation.
RegionT * getParent() const
Get the parent of the Region.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
block_iterator_wrapper(super I)
DomTreeNodeBase< BasicBlock > DomTreeNode
void clearNodeCache()
Clear the Node Cache for all Regions.
static bool VerifyRegionInfo
This class implements an extremely fast bulk output stream that can only output to a stream...
print Instructions which execute on loop entry
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
iterator_range< element_iterator > elements()
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)