[PATCH] D49731: [Dominators] Assert if there is modification to DelBB while it is awaiting deletion

Chijun Sima via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 07:42:30 PDT 2018


NutshellySima created this revision.
NutshellySima added reviewers: kuhar, brzycki, dmgreen.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D49731

Files:
  include/llvm/IR/DomTreeUpdater.h
  lib/IR/DomTreeUpdater.cpp


Index: lib/IR/DomTreeUpdater.cpp
===================================================================
--- lib/IR/DomTreeUpdater.cpp
+++ lib/IR/DomTreeUpdater.cpp
@@ -136,6 +136,9 @@
     return false;
 
   for (auto *BB : DeletedBBs) {
+    assert(BB->getInstList().size() == 1 &&
+           isa<UnreachableInst>(BB->getTerminator()) &&
+           "DelBB has been modified while awaiting deletion.");
     BB->removeFromParent();
     eraseDelBBNode(BB);
     delete BB;
Index: include/llvm/IR/DomTreeUpdater.h
===================================================================
--- include/llvm/IR/DomTreeUpdater.h
+++ include/llvm/IR/DomTreeUpdater.h
@@ -143,17 +143,19 @@
   /// 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
   /// 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.
-  /// 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<void(BasicBlock *)> Callback);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49731.157032.patch
Type: text/x-patch
Size: 2059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180724/1781775a/attachment.bin>


More information about the llvm-commits mailing list