[NFC] Add parameter for keeping one-input Phis in DeleteDeadBlock(s)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353799 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Transforms/Utils/BasicBlockUtils.h b/include/llvm/Transforms/Utils/BasicBlockUtils.h
index fad01f6..c264aae 100644
--- a/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -41,19 +41,25 @@
 
 /// Replace contents of every block in \p BBs with single unreachable
 /// instruction. If \p Updates is specified, collect all necessary DT updates
-/// into this vector.
+/// into this vector. If \p DontDeleteUselessPHIs is true, one-input Phis in
+/// successors of blocks being deleted will be preserved.
 void DetatchDeadBlocks(ArrayRef <BasicBlock *> BBs,
-                       SmallVectorImpl<DominatorTree::UpdateType> *Updates);
+                       SmallVectorImpl<DominatorTree::UpdateType> *Updates,
+                       bool DontDeleteUselessPHIs = false);
 
 /// Delete the specified block, which must have no predecessors.
-void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU = nullptr);
+void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU = nullptr,
+                     bool DontDeleteUselessPHIs = false);
 
 /// Delete the specified blocks from \p BB. The set of deleted blocks must have
 /// no predecessors that are not being deleted themselves. \p BBs must have no
 /// duplicating blocks. If there are loops among this set of blocks, all
 /// relevant loop info updates should be done before this function is called.
+/// If \p DontDeleteUselessPHIs is true, one-input Phis in successors of blocks
+/// being deleted will be preserved.
 void DeleteDeadBlocks(ArrayRef <BasicBlock *> BBs,
-                      DomTreeUpdater *DTU = nullptr);
+                      DomTreeUpdater *DTU = nullptr,
+                      bool DontDeleteUselessPHIs = false);
 
 /// We know that BB has one predecessor. If there are any single-entry PHI nodes
 /// in it, fold them away. This handles the case when all entries to the PHI
diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp
index 2410f65..c0148b9 100644
--- a/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -49,13 +49,14 @@
 
 void llvm::DetatchDeadBlocks(
     ArrayRef<BasicBlock *> BBs,
-    SmallVectorImpl<DominatorTree::UpdateType> *Updates) {
+    SmallVectorImpl<DominatorTree::UpdateType> *Updates,
+    bool DontDeleteUselessPHIs) {
   for (auto *BB : BBs) {
     // Loop through all of our successors and make sure they know that one
     // of their predecessors is going away.
     SmallPtrSet<BasicBlock *, 4> UniqueSuccessors;
     for (BasicBlock *Succ : successors(BB)) {
-      Succ->removePredecessor(BB);
+      Succ->removePredecessor(BB, DontDeleteUselessPHIs);
       if (Updates && UniqueSuccessors.insert(Succ).second)
         Updates->push_back({DominatorTree::Delete, BB, Succ});
     }
@@ -80,12 +81,13 @@
   }
 }
 
-void llvm::DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU) {
-  DeleteDeadBlocks({BB}, DTU);
+void llvm::DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU,
+                           bool DontDeleteUselessPHIs) {
+  DeleteDeadBlocks({BB}, DTU, DontDeleteUselessPHIs);
 }
 
-void llvm::DeleteDeadBlocks(ArrayRef <BasicBlock *> BBs,
-                            DomTreeUpdater *DTU) {
+void llvm::DeleteDeadBlocks(ArrayRef <BasicBlock *> BBs, DomTreeUpdater *DTU,
+                            bool DontDeleteUselessPHIs) {
 #ifndef NDEBUG
   // Make sure that all predecessors of each dead block is also dead.
   SmallPtrSet<BasicBlock *, 4> Dead(BBs.begin(), BBs.end());
@@ -96,7 +98,7 @@
 #endif
 
   SmallVector<DominatorTree::UpdateType, 4> Updates;
-  DetatchDeadBlocks(BBs, DTU ? &Updates : nullptr);
+  DetatchDeadBlocks(BBs, DTU ? &Updates : nullptr, DontDeleteUselessPHIs);
 
   if (DTU)
     DTU->applyUpdates(Updates, /*ForceRemoveDuplicates*/ true);