24 bool DomTreeUpdater::isUpdateValid(
26 const auto *From = Update.getFrom();
27 const auto *To = Update.getTo();
28 const auto Kind = Update.getKind();
51 bool DomTreeUpdater::isSelfDominance(
54 return Update.getFrom() == Update.getTo();
60 "Call applyLazyUpdate() when both DT and PDT are nullptrs.");
62 "Call applyLazyUpdate() with Eager strategy error");
71 PendUpdates.
begin() +
std::max(PendDTUpdateIndex, PendPDTUpdateIndex);
72 const auto E = PendUpdates.
end();
74 assert(
I <=
E &&
"Iterator out of range.");
92 void DomTreeUpdater::applyDomTreeUpdates() {
99 const auto I = PendUpdates.
begin() + PendDTUpdateIndex;
100 const auto E = PendUpdates.
end();
101 assert(
I <
E &&
"Iterator range invalid; there should be DomTree updates.");
103 PendDTUpdateIndex = PendUpdates.
size();
108 applyDomTreeUpdates();
109 applyPostDomTreeUpdates();
110 dropOutOfDateUpdates();
113 void DomTreeUpdater::applyPostDomTreeUpdates() {
120 const auto I = PendUpdates.
begin() + PendPDTUpdateIndex;
121 const auto E = PendUpdates.
end();
123 "Iterator range invalid; there should be PostDomTree updates.");
125 PendPDTUpdateIndex = PendUpdates.
size();
129 void DomTreeUpdater::tryFlushDeletedBB() {
131 forceFlushDeletedBB();
134 bool DomTreeUpdater::forceFlushDeletedBB() {
135 if (DeletedBBs.empty())
138 for (
auto *BB : DeletedBBs) {
143 assert(BB->getInstList().size() == 1 &&
144 isa<UnreachableInst>(BB->getTerminator()) &&
145 "DelBB has been modified while awaiting deletion.");
146 BB->removeFromParent();
168 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
true;
179 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
false;
180 PendDTUpdateIndex = PendPDTUpdateIndex = PendUpdates.
size();
181 dropOutOfDateUpdates();
186 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
false;
197 return PendUpdates.
size() != PendDTUpdateIndex;
203 return PendUpdates.
size() != PendPDTUpdateIndex;
209 return DeletedBBs.count(DelBB) != 0;
218 validateDeleteBB(DelBB);
220 DeletedBBs.insert(DelBB);
225 eraseDelBBNode(DelBB);
231 validateDeleteBB(DelBB);
233 Callbacks.push_back(CallBackOnDeletion(DelBB, Callback));
234 DeletedBBs.insert(DelBB);
239 eraseDelBBNode(DelBB);
244 void DomTreeUpdater::eraseDelBBNode(
BasicBlock *DelBB) {
245 if (DT && !IsRecalculatingDomTree)
249 if (PDT && !IsRecalculatingPostDomTree)
254 void DomTreeUpdater::validateDeleteBB(
BasicBlock *DelBB) {
255 assert(DelBB &&
"Invalid push_back of nullptr DelBB.");
258 while (!DelBB->
empty()) {
271 bool ForceRemoveDuplicates) {
277 for (
const auto U : Updates)
283 isUpdateValid(U) && !isSelfDominance(U)) {
286 applyLazyUpdate(U.getKind(), U.getFrom(), U.getTo());
305 assert(DT &&
"Invalid acquisition of a null DomTree");
306 applyDomTreeUpdates();
307 dropOutOfDateUpdates();
312 assert(PDT &&
"Invalid acquisition of a null PostDomTree");
313 applyPostDomTreeUpdates();
314 dropOutOfDateUpdates();
322 "Inserted edge does not appear in the CFG");
368 "Deleted edge still exists in the CFG!");
410 void DomTreeUpdater::dropOutOfDateUpdates() {
418 PendDTUpdateIndex = PendUpdates.
size();
420 PendPDTUpdateIndex = PendUpdates.
size();
422 const size_t dropIndex = std::min(PendDTUpdateIndex, PendPDTUpdateIndex);
423 const auto B = PendUpdates.
begin();
424 const auto E = PendUpdates.
begin() + dropIndex;
425 assert(B <=
E &&
"Iterator out of range.");
428 PendDTUpdateIndex -= dropIndex;
429 PendPDTUpdateIndex -= dropIndex;
432 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 436 OS <<
"Available Trees: ";
441 OS <<
"PostDomTree ";
446 OS <<
"UpdateStrategy: ";
460 for (
auto It = begin, ItEnd =
end; It != ItEnd; ++It) {
462 OS <<
" " << Index <<
" : ";
473 OS << S <<
"(" << From <<
"), ";
482 OS << S <<
"(" << To <<
")\n";
490 const auto I = PendUpdates.
begin() + PendDTUpdateIndex;
492 "Iterator out of range.");
493 OS <<
"Applied but not cleared DomTreeUpdates:\n";
494 printUpdates(PendUpdates.
begin(),
I);
495 OS <<
"Pending DomTreeUpdates:\n";
496 printUpdates(I, PendUpdates.
end());
500 const auto I = PendUpdates.
begin() + PendPDTUpdateIndex;
502 "Iterator out of range.");
503 OS <<
"Applied but not cleared PostDomTreeUpdates:\n";
504 printUpdates(PendUpdates.
begin(),
I);
505 OS <<
"Pending PostDomTreeUpdates:\n";
506 printUpdates(I, PendUpdates.
end());
509 OS <<
"Pending DeletedBBs:\n";
511 for (
auto BB : DeletedBBs) {
512 OS <<
" " << Index <<
" : ";
515 OS << BB->getName() <<
"(";
521 OS <<
"Pending Callbacks:\n";
523 for (
auto BB : Callbacks) {
524 OS <<
" " << Index <<
" : ";
527 OS << BB->getName() <<
"(";
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Compute iterated dominance frontiers using a linear time algorithm.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
DominatorTree & getDomTree()
Flush DomTree updates and return DomTree.
void flush()
Apply all pending updates to available trees and flush all BasicBlocks awaiting deletion.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
LLVMContext & getContext() const
Get the context in which this basic block lives.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
static constexpr UpdateKind Delete
void deleteEdge(NodeT *From, NodeT *To)
Inform the dominator tree about a CFG edge deletion and update the tree.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
PostDominatorTree & getPostDomTree()
Flush PostDomTree updates and return PostDomTree.
Type * getType() const
All values are typed, get the type of this value.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void insertEdge(NodeT *From, NodeT *To)
Inform the dominator tree about a CFG edge insertion and update the tree.
void applyUpdates(ArrayRef< UpdateType > Updates)
Inform the dominator tree about a sequence of CFG edge insertions and deletions and perform a batch u...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static constexpr UpdateKind Insert
LLVM Basic Block Representation.
void deleteBB(BasicBlock *DelBB)
Delete DelBB.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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
bool recalculate(Function &F)
Recalculate all available trees.
bool pred_empty(const BasicBlock *BB)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
iterator erase(const_iterator CI)
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
void deleteEdge(BasicBlock *From, BasicBlock *To)
Notify all available trees on an edge deletion.
const InstListType & getInstList() const
Return the underlying instruction list container.
void insertEdge(BasicBlock *From, BasicBlock *To)
Notify all available trees on an edge insertion.
void removeFromParent()
Unlink 'this' from the containing function, but do not delete it.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool hasPendingUpdates() const
Returns true if either of DT or PDT is valid and the tree has at least one update pending...
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates, bool ForceRemoveDuplicates=false)
Apply updates on all available trees.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
DomTreeBuilder::UpdateKind UpdateKind
void deleteEdgeRelaxed(BasicBlock *From, BasicBlock *To)
Notify all available trees on an edge deletion.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
bool hasPendingDomTreeUpdates() const
Returns true if there are DominatorTree updates queued.
StringRef getName() const
Return a constant reference to the value's name.
void insertEdgeRelaxed(BasicBlock *From, BasicBlock *To)
Notify all available trees on an edge insertion.
void callbackDeleteBB(BasicBlock *DelBB, std::function< void(BasicBlock *)> Callback)
Delete DelBB.
bool isBBPendingDeletion(BasicBlock *DelBB) const
Returns true if DelBB is awaiting deletion.
bool hasPendingPostDomTreeUpdates() const
Returns true if there are PostDominatorTree updates queued.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM_DUMP_METHOD void dump() const
Debug method to help view the internal state of this class.
DomTreeBuilder::Update< NodePtr > UpdateType
succ_range successors(BasicBlock *BB)
This class implements an extremely fast bulk output stream that can only output to a stream...
print Print MemDeps of function
This file defines a set of templates that efficiently compute a dominator tree over a generic graph...