1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Simplify the fast-patch interval spilling by using MachineRegisterInfo::reg_iterator.

llvm-svn: 54930
This commit is contained in:
Owen Anderson 2008-08-18 18:38:12 +00:00
parent 98fb8113e8
commit 751ff13625

View File

@ -1618,83 +1618,61 @@ addIntervalsForSpillsFast(const LiveInterval &li,
const TargetRegisterClass* rc = mri_->getRegClass(li.reg); const TargetRegisterClass* rc = mri_->getRegClass(li.reg);
for (LiveInterval::Ranges::const_iterator DenseMap<MachineInstr*, unsigned> VRegMap;
i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) { DenseMap<MachineInstr*, VNInfo*> VNMap;
unsigned index = getBaseIndex(i->start);
unsigned end = getBaseIndex(i->end-1) + InstrSlots::NUM;
for (; index != end; index += InstrSlots::NUM) {
// skip deleted instructions
while (index != end && !getInstructionFromIndex(index))
index += InstrSlots::NUM;
if (index == end) break;
MachineInstr *MI = getInstructionFromIndex(index); for (MachineRegisterInfo::reg_iterator RI = mri_->reg_begin(li.reg),
RE = mri_->reg_end(); RI != RE; ) {
// Create a new virtual register for the spill interval.
MachineOperand& MO = RI.getOperand();
unsigned NewVReg = 0;
if (!VRegMap.count(MO.getParent()))
VRegMap[MO.getParent()] = NewVReg = mri_->createVirtualRegister(rc);
else
NewVReg = VRegMap[MO.getParent()];
// Increment iterator to avoid invalidation.
++RI;
MO.setReg(NewVReg);
for (unsigned i = 0; i != MI->getNumOperands(); ++i) { // create a new register for this spill
MachineOperand& mop = MI->getOperand(i); vrm.grow();
if (mop.isRegister() && mop.getReg() == li.reg) { vrm.assignVirt2StackSlot(NewVReg, slot);
// Create a new virtual register for the spill interval. LiveInterval &nI = getOrCreateInterval(NewVReg);
unsigned NewVReg = mri_->createVirtualRegister(rc); assert(nI.empty());
// Scan all of the operands of this instruction rewriting operands
// to use NewVReg instead of li.reg as appropriate. We do this for
// two reasons:
//
// 1. If the instr reads the same spilled vreg multiple times, we
// want to reuse the NewVReg.
// 2. If the instr is a two-addr instruction, we are required to
// keep the src/dst regs pinned.
//
// Keep track of whether we replace a use and/or def so that we can
// create the spill interval with the appropriate range.
mop.setReg(NewVReg);
bool HasUse = mop.isUse();
bool HasDef = mop.isDef();
for (unsigned j = i+1, e = MI->getNumOperands(); j != e; ++j) {
if (MI->getOperand(j).isReg() &&
MI->getOperand(j).getReg() == li.reg) {
MI->getOperand(j).setReg(NewVReg);
HasUse |= MI->getOperand(j).isUse();
HasDef |= MI->getOperand(j).isDef();
}
}
// create a new register for this spill // the spill weight is now infinity as it
vrm.grow(); // cannot be spilled again
vrm.assignVirt2StackSlot(NewVReg, slot); nI.weight = HUGE_VALF;
LiveInterval &nI = getOrCreateInterval(NewVReg);
assert(nI.empty());
// the spill weight is now infinity as it unsigned index = getInstructionIndex(MO.getParent());
// cannot be spilled again bool HasUse = MO.isUse();
nI.weight = HUGE_VALF; bool HasDef = MO.isDef();
if (!VNMap.count(MO.getParent()))
if (HasUse) { VNMap[MO.getParent()] = nI.getNextValue(~0U, 0, getVNInfoAllocator());
LiveRange LR(getLoadIndex(index), getUseIndex(index), if (HasUse) {
nI.getNextValue(~0U, 0, getVNInfoAllocator())); LiveRange LR(getLoadIndex(index), getUseIndex(index),
DOUT << " +" << LR; VNMap[MO.getParent()]);
nI.addRange(LR); DOUT << " +" << LR;
} nI.addRange(LR);
if (HasDef) {
LiveRange LR(getDefIndex(index), getStoreIndex(index),
nI.getNextValue(~0U, 0, getVNInfoAllocator()));
DOUT << " +" << LR;
nI.addRange(LR);
}
added.push_back(&nI);
// update live variables if it is available
if (lv_)
lv_->addVirtualRegisterKilled(NewVReg, MI);
DOUT << "\t\t\t\tadded new interval: ";
DEBUG(nI.dump());
DOUT << '\n';
}
}
} }
if (HasDef) {
LiveRange LR(getDefIndex(index), getStoreIndex(index),
VNMap[MO.getParent()]);
DOUT << " +" << LR;
nI.addRange(LR);
}
added.push_back(&nI);
// update live variables if it is available
if (lv_)
lv_->addVirtualRegisterKilled(NewVReg, MO.getParent());
DOUT << "\t\t\t\tadded new interval: ";
DEBUG(nI.dump());
DOUT << '\n';
} }
SSWeight = HUGE_VALF; SSWeight = HUGE_VALF;