36 #ifndef LLVM_ANALYSIS_REGIONINFO_H 37 #define LLVM_ANALYSIS_REGIONINFO_H 44 #include "llvm/Config/llvm-config.h" 56 #include <type_traits> 61 class DominanceFrontier;
65 class PostDominatorTree;
75 template <
class FuncT_>
82 using BrokenT =
typename FuncT_::UnknownRegionTypeError;
112 template <
class GraphType>
123 using RegionT =
typename Tr::RegionT;
152 bool isSubRegion =
false)
153 : entry(Entry, isSubRegion), parent(Parent) {}
183 template <
class T>
inline T *getNodeAs()
const;
258 using FuncT =
typename Tr::FuncT;
259 using BlockT =
typename Tr::BlockT;
260 using RegionInfoT =
typename Tr::RegionInfoT;
261 using RegionT =
typename Tr::RegionT;
262 using RegionNodeT =
typename Tr::RegionNodeT;
263 using DomTreeT =
typename Tr::DomTreeT;
264 using LoopT =
typename Tr::LoopT;
265 using LoopInfoT =
typename Tr::LoopInfoT;
266 using InstT =
typename Tr::InstT;
270 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
271 using PredIterTy =
typename InvBlockTraits::ChildIteratorType;
281 using RegionSet = std::vector<std::unique_ptr<RegionT>>;
286 using BBNodeMapT = std::map<BlockT *, std::unique_ptr<RegionNodeT>>;
289 mutable BBNodeMapT BBNodeMap;
293 void verifyBBInRegion(BlockT *BB)
const;
298 void verifyWalk(BlockT *BB, std::set<BlockT *> *visitedBB)
const;
301 void verifyRegionNest()
const;
313 RegionT *Parent =
nullptr);
331 void replaceEntry(BlockT *BB);
337 void replaceExit(BlockT *BB);
346 void replaceEntryRecursive(BlockT *NewEntry);
355 void replaceExitRecursive(BlockT *NewExit);
372 return const_cast<RegionNodeT *
>(
373 reinterpret_cast<const RegionNodeT *
>(
this));
394 RegionT *getExpandedRegion()
const;
401 BlockT *getEnteringBlock()
const;
408 BlockT *getExitingBlock()
const;
424 std::string getNameStr()
const;
440 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 449 bool contains(
const BlockT *BB)
const;
460 return contains(SubRegion->getEntry()) &&
462 SubRegion->getExit() == getExit());
479 bool contains(
const LoopT *L)
const;
489 LoopT *outermostLoopInRegion(LoopT *L)
const;
500 LoopT *outermostLoopInRegion(LoopInfoT *LI, BlockT *BB)
const;
506 RegionT *getSubRegionNode(BlockT *BB)
const;
514 RegionNodeT *getNode(BlockT *BB)
const;
520 RegionNodeT *getBBNode(BlockT *BB)
const;
527 void addSubRegion(RegionT *SubRegion,
bool moveChildren =
false);
534 RegionT *removeSubRegion(RegionT *SubRegion);
539 void transferChildrenTo(RegionT *To);
552 void clearNodeCache();
574 template <
bool IsConst>
577 typename std::conditional<IsConst, const BlockT, BlockT>::type *> {
580 typename std::conditional<IsConst, const BlockT, BlockT>::type *>;
592 super::Visited.insert(Exit);
654 return make_range(element_begin(), element_end());
660 return make_range(element_begin(), element_end());
667 inline raw_ostream &operator<<(raw_ostream &OS, const RegionNodeBase<Tr> &
Node);
680 using BlockT =
typename Tr::BlockT;
681 using FuncT =
typename Tr::FuncT;
682 using RegionT =
typename Tr::RegionT;
683 using RegionInfoT =
typename Tr::RegionInfoT;
684 using DomTreeT =
typename Tr::DomTreeT;
685 using DomTreeNodeT =
typename Tr::DomTreeNodeT;
686 using PostDomTreeT =
typename Tr::PostDomTreeT;
687 using DomFrontierT =
typename Tr::DomFrontierT;
690 using SuccIterTy =
typename BlockTraits::ChildIteratorType;
691 using PredIterTy =
typename InvBlockTraits::ChildIteratorType;
700 TopLevelRegion(
std::move(
Arg.TopLevelRegion)),
701 BBtoRegion(
std::move(
Arg.BBtoRegion)) {
706 DT = std::move(RHS.DT);
707 PDT = std::move(RHS.PDT);
708 DF = std::move(RHS.DF);
709 TopLevelRegion = std::move(RHS.TopLevelRegion);
710 BBtoRegion = std::move(RHS.BBtoRegion);
722 RegionT *TopLevelRegion =
nullptr;
732 template<
typename TheRegionT>
737 for (
auto &SubR : *R)
738 updateRegionTree(RI, SubR.get());
750 TopLevelRegion =
nullptr;
757 void verifyBBMap(
const RegionT *SR)
const;
762 bool isCommonDomFrontier(BlockT *BB, BlockT *
entry, BlockT *exit)
const;
766 bool isRegion(BlockT *entry, BlockT *exit)
const;
770 void insertShortCut(BlockT *entry, BlockT *exit,
BBtoBBMap *ShortCut)
const;
774 DomTreeNodeT *getNextPostDom(DomTreeNodeT *
N,
BBtoBBMap *ShortCut)
const;
777 bool isTrivialRegion(BlockT *entry, BlockT *exit)
const;
780 RegionT *createRegion(BlockT *entry, BlockT *exit);
783 void findRegionsWithEntry(BlockT *entry,
BBtoBBMap *ShortCut);
786 void scanForRegions(FuncT &
F,
BBtoBBMap *ShortCut);
789 RegionT *getTopMostParent(RegionT *region);
792 void buildRegionsTree(DomTreeNodeT *N, RegionT *region);
795 virtual void updateStatistics(RegionT *
R) = 0;
798 void calculate(FuncT &F);
808 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 812 void releaseMemory();
819 RegionT *getRegionFor(BlockT *BB)
const;
825 void setRegionFor(BlockT *BB, RegionT *R);
832 RegionT *operator[](BlockT *BB)
const;
838 BlockT *getMaxRegionExit(BlockT *BB)
const;
845 RegionT *getCommonRegion(RegionT *
A, RegionT *
B)
const;
853 return getCommonRegion(getRegionFor(A), getRegionFor(B));
875 TopLevelRegion->clearNodeCache();
878 void verifyAnalysis()
const;
889 return this ==
reinterpret_cast<const RegionNode *
>(&
RN);
896 Region *Parent =
nullptr);
900 return &RN ==
reinterpret_cast<const RegionNode *
>(
this);
911 updateRegionTree(*
this, TopLevelRegion);
915 Base::operator=(std::move(static_cast<Base &>(RHS)));
916 updateRegionTree(*
this, TopLevelRegion);
927 void updateStatistics(
Region *R)
final;
962 void releaseMemory()
override;
963 void verifyAnalysis()
const override;
1001 assert(!isSubRegion() &&
"This is not a BasicBlock RegionNode!");
1009 assert(isSubRegion() &&
"This is not a subregion RegionNode!");
1011 return reinterpret_cast<Region *
>(Unconst);
1017 using BlockT =
typename Tr::BlockT;
1018 using RegionT =
typename Tr::RegionT;
1021 return OS << Node.template getNodeAs<RegionT>()->getNameStr();
1023 return OS << Node.template getNodeAs<BlockT>()->
getName();
1032 #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.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
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.
static unsigned getDepth(const SmallVectorImpl< const MachineBasicBlock *> &Stack, const MachineBasicBlock *MBB)
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...
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)