Replace the odd kill# hack with something less fragile.

llvm-svn: 44434
This commit is contained in:
Evan Cheng 2007-11-29 09:49:23 +00:00
parent 8dfcd5975e
commit f85c063ec0
4 changed files with 22 additions and 18 deletions

View File

@ -38,16 +38,18 @@ namespace llvm {
/// contains ~1u,x to indicate that the value # is not used. /// contains ~1u,x to indicate that the value # is not used.
/// def - Instruction # of the definition. /// def - Instruction # of the definition.
/// reg - Source reg iff val# is defined by a copy; zero otherwise. /// reg - Source reg iff val# is defined by a copy; zero otherwise.
/// hasPHIKill - One or more of the kills are PHI nodes.
/// kills - Instruction # of the kills. If a kill is an odd #, it means /// kills - Instruction # of the kills. If a kill is an odd #, it means
/// the kill is a phi join point. /// the kill is a phi join point.
struct VNInfo { struct VNInfo {
unsigned id; unsigned id;
unsigned def; unsigned def;
unsigned reg; unsigned reg;
bool hasPHIKill;
SmallVector<unsigned, 4> kills; SmallVector<unsigned, 4> kills;
VNInfo() : id(~1U), def(~1U), reg(0) {} VNInfo() : id(~1U), def(~1U), reg(0), hasPHIKill(false) {}
VNInfo(unsigned i, unsigned d, unsigned r) VNInfo(unsigned i, unsigned d, unsigned r)
: id(i), def(d), reg(r) {} : id(i), def(d), reg(r), hasPHIKill(false) {}
}; };
/// LiveRange structure - This represents a simple register range in the /// LiveRange structure - This represents a simple register range in the
@ -158,6 +160,7 @@ namespace llvm {
void copyValNumInfo(VNInfo *DstValNo, const VNInfo *SrcValNo) { void copyValNumInfo(VNInfo *DstValNo, const VNInfo *SrcValNo) {
DstValNo->def = SrcValNo->def; DstValNo->def = SrcValNo->def;
DstValNo->reg = SrcValNo->reg; DstValNo->reg = SrcValNo->reg;
DstValNo->hasPHIKill = SrcValNo->hasPHIKill;
DstValNo->kills = SrcValNo->kills; DstValNo->kills = SrcValNo->kills;
} }

View File

@ -206,7 +206,7 @@ LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
// endpoint as well. // endpoint as well.
if (End > it->end) if (End > it->end)
extendIntervalEndTo(it, End); extendIntervalEndTo(it, End);
else else if (End < it->end)
// Overlapping intervals, there might have been a kill here. // Overlapping intervals, there might have been a kill here.
removeKill(it->valno, End); removeKill(it->valno, End);
return it; return it;
@ -631,6 +631,8 @@ void LiveInterval::print(std::ostream &OS, const MRegisterInfo *MRI) const {
if (j != ee-1) if (j != ee-1)
OS << " "; OS << " ";
} }
if (vni->hasPHIKill)
OS << " phi";
OS << ")"; OS << ")";
} }
} }

View File

