]> granicus.if.org Git - llvm/commitdiff
[NFC] BasicBlock: generalize replaceSuccessorsPhiUsesWith(), take Old bb
authorRoman Lebedev <lebedev.ri@gmail.com>
Sun, 5 May 2019 18:59:45 +0000 (18:59 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sun, 5 May 2019 18:59:45 +0000 (18:59 +0000)
Thus it does not assume that the old basic block is the basic block
for which we are looking at successors.

Not reviewed, but seems rather trivial, in line with the rest of
previous few patches.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359997 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/BasicBlock.h
lib/IR/BasicBlock.cpp

index c88b1b5101426ffbcb93c4f17ebbef11649f6f84..69555af50e1fe3543d90ac8bcb7c12c59e64c69d 100644 (file)
@@ -394,6 +394,10 @@ public:
   /// instead of basic block \p Old.
   void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New);
 
+  /// Update all phi nodes in this basic block's successors to refer to basic
+  /// block \p New instead of basic block \p Old.
+  void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New);
+
   /// Update all phi nodes in this basic block's successors to refer to basic
   /// block \p New instead of to it.
   void replaceSuccessorsPhiUsesWith(BasicBlock *New);
index b3980cf9c3141a4d7935ee8dec10ea4fb0c5cce7..34410712645dad2e3645a48b8fc72b871028d517 100644 (file)
@@ -425,11 +425,9 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
   // Now we must loop through all of the successors of the New block (which
   // _were_ the successors of the 'this' block), and update any PHI nodes in
   // successors.  If there were PHI nodes in the successors, then they need to
-  // know that incoming branches will be from New, not from Old.
+  // know that incoming branches will be from New, not from Old (this).
   //
-  llvm::for_each(successors(New), [this, New](BasicBlock *Succ) {
-    Succ->replacePhiUsesWith(this, New);
-  });
+  New->replaceSuccessorsPhiUsesWith(this, New);
   return New;
 }
 
@@ -444,17 +442,22 @@ void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
   }
 }
 
-void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
+void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,
+                                              BasicBlock *New) {
   Instruction *TI = getTerminator();
   if (!TI)
     // Cope with being called on a BasicBlock that doesn't have a terminator
     // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
     return;
-  llvm::for_each(successors(TI), [this, New](BasicBlock *Succ) {
-    Succ->replacePhiUsesWith(this, New);
+  llvm::for_each(successors(TI), [Old, New](BasicBlock *Succ) {
+    Succ->replacePhiUsesWith(Old, New);
   });
 }
 
+void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *New) {
+  this->replaceSuccessorsPhiUsesWith(this, New);
+}
+
 /// Return true if this basic block is a landing pad. I.e., it's
 /// the destination of the 'unwind' edge of an invoke instruction.
 bool BasicBlock::isLandingPad() const {