[PATCH] D66750: [CodeGen] Introduce MachineBasicBlock::replacePhiUsesOfBlockWith helper and use it. NFC
Bjorn Pettersson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 04:22:17 PDT 2019
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370463: [CodeGen] Introduce MachineBasicBlock::replacePhiUsesWith helper and use it. NFC (authored by bjope, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D66750?vs=217316&id=218068#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D66750/new/
https://reviews.llvm.org/D66750
Files:
llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
llvm/trunk/lib/CodeGen/MachinePipeliner.cpp
Index: llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
===================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
+++ llvm/trunk/include/llvm/CodeGen/MachineBasicBlock.h
@@ -735,6 +735,10 @@
/// CFG so that it branches to 'New' instead.
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New);
+ /// Update all phi nodes in this basic block to refer to basic block \p New
+ /// instead of basic block \p Old.
+ void replacePhiUsesWith(MachineBasicBlock *Old, MachineBasicBlock *New);
+
/// Various pieces of code can cause excess edges in the CFG to be inserted.
/// If we have proven that MBB can only branch to DestA and DestB, remove any
/// other MBB successors from the CFG. DestA and DestB can be null. Besides
Index: llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
+++ llvm/trunk/lib/CodeGen/MachineBasicBlock.cpp
@@ -778,7 +778,8 @@
while (!FromMBB->succ_empty()) {
MachineBasicBlock *Succ = *FromMBB->succ_begin();
- // If probability list is empty it means we don't use it (disabled optimization).
+ // If probability list is empty it means we don't use it (disabled
+ // optimization).
if (!FromMBB->Probs.empty()) {
auto Prob = *FromMBB->Probs.begin();
addSuccessor(Succ, Prob);
@@ -804,13 +805,7 @@
FromMBB->removeSuccessor(Succ);
// Fix up any PHI nodes in the successor.
- for (MachineBasicBlock::instr_iterator MI = Succ->instr_begin(),
- ME = Succ->instr_end(); MI != ME && MI->isPHI(); ++MI)
- for (unsigned i = 2, e = MI->getNumOperands()+1; i != e; i += 2) {
- MachineOperand &MO = MI->getOperand(i);
- if (MO.getMBB() == FromMBB)
- MO.setMBB(this);
- }
+ Succ->replacePhiUsesWith(FromMBB, this);
}
normalizeSuccProbs();
}
@@ -985,13 +980,8 @@
}
}
- // Fix PHI nodes in Succ so they refer to NMBB instead of this
- for (MachineBasicBlock::instr_iterator
- i = Succ->instr_begin(),e = Succ->instr_end();
- i != e && i->isPHI(); ++i)
- for (unsigned ni = 1, ne = i->getNumOperands(); ni != ne; ni += 2)
- if (i->getOperand(ni+1).getMBB() == this)
- i->getOperand(ni+1).setMBB(NMBB);
+ // Fix PHI nodes in Succ so they refer to NMBB instead of this.
+ Succ->replacePhiUsesWith(this, NMBB);
// Inherit live-ins from the successor
for (const auto &LI : Succ->liveins())
@@ -1223,6 +1213,16 @@
replaceSuccessor(Old, New);
}
+void MachineBasicBlock::replacePhiUsesWith(MachineBasicBlock *Old,
+ MachineBasicBlock *New) {
+ for (MachineInstr &MI : phis())
+ for (unsigned i = 2, e = MI.getNumOperands() + 1; i != e; i += 2) {
+ MachineOperand &MO = MI.getOperand(i);
+ if (MO.getMBB() == Old)
+ MO.setMBB(New);
+ }
+}
+
/// Various pieces of code can cause excess edges in the CFG to be inserted. If
/// we have proven that MBB can only branch to DestA and DestB, remove any other
/// MBB successors from the CFG. DestA and DestB can be null.
Index: llvm/trunk/lib/CodeGen/MachinePipeliner.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/MachinePipeliner.cpp
+++ llvm/trunk/lib/CodeGen/MachinePipeliner.cpp
@@ -2234,15 +2234,7 @@
}
// Fix any Phi nodes in the loop exit block.
- for (MachineInstr &MI : *LoopExitBB) {
- if (!MI.isPHI())
- break;
- for (unsigned i = 2, e = MI.getNumOperands() + 1; i != e; i += 2) {
- MachineOperand &MO = MI.getOperand(i);
- if (MO.getMBB() == BB)
- MO.setMBB(PredBB);
- }
- }
+ LoopExitBB->replacePhiUsesWith(BB, PredBB);
// Create a branch to the new epilog from the kernel.
// Remove the original branch and add a new branch to the epilog.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66750.218068.patch
Type: text/x-patch
Size: 3947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190830/cb8fd17b/attachment.bin>
More information about the llvm-commits
mailing list