Skip to content

Commit

Permalink
[CodeGen] Make use of MachineBasicBlock::phis. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayfoad committed May 2, 2023
1 parent 8a11c55 commit 4b2381a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
6 changes: 2 additions & 4 deletions llvm/lib/CodeGen/TailDuplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,13 +1019,11 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB,

DenseMap<Register, RegSubRegPair> LocalVRMap;
SmallVector<std::pair<Register, RegSubRegPair>, 4> CopyInfos;
MachineBasicBlock::iterator I = TailBB->begin();
// Process PHI instructions first.
while (I != TailBB->end() && I->isPHI()) {
for (MachineInstr &MI : make_early_inc_range(TailBB->phis())) {
// Replace the uses of the def of the PHI with the register coming
// from PredBB.
MachineInstr *MI = &*I++;
processPHI(MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, false);
processPHI(&MI, TailBB, PredBB, LocalVRMap, CopyInfos, UsedByPhi, false);
}
appendCopies(PredBB, CopyInfos, Copies);
}
Expand Down
25 changes: 11 additions & 14 deletions llvm/lib/CodeGen/UnreachableBlockElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
// Prune unneeded PHI entries.
SmallPtrSet<MachineBasicBlock*, 8> preds(BB.pred_begin(),
BB.pred_end());
MachineBasicBlock::iterator phi = BB.begin();
while (phi != BB.end() && phi->isPHI()) {
for (unsigned i = phi->getNumOperands() - 1; i >= 2; i-=2)
if (!preds.count(phi->getOperand(i).getMBB())) {
phi->removeOperand(i);
phi->removeOperand(i-1);
for (MachineInstr &Phi : make_early_inc_range(BB.phis())) {
for (unsigned i = Phi.getNumOperands() - 1; i >= 2; i -= 2) {
if (!preds.count(Phi.getOperand(i).getMBB())) {
Phi.removeOperand(i);
Phi.removeOperand(i - 1);
ModifiedPHI = true;
}
}

if (phi->getNumOperands() == 3) {
const MachineOperand &Input = phi->getOperand(1);
const MachineOperand &Output = phi->getOperand(0);
if (Phi.getNumOperands() == 3) {
const MachineOperand &Input = Phi.getOperand(1);
const MachineOperand &Output = Phi.getOperand(0);
Register InputReg = Input.getReg();
Register OutputReg = Output.getReg();
assert(Output.getSubReg() == 0 && "Cannot have output subregister");
Expand All @@ -182,16 +182,13 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
// insert a COPY instead of simply replacing the output
// with the input.
const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo();
BuildMI(BB, BB.getFirstNonPHI(), phi->getDebugLoc(),
BuildMI(BB, BB.getFirstNonPHI(), Phi.getDebugLoc(),
TII->get(TargetOpcode::COPY), OutputReg)
.addReg(InputReg, getRegState(Input), InputSub);
}
phi++->eraseFromParent();
Phi.eraseFromParent();
}
continue;
}

++phi;
}
}

Expand Down

0 comments on commit 4b2381a

Please sign in to comment.