mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
LiveIntervalAnalysis: Factor out code to update liveness on vreg def removal
This cleans up code and is more in line with the general philosophy of modifying LiveIntervals through LiveIntervalAnalysis instead of changing them directly. This also fixes a case where SplitEditor::removeBackCopies() would miss the subregister ranges. llvm-svn: 226690
This commit is contained in:
parent
938927861a
commit
3e16064f18
@ -398,6 +398,10 @@ namespace llvm {
|
||||
/// of its subregisters.
|
||||
void removePhysRegDefAt(unsigned Reg, SlotIndex Pos);
|
||||
|
||||
/// Remove value number and related live segments of @p LI and its subranges
|
||||
/// that start at position @p Pos.
|
||||
void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos);
|
||||
|
||||
private:
|
||||
/// Compute live intervals for all virtual registers.
|
||||
void computeVirtRegs();
|
||||
|
@ -1375,3 +1375,17 @@ void LiveIntervals::removePhysRegDefAt(unsigned Reg, SlotIndex Pos) {
|
||||
LR->removeValNo(VNI);
|
||||
}
|
||||
}
|
||||
|
||||
void LiveIntervals::removeVRegDefAt(LiveInterval &LI, SlotIndex Pos) {
|
||||
VNInfo *VNI = LI.getVNInfoAt(Pos);
|
||||
if (VNI == nullptr)
|
||||
return;
|
||||
LI.removeValNo(VNI);
|
||||
|
||||
// Also remove the value in subranges.
|
||||
for (LiveInterval::SubRange &S : LI.subranges()) {
|
||||
if (VNInfo *SVNI = S.getVNInfoAt(Pos))
|
||||
S.removeValNo(SVNI);
|
||||
}
|
||||
LI.removeEmptySubRanges();
|
||||
}
|
||||
|
@ -273,21 +273,11 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {
|
||||
|
||||
// Remove defined value.
|
||||
if (MOI->isDef()) {
|
||||
if (VNInfo *VNI = LI.getVNInfoAt(Idx)) {
|
||||
if (TheDelegate)
|
||||
TheDelegate->LRE_WillShrinkVirtReg(LI.reg);
|
||||
LI.removeValNo(VNI);
|
||||
if (LI.empty()) {
|
||||
RegsToErase.push_back(Reg);
|
||||
} else {
|
||||
// Also remove the value in subranges.
|
||||
for (LiveInterval::SubRange &S : LI.subranges()) {
|
||||
if (VNInfo *SVNI = S.getVNInfoAt(Idx))
|
||||
S.removeValNo(SVNI);
|
||||
}
|
||||
LI.removeEmptySubRanges();
|
||||
}
|
||||
}
|
||||
if (TheDelegate && LI.getVNInfoAt(Idx) != nullptr)
|
||||
TheDelegate->LRE_WillShrinkVirtReg(LI.reg);
|
||||
LIS.removeVRegDefAt(LI, Idx);
|
||||
if (LI.empty())
|
||||
RegsToErase.push_back(Reg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -802,7 +802,6 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP,
|
||||
VNInfo *BSubValNo = NewRange->getNextValue(CopyIdx, Allocator);
|
||||
addSegmentsWithValNo(*NewRange, BSubValNo, SA, ASubValNo);
|
||||
}
|
||||
SA.removeValNo(ASubValNo);
|
||||
}
|
||||
}
|
||||
|
||||
@ -810,17 +809,8 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP,
|
||||
addSegmentsWithValNo(IntB, BValNo, IntA, AValNo);
|
||||
DEBUG(dbgs() << "\t\textended: " << IntB << '\n');
|
||||
|
||||
IntA.removeValNo(AValNo);
|
||||
// Remove valuenos in subranges (the A+B have subranges case has already been
|
||||
// handled above)
|
||||
if (!IntB.hasSubRanges()) {
|
||||
SlotIndex AIdx = CopyIdx.getRegSlot(true);
|
||||
for (LiveInterval::SubRange &SA : IntA.subranges()) {
|
||||
VNInfo *ASubValNo = SA.getVNInfoAt(AIdx);
|
||||
assert(ASubValNo != nullptr);
|
||||
SA.removeValNo(ASubValNo);
|
||||
}
|
||||
}
|
||||
LIS->removeVRegDefAt(IntA, AValNo->def);
|
||||
|
||||
DEBUG(dbgs() << "\t\ttrimmed: " << IntA << '\n');
|
||||
++numCommutes;
|
||||
return true;
|
||||
@ -1013,13 +1003,6 @@ bool RegisterCoalescer::reMaterializeTrivialDef(CoalescerPair &CP,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void removeUndefValue(LiveRange &LR, SlotIndex At)
|
||||
{
|
||||
VNInfo *VNInfo = LR.getVNInfoAt(At);
|
||||
assert(VNInfo != nullptr && SlotIndex::isSameInstr(VNInfo->def, At));
|
||||
LR.removeValNo(VNInfo);
|
||||
}
|
||||
|
||||
bool RegisterCoalescer::eliminateUndefCopy(MachineInstr *CopyMI) {
|
||||
// ProcessImpicitDefs may leave some copies of <undef> values, it only removes
|
||||
// local variables. When we have a copy like:
|
||||
@ -1053,22 +1036,25 @@ bool RegisterCoalescer::eliminateUndefCopy(MachineInstr *CopyMI) {
|
||||
|
||||
// Remove any DstReg segments starting at the instruction.
|
||||
LiveInterval &DstLI = LIS->getInterval(DstReg);
|
||||
unsigned DstMask = TRI->getSubRegIndexLaneMask(DstSubIdx);
|
||||
SlotIndex RegIndex = Idx.getRegSlot();
|
||||
for (LiveInterval::SubRange &SR : DstLI.subranges()) {
|
||||
if ((SR.LaneMask & DstMask) == 0)
|
||||
continue;
|
||||
removeUndefValue(SR, RegIndex);
|
||||
|
||||
DstLI.removeEmptySubRanges();
|
||||
}
|
||||
// Remove value or merge with previous one in case of a subregister def.
|
||||
if (VNInfo *PrevVNI = DstLI.getVNInfoAt(Idx)) {
|
||||
VNInfo *VNInfo = DstLI.getVNInfoAt(RegIndex);
|
||||
DstLI.MergeValueNumberInto(VNInfo, PrevVNI);
|
||||
} else {
|
||||
removeUndefValue(DstLI, RegIndex);
|
||||
}
|
||||
VNInfo *VNI = DstLI.getVNInfoAt(RegIndex);
|
||||
DstLI.MergeValueNumberInto(VNI, PrevVNI);
|
||||
|
||||
// The affected subregister segments can be removed.
|
||||
unsigned DstMask = TRI->getSubRegIndexLaneMask(DstSubIdx);
|
||||
for (LiveInterval::SubRange &SR : DstLI.subranges()) {
|
||||
if ((SR.LaneMask & DstMask) == 0)
|
||||
continue;
|
||||
|
||||
VNInfo *SVNI = SR.getVNInfoAt(RegIndex);
|
||||
assert(SVNI != nullptr && SlotIndex::isSameInstr(SVNI->def, RegIndex));
|
||||
SR.removeValNo(SVNI);
|
||||
}
|
||||
DstLI.removeEmptySubRanges();
|
||||
} else
|
||||
LIS->removeVRegDefAt(DstLI, RegIndex);
|
||||
|
||||
// Mark uses as undef.
|
||||
for (MachineOperand &MO : MRI->reg_nodbg_operands(DstReg)) {
|
||||
|
@ -623,8 +623,7 @@ void SplitEditor::removeBackCopies(SmallVectorImpl<VNInfo*> &Copies) {
|
||||
AssignI.setMap(RegAssign);
|
||||
|
||||
for (unsigned i = 0, e = Copies.size(); i != e; ++i) {
|
||||
VNInfo *VNI = Copies[i];
|
||||
SlotIndex Def = VNI->def;
|
||||
SlotIndex Def = Copies[i]->def;
|
||||
MachineInstr *MI = LIS.getInstructionFromIndex(Def);
|
||||
assert(MI && "No instruction for back-copy");
|
||||
|
||||
@ -635,13 +634,12 @@ void SplitEditor::removeBackCopies(SmallVectorImpl<VNInfo*> &Copies) {
|
||||
while (!AtBegin && (--MBBI)->isDebugValue());
|
||||
|
||||
DEBUG(dbgs() << "Removing " << Def << '\t' << *MI);
|
||||
LI->removeValNo(VNI);
|
||||
LIS.removeVRegDefAt(*LI, Def);
|
||||
LIS.RemoveMachineInstrFromMaps(MI);
|
||||
MI->eraseFromParent();
|
||||
|
||||
// Adjust RegAssign if a register assignment is killed at VNI->def. We
|
||||
// want to avoid calculating the live range of the source register if
|
||||
// possible.
|
||||
// Adjust RegAssign if a register assignment is killed at Def. We want to
|
||||
// avoid calculating the live range of the source register if possible.
|
||||
AssignI.find(Def.getPrevSlot());
|
||||
if (!AssignI.valid() || AssignI.start() >= Def)
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user