[PATCH] D49807: [Dominators] Make DTU be able to delete a BB before recalculation under Eager UpdateStrategy

Chijun Sima via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 25 11:15:21 PDT 2018


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

Previously, when user tries to delete a BasicBlock without applying updates under Eager UpdateStrategy (typically before recalculation),

  DomTreeUpdater DTU(DT, ...::Eager);
  ... // Decide to remove BB
  DTU.deleteBB(BB); // Call DT.eraseNode(BB) and find BB is not a leaf node.
  *Asserts*
  DTU.recalculate(F);

When we need this code pattern to be compatible with both Eager and Lazy Strategy instances of DTU, we cannot just replace `DTU.deleteBB(BB)` into `BB->eraseFromParent()` because `DTU.recalculate()` under Lazy Strategy checks whether there is any pending updates/DelBB to proceed.
Under Lazy Strategy, things won't be affected because `deleteBB` always goes after applying updates or automatically disables DT node removal during recalculation.
Thus, a new parameter is added to bypass this removal under only Eager UpdateStrategy in this special scenario (trying to delete a BasicBlock without applying any update under Eager UpdateStrategy).

  DTU.deleteBB(BB, /*DisableNodeErasing*/ true);
  DTU.recalculate(F);


Repository:
  rL LLVM

https://reviews.llvm.org/D49807

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


Index: lib/IR/DomTreeUpdater.cpp
===================================================================
--- lib/IR/DomTreeUpdater.cpp
+++ lib/IR/DomTreeUpdater.cpp
@@ -214,29 +214,32 @@
 // 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);
     return;
   }
 
   DelBB->removeFromParent();
-  eraseDelBBNode(DelBB);
+  if (!DisableNodeErasing)
+    eraseDelBBNode(DelBB);
   delete DelBB;
 }
 
 void DomTreeUpdater::callbackDeleteBB(
-    BasicBlock *DelBB, std::function<void(BasicBlock *)> Callback) {
+    BasicBlock *DelBB, std::function<void(BasicBlock *)> Callback,
+    bool DisableNodeErasing) {
   validateDeleteBB(DelBB);
   if (Strategy == UpdateStrategy::Lazy) {
     Callbacks.push_back(CallBackOnDeletion(DelBB, Callback));
     DeletedBBs.insert(DelBB);
     return;
   }
 
   DelBB->removeFromParent();
-  eraseDelBBNode(DelBB);
+  if (!DisableNodeErasing)
+    eraseDelBBNode(DelBB);
   Callback(DelBB);
   delete DelBB;
 }
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<void(BasicBlock *)> Callback);
+                        std::function<void(BasicBlock *)> Callback,
+                        bool DisableNodeErasing = false);
 
   /// Recalculate all available trees.
   /// Under Lazy Strategy, available trees will only be recalculated if there


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49807.157304.patch
Type: text/x-patch
Size: 3965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180725/089d3a9f/attachment.bin>


More information about the llvm-commits mailing list