Skip to content

Commit 4b2381a

Browse files
committed
[CodeGen] Make use of MachineBasicBlock::phis. NFC.
1 parent 8a11c55 commit 4b2381a

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

llvm/lib/CodeGen/TailDuplicator.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,11 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB,
10191019

10201020
DenseMap<Register, RegSubRegPair> LocalVRMap;
10211021
SmallVector<std::pair<Register, RegSubRegPair>, 4> CopyInfos;
1022-
MachineBasicBlock::iterator I = TailBB->begin();
10231022
// Process PHI instructions first.
1024-
while (I != TailBB->end() && I->isPHI()) {
1023+
for (MachineInstr &MI : make_early_inc_range(TailBB->phis())) {
10251024
// Replace the uses of the def of the PHI with the register coming
10261025
// from PredBB.
1027-
MachineInstr *MI = &*I++;
1028-
processPHI(MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, false);
1026+
processPHI(&MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, false);
10291027
}
10301028
appendCopies(PredBB, CopyInfos, Copies);
10311029
}

llvm/lib/CodeGen/UnreachableBlockElim.cpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,18 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
152152
// Prune unneeded PHI entries.
153153
SmallPtrSet<MachineBasicBlock*, 8> preds(BB.pred_begin(),
154154
BB.pred_end());
155-
MachineBasicBlock::iterator phi = BB.begin();
156-
while (phi != BB.end() && phi->isPHI()) {
157-
for (unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
158-
if (!preds.count(phi->getOperand(i).getMBB())) {
159-
phi->removeOperand(i);
160-
phi->removeOperand(i-1);
155+
for (MachineInstr &Phi : make_early_inc_range(BB.phis())) {
156+
for (unsigned i = Phi.getNumOperands() - 1; i >= 2; i -= 2) {
157+
if (!preds.count(Phi.getOperand(i).getMBB())) {
158+
Phi.removeOperand(i);
159+
Phi.removeOperand(i - 1);
161160
ModifiedPHI = true;
162161
}
162+
}
163163

164-
if (phi->getNumOperands() == 3) {
165-
const MachineOperand &Input = phi->getOperand(1);
166-
const MachineOperand &Output = phi->getOperand(0);
164+
if (Phi.getNumOperands() == 3) {
165+
const MachineOperand &Input = Phi.getOperand(1);
166+
const MachineOperand &Output = Phi.getOperand(0);
167167
Register InputReg = Input.getReg();
168168
Register OutputReg = Output.getReg();
169169
assert(Output.getSubReg() == 0 && "Cannot have output subregister");
@@ -182,16 +182,13 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
182182
// insert a COPY instead of simply replacing the output
183183
// with the input.
184184
const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo();
185-
BuildMI(BB, BB.getFirstNonPHI(), phi->getDebugLoc(),
185+
BuildMI(BB, BB.getFirstNonPHI(), Phi.getDebugLoc(),
186186
TII->get(TargetOpcode::COPY), OutputReg)
187187
.addReg(InputReg, getRegState(Input), InputSub);
188188
}
189-
phi++->eraseFromParent();
189+
Phi.eraseFromParent();
190190
}
191-
continue;
192191
}
193-
194-
++phi;
195192
}
196193
}
197194

0 commit comments

Comments
 (0)