36#ifndef LLVM_ANALYSIS_REGIONINFO_H 
   37#define LLVM_ANALYSIS_REGIONINFO_H 
   72template <
class FuncT_>
 
   79  using BrokenT = 
typename FuncT_::UnknownRegionTypeError;
 
 
  109template <
class GraphType>
 
  255  using FuncT = 
typename Tr::FuncT;
 
  256  using BlockT = 
typename Tr::BlockT;
 
  257  using RegionInfoT = 
typename Tr::RegionInfoT;
 
  258  using RegionT = 
typename Tr::RegionT;
 
  259  using RegionNodeT = 
typename Tr::RegionNodeT;
 
  260  using DomTreeT = 
typename Tr::DomTreeT;
 
  261  using LoopT = 
typename Tr::LoopT;
 
  262  using LoopInfoT = 
typename Tr::LoopInfoT;
 
  263  using InstT = 
typename Tr::InstT;
 
  267  using SuccIterTy = 
typename BlockTraits::ChildIteratorType;
 
  268  using PredIterTy = 
typename InvBlockTraits::ChildIteratorType;
 
  278  using RegionSet = std::vector<std::unique_ptr<RegionT>>;
 
  283  using BBNodeMapT = std::map<BlockT *, std::unique_ptr<RegionNodeT>>;
 
  286  mutable BBNodeMapT BBNodeMap;
 
  290  void verifyBBInRegion(BlockT *BB) 
const;
 
  295  void verifyWalk(BlockT *BB, std::set<BlockT *> *visitedBB) 
const;
 
  298  void verifyRegionNest() 
const;
 
  309  RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT,
 
  310             RegionT *Parent = 
nullptr);
 
  369    return const_cast<RegionNodeT *
>(
 
  370        reinterpret_cast<const RegionNodeT *
>(
this));
 
 
  437#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 
  457    return contains(SubRegion->getEntry()) &&
 
  459            SubRegion->getExit() == 
getExit());
 
 
  476  bool contains(
const LoopT *L) 
const;
 
  571  template <
bool IsConst>
 
  573      : 
