25 bool DomTreeUpdater::isUpdateValid(
27 const auto *
From = Update.getFrom();
28 const auto *To = Update.getTo();
29 const auto Kind = Update.getKind();
52 bool DomTreeUpdater::isSelfDominance(
55 return Update.getFrom() == Update.getTo();
58 void DomTreeUpdater::applyDomTreeUpdates() {
65 const auto I = PendUpdates.
begin() + PendDTUpdateIndex;
66 const auto E = PendUpdates.
end();
67 assert(
I <
E &&
"Iterator range invalid; there should be DomTree updates.");
69 PendDTUpdateIndex = PendUpdates.
size();
74 applyDomTreeUpdates();
75 applyPostDomTreeUpdates();
76 dropOutOfDateUpdates();
79 void DomTreeUpdater::applyPostDomTreeUpdates() {
86 const auto I = PendUpdates.
begin() + PendPDTUpdateIndex;
87 const auto E = PendUpdates.
end();
89 "Iterator range invalid; there should be PostDomTree updates.");
91 PendPDTUpdateIndex = PendUpdates.
size();
95 void DomTreeUpdater::tryFlushDeletedBB() {
97 forceFlushDeletedBB();
100 bool DomTreeUpdater::forceFlushDeletedBB() {
101 if (DeletedBBs.empty())
104 for (
auto *BB : DeletedBBs) {
109 assert(BB->getInstList().size() == 1 &&
110 isa<UnreachableInst>(BB->getTerminator()) &&
111 "DelBB has been modified while awaiting deletion.");
112 BB->removeFromParent();
135 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
true;
139 forceFlushDeletedBB();
146 IsRecalculatingDomTree = IsRecalculatingPostDomTree =
false;
147 PendDTUpdateIndex = PendPDTUpdateIndex = PendUpdates.
size();
148 dropOutOfDateUpdates();
158 return PendUpdates.
size() != PendDTUpdateIndex;
164 return PendUpdates.
size() != PendPDTUpdateIndex;
170 return DeletedBBs.count(DelBB) != 0;
179 validateDeleteBB(DelBB);
181 DeletedBBs.insert(DelBB);
186 eraseDelBBNode(DelBB);
192 validateDeleteBB(DelBB);
194 Callbacks.push_back(CallBackOnDeletion(DelBB, Callback));
195 DeletedBBs.insert(DelBB);
200 eraseDelBBNode(DelBB);
205 void DomTreeUpdater::eraseDelBBNode(
BasicBlock *DelBB) {
206 if (DT && !IsRecalculatingDomTree)
210 if (PDT && !IsRecalculatingPostDomTree)
215 void DomTreeUpdater::validateDeleteBB(
BasicBlock *DelBB) {
216 assert(DelBB &&
"Invalid push_back of nullptr DelBB.");
219 while (!DelBB->
empty()) {
236 for (
const auto &U : Updates)
237 if (!isSelfDominance(U))
256 for (
const auto &U : Updates) {
257 auto Edge = std::make_pair(U.getFrom(), U.getTo());
280 if (!isSelfDominance(U) && Seen.
count(Edge) == 0) {
285 if (isUpdateValid(U)) {
304 assert(DT &&
"Invalid acquisition of a null DomTree");
305 applyDomTreeUpdates();
306 dropOutOfDateUpdates();
311 assert(PDT &&
"Invalid acquisition of a null PostDomTree");
312 applyPostDomTreeUpdates();
313 dropOutOfDateUpdates();
321 "Inserted edge does not appear in the CFG");
367 "Deleted edge still exists in the CFG!");
409 void DomTreeUpdater::dropOutOfDateUpdates() {
417 PendDTUpdateIndex = PendUpdates.
size();
419 PendPDTUpdateIndex = PendUpdates.
size();
421 const size_t dropIndex = std::min(PendDTUpdateIndex, PendPDTUpdateIndex);
422 const auto B = PendUpdates.
begin();
423 const auto E = PendUpdates.
begin() + dropIndex;
424 assert(B <=
E &&
"Iterator out of range.");
427 PendDTUpdateIndex -= dropIndex;
428 PendPDTUpdateIndex -= dropIndex;
431 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 435 OS <<
"Available Trees: ";
440 OS <<
"PostDomTree ";
445 OS <<
"UpdateStrategy: ";
459 for (
auto It = begin, ItEnd =
end; It != ItEnd; ++It) {
461 OS <<
" " << Index <<
" : ";
472 OS << S <<
"(" << From <<
"), ";
481 OS << S <<
"(" << To <<
")\n";
489 const auto I = PendUpdates.
begin() + PendDTUpdateIndex;
491 "Iterator out of range.");
492 OS <<
"Applied but not cleared DomTreeUpdates:\n";
493 printUpdates(PendUpdates.
begin(),
I);
494 OS <<
"Pending DomTreeUpdates:\n";
495 printUpdates(I, PendUpdates.
end());
499 const auto I = PendUpdates.
begin() + PendPDTUpdateIndex;
501 "Iterator out of range.");
502 OS <<
"Applied but not cleared PostDomTreeUpdates:\n";
503 printUpdates(PendUpdates.
begin(),
I);
504 OS <<
"Pending PostDomTreeUpdates:\n";
505 printUpdates(I, PendUpdates.
end());
508 OS <<
"Pending DeletedBBs:\n";
510 for (
auto BB : DeletedBBs) {
511 OS <<
" " << Index <<
" : ";
514 OS << BB->getName() <<
"(";
520 OS <<
"Pending Callbacks:\n";
522 for (
auto BB : Callbacks) {
523 OS <<
" " << Index <<
" : ";
526 OS << BB->getName() <<
"(";
const_iterator end(StringRef path)
Get end iterator over path.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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.
bool isLazy() const
Returns true if the current strategy is Lazy.
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.
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")
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
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
void applyUpdatesPermissive(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
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.
const InstListType & getInstList() const
Return the underlying instruction list container.
void removeFromParent()
Unlink 'this' from the containing function, but do not delete it.
BlockVerifier::State From
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
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...
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 recalculate(Function &F)
Notify DTU that the entry block was replaced.
bool hasPendingDomTreeUpdates() const
Returns true if there are DominatorTree updates queued.
StringRef getName() const
Return a constant reference to the value's name.
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...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.