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();
169 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
true;
173 forceFlushDeletedBB();
180 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
false;
181 PendDTUpdateIndex = PendPDTUpdateIndex = PendUpdates.
size();
182 dropOutOfDateUpdates();
192 return PendUpdates.
size() != PendDTUpdateIndex;
198 return PendUpdates.
size() != PendPDTUpdateIndex;
204 return DeletedBBs.count(DelBB) != 0;
213 validateDeleteBB(DelBB);
215 DeletedBBs.insert(DelBB);
220 eraseDelBBNode(DelBB);
226 validateDeleteBB(DelBB);
228 Callbacks.push_back(CallBackOnDeletion(DelBB, Callback));
229 DeletedBBs.insert(DelBB);
234 eraseDelBBNode(DelBB);
239 void DomTreeUpdater::eraseDelBBNode(
BasicBlock *DelBB) {
240 if (DT && !IsRecalculatingDomTree)
244 if (PDT && !IsRecalculatingPostDomTree)
249 void DomTreeUpdater::validateDeleteBB(
BasicBlock *DelBB) {
250 assert(DelBB &&
"Invalid push_back of nullptr DelBB.");
253 while (!DelBB->
empty()) {
266 bool ForceRemoveDuplicates) {
272 for (
const auto U : Updates)
278 isUpdateValid(U) && !isSelfDominance(U)) {
281 applyLazyUpdate(U.getKind(), U.getFrom(), U.getTo());
300 assert(DT &&
"Invalid acquisition of a null DomTree");
301 applyDomTreeUpdates();
302 dropOutOfDateUpdates();
307 assert(PDT &&
"Invalid acquisition of a null PostDomTree");
308 applyPostDomTreeUpdates();
309 dropOutOfDateUpdates();
317 "Inserted edge does not appear in the CFG");
363 "Deleted edge still exists in the CFG!");
405 void DomTreeUpdater::dropOutOfDateUpdates() {
413 PendDTUpdateIndex = PendUpdates.
size();
415 PendPDTUpdateIndex = PendUpdates.
size();
417 const size_t dropIndex = std::min(PendDTUpdateIndex, PendPDTUpdateIndex);
418 const auto B = PendUpdates.
begin();
419 const auto E = PendUpdates.
begin() + dropIndex;
420 assert(B <=
E &&
"Iterator out of range.");
423 PendDTUpdateIndex -= dropIndex;
424 PendPDTUpdateIndex -= dropIndex;
427 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 431 OS <<
"Available Trees: ";
436 OS <<
"PostDomTree ";
441 OS <<
"UpdateStrategy: ";
455 for (
auto It = begin, ItEnd =
end; It != ItEnd; ++It) {
457 OS <<
" " << Index <<
" : ";
468 OS << S <<
"(" << From <<
"), ";
477 OS << S <<
"(" << To <<
")\n";
485 const auto I = PendUpdates.
begin() + PendDTUpdateIndex;
487 "Iterator out of range.");
488 OS <<
"Applied but not cleared DomTreeUpdates:\n";
489 printUpdates(PendUpdates.
begin(),
I);
490 OS <<
"Pending DomTreeUpdates:\n";
491 printUpdates(I, PendUpdates.
end());
495 const auto I = PendUpdates.
begin() + PendPDTUpdateIndex;
497 "Iterator out of range.");
498 OS <<
"Applied but not cleared PostDomTreeUpdates:\n";
499 printUpdates(PendUpdates.
begin(),
I);
500 OS <<
"Pending PostDomTreeUpdates:\n";
501 printUpdates(I, PendUpdates.
end());
504 OS <<
"Pending DeletedBBs:\n";
506 for (
auto BB : DeletedBBs) {
507 OS <<
" " << Index <<
" : ";
510 OS << BB->getName() <<
"(";
516 OS <<
"Pending Callbacks:\n";
518 for (
auto BB : Callbacks) {
519 OS <<
" " << Index <<
" : ";
522 OS << BB->getName() <<
"(";
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.
This class represents lattice values for constants.
void push_back(const T &Elt)
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.
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...
cfg::Update< NodePtr > UpdateType
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 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.
BlockVerifier::State From
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...
void deleteEdgeRelaxed(BasicBlock *From, BasicBlock *To)
Notify all available trees on an edge deletion.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void recalculate(Function &F)
Recalculate all available trees and flush all BasicBlocks awaiting deletion immediately.
bool hasPendingDomTreeUpdates() const
Returns true if there are DominatorTree updates queued.
StringRef getName() const
Return a constant reference to the value's name.
cfg::UpdateKind UpdateKind
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.
succ_range successors(Instruction *I)
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...