26 "dom-tree-reachability-max-bbs-to-explore",
cl::Hidden,
27 cl::desc(
"Max number of BBs to explore for reachability analysis"),
36 SmallVectorImpl<std::pair<const BasicBlock*,const BasicBlock*> > &Result) {
49 std::pair<const BasicBlock *, const_succ_iterator> &Top = VisitStack.
back();
53 bool FoundNew =
false;
56 if (Visited.
insert(BB).second) {
61 if (InStack.
count(BB))
62 Result.push_back(std::make_pair(ParentBB, BB));
73 }
while (!VisitStack.
empty());
84 unsigned e = Term->getNumSuccessors();
86 for (
unsigned i = 0; ; ++i) {
87 assert(i != e &&
"Didn't find edge?");
88 if (Term->getSuccessor(i) == Succ)
97 bool AllowIdenticalEdges) {
98 assert(SuccNum < TI->getNumSuccessors() &&
"Illegal edge specification!");
103 bool AllowIdenticalEdges) {
108 "No edge between TI's block and Dest.");
113 assert(
I != E &&
"No preds, but we have an edge to the block?");
116 if (!AllowIdenticalEdges)
131 return L ? L->getOutermostLoop() :
nullptr;
134template <
class StopSetT>
136 const StopSetT &StopSet,
142 for (
auto *BB : StopSet) {
152 if (ExclusionSet && !ExclusionSet->
empty())
159 if (LI && ExclusionSet) {
160 for (
auto *BB : *ExclusionSet) {
168 for (
auto *StopSetBB : StopSet) {
178 if (!Visited.
insert(BB).second)
180 if (StopSet.contains(BB))
182 if (ExclusionSet && ExclusionSet->
count(BB))
191 const Loop *Outer =
nullptr;
198 if (LoopsWithHoles.
count(Outer))
214 Outer->getExitBlocks(Worklist);
218 }
while (!Worklist.
empty());
244 return isReachableImpl<SingleEntrySet<const BasicBlock *>>(
254 return isReachableImpl<SmallPtrSetImpl<const BasicBlock *>>(
255 Worklist, StopSet, ExclusionSet, DT, LI);
262 assert(
A->getParent() ==
B->getParent() &&
263 "This analysis is function-local!");
268 if (!ExclusionSet || ExclusionSet->
empty()) {
286 assert(
A->getParent()->getParent() ==
B->getParent()->getParent() &&
287 "This analysis is function-local!");
289 if (
A->getParent() ==
B->getParent()) {
303 if (
A ==
B ||
A->comesBefore(
B))
314 if (Worklist.
empty()) {
320 ExclusionSet, DT, LI);
324 A->getParent(),
B->getParent(), ExclusionSet, DT, LI);
328 if (
auto *CB = dyn_cast<CallBase>(&
I))
329 return CB->hasFnAttr(Attribute::NoReturn);
354 if (Visited.
insert(Succ).second)
356 }
while (!Worklist.
empty());
364 if (!Src.getParent()->isPresplitCoroutine())
366 if (
auto *SW = dyn_cast<SwitchInst>(Src.getTerminator()))
367 if (
auto *
Intr = dyn_cast<IntrinsicInst>(SW->getCondition()))
368 return Intr->getIntrinsicID() == Intrinsic::coro_suspend &&
369 SW->getDefaultDest() == &Dest;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static cl::opt< unsigned > DefaultMaxBBsToExplore("dom-tree-reachability-max-bbs-to-explore", cl::Hidden, cl::desc("Max number of BBs to explore for reachability analysis"), cl::init(32))
static bool isReachableImpl(SmallVectorImpl< BasicBlock * > &Worklist, const StopSetT &StopSet, const SmallPtrSetImpl< BasicBlock * > *ExclusionSet, const DominatorTree *DT, const LoopInfo *LI)
static const Loop * getOutermostLoop(const LoopInfo *LI, const BasicBlock *BB)
static bool instructionDoesNotReturn(const Instruction &I)
static bool basicBlockCanReturn(const BasicBlock &BB)
std::optional< std::vector< StOtherPiece > > Other
const_iterator end() const
const_iterator begin() const
bool contains(T Other) const
LLVM Basic Block Representation.
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
bool isTerminator() const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Represents a single loop in the control flow graph.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool erase(PtrType Ptr)
Remove pointer from the set.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
const ParentTy * getParent() const
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool succ_empty(const Instruction *I)
LLVM_ABI unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
auto pred_end(const MachineBasicBlock *BB)
LLVM_ABI bool isPotentiallyReachableFromMany(SmallVectorImpl< BasicBlock * > &Worklist, const BasicBlock *StopBB, const SmallPtrSetImpl< BasicBlock * > *ExclusionSet, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether there is at least one path from a block in 'Worklist' to 'StopBB' without passing t...
auto successors(const MachineBasicBlock *BB)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool isManyPotentiallyReachableFromMany(SmallVectorImpl< BasicBlock * > &Worklist, const SmallPtrSetImpl< const BasicBlock * > &StopSet, const SmallPtrSetImpl< BasicBlock * > *ExclusionSet, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether there is a potentially a path from at least one block in 'Worklist' to at least one...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
LLVM_ABI bool isCriticalEdge(const Instruction *TI, unsigned SuccNum, bool AllowIdenticalEdges=false)
Return true if the specified edge is a critical edge.
auto pred_begin(const MachineBasicBlock *BB)
LLVM_ABI bool isPresplitCoroSuspendExitEdge(const BasicBlock &Src, const BasicBlock &Dest)
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void FindFunctionBackedges(const Function &F, SmallVectorImpl< std::pair< const BasicBlock *, const BasicBlock * > > &Result)
Analyze the specified function to find all of the loop backedges in the function and return them.
LLVM_ABI bool canReturn(const Function &F)
Return true if there is at least a path through which F can return, false if there is no such path.
LLVM_ABI bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const SmallPtrSetImpl< BasicBlock * > *ExclusionSet=nullptr, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', without passing through any blocks in Ex...