mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-17 20:23:59 +00:00
Remove implicit_def instructions that become dead as result of coalescing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49513 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -632,8 +632,8 @@ SimpleRegisterCoalescing::ShortenDeadCopySrcLiveRange(LiveInterval &li,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
unsigned LastUseIdx;
|
unsigned LastUseIdx;
|
||||||
MachineOperand *LastUse =
|
MachineOperand *LastUse = lastRegisterUse(LR->start, CopyIdx-1, li.reg,
|
||||||
lastRegisterUse(LR->start, CopyIdx-1, li.reg, LastUseIdx);
|
LastUseIdx);
|
||||||
if (LastUse) {
|
if (LastUse) {
|
||||||
// There are uses before the copy, just shorten the live range to the end
|
// There are uses before the copy, just shorten the live range to the end
|
||||||
// of last use.
|
// of last use.
|
||||||
@ -714,29 +714,48 @@ bool SimpleRegisterCoalescing::CanCoalesceWithImpDef(MachineInstr *CopyMI,
|
|||||||
/// identity copies so they will be removed.
|
/// identity copies so they will be removed.
|
||||||
void SimpleRegisterCoalescing::RemoveCopiesFromValNo(LiveInterval &li,
|
void SimpleRegisterCoalescing::RemoveCopiesFromValNo(LiveInterval &li,
|
||||||
VNInfo *VNI) {
|
VNInfo *VNI) {
|
||||||
for (MachineRegisterInfo::use_iterator UI = mri_->use_begin(li.reg),
|
MachineInstr *ImpDef = NULL;
|
||||||
UE = mri_->use_end(); UI != UE;) {
|
MachineOperand *LastUse = NULL;
|
||||||
MachineInstr *UseMI = &*UI;
|
unsigned LastUseIdx = li_->getUseIndex(VNI->def);
|
||||||
++UI;
|
for (MachineRegisterInfo::reg_iterator RI = mri_->reg_begin(li.reg),
|
||||||
if (JoinedCopies.count(UseMI))
|
RE = mri_->reg_end(); RI != RE;) {
|
||||||
|
MachineOperand *MO = &RI.getOperand();
|
||||||
|
MachineInstr *MI = &*RI;
|
||||||
|
++RI;
|
||||||
|
if (MO->isDef()) {
|
||||||
|
if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
|
||||||
|
assert(!ImpDef && "Multiple implicit_def defining same register?");
|
||||||
|
ImpDef = MI;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
unsigned UseIdx = li_->getUseIndex(li_->getInstructionIndex(UseMI));
|
}
|
||||||
|
if (JoinedCopies.count(MI))
|
||||||
|
continue;
|
||||||
|
unsigned UseIdx = li_->getUseIndex(li_->getInstructionIndex(MI));
|
||||||
LiveInterval::iterator ULR = li.FindLiveRangeContaining(UseIdx);
|
LiveInterval::iterator ULR = li.FindLiveRangeContaining(UseIdx);
|
||||||
if (ULR->valno != VNI)
|
if (ULR->valno != VNI)
|
||||||
continue;
|
continue;
|
||||||
if (UseMI->getOpcode() == TargetInstrInfo::INSERT_SUBREG)
|
|
||||||
continue;
|
|
||||||
// If the use is a copy, turn it into an identity copy.
|
// If the use is a copy, turn it into an identity copy.
|
||||||
unsigned SrcReg, DstReg;
|
unsigned SrcReg, DstReg;
|
||||||
if (!tii_->isMoveInstr(*UseMI, SrcReg, DstReg) || SrcReg != li.reg)
|
if (tii_->isMoveInstr(*MI, SrcReg, DstReg) && SrcReg == li.reg) {
|
||||||
assert(0 && "Unexpected use of implicit def!");
|
// Each use MI may have multiple uses of this register. Change them all.
|
||||||
// Each UseMI may have multiple uses of this register. Change them all.
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
|
||||||
for (unsigned i = 0, e = UseMI->getNumOperands(); i != e; ++i) {
|
MachineOperand &MO = MI->getOperand(i);
|
||||||
MachineOperand &MO = UseMI->getOperand(i);
|
|
||||||
if (MO.isReg() && MO.getReg() == li.reg)
|
if (MO.isReg() && MO.getReg() == li.reg)
|
||||||
MO.setReg(DstReg);
|
MO.setReg(DstReg);
|
||||||
}
|
}
|
||||||
JoinedCopies.insert(UseMI);
|
JoinedCopies.insert(MI);
|
||||||
|
} else if (UseIdx > LastUseIdx) {
|
||||||
|
LastUseIdx = UseIdx;
|
||||||
|
LastUse = MO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (LastUse)
|
||||||
|
LastUse->setIsKill();
|
||||||
|
else {
|
||||||
|
// Remove dead implicit_def.
|
||||||
|
li_->RemoveMachineInstrFromMaps(ImpDef);
|
||||||
|
ImpDef->eraseFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1874,7 +1893,6 @@ SimpleRegisterCoalescing::TurnCopyIntoImpDef(MachineBasicBlock::iterator &I,
|
|||||||
assert(DefMI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF);
|
assert(DefMI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF);
|
||||||
li_->RemoveMachineInstrFromMaps(DefMI);
|
li_->RemoveMachineInstrFromMaps(DefMI);
|
||||||
DefMI->eraseFromParent();
|
DefMI->eraseFromParent();
|
||||||
++numPeep;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++I;
|
++I;
|
||||||
|
Reference in New Issue
Block a user