From: Chijun Sima Date: Wed, 25 Jul 2018 06:18:33 +0000 (+0000) Subject: [Dominators] Assert if there is modification to DelBB while it is awaiting deletion X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a23be0643b82dad02c1af9cf235beb555a80dc05;p=llvm [Dominators] Assert if there is modification to DelBB while it is awaiting deletion Summary: Previously, passes use ``` DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy); DTU.deleteBB(DelBB); ``` to delete a BasicBlock. But passes which don't have the ability to update DomTree (e.g. tailcallelim, simplifyCFG) cannot recognize a DelBB awaiting deletion and will continue to process this DelBB. This is a simple approach to notify devs of passes which may use DTU in the future to deal with deleted BasicBlocks under Lazy Strategy correctly. Reviewers: kuhar, brzycki, dmgreen Reviewed By: kuhar Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49731 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337891 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/DomTreeUpdater.h b/include/llvm/IR/DomTreeUpdater.h index 91a7658a15f..81ba670ac0f 100644 --- a/include/llvm/IR/DomTreeUpdater.h +++ b/include/llvm/IR/DomTreeUpdater.h @@ -143,8 +143,9 @@ public: /// 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. When both DT and PDT are nullptrs, - /// DelBB will be queued until flush() is called. + /// 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); /// Delete DelBB. DelBB will be removed from its Parent and @@ -152,8 +153,9 @@ public: /// 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. - /// Multiple callbacks can be queued for one DelBB under Lazy UpdateStrategy. + /// 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); diff --git a/lib/IR/DomTreeUpdater.cpp b/lib/IR/DomTreeUpdater.cpp index 9af22b16224..f035a86edda 100644 --- a/lib/IR/DomTreeUpdater.cpp +++ b/lib/IR/DomTreeUpdater.cpp @@ -136,6 +136,13 @@ bool DomTreeUpdater::forceFlushDeletedBB() { return false; for (auto *BB : DeletedBBs) { + // After calling deleteBB or callbackDeleteBB under Lazy UpdateStrategy, + // validateDeleteBB() removes all instructions of DelBB and adds an + // UnreachableInst as its terminator. So we check whether the BasicBlock to + // delete only has an UnreachableInst inside. + assert(BB->getInstList().size() == 1 && + isa(BB->getTerminator()) && + "DelBB has been modified while awaiting deletion."); BB->removeFromParent(); eraseDelBBNode(BB); delete BB;