LiveInterval: Use range based for loops for subregister ranges.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223991 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matthias Braun 2014-12-11 00:59:06 +00:00
parent d1db29860c
commit 1bfcc2d56f
9 changed files with 110 additions and 126 deletions

View File

@ -640,6 +640,14 @@ namespace llvm {
return const_subrange_iterator(nullptr); return const_subrange_iterator(nullptr);
} }
iterator_range<subrange_iterator> subranges() {
return make_range(subrange_begin(), subrange_end());
}
iterator_range<const_subrange_iterator> subranges() const {
return make_range(subrange_begin(), subrange_end());
}
/// Creates a new empty subregister live range. The range is added at the /// Creates a new empty subregister live range. The range is added at the
/// beginning of the subrange list; subrange iterators stay valid. /// beginning of the subrange list; subrange iterators stay valid.
SubRange *createSubRange(BumpPtrAllocator &Allocator, unsigned LaneMask) { SubRange *createSubRange(BumpPtrAllocator &Allocator, unsigned LaneMask) {

View File

@ -660,9 +660,8 @@ void LiveInterval::print(raw_ostream &OS) const {
OS << PrintReg(reg) << ' '; OS << PrintReg(reg) << ' ';
super::print(OS); super::print(OS);
// Print subranges // Print subranges
for (const_subrange_iterator I = subrange_begin(), E = subrange_end(); for (const SubRange &SR : subranges()) {
I != E; ++I) { OS << format(" L%04X ", SR.LaneMask) << SR;
OS << format(" L%04X ", I->LaneMask) << *I;
} }
} }
@ -699,18 +698,17 @@ void LiveInterval::verify(const MachineRegisterInfo *MRI) const {
// Make sure SubRanges are fine and LaneMasks are disjunct. // Make sure SubRanges are fine and LaneMasks are disjunct.
unsigned Mask = 0; unsigned Mask = 0;
unsigned MaxMask = MRI != nullptr ? MRI->getMaxLaneMaskForVReg(reg) : ~0u; unsigned MaxMask = MRI != nullptr ? MRI->getMaxLaneMaskForVReg(reg) : ~0u;
for (const_subrange_iterator I = subrange_begin(), E = subrange_end(); I != E; for (const SubRange &SR : subranges()) {
++I) {
// Subrange lanemask should be disjunct to any previous subrange masks. // Subrange lanemask should be disjunct to any previous subrange masks.
assert((Mask & I->LaneMask) == 0); assert((Mask & SR.LaneMask) == 0);
Mask |= I->LaneMask; Mask |= SR.LaneMask;
// subrange mask should not contained in maximum lane mask for the vreg. // subrange mask should not contained in maximum lane mask for the vreg.
assert((Mask & ~MaxMask) == 0); assert((Mask & ~MaxMask) == 0);
I->verify(); SR.verify();
// Main liverange should cover subrange. // Main liverange should cover subrange.
assert(covers(*I)); assert(covers(SR));
} }
} }
#endif #endif

View File

