Index: include/llvm/IR/DomTreeUpdater.h =================================================================== --- include/llvm/IR/DomTreeUpdater.h +++ include/llvm/IR/DomTreeUpdater.h @@ -73,26 +73,27 @@ bool hasPendingUpdates() const; /// Returns true if there are DominatorTree updates queued. - /// Returns false under Eager UpdateStrategy. + /// Returns false under Eager UpdateStrategy or DT is nullptr. bool hasPendingDomTreeUpdates() const; /// Returns true if there are PostDominatorTree updates queued. - /// Returns false under Eager UpdateStrategy. + /// Returns false under Eager UpdateStrategy or PDT is nullptr. bool hasPendingPostDomTreeUpdates() const; /// Apply updates on all available trees. Under Eager UpdateStrategy with /// ForceRemoveDuplicates enabled or under Lazy UpdateStrategy, it will - /// discard duplicated updates and self-dominance updates. The Eager - /// Strategy applies the updates immediately while the Lazy Strategy - /// queues the updates. It is required for the state of - /// the LLVM IR to be updated *before* applying the Updates because the - /// internal update routine will analyze the current state of the relationship - /// between a pair of (From, To) BasicBlocks to determine whether a single - /// update needs to be discarded. + /// discard duplicated updates and self-dominance updates. If both DT and PDT + /// are nullptrs, this function discards all updates. The Eager Strategy + /// applies the updates immediately while the Lazy Strategy queues the + /// updates. It is required for the state of the LLVM IR to be updated + /// *before* applying the Updates because the internal update routine will + /// analyze the current state of the relationship between a pair of (From, To) + /// BasicBlocks to determine whether a single update needs to be discarded. void applyUpdates(ArrayRef Updates, bool ForceRemoveDuplicates = false); - /// Notify all available trees on an edge insertion. Under either Strategy, + /// Notify all available trees on an edge insertion. If both DT and PDT are + /// nullptrs, this function discards the update. Under either Strategy, /// self-dominance update will be removed. The Eager Strategy applies /// the update immediately while the Lazy Strategy queues the update. /// It is recommended to only use this method when you have exactly one @@ -107,13 +108,15 @@ /// following sequence /// 1. Invalid - Inserting an edge that does not exist in the CFG. /// 2. Self-dominance update. + /// 3. Both DT and PDT are nullptrs. /// The Eager Strategy applies the update immediately while the Lazy Strategy /// queues the update. It is recommended to only use this method when you have /// exactly one insertion (and no deletions) and want to discard an invalid /// update. Returns true if the update is valid. bool insertEdgeRelaxed(BasicBlock *From, BasicBlock *To); - /// Notify all available trees on an edge deletion. Under either Strategy, + /// Notify all available trees on an edge deletion. If both DT and PDT are + /// nullptrs, this function discards the update. Under either Strategy, /// self-dominance update will be removed. The Eager Strategy applies /// the update immediately while the Lazy Strategy queues the update. /// It is recommended to only use this method when you have exactly one @@ -128,6 +131,7 @@ /// following sequence: /// 1. Invalid - Deleting an edge that still exists in the CFG. /// 2. Self-dominance update. + /// 3. Both DT and PDT are nullptrs. /// The Eager Strategy applies the update immediately while the Lazy Strategy /// queues the update. It is recommended to only use this method when you have /// exactly one deletion (and no insertions) and want to discard an invalid Index: lib/IR/DomTreeUpdater.cpp =================================================================== --- lib/IR/DomTreeUpdater.cpp +++ lib/IR/DomTreeUpdater.cpp @@ -56,6 +56,8 @@ bool DomTreeUpdater::applyLazyUpdate(DominatorTree::UpdateKind Kind, BasicBlock *From, BasicBlock *To) { + assert(DT || + PDT && "Call applyLazyUpdate() when both DT and PDT are nullptrs."); assert(Strategy == DomTreeUpdater::UpdateStrategy::Lazy && "Call applyLazyUpdate() with Eager strategy error"); // Analyze pending updates to determine if the update is unnecessary. @@ -260,6 +262,9 @@ void DomTreeUpdater::applyUpdates(ArrayRef Updates, bool ForceRemoveDuplicates) { + if (!DT && !PDT) + return; + if (Strategy == UpdateStrategy::Lazy || ForceRemoveDuplicates) { SmallVector Seen; for (const auto U : Updates) @@ -310,6 +315,9 @@ "Inserted edge does not appear in the CFG"); #endif + if (!DT && !PDT) + return; + // Won't affect DomTree and PostDomTree; discard update. if (From == To) return; @@ -332,6 +340,9 @@ if (From == To) return true; + if (!DT && !PDT) + return true; + if (Strategy == UpdateStrategy::Eager) { if (DT) DT->insertEdge(From, To); @@ -351,6 +362,9 @@ "Deleted edge still exists in the CFG!"); #endif + if (!DT && !PDT) + return; + // Won't affect DomTree and PostDomTree; discard update. if (From == To) return; @@ -373,6 +387,9 @@ if (From == To) return true; + if (!DT && !PDT) + return true; + if (Strategy == UpdateStrategy::Eager) { if (DT) DT->deleteEdge(From, To);