@ -362,7 +362,8 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
DOUT << " Removing [" << Start << "," << End << "] from: "; DOUT << " Removing [" << Start << "," << End << "] from: ";
interval.print(DOUT, mri_); DOUT << "\n"; interval.print(DOUT, mri_); DOUT << "\n";
interval.removeRange(Start, End); interval.removeRange(Start, End);
interval.addKill(VNI, Start+1); // odd # means phi node interval.addKill(VNI, Start);
VNI->hasPHIKill = true;
DOUT << " RESULT: "; interval.print(DOUT, mri_); DOUT << " RESULT: "; interval.print(DOUT, mri_);
// Replace the interval with one of a NEW value number. Note that this // Replace the interval with one of a NEW value number. Note that this
@ -392,7 +393,8 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
unsigned killIndex = getInstructionIndex(&mbb->back()) + InstrSlots::NUM; unsigned killIndex = getInstructionIndex(&mbb->back()) + InstrSlots::NUM;
LiveRange LR(defIndex, killIndex, ValNo); LiveRange LR(defIndex, killIndex, ValNo);
interval.addRange(LR); interval.addRange(LR);
interval.addKill(ValNo, killIndex+1); // odd # means phi node interval.addKill(ValNo, killIndex);
ValNo->hasPHIKill = true;
DOUT << " +" << LR; DOUT << " +" << LR;
} }
} }
@ -1081,21 +1083,14 @@ addIntervalsForSpills(const LiveInterval &li,
vrm.setVirtIsReMaterialized(li.reg, ReMatDefMI); vrm.setVirtIsReMaterialized(li.reg, ReMatDefMI);
bool CanDelete = true; bool CanDelete = true;
for (unsigned j = 0, ee = VNI->kills.size(); j != ee; ++j) { if (VNI->hasPHIKill) {
unsigned KillIdx = VNI->kills[j]; // A kill is a phi node, not all of its uses can be rematerialized.
MachineInstr *KillMI = (KillIdx & 1)
? NULL : getInstructionFromIndex(KillIdx);
// Kill is a phi node, not all of its uses can be rematerialized.
// It must not be deleted. // It must not be deleted.
if (!KillMI) { CanDelete = false;
CanDelete = false; // Need a stack slot if there is any live range where uses cannot be
// Need a stack slot if there is any live range where uses cannot be // rematerialized.
// rematerialized. NeedStackSlot = true;
NeedStackSlot = true;
break;
}
} }
if (CanDelete) if (CanDelete)
ReMatDelete.set(VN); ReMatDelete.set(VN);
} else { } else {

View File

@ -490,6 +490,7 @@ bool SimpleRegisterCoalescing::JoinCopy(CopyRec TheCopy, bool &Again) {
if (CopiedValNos.insert(DstValNo)) { if (CopiedValNos.insert(DstValNo)) {
VNInfo *ValNo = RealDstInt.getNextValue(DstValNo->def, DstValNo->reg, VNInfo *ValNo = RealDstInt.getNextValue(DstValNo->def, DstValNo->reg,
li_->getVNInfoAllocator()); li_->getVNInfoAllocator());
ValNo->hasPHIKill = DstValNo->hasPHIKill;
RealDstInt.addKills(ValNo, DstValNo->kills); RealDstInt.addKills(ValNo, DstValNo->kills);
RealDstInt.MergeValueInAsValue(*ResDstInt, DstValNo, ValNo); RealDstInt.MergeValueInAsValue(*ResDstInt, DstValNo, ValNo);
} }
@ -734,6 +735,7 @@ bool SimpleRegisterCoalescing::SimpleJoin(LiveInterval &LHS, LiveInterval &RHS)
// Okay, the final step is to loop over the RHS live intervals, adding them to // Okay, the final step is to loop over the RHS live intervals, adding them to
// the LHS. // the LHS.
LHSValNo->hasPHIKill |= VNI->hasPHIKill;
LHS.addKills(LHSValNo, VNI->kills); LHS.addKills(LHSValNo, VNI->kills);
LHS.MergeRangesInAsValue(RHS, LHSValNo); LHS.MergeRangesInAsValue(RHS, LHSValNo);
LHS.weight += RHS.weight; LHS.weight += RHS.weight;
@ -969,6 +971,7 @@ bool SimpleRegisterCoalescing::JoinIntervals(LiveInterval &LHS,
VNInfo *VNI = I->first; VNInfo *VNI = I->first;
unsigned LHSValID = LHSValNoAssignments[VNI->id]; unsigned LHSValID = LHSValNoAssignments[VNI->id];
LiveInterval::removeKill(NewVNInfo[LHSValID], VNI->def); LiveInterval::removeKill(NewVNInfo[LHSValID], VNI->def);
NewVNInfo[LHSValID]->hasPHIKill |= VNI->hasPHIKill;
RHS.addKills(NewVNInfo[LHSValID], VNI->kills); RHS.addKills(NewVNInfo[LHSValID], VNI->kills);
} }
@ -978,6 +981,7 @@ bool SimpleRegisterCoalescing::JoinIntervals(LiveInterval &LHS,
VNInfo *VNI = I->first; VNInfo *VNI = I->first;
unsigned RHSValID = RHSValNoAssignments[VNI->id]; unsigned RHSValID = RHSValNoAssignments[VNI->id];
LiveInterval::removeKill(NewVNInfo[RHSValID], VNI->def); LiveInterval::removeKill(NewVNInfo[RHSValID], VNI->def);
NewVNInfo[RHSValID]->hasPHIKill |= VNI->hasPHIKill;
LHS.addKills(NewVNInfo[RHSValID], VNI->kills); LHS.addKills(NewVNInfo[RHSValID], VNI->kills);
} }