@ -395,9 +395,8 @@ bool LiveIntervals::shrinkToUses(LiveInterval *li,
&& "Can only shrink virtual registers"); && "Can only shrink virtual registers");
// Shrink subregister live ranges. // Shrink subregister live ranges.
for (LiveInterval::subrange_iterator I = li->subrange_begin(), for (LiveInterval::SubRange &S : li->subranges()) {
E = li->subrange_end(); I != E; ++I) { shrinkToUses(S, li->reg);
shrinkToUses(*I, li->reg);
} }
// Find all the values used, including PHI kills. // Find all the values used, including PHI kills.
@ -606,9 +605,8 @@ void LiveIntervals::pruneValue(LiveInterval &LI, SlotIndex Kill,
SmallVectorImpl<SlotIndex> *EndPoints) { SmallVectorImpl<SlotIndex> *EndPoints) {
pruneValue((LiveRange&)LI, Kill, EndPoints); pruneValue((LiveRange&)LI, Kill, EndPoints);
for (LiveInterval::subrange_iterator SR = LI.subrange_begin(), for (LiveInterval::SubRange &SR : LI.subranges()) {
SE = LI.subrange_end(); SR != SE; ++SR) { pruneValue(SR, Kill, nullptr);
pruneValue(*SR, Kill, nullptr);
} }
} }
@ -882,11 +880,10 @@ public:
if (LI.hasSubRanges()) { if (LI.hasSubRanges()) {
unsigned SubReg = MO->getSubReg(); unsigned SubReg = MO->getSubReg();
unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg); unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg);
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) { if ((S.LaneMask & LaneMask) == 0)
if ((S->LaneMask & LaneMask) == 0)
continue; continue;
updateRange(*S, Reg, S->LaneMask); updateRange(S, Reg, S.LaneMask);
} }
} }
updateRange(LI, Reg, 0); updateRange(LI, Reg, 0);
@ -1322,9 +1319,8 @@ LiveIntervals::repairIntervalsInRange(MachineBasicBlock *MBB,
if (!LI.hasAtLeastOneValue()) if (!LI.hasAtLeastOneValue())
continue; continue;
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) { repairOldRegInRange(Begin, End, endIdx, S, Reg, S.LaneMask);
repairOldRegInRange(Begin, End, endIdx, *S, Reg, S->LaneMask);
} }
repairOldRegInRange(Begin, End, endIdx, LI, Reg); repairOldRegInRange(Begin, End, endIdx, LI, Reg);
} }

View File

@ -66,22 +66,21 @@ void LiveRangeCalc::createDeadDefs(LiveInterval &LI) {
LI.createSubRangeFrom(*Alloc, ClassMask, LI); LI.createSubRangeFrom(*Alloc, ClassMask, LI);
} }
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) {
// A Mask for subregs common to the existing subrange and current def. // A Mask for subregs common to the existing subrange and current def.
unsigned Common = S->LaneMask & Mask; unsigned Common = S.LaneMask & Mask;
if (Common == 0) if (Common == 0)
continue; continue;
// A Mask for subregs covered by the subrange but not the current def. // A Mask for subregs covered by the subrange but not the current def.
unsigned LRest = S->LaneMask & ~Mask; unsigned LRest = S.LaneMask & ~Mask;
LiveInterval::SubRange *CommonRange; LiveInterval::SubRange *CommonRange;
if (LRest != 0) { if (LRest != 0) {
// Split current subrange into Common and LRest ranges. // Split current subrange into Common and LRest ranges.
S->LaneMask = LRest; S.LaneMask = LRest;
CommonRange = LI.createSubRangeFrom(*Alloc, Common, *S); CommonRange = LI.createSubRangeFrom(*Alloc, Common, S);
} else { } else {
assert(Common == S->LaneMask); assert(Common == S.LaneMask);
CommonRange = &*S; CommonRange = &S;
} }
CommonRange->createDeadDef(Idx, *Alloc); CommonRange->createDeadDef(Idx, *Alloc);
Mask &= ~Common; Mask &= ~Common;
@ -162,8 +161,9 @@ void LiveRangeCalc::extendToUses(LiveInterval &LI) {
const TargetRegisterInfo &TRI = *MRI->getTargetRegisterInfo(); const TargetRegisterInfo &TRI = *MRI->getTargetRegisterInfo();
SmallVector<LiveOutData,2> LiveOuts; SmallVector<LiveOutData,2> LiveOuts;
unsigned NumSubRanges = 0; unsigned NumSubRanges = 0;
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (const auto &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S, ++NumSubRanges) { (void)S;
++NumSubRanges;
LiveOuts.push_back(LiveOutData()); LiveOuts.push_back(LiveOutData());
LiveOuts.back().reset(MF->getNumBlockIDs()); LiveOuts.back().reset(MF->getNumBlockIDs());
} }

View File

@ -288,10 +288,9 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {
RegsToErase.push_back(Reg); RegsToErase.push_back(Reg);
} else { } else {
// Also remove the value in subranges. // Also remove the value in subranges.
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) { if (VNInfo *SVNI = S.getVNInfoAt(Idx))
if (VNInfo *SVNI = S->getVNInfoAt(Idx)) S.removeValNo(SVNI);
S->removeValNo(SVNI);
} }
} }
} }

