// the dstination register's live interval.
if (MO->isDead()) {
unsigned MoveIdx = getDefIndex(getInstructionIndex(mii));
- RegInt.removeRange(*RegInt.FindLiveRangeContaining(MoveIdx));
+ LiveInterval::iterator MLR = RegInt.FindLiveRangeContaining(MoveIdx);
+ RegInt.removeRange(MLR->start, MoveIdx+1);
if (RegInt.empty())
removeInterval(RegRep);
}
}
void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
+ unsigned MIIdx,
LiveInterval &interval) {
DOUT << "\t\tlivein register: "; DEBUG(printRegName(interval.reg));
// Look for kills, if it reaches a def before it's killed, then it shouldn't
// be considered a livein.
MachineBasicBlock::iterator mi = MBB->begin();
- unsigned baseIndex = 0;
- unsigned start = 0;
+ unsigned baseIndex = MIIdx;
+ unsigned start = baseIndex;
unsigned end = start;
while (mi != MBB->end()) {
if (lv_->KillsRegister(mi, interval.reg)) {
assert(start < end && "did not find end of interval?");
LiveRange LR(start, end, interval.getNextValue(~0U, 0));
- interval.addRange(LR);
DOUT << " +" << LR << '\n';
+ interval.addRange(LR);
}
/// computeIntervals - computes the live intervals for virtual
// Create intervals for live-ins to this BB first.
for (MachineBasicBlock::const_livein_iterator LI = MBB->livein_begin(),
LE = MBB->livein_end(); LI != LE; ++LI) {
- handleLiveInRegister(MBB, getOrCreateInterval(*LI));
+ handleLiveInRegister(MBB, MIIndex, getOrCreateInterval(*LI));
for (const unsigned* AS = mri_->getAliasSet(*LI); *AS; ++AS)
- handleLiveInRegister(MBB, getOrCreateInterval(*AS));
+ handleLiveInRegister(MBB, MIIndex, getOrCreateInterval(*AS));
}
}
DOUT << "\n\t\tJoined. Result = "; DestInt.print(DOUT, mri_);
DOUT << "\n";
-
+
+ // Live range has been lengthened due to colaescing, eliminate the
+ // unnecessary kills at the end of the source live ranges.
+ LiveVariables::VarInfo& svi = lv_->getVarInfo(repSrcReg);
+ for (unsigned i = 0, e = svi.Kills.size(); i != e; ++i) {
+ MachineInstr *Kill = svi.Kills[i];
+ if (Kill == CopyMI || isRemoved(Kill))
+ continue;
+ if (DestInt.liveAt(getInstructionIndex(Kill) + InstrSlots::NUM))
+ unsetRegisterKill(Kill, repSrcReg);
+ }
+ if (MRegisterInfo::isVirtualRegister(repDstReg)) {
+ // If both are virtual registers...
+ LiveVariables::VarInfo& dvi = lv_->getVarInfo(repDstReg);
+ for (unsigned i = 0, e = dvi.Kills.size(); i != e; ++i) {
+ MachineInstr *Kill = dvi.Kills[i];
+ if (Kill == CopyMI || isRemoved(Kill))
+ continue;
+ if (DestInt.liveAt(getInstructionIndex(Kill) + InstrSlots::NUM))
+ unsetRegisterKill(Kill, repDstReg);
+ }
+ }
+
// If the intervals were swapped by Join, swap them back so that the register
// mapping (in the r2i map) is correct.
if (Swapped) SrcInt.swap(DestInt);
/// reg between indexes Start and End.
bool
LiveIntervals::hasRegisterUse(unsigned Reg, unsigned Start, unsigned End) {
- for (unsigned Index = Start+InstrSlots::NUM; Index != End;
+ for (unsigned Index = Start+InstrSlots::NUM; Index < End;
Index += InstrSlots::NUM) {
// Skip deleted instructions
- while (Index != End && !getInstructionFromIndex(Index))
+ while (Index < End && !getInstructionFromIndex(Index))
Index += InstrSlots::NUM;
if (Index >= End) break;
return false;
}
+/// unsetRegisterKill - Unset IsKill property of all uses of specific register
+/// of the specific instruction.
+void LiveIntervals::unsetRegisterKill(MachineInstr *MI, unsigned Reg) {
+ for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
+ MachineOperand &MO = MI->getOperand(i);
+ if (MO.isReg() && MO.isUse() && MO.isKill() && MO.getReg() &&
+ mri_->regsOverlap(rep(MO.getReg()), Reg))
+ MO.unsetIsKill();
+ }
+}
+
LiveInterval LiveIntervals::createInterval(unsigned reg) {
float Weight = MRegisterInfo::isPhysicalRegister(reg) ?
HUGE_VALF : 0.0F;