20 #include "llvm/Config/llvm-config.h" 35 cl::desc(
"Verify dominator info (time consuming)"));
37 #ifdef EXPENSIVE_CHECKS 40 static constexpr
bool ExpensiveChecksEnabled =
false;
45 unsigned NumEdgesToEnd = 0;
49 if (NumEdgesToEnd >= 2)
52 assert(NumEdgesToEnd == 1);
72 template void llvm::DomTreeBuilder::Calculate<DomTreeBuilder::BBDomTree>(
74 template void llvm::DomTreeBuilder::Calculate<DomTreeBuilder::BBPostDomTree>(
77 template void llvm::DomTreeBuilder::InsertEdge<DomTreeBuilder::BBDomTree>(
79 template void llvm::DomTreeBuilder::InsertEdge<DomTreeBuilder::BBPostDomTree>(
82 template void llvm::DomTreeBuilder::DeleteEdge<DomTreeBuilder::BBDomTree>(
84 template void llvm::DomTreeBuilder::DeleteEdge<DomTreeBuilder::BBPostDomTree>(
87 template void llvm::DomTreeBuilder::ApplyUpdates<DomTreeBuilder::BBDomTree>(
89 template void llvm::DomTreeBuilder::ApplyUpdates<DomTreeBuilder::BBPostDomTree>(
92 template bool llvm::DomTreeBuilder::Verify<DomTreeBuilder::BBDomTree>(
95 template bool llvm::DomTreeBuilder::Verify<DomTreeBuilder::BBPostDomTree>(
117 if (!isReachableFromEntry(UseBB))
121 if (!isReachableFromEntry(DefBB))
132 if (isa<InvokeInst>(Def) || isa<PHINode>(User))
133 return dominates(Def, UseBB);
136 return dominates(DefBB, UseBB);
140 for (; &*I != Def && &*I != User; ++
I)
153 if (!isReachableFromEntry(UseBB))
157 if (!isReachableFromEntry(DefBB))
165 if (
const auto *II = dyn_cast<InvokeInst>(Def)) {
168 return dominates(E, UseBB);
171 return dominates(DefBB, UseBB);
180 if (!dominates(End, UseBB))
208 int IsDuplicateEdge = 0;
215 if (IsDuplicateEdge++)
220 if (!dominates(End, BB))
230 if (PN && PN->getParent() == BBE.
getEnd() &&
231 PN->getIncomingBlock(U) == BBE.
getStart())
238 UseBB = PN->getIncomingBlock(U);
241 return dominates(BBE, UseBB);
252 if (
PHINode *PN = dyn_cast<PHINode>(UserInst))
253 UseBB = PN->getIncomingBlock(U);
258 if (!isReachableFromEntry(UseBB))
262 if (!isReachableFromEntry(DefBB))
270 if (
const InvokeInst *II = dyn_cast<InvokeInst>(Def)) {
273 return dominates(E, U);
279 return dominates(DefBB, UseBB);
284 if (isa<PHINode>(UserInst))
289 for (; &*I != Def && &*I != UserInst; ++
I)
292 return &*I != UserInst;
303 if (
PHINode *PN = dyn_cast<PHINode>(I))
304 return isReachableFromEntry(PN->getIncomingBlock(U));
307 return isReachableFromEntry(I->
getParent());
332 OS <<
"DominatorTree for function: " << F.
getName() <<
"\n";
357 "Dominator Tree Construction",
true,
true)
367 else if (ExpensiveChecksEnabled)
388 for (
auto U : Updates)
393 applyUpdate(U.getKind(), U.getFrom(), U.getTo());
415 assert(DelBB &&
"Invalid push_back of nullptr DelBB.");
418 while (!DelBB->
empty()) {
428 DeletedBBs.insert(DelBB);
433 if (DeletedBBs.empty())
435 return DeletedBBs.count(DelBB) != 0;
446 if (!PendUpdates.empty()) {
461 if (flushDelBB() || !PendUpdates.empty()) {
468 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 471 OS <<
"PendUpdates:\n";
473 for (
auto U : PendUpdates) {
474 OS <<
" " << I <<
" : ";
485 OS << S <<
"(" << From <<
"), ";
494 OS << S <<
"(" << To <<
")\n";
499 OS <<
"DeletedBBs:\n";
501 for (
auto BB : DeletedBBs) {
502 OS <<
" " << I <<
" : ";
505 OS << BB->getName() <<
"(";
539 for (
auto I = PendUpdates.begin(),
E = PendUpdates.end();
I !=
E; ++
I) {
545 PendUpdates.erase(
I);
549 PendUpdates.push_back(Update);
557 bool DeferredDominance::flushDelBB() {
558 if (DeletedBBs.empty())
560 for (
auto *BB : DeletedBBs)
void push_back(const T &Elt)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
static constexpr bool ExpensiveChecksEnabled
Analysis pass which computes a DominatorTree.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
const BasicBlock * getEnd() const
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
void insertEdge(BasicBlock *From, BasicBlock *To)
Helper method for a single edge insertion.
iterator begin()
Instruction iterator methods.
bool isSingleEdge() const
Check if this is the only edge between Start and End.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
static constexpr UpdateKind Delete
A Use represents the edge between a Value definition and its users.
bool pendingDeletedBB(BasicBlock *DelBB)
Returns true if DelBB is awaiting deletion at a flush() event.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
LLVM_DUMP_METHOD void dump() const
Debug method to help view the state of pending updates.
Type * getType() const
All values are typed, get the type of this value.
void deleteBB(BasicBlock *DelBB)
Delays the deletion of a basic block until a flush() event.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
DominatorTreePrinterPass(raw_ostream &OS)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
DominatorTree & flush()
Flushes all pending updates and block deletions.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Queues multiple updates and discards duplicates.
Interval::succ_iterator succ_end(Interval *I)
void applyUpdates(ArrayRef< UpdateType > Updates)
Inform the dominator tree about a sequence of CFG edge insertions and deletions and perform a batch u...
static bool runOnFunction(Function &F, bool PostInlining)
void deleteEdge(BasicBlock *From, BasicBlock *To)
Helper method for a single edge deletion.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Subclasses of this class are all able to terminate a basic block.
A set of analyses that are preserved following a run of a transformation pass.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
static constexpr UpdateKind Insert
LLVM Basic Block Representation.
DominatorTree run(Function &F, FunctionAnalysisManager &)
Run the analysis pass over a function and produce a dominator tree.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
const Instruction & back() const
Interval::pred_iterator pred_end(Interval *I)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool VerifyDomInfo
Enables verification of dominator trees.
bool pred_empty(const BasicBlock *BB)
INITIALIZE_PASS(DominatorTreeWrapperPass, "domtree", "Dominator Tree Construction", true, true) bool DominatorTreeWrapperPass
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
ArrayRef< Update< BasicBlock * > > BBUpdates
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
const InstListType & getInstList() const
Return the underlying instruction list container.
Iterator for intrusive lists based on ilist_node.
Generic dominator tree construction - This file provides routines to construct immediate dominator in...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static cl::opt< bool, true > VerifyDomInfoX("verify-dom-info", cl::location(VerifyDomInfo), cl::Hidden, cl::desc("Verify dominator info (time consuming)"))
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
Handle invalidation explicitly.
Represents analyses that only rely on functions' control flow.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
StringRef getName() const
Return a constant reference to the value's name.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool pending()
Returns true if pending DT updates are queued for a flush() event.
API to communicate dependencies between analyses during invalidation.
void recalculate(Function &F)
Drops all internal state and forces a (slow) recalculation of the DominatorTree based on the current ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
const BasicBlock * getStart() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
This class implements an extremely fast bulk output stream that can only output to a stream...
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
This header defines various interfaces for pass management in LLVM.
A special type used by analysis passes to provide an address that identifies that particular analysis...
LocationClass< Ty > location(Ty &L)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
const BasicBlock * getParent() const