public df_iterator<
 
  574            std::conditional_t<IsConst, const BlockT, BlockT> *> {
 
  576        df_iterator<std::conditional_t<IsConst, const BlockT, BlockT> *>;
 
 
 
  663inline raw_ostream &
operator<<(raw_ostream &OS, 
const RegionNodeBase<Tr> &
Node);
 
  672class RegionInfoBase {
 
  676  using BlockT = 
typename Tr::BlockT;
 
  677  using FuncT = 
typename Tr::FuncT;
 
  678  using RegionT = 
typename Tr::RegionT;
 
  679  using RegionInfoT = 
typename Tr::RegionInfoT;
 
  680  using DomTreeT = 
typename Tr::DomTreeT;
 
  681  using DomTreeNodeT = 
typename Tr::DomTreeNodeT;
 
  682  using PostDomTreeT = 
typename Tr::PostDomTreeT;
 
  683  using DomFrontierT = 
typename Tr::DomFrontierT;
 
  686  using SuccIterTy = 
typename BlockTraits::ChildIteratorType;
 
  687  using PredIterTy = 
typename InvBlockTraits::ChildIteratorType;
 
  694  RegionInfoBase(RegionInfoBase &&Arg)
 
  696      TopLevelRegion(
std::
move(Arg.TopLevelRegion)),
 
  697      BBtoRegion(
std::
move(Arg.BBtoRegion)) {
 
  702    DT = std::move(
RHS.DT);
 
  703    PDT = std::move(
RHS.PDT);
 
  704    DF = std::move(
RHS.DF);
 
  705    TopLevelRegion = std::move(
RHS.TopLevelRegion);
 
  706    BBtoRegion = std::move(
RHS.BBtoRegion);
 
  711  virtual ~RegionInfoBase();
 
  718  RegionT *TopLevelRegion = 
nullptr;
 
  721  BBtoRegionMap BBtoRegion;
 
  728  template<
typename TheRegionT>
 
  733    for (
auto &SubR : *R)
 
 
  746    TopLevelRegion = 
nullptr;
 
  753  void verifyBBMap(
const RegionT *SR) 
const;
 
  758  bool isCommonDomFrontier(BlockT *BB, BlockT *entry, BlockT *exit) 
const;
 
  762  bool isRegion(BlockT *entry, BlockT *exit) 
const;
 
  766  void insertShortCut(BlockT *entry, BlockT *exit, BBtoBBMap *ShortCut) 
const;
 
  770  DomTreeNodeT *getNextPostDom(DomTreeNodeT *
N, BBtoBBMap *ShortCut) 
const;
 
  773  bool isTrivialRegion(BlockT *entry, BlockT *exit) 
const;
 
  776  RegionT *createRegion(BlockT *entry, BlockT *exit);
 
  779  void findRegionsWithEntry(BlockT *entry, BBtoBBMap *ShortCut);
 
  782  void scanForRegions(FuncT &
F, BBtoBBMap *ShortCut);
 
  785  RegionT *getTopMostParent(RegionT *
region);
 
  788  void buildRegionsTree(DomTreeNodeT *
N, RegionT *
region);
 
  791  virtual void updateStatistics(RegionT *R) = 0;
 
  794  void calculate(FuncT &
F);
 
  798  RegionInfoBase &
operator=(
const RegionInfoBase &) = 
delete;
 
  804#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 
  871      TopLevelRegion->clearNodeCache();
 
 
 
  883    return this == 
reinterpret_cast<const RegionNode *
>(&RN);
 
 
 
  890         Region *Parent = 
nullptr);
 
  894    return &RN == 
reinterpret_cast<const RegionNode *
>(
this);
 
 
 
  898class RegionInfo : 
public RegionInfoBase<RegionTraits<Function>> {
 
  900  using Base = RegionInfoBase<RegionTraits<Function>>;
 
  909    Base::operator=(std::move(
static_cast<Base &
>(
RHS)));
 
 
  918                  FunctionAnalysisManager::Invalidator &);
 
 
 1008  return reinterpret_cast<Region *
>(Unconst);
 
 
 1014  using BlockT = 
typename Tr::BlockT;
 
 1015  using RegionT = 
typename Tr::RegionT;
 
 1017  if (
Node.isSubRegion())
 
 1018    return OS << 
Node.template getNodeAs<RegionT>()->getNameStr();
 
 1020    return OS << 
Node.template getNodeAs<BlockT>()->getName();
 
 
 1023extern template class RegionBase<RegionTraits<Function>>;
 
 1024extern template class RegionNodeBase<RegionTraits<Function>>;
 
 1025extern template class RegionInfoBase<RegionTraits<Function>>;
 
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
 
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
 
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
 
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...
 
This header defines various interfaces for pass management in LLVM.
 
This file defines the PointerIntPair class.
 
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.
 
LLVM_ABI 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< IsConst > Self
 
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()
 
bool isSimple() const
Is this a simple region?
 
bool isTopLevelRegion() const
Check if a Region is the TopLevel region.
 
RegionBase(BlockT *Entry, BlockT *Exit, RegionInfoT *RI, DomTreeT *DT, RegionT *Parent=nullptr)
Create a new 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
 
df_iterator< const RegionNodeT *, df_iterator_default_set< const RegionNodeT * >, false, GraphTraits< const RegionNodeT * > > const_element_iterator
 
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.
 
df_iterator< RegionNodeT *, df_iterator_default_set< RegionNodeT * >, false, GraphTraits< RegionNodeT * > > element_iterator
 
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
 
RegionT * getCommonRegion(SmallVectorImpl< BlockT * > &BBs) const
Find the smallest region that contains a set of basic blocks.
 
void print(raw_ostream &OS) const
 
RegionT * getTopLevelRegion() const
 
friend class MachineRegionInfo
 
RegionT * getRegionFor(BlockT *BB) const
Get the smallest region that contains a BasicBlock.
 
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
 
static RegionT::PrintStyle printStyle
 
RegionT * getCommonRegion(RegionT *A, RegionT *B) const
Find the smallest region that contains two regions.
 
RegionT * getCommonRegion(SmallVectorImpl< RegionT * > &Regions) const
Find the smallest region that contains a set of 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...
 
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
 
RegionInfoPrinterPass(raw_ostream &OS)
 
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.
 
RegionInfoBase< RegionTraits< Function > > Base
 
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.
 
BasicBlock * getNodeAs() const
 
RegionNode(Region *Parent, BasicBlock *Entry, bool isSubRegion=false)
 
bool operator==(const Region &RN) const
 
bool operator==(const RegionNode &RN) const
 
Region(BasicBlock *Entry, BasicBlock *Exit, RegionInfo *RI, DominatorTree *DT, Region *Parent=nullptr)
 
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
 
reference operator*() const
 
typename GraphTraits< std::conditional_t< IsConst, const BlockT, BlockT > * >::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.
 
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.
 
df_iterator< T > df_end(const T &G)
 
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
 
Implement std::hash so that hash_code can be used in STL containers.
 
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)
 
PostDominatorTree PostDomTreeT
 
DominanceFrontier DomFrontierT
 
static unsigned getNumSuccessors(BasicBlock *BB)
 
typename FuncT_::UnknownRegionTypeError BrokenT