[PATCH] D61013: [NFC] BasicBlock: refactor changePhiUses() out of replacePhiUsesWith(), use it

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 03:33:22 PDT 2019


lebedev.ri updated this revision to Diff 196414.
lebedev.ri marked an inline comment as done.
lebedev.ri retitled this revision from "[NFC] BasicBlock: refactor changePhiUses() out of replaceSuccessorsPhiUsesWith(), use it" to "[NFC] BasicBlock: refactor changePhiUses() out of replacePhiUsesWith(), use it".

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61013/new/

https://reviews.llvm.org/D61013

Files:
  include/llvm/IR/BasicBlock.h
  lib/CodeGen/CodeGenPrepare.cpp
  lib/IR/BasicBlock.cpp
  lib/Transforms/Scalar/LoopInterchange.cpp


Index: lib/Transforms/Scalar/LoopInterchange.cpp
===================================================================
--- lib/Transforms/Scalar/LoopInterchange.cpp
+++ lib/Transforms/Scalar/LoopInterchange.cpp
@@ -1281,8 +1281,7 @@
 
 static void updateIncomingBlock(BasicBlock *CurrBlock, BasicBlock *OldPred,
                                 BasicBlock *NewPred) {
-  for (PHINode &PHI : CurrBlock->phis())
-    PHI.replaceIncomingBlockWith(OldPred, NewPred);
+  CurrBlock->replacePhiUsesWith(OldPred, NewPred);
 }
 
 /// Update BI to jump to NewBB instead of OldBB. Records updates to
Index: lib/IR/BasicBlock.cpp
===================================================================
--- lib/IR/BasicBlock.cpp
+++ lib/IR/BasicBlock.cpp
@@ -437,22 +437,26 @@
   return New;
 }
 
+void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
+  // N.B. This might not be a complete BasicBlock, so don't assume
+  // that it ends with a non-phi instruction.
+  for (iterator II = begin(), IE = end(); II != IE; ++II) {
+    PHINode *PN = dyn_cast<PHINode>(II);
+    if (!PN)
+      break;
+    PN->replaceIncomingBlockWith(Old, New);
+  }
+}
+
 void BasicBlock::replaceSuccessorsPhiUsesWith(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;
-  for (BasicBlock *Succ : successors(TI)) {
-    // N.B. Succ might not be a complete BasicBlock, so don't assume
-    // that it ends with a non-phi instruction.
-    for (iterator II = Succ->begin(), IE = Succ->end(); II != IE; ++II) {
-      PHINode *PN = dyn_cast<PHINode>(II);
-      if (!PN)
-        break;
-      PN->replaceIncomingBlockWith(this, New);
-    }
-  }
+  llvm::for_each(successors(TI), [this, New](BasicBlock *Succ) {
+    Succ->replacePhiUsesWith(this, New);
+  });
 }
 
 /// Return true if this basic block is a landing pad. I.e., it's
Index: lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- lib/CodeGen/CodeGenPrepare.cpp
+++ lib/CodeGen/CodeGenPrepare.cpp
@@ -7226,8 +7226,7 @@
       std::swap(TBB, FBB);
 
     // Replace the old BB with the new BB.
-    for (PHINode &PN : TBB->phis())
-      PN.replaceIncomingBlockWith(&BB, TmpBB);
+    TBB->replacePhiUsesWith(&BB, TmpBB);
 
     // Add another incoming edge form the new BB.
     for (PHINode &PN : FBB->phis()) {
Index: include/llvm/IR/BasicBlock.h
===================================================================
--- include/llvm/IR/BasicBlock.h
+++ include/llvm/IR/BasicBlock.h
@@ -390,6 +390,10 @@
   /// direct branches, switches, etc. to it.
   bool hasAddressTaken() const { return getSubclassDataFromValue() != 0; }
 
+  /// Update all phi nodes in this basic block to refer to basic block \p New
+  /// 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 to it.
   void replaceSuccessorsPhiUsesWith(BasicBlock *New);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61013.196414.patch
Type: text/x-patch
Size: 3153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190424/a282013a/attachment.bin>


More information about the llvm-commits mailing list