View File

@ -79,10 +79,9 @@ bool foreachUnit(const TargetRegisterInfo *TRI, LiveInterval &VRegInterval,
for (MCRegUnitMaskIterator Units(PhysReg, TRI); Units.isValid(); ++Units) { for (MCRegUnitMaskIterator Units(PhysReg, TRI); Units.isValid(); ++Units) {
unsigned Unit = (*Units).first; unsigned Unit = (*Units).first;
unsigned Mask = (*Units).second; unsigned Mask = (*Units).second;
for (LiveInterval::subrange_iterator S = VRegInterval.subrange_begin(), for (LiveInterval::SubRange &S : VRegInterval.subranges()) {
SE = VRegInterval.subrange_end(); S != SE; ++S) { if (S.LaneMask & Mask) {
if (S->LaneMask & Mask) { if (Func(Unit, S))
if (Func(Unit, *S))
return true; return true;
break; break;
} }

View File

@ -1657,15 +1657,14 @@ void MachineVerifier::verifyLiveInterval(const LiveInterval &LI) {
if (TargetRegisterInfo::isVirtualRegister(Reg)) { if (TargetRegisterInfo::isVirtualRegister(Reg)) {
unsigned Mask = 0; unsigned Mask = 0;
unsigned MaxMask = MRI->getMaxLaneMaskForVReg(Reg); unsigned MaxMask = MRI->getMaxLaneMaskForVReg(Reg);
for (LiveInterval::const_subrange_iterator I = LI.subrange_begin(), for (const LiveInterval::SubRange &SR : LI.subranges()) {
E = LI.subrange_end(); I != E; ++I) { if ((Mask & SR.LaneMask) != 0)
if ((Mask & I->LaneMask) != 0)
report("Lane masks of sub ranges overlap in live interval", MF, LI); report("Lane masks of sub ranges overlap in live interval", MF, LI);
if ((I->LaneMask & ~MaxMask) != 0) if ((SR.LaneMask & ~MaxMask) != 0)
report("Subrange lanemask is invalid", MF, LI); report("Subrange lanemask is invalid", MF, LI);
Mask |= I->LaneMask; Mask |= SR.LaneMask;
verifyLiveRange(*I, LI.reg, I->LaneMask); verifyLiveRange(SR, LI.reg, SR.LaneMask);
if (!LI.covers(*I)) if (!LI.covers(SR))
report("A Subrange is not covered by the main range", MF, LI); report("A Subrange is not covered by the main range", MF, LI);
} }
} else if (LI.hasSubRanges()) { } else if (LI.hasSubRanges()) {

View File

@ -514,13 +514,12 @@ bool RegisterCoalescer::adjustCopiesBackFrom(const CoalescerPair &CP,
IntB.MergeValueNumberInto(BValNo, ValS->valno); IntB.MergeValueNumberInto(BValNo, ValS->valno);
// Do the same for the subregister segments. // Do the same for the subregister segments.
for (LiveInterval::subrange_iterator S = IntB.subrange_begin(), for (LiveInterval::SubRange &S : IntB.subranges()) {
SE = IntB.subrange_end(); S != SE; ++S) { VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx);
VNInfo *SubBValNo = S->getVNInfoAt(CopyIdx); S.addSegment(LiveInterval::Segment(FillerStart, FillerEnd, SubBValNo));
S->addSegment(LiveInterval::Segment(FillerStart, FillerEnd, SubBValNo)); VNInfo *SubValSNo = S.getVNInfoAt(AValNo->def.getPrevSlot());
VNInfo *SubValSNo = S->getVNInfoAt(AValNo->def.getPrevSlot());
if (SubBValNo != SubValSNo) if (SubBValNo != SubValSNo)
S->MergeValueNumberInto(SubBValNo, SubValSNo); S.MergeValueNumberInto(SubBValNo, SubValSNo);
} }
DEBUG(dbgs() << " result = " << IntB << '\n'); DEBUG(dbgs() << " result = " << IntB << '\n');
@ -745,13 +744,12 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP,
DEBUG(dbgs() << "\t\tnoop: " << DefIdx << '\t' << *UseMI); DEBUG(dbgs() << "\t\tnoop: " << DefIdx << '\t' << *UseMI);
assert(DVNI->def == DefIdx); assert(DVNI->def == DefIdx);
BValNo = IntB.MergeValueNumberInto(BValNo, DVNI); BValNo = IntB.MergeValueNumberInto(BValNo, DVNI);
for (LiveInterval::subrange_iterator S = IntB.subrange_begin(), for (LiveInterval::SubRange &S : IntB.subranges()) {
SE = IntB.subrange_end(); S != SE; ++S) { VNInfo *SubDVNI = S.getVNInfoAt(DefIdx);
VNInfo *SubDVNI = S->getVNInfoAt(DefIdx);
if (!SubDVNI) if (!SubDVNI)
continue; continue;
VNInfo *SubBValNo = S->getVNInfoAt(CopyIdx); VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx);
S->MergeValueNumberInto(SubBValNo, SubDVNI); S.MergeValueNumberInto(SubBValNo, SubDVNI);
} }
ErasedInstrs.insert(UseMI); ErasedInstrs.insert(UseMI);
@ -768,19 +766,17 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP,
IntA.createSubRangeFrom(Allocator, Mask, IntA); IntA.createSubRangeFrom(Allocator, Mask, IntA);
} }
SlotIndex AIdx = CopyIdx.getRegSlot(true); SlotIndex AIdx = CopyIdx.getRegSlot(true);
for (LiveInterval::subrange_iterator SA = IntA.subrange_begin(), for (LiveInterval::SubRange &SA : IntA.subranges()) {
SAE = IntA.subrange_end(); SA != SAE; ++SA) { VNInfo *ASubValNo = SA.getVNInfoAt(AIdx);
VNInfo *ASubValNo = SA->getVNInfoAt(AIdx);
if (ASubValNo == nullptr) { if (ASubValNo == nullptr) {
DEBUG(dbgs() << "No A Range at " << AIdx << " with mask " DEBUG(dbgs() << "No A Range at " << AIdx << " with mask "
<< format("%04X", SA->LaneMask) << "\n"); << format("%04X", SA.LaneMask) << "\n");
continue; continue;
} }
unsigned AMask = SA->LaneMask; unsigned AMask = SA.LaneMask;
for (LiveInterval::subrange_iterator SB = IntB.subrange_begin(), for (LiveInterval::SubRange &SB : IntB.subranges()) {
SBE = IntB.subrange_end(); SB != SBE; ++SB) { unsigned BMask = SB.LaneMask;
unsigned BMask = SB->LaneMask;
unsigned Common = BMask & AMask; unsigned Common = BMask & AMask;
if (Common == 0) if (Common == 0)
continue; continue;
@ -789,42 +785,41 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP,
unsigned BRest = BMask & ~AMask; unsigned BRest = BMask & ~AMask;
LiveInterval::SubRange *CommonRange; LiveInterval::SubRange *CommonRange;
if (BRest != 0) { if (BRest != 0) {
SB->LaneMask = BRest; SB.LaneMask = BRest;
DEBUG(dbgs() << format("\t\tReduce Lane to %04X\n", BRest)); DEBUG(dbgs() << format("\t\tReduce Lane to %04X\n", BRest));
// Duplicate SubRange for newly merged common stuff. // Duplicate SubRange for newly merged common stuff.
CommonRange = IntB.createSubRangeFrom(Allocator, Common, *SB); CommonRange = IntB.createSubRangeFrom(Allocator, Common, SB);
} else { } else {
// We van reuse the L SubRange. // We van reuse the L SubRange.
SB->LaneMask = Common; SB.LaneMask = Common;
CommonRange = &*SB; CommonRange = &SB;
} }
LiveRange RangeCopy(*SB, Allocator); LiveRange RangeCopy(SB, Allocator);
VNInfo *BSubValNo = CommonRange->getVNInfoAt(CopyIdx); VNInfo *BSubValNo = CommonRange->getVNInfoAt(CopyIdx);
assert(BSubValNo->def == CopyIdx); assert(BSubValNo->def == CopyIdx);
BSubValNo->def = ASubValNo->def; BSubValNo->def = ASubValNo->def;
addSegmentsWithValNo(*CommonRange, BSubValNo, *SA, ASubValNo); addSegmentsWithValNo(*CommonRange, BSubValNo, SA, ASubValNo);
AMask &= ~BMask; AMask &= ~BMask;
} }
if (AMask != 0) { if (AMask != 0) {
DEBUG(dbgs() << format("\t\tNew Lane %04X\n", AMask)); DEBUG(dbgs() << format("\t\tNew Lane %04X\n", AMask));
LiveRange *NewRange = IntB.createSubRange(Allocator, AMask); LiveRange *NewRange = IntB.createSubRange(Allocator, AMask);
VNInfo *BSubValNo = NewRange->getNextValue(CopyIdx, Allocator); VNInfo *BSubValNo = NewRange->getNextValue(CopyIdx, Allocator);
addSegmentsWithValNo(*NewRange, BSubValNo, *SA, ASubValNo); addSegmentsWithValNo(*NewRange, BSubValNo, SA, ASubValNo);
} }
SA->removeValNo(ASubValNo); SA.removeValNo(ASubValNo);
} }
} else if (IntA.hasSubRanges()) { } else if (IntA.hasSubRanges()) {
SlotIndex AIdx = CopyIdx.getRegSlot(true); SlotIndex AIdx = CopyIdx.getRegSlot(true);
for (LiveInterval::subrange_iterator SA = IntA.subrange_begin(), for (LiveInterval::SubRange &SA : IntA.subranges()) {
SAE = IntA.subrange_end(); SA != SAE; ++SA) { VNInfo *ASubValNo = SA.getVNInfoAt(AIdx);
VNInfo *ASubValNo = SA->getVNInfoAt(AIdx);
if (ASubValNo == nullptr) { if (ASubValNo == nullptr) {
DEBUG(dbgs() << "No A Range at " << AIdx << " with mask " DEBUG(dbgs() << "No A Range at " << AIdx << " with mask "
<< format("%04X", SA->LaneMask) << "\n"); << format("%04X", SA.LaneMask) << "\n");
continue; continue;
} }
SA->removeValNo(ASubValNo); SA.removeValNo(ASubValNo);
} }
} }
@ -1054,12 +1049,11 @@ bool RegisterCoalescer::eliminateUndefCopy(MachineInstr *CopyMI,
assert(DeadVNI && "No value defined in DstInt"); assert(DeadVNI && "No value defined in DstInt");
DstInt->removeValNo(DeadVNI); DstInt->removeValNo(DeadVNI);
// Eliminate the corresponding values in the subregister ranges. // Eliminate the corresponding values in the subregister ranges.
for (LiveInterval::subrange_iterator S = DstInt->subrange_begin(), for (LiveInterval::SubRange &S : DstInt->subranges()) {
E = DstInt->subrange_end(); S != E; ++S) { VNInfo *DeadVNI = S.getVNInfoAt(RegIndex);
VNInfo *DeadVNI = S->getVNInfoAt(RegIndex);
if (DeadVNI == nullptr) if (DeadVNI == nullptr)
continue; continue;
S->removeValNo(DeadVNI); S.removeValNo(DeadVNI);
} }
// Find new undef uses. // Find new undef uses.
@ -1133,11 +1127,10 @@ void RegisterCoalescer::updateRegDefsUses(unsigned SrcReg,
? LIS->getSlotIndexes()->getIndexBefore(UseMI) ? LIS->getSlotIndexes()->getIndexBefore(UseMI)
: LIS->getInstructionIndex(UseMI); : LIS->getInstructionIndex(UseMI);
SlotIndex UseIdx = MIIdx.getRegSlot(true); SlotIndex UseIdx = MIIdx.getRegSlot(true);
for (LiveInterval::subrange_iterator S = DstInt->subrange_begin(), for (LiveInterval::SubRange &S : DstInt->subranges()) {
SE = DstInt->subrange_end(); S != SE; ++S) { if ((S.LaneMask & Mask) == 0)
if ((S->LaneMask & Mask) == 0)
continue; continue;
if (S->liveAt(UseIdx)) { if (S.liveAt(UseIdx)) {
IsUndef = false; IsUndef = false;
break; break;
} }
@ -1252,12 +1245,11 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
LI.MergeValueNumberInto(DefVNI, ReadVNI); LI.MergeValueNumberInto(DefVNI, ReadVNI);
// Process subregister liveranges. // Process subregister liveranges.
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) { LiveQueryResult SLRQ = S.Query(CopyIdx);
LiveQueryResult SLRQ = S->Query(CopyIdx);
if (VNInfo *SDefVNI = SLRQ.valueDefined()) { if (VNInfo *SDefVNI = SLRQ.valueDefined()) {
VNInfo *SReadVNI = SLRQ.valueIn(); VNInfo *SReadVNI = SLRQ.valueIn();
S->MergeValueNumberInto(SDefVNI, SReadVNI); S.MergeValueNumberInto(SDefVNI, SReadVNI);
} }
} }
DEBUG(dbgs() << "\tMerged values: " << LI << '\n'); DEBUG(dbgs() << "\tMerged values: " << LI << '\n');
@ -1362,13 +1354,12 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
// Shrink subregister ranges if necessary. // Shrink subregister ranges if necessary.
if (ShrinkMask != 0) { if (ShrinkMask != 0) {
LiveInterval &LI = LIS->getInterval(CP.getDstReg()); LiveInterval &LI = LIS->getInterval(CP.getDstReg());
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) { if ((S.LaneMask & ShrinkMask) == 0)
if ((S->LaneMask & ShrinkMask) == 0)
continue; continue;
DEBUG(dbgs() << "Shrink LaneUses (Lane " DEBUG(dbgs() << "Shrink LaneUses (Lane "
<< format("%04X", S->LaneMask) << ")\n"); << format("%04X", S.LaneMask) << ")\n");
LIS->shrinkToUses(*S, LI.reg); LIS->shrinkToUses(S, LI.reg);
} }
} }
if (ShrinkMainRange) { if (ShrinkMainRange) {
@ -2216,17 +2207,16 @@ void JoinVals::pruneSubRegValues(LiveInterval &LI, unsigned &ShrinkMask)
// Check subranges at the point where the copy will be removed. // Check subranges at the point where the copy will be removed.
SlotIndex Def = LR.getValNumInfo(i)->def; SlotIndex Def = LR.getValNumInfo(i)->def;
for (LiveInterval::subrange_iterator I = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
E = LI.subrange_end(); I != E; ++I) { LiveQueryResult Q = S.Query(Def);
LiveQueryResult Q = I->Query(Def);
// If a subrange starts at the copy then an undefined value has been // If a subrange starts at the copy then an undefined value has been
// copied and we must remove that subrange value as well. // copied and we must remove that subrange value as well.
VNInfo *ValueOut = Q.valueOutOrDead(); VNInfo *ValueOut = Q.valueOutOrDead();
if (ValueOut != nullptr && Q.valueIn() == nullptr) { if (ValueOut != nullptr && Q.valueIn() == nullptr) {
DEBUG(dbgs() << "\t\tPrune sublane " << format("%04X", I->LaneMask) DEBUG(dbgs() << "\t\tPrune sublane " << format("%04X", S.LaneMask)
<< " at " << Def << "\n"); << " at " << Def << "\n");
LIS->pruneValue(*I, Def, nullptr); LIS->pruneValue(S, Def, nullptr);
DidPrune = true; DidPrune = true;
// Mark value number as unused. // Mark value number as unused.
ValueOut->markUnused(); ValueOut->markUnused();
@ -2236,8 +2226,8 @@ void JoinVals::pruneSubRegValues(LiveInterval &LI, unsigned &ShrinkMask)
// partially used later. Shrink the subregister range apropriately. // partially used later. Shrink the subregister range apropriately.
if (Q.valueIn() != nullptr && Q.valueOut() == nullptr) { if (Q.valueIn() != nullptr && Q.valueOut() == nullptr) {
DEBUG(dbgs() << "\t\tDead uses at sublane " DEBUG(dbgs() << "\t\tDead uses at sublane "
<< format("%04X", I->LaneMask) << " at " << Def << "\n"); << format("%04X", S.LaneMask) << " at " << Def << "\n");
ShrinkMask |= I->LaneMask; ShrinkMask |= S.LaneMask;
} }
} }
} }
@ -2333,9 +2323,8 @@ void RegisterCoalescer::mergeSubRangeInto(LiveInterval &LI,
unsigned LaneMask, unsigned LaneMask,
CoalescerPair &CP) { CoalescerPair &CP) {
BumpPtrAllocator &Allocator = LIS->getVNInfoAllocator(); BumpPtrAllocator &Allocator = LIS->getVNInfoAllocator();
for (LiveInterval::subrange_iterator R = LI.subrange_begin(), for (LiveInterval::SubRange &R : LI.subranges()) {
RE = LI.subrange_end(); R != RE; ++R) { unsigned RMask = R.LaneMask;
unsigned RMask = R->LaneMask;
// LaneMask of subregisters common to subrange R and ToMerge. // LaneMask of subregisters common to subrange R and ToMerge.
unsigned Common = RMask & LaneMask; unsigned Common = RMask & LaneMask;
// There is nothing to do without common subregs. // There is nothing to do without common subregs.
@ -2348,14 +2337,14 @@ void RegisterCoalescer::mergeSubRangeInto(LiveInterval &LI,
unsigned LRest = RMask & ~LaneMask; unsigned LRest = RMask & ~LaneMask;
LiveInterval::SubRange *CommonRange; LiveInterval::SubRange *CommonRange;
if (LRest != 0) { if (LRest != 0) {
R->LaneMask = LRest; R.LaneMask = LRest;
DEBUG(dbgs() << format("\t\tReduce Lane to %04X\n", LRest)); DEBUG(dbgs() << format("\t\tReduce Lane to %04X\n", LRest));
// Duplicate SubRange for newly merged common stuff. // Duplicate SubRange for newly merged common stuff.
CommonRange = LI.createSubRangeFrom(Allocator, Common, *R); CommonRange = LI.createSubRangeFrom(Allocator, Common, R);
} else { } else {
// Reuse the existing range. // Reuse the existing range.
R->LaneMask = Common; R.LaneMask = Common;
CommonRange = &*R; CommonRange = &R;
} }
LiveRange RangeCopy(ToMerge, Allocator); LiveRange RangeCopy(ToMerge, Allocator);
joinSubRegRanges(*CommonRange, RangeCopy, CP); joinSubRegRanges(*CommonRange, RangeCopy, CP);
@ -2405,10 +2394,9 @@ bool RegisterCoalescer::joinVirtRegs(CoalescerPair &CP) {
<< ' ' << LHS << '\n'); << ' ' << LHS << '\n');
} else if (DstIdx != 0) { } else if (DstIdx != 0) {
// Transform LHS lanemasks to new register class if necessary. // Transform LHS lanemasks to new register class if necessary.
for (LiveInterval::subrange_iterator R = LHS.subrange_begin(), for (LiveInterval::SubRange &R : LHS.subranges()) {
RE = LHS.subrange_end(); R != RE; ++R) { unsigned DstMask = TRI->composeSubRegIndexLaneMask(DstIdx, R.LaneMask);
unsigned DstMask = TRI->composeSubRegIndexLaneMask(DstIdx, R->LaneMask); R.LaneMask = DstMask;
R->LaneMask = DstMask;
} }
DEBUG(dbgs() << "\t\tLHST = " << PrintReg(CP.getDstReg()) DEBUG(dbgs() << "\t\tLHST = " << PrintReg(CP.getDstReg())
<< ' ' << LHS << '\n'); << ' ' << LHS << '\n');
@ -2425,19 +2413,18 @@ bool RegisterCoalescer::joinVirtRegs(CoalescerPair &CP) {
mergeSubRangeInto(LHS, RHS, Mask, CP); mergeSubRangeInto(LHS, RHS, Mask, CP);
} else { } else {
// Pair up subranges and merge. // Pair up subranges and merge.
for (LiveInterval::subrange_iterator R = RHS.subrange_begin(), for (LiveInterval::SubRange &R : RHS.subranges()) {
RE = RHS.subrange_end(); R != RE; ++R) { unsigned RMask = R.LaneMask;
unsigned RMask = R->LaneMask;
if (SrcIdx != 0) { if (SrcIdx != 0) {
// Transform LaneMask of RHS subranges to the ones on LHS. // Transform LaneMask of RHS subranges to the ones on LHS.
RMask = TRI->composeSubRegIndexLaneMask(SrcIdx, RMask); RMask = TRI->composeSubRegIndexLaneMask(SrcIdx, RMask);
DEBUG(dbgs() << "\t\tTransform RHS Mask " DEBUG(dbgs() << "\t\tTransform RHS Mask "
<< format("%04X", R->LaneMask) << " to subreg " << format("%04X", R.LaneMask) << " to subreg "
<< TRI->getSubRegIndexName(SrcIdx) << TRI->getSubRegIndexName(SrcIdx)
<< " => " << format("%04X", RMask) << "\n"); << " => " << format("%04X", RMask) << "\n");
} }
mergeSubRangeInto(LHS, *R, RMask, CP); mergeSubRangeInto(LHS, R, RMask, CP);
} }
} }
@ -2708,9 +2695,8 @@ bool RegisterCoalescer::runOnMachineFunction(MachineFunction &fn) {
// If subranges are still supported, then the same subregs should still // If subranges are still supported, then the same subregs should still
// be supported. // be supported.
#ifndef NDEBUG #ifndef NDEBUG
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
E = LI.subrange_end(); S != E; ++S) { assert ((S.LaneMask & ~MaxMask) == 0);
assert ((S->LaneMask & ~MaxMask) == 0);
} }
#endif #endif
} }

View File

@ -253,16 +253,15 @@ void VirtRegRewriter::addMBBLiveIns() {
assert(PhysReg != VirtRegMap::NO_PHYS_REG && "Unmapped virtual register."); assert(PhysReg != VirtRegMap::NO_PHYS_REG && "Unmapped virtual register.");
if (LI.hasSubRanges()) { if (LI.hasSubRanges()) {
for (LiveInterval::subrange_iterator S = LI.subrange_begin(), for (LiveInterval::SubRange &S : LI.subranges()) {
SE = LI.subrange_end(); S != SE; ++S) { for (const auto &Seg : S.segments) {
for (const auto &Seg : S->segments) {
if (!Indexes->findLiveInMBBs(Seg.start, Seg.end, LiveIn)) if (!Indexes->findLiveInMBBs(Seg.start, Seg.end, LiveIn))
continue; continue;
for (MCSubRegIndexIterator SR(PhysReg, TRI); SR.isValid(); ++SR) { for (MCSubRegIndexIterator SR(PhysReg, TRI); SR.isValid(); ++SR) {
unsigned SubReg = SR.getSubReg(); unsigned SubReg = SR.getSubReg();
unsigned SubRegIndex = SR.getSubRegIndex(); unsigned SubRegIndex = SR.getSubRegIndex();
unsigned SubRegLaneMask = TRI->getSubRegIndexLaneMask(SubRegIndex); unsigned SubRegLaneMask = TRI->getSubRegIndexLaneMask(SubRegIndex);
if ((SubRegLaneMask & S->LaneMask) == 0) if ((SubRegLaneMask & S.LaneMask) == 0)
continue; continue;
for (unsigned i = 0, e = LiveIn.size(); i != e; ++i) { for (unsigned i = 0, e = LiveIn.size(); i != e; ++i) {
if (!LiveIn[i]->isLiveIn(SubReg)) if (!LiveIn[i]->isLiveIn(SubReg))