Index: include/llvm/IR/DomTreeUpdater.h =================================================================== --- include/llvm/IR/DomTreeUpdater.h +++ include/llvm/IR/DomTreeUpdater.h @@ -141,23 +141,27 @@ /// Delete DelBB. DelBB will be removed from its Parent and /// erased from available trees if it exists and finally get deleted. - /// Under Eager UpdateStrategy, DelBB will be processed immediately. - /// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and - /// all available trees are up-to-date. Assert if any instruction of DelBB is - /// modified while awaiting deletion. When both DT and PDT are nullptrs, DelBB - /// will be queued until flush() is called. - void deleteBB(BasicBlock *DelBB); + /// Under Eager UpdateStrategy, DelBB will be processed immediately; If + /// DisableNodeErasing is true, DelBB will not be erased from available trees. + /// It is used before a recalculation event. Under Lazy UpdateStrategy, DelBB + /// will be queued until a flush event and all available trees are up-to-date. + /// Assert if any instruction of DelBB is modified while awaiting deletion. + /// When both DT and PDT are nullptrs, DelBB will be queued until flush() is + /// called. + void deleteBB(BasicBlock *DelBB, bool DisableNodeErasing = false); /// Delete DelBB. DelBB will be removed from its Parent and /// erased from available trees if it exists. Then the callback will /// be called. Finally, DelBB will be deleted. - /// Under Eager UpdateStrategy, DelBB will be processed immediately. - /// Under Lazy UpdateStrategy, DelBB will be queued until a flush event and - /// all available trees are up-to-date. Assert if any instruction of DelBB is - /// modified while awaiting deletion. Multiple callbacks can be queued for one - /// DelBB under Lazy UpdateStrategy. + /// Under Eager UpdateStrategy, DelBB will be processed immediately; If + /// DisableNodeErasing is true, DelBB will not be erased from available trees. + /// It is used before a recalculation event. Under Lazy UpdateStrategy, DelBB + /// will be queued until a flush event and all available trees are up-to-date. + /// Assert if any instruction of DelBB is modified while awaiting deletion. + /// Multiple callbacks can be queued for one DelBB under Lazy UpdateStrategy. void callbackDeleteBB(BasicBlock *DelBB, - std::function Callback); + std::function Callback, + bool DisableNodeErasing = false); /// Recalculate all available trees. /// Under Lazy Strategy, available trees will only be recalculated if there Index: lib/IR/DomTreeUpdater.cpp =================================================================== --- lib/IR/DomTreeUpdater.cpp +++ lib/IR/DomTreeUpdater.cpp @@ -214,7 +214,7 @@ // So BasicBlock deletions must be pended when the // UpdateStrategy is Lazy. When the UpdateStrategy is // Eager, the BasicBlock will be deleted immediately. -void DomTreeUpdater::deleteBB(BasicBlock *DelBB) { +void DomTreeUpdater::deleteBB(BasicBlock *DelBB, bool DisableNodeErasing) { validateDeleteBB(DelBB); if (Strategy == UpdateStrategy::Lazy) { DeletedBBs.insert(DelBB); @@ -222,12 +222,14 @@ } DelBB->removeFromParent(); - eraseDelBBNode(DelBB); + if (!DisableNodeErasing) + eraseDelBBNode(DelBB); delete DelBB; } void DomTreeUpdater::callbackDeleteBB( - BasicBlock *DelBB, std::function Callback) { + BasicBlock *DelBB, std::function Callback, + bool DisableNodeErasing) { validateDeleteBB(DelBB); if (Strategy == UpdateStrategy::Lazy) { Callbacks.push_back(CallBackOnDeletion(DelBB, Callback)); @@ -236,7 +238,8 @@ } DelBB->removeFromParent(); - eraseDelBBNode(DelBB); + if (!DisableNodeErasing) + eraseDelBBNode(DelBB); Callback(DelBB); delete DelBB; }