From 1bfcc2d56f701162e12bab31b55f3bfee07af8af Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Thu, 11 Dec 2014 00:59:06 +0000 Subject: [PATCH] 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 --- include/llvm/CodeGen/LiveInterval.h | 8 ++ lib/CodeGen/LiveInterval.cpp | 16 ++-- lib/CodeGen/LiveIntervalAnalysis.cpp | 22 ++--- lib/CodeGen/LiveRangeCalc.cpp | 20 ++-- lib/CodeGen/LiveRangeEdit.cpp | 7 +- lib/CodeGen/LiveRegMatrix.cpp | 7 +- lib/CodeGen/MachineVerifier.cpp | 13 ++- lib/CodeGen/RegisterCoalescer.cpp | 136 ++++++++++++--------------- lib/CodeGen/VirtRegMap.cpp | 7 +- 9 files changed, 110 insertions(+), 126 deletions(-) diff --git a/include/llvm/CodeGen/LiveInterval.h b/include/llvm/CodeGen/LiveInterval.h index 51a8aaee66e..594767a4ea6 100644 --- a/include/llvm/CodeGen/LiveInterval.h +++ b/include/llvm/CodeGen/LiveInterval.h @@ -640,6 +640,14 @@ namespace llvm { return const_subrange_iterator(nullptr); } + iterator_range subranges() { + return make_range(subrange_begin(), subrange_end()); + } + + iterator_range subranges() const { + return make_range(subrange_begin(), subrange_end()); + } + /// Creates a new empty subregister live range. The range is added at the /// beginning of the subrange list; subrange iterators stay valid. SubRange *createSubRange(BumpPtrAllocator &Allocator, unsigned LaneMask) { diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp index 7953be6fa2b..67e7a8ae85d 100644 --- a/lib/CodeGen/LiveInterval.cpp +++ b/lib/CodeGen/LiveInterval.cpp @@ -660,9 +660,8 @@ void LiveInterval::print(raw_ostream &OS) const { OS << PrintReg(reg) << ' '; super::print(OS); // Print subranges - for (const_subrange_iterator I = subrange_begin(), E = subrange_end(); - I != E; ++I) { - OS << format(" L%04X ", I->LaneMask) << *I; + for (const SubRange &SR : subranges()) { + OS << format(" L%04X ", SR.LaneMask) << SR; } } @@ -699,18 +698,17 @@ void LiveInterval::verify(const MachineRegisterInfo *MRI) const { // Make sure SubRanges are fine and LaneMasks are disjunct. unsigned Mask = 0; unsigned MaxMask = MRI != nullptr ? MRI->getMaxLaneMaskForVReg(reg) : ~0u; - for (const_subrange_iterator I = subrange_begin(), E = subrange_end(); I != E; - ++I) { + for (const SubRange &SR : subranges()) { // Subrange lanemask should be disjunct to any previous subrange masks. - assert((Mask & I->LaneMask) == 0); - Mask |= I->LaneMask; + assert((Mask & SR.LaneMask) == 0); + Mask |= SR.LaneMask; // subrange mask should not contained in maximum lane mask for the vreg. assert((Mask & ~MaxMask) == 0); - I->verify(); + SR.verify(); // Main liverange should cover subrange. - assert(covers(*I)); + assert(covers(SR)); } } #endif diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index a384e3c1517..f48be4d5eb0 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -395,9 +395,8 @@ bool LiveIntervals::shrinkToUses(LiveInterval *li, && "Can only shrink virtual registers"); // Shrink subregister live ranges. - for (LiveInterval::subrange_iterator I = li->subrange_begin(), - E = li->subrange_end(); I != E; ++I) { - shrinkToUses(*I, li->reg); + for (LiveInterval::SubRange &S : li->subranges()) { + shrinkToUses(S, li->reg); } // Find all the values used, including PHI kills. @@ -606,9 +605,8 @@ void LiveIntervals::pruneValue(LiveInterval &LI, SlotIndex Kill, SmallVectorImpl *EndPoints) { pruneValue((LiveRange&)LI, Kill, EndPoints); - for (LiveInterval::subrange_iterator SR = LI.subrange_begin(), - SE = LI.subrange_end(); SR != SE; ++SR) { - pruneValue(*SR, Kill, nullptr); + for (LiveInterval::SubRange &SR : LI.subranges()) { + pruneValue(SR, Kill, nullptr); } } @@ -882,11 +880,10 @@ public: if (LI.hasSubRanges()) { unsigned SubReg = MO->getSubReg(); unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg); - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { - if ((S->LaneMask & LaneMask) == 0) + for (LiveInterval::SubRange &S : LI.subranges()) { + if ((S.LaneMask & LaneMask) == 0) continue; - updateRange(*S, Reg, S->LaneMask); + updateRange(S, Reg, S.LaneMask); } } updateRange(LI, Reg, 0); @@ -1322,9 +1319,8 @@ LiveIntervals::repairIntervalsInRange(MachineBasicBlock *MBB, if (!LI.hasAtLeastOneValue()) continue; - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { - repairOldRegInRange(Begin, End, endIdx, *S, Reg, S->LaneMask); + for (LiveInterval::SubRange &S : LI.subranges()) { + repairOldRegInRange(Begin, End, endIdx, S, Reg, S.LaneMask); } repairOldRegInRange(Begin, End, endIdx, LI, Reg); } diff --git a/lib/CodeGen/LiveRangeCalc.cpp b/lib/CodeGen/LiveRangeCalc.cpp index bc88486ce25..625a3630d7f 100644 --- a/lib/CodeGen/LiveRangeCalc.cpp +++ b/lib/CodeGen/LiveRangeCalc.cpp @@ -66,22 +66,21 @@ void LiveRangeCalc::createDeadDefs(LiveInterval &LI) { LI.createSubRangeFrom(*Alloc, ClassMask, LI); } - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { + for (LiveInterval::SubRange &S : LI.subranges()) { // 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) continue; // 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; if (LRest != 0) { // Split current subrange into Common and LRest ranges. - S->LaneMask = LRest; - CommonRange = LI.createSubRangeFrom(*Alloc, Common, *S); + S.LaneMask = LRest; + CommonRange = LI.createSubRangeFrom(*Alloc, Common, S); } else { - assert(Common == S->LaneMask); - CommonRange = &*S; + assert(Common == S.LaneMask); + CommonRange = &S; } CommonRange->createDeadDef(Idx, *Alloc); Mask &= ~Common; @@ -162,8 +161,9 @@ void LiveRangeCalc::extendToUses(LiveInterval &LI) { const TargetRegisterInfo &TRI = *MRI->getTargetRegisterInfo(); SmallVector LiveOuts; unsigned NumSubRanges = 0; - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S, ++NumSubRanges) { + for (const auto &S : LI.subranges()) { + (void)S; + ++NumSubRanges; LiveOuts.push_back(LiveOutData()); LiveOuts.back().reset(MF->getNumBlockIDs()); } diff --git a/lib/CodeGen/LiveRangeEdit.cpp b/lib/CodeGen/LiveRangeEdit.cpp index 83a4e96fa71..765a39a9b5e 100644 --- a/lib/CodeGen/LiveRangeEdit.cpp +++ b/lib/CodeGen/LiveRangeEdit.cpp @@ -288,10 +288,9 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) { RegsToErase.push_back(Reg); } else { // Also remove the value in subranges. - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { - if (VNInfo *SVNI = S->getVNInfoAt(Idx)) - S->removeValNo(SVNI); + for (LiveInterval::SubRange &S : LI.subranges()) { + if (VNInfo *SVNI = S.getVNInfoAt(Idx)) + S.removeValNo(SVNI); } } } diff --git a/lib/CodeGen/LiveRegMatrix.cpp b/lib/CodeGen/LiveRegMatrix.cpp index 66709aec77a..b0438db4417 100644 --- a/lib/CodeGen/LiveRegMatrix.cpp +++ b/lib/CodeGen/LiveRegMatrix.cpp @@ -79,10 +79,9 @@ bool foreachUnit(const TargetRegisterInfo *TRI, LiveInterval &VRegInterval, for (MCRegUnitMaskIterator Units(PhysReg, TRI); Units.isValid(); ++Units) { unsigned Unit = (*Units).first; unsigned Mask = (*Units).second; - for (LiveInterval::subrange_iterator S = VRegInterval.subrange_begin(), - SE = VRegInterval.subrange_end(); S != SE; ++S) { - if (S->LaneMask & Mask) { - if (Func(Unit, *S)) + for (LiveInterval::SubRange &S : VRegInterval.subranges()) { + if (S.LaneMask & Mask) { + if (Func(Unit, S)) return true; break; } diff --git a/lib/CodeGen/MachineVerifier.cpp b/lib/CodeGen/MachineVerifier.cpp index 05d3a7b793f..ecbb3156f95 100644 --- a/lib/CodeGen/MachineVerifier.cpp +++ b/lib/CodeGen/MachineVerifier.cpp @@ -1657,15 +1657,14 @@ void MachineVerifier::verifyLiveInterval(const LiveInterval &LI) { if (TargetRegisterInfo::isVirtualRegister(Reg)) { unsigned Mask = 0; unsigned MaxMask = MRI->getMaxLaneMaskForVReg(Reg); - for (LiveInterval::const_subrange_iterator I = LI.subrange_begin(), - E = LI.subrange_end(); I != E; ++I) { - if ((Mask & I->LaneMask) != 0) + for (const LiveInterval::SubRange &SR : LI.subranges()) { + if ((Mask & SR.LaneMask) != 0) 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); - Mask |= I->LaneMask; - verifyLiveRange(*I, LI.reg, I->LaneMask); - if (!LI.covers(*I)) + Mask |= SR.LaneMask; + verifyLiveRange(SR, LI.reg, SR.LaneMask); + if (!LI.covers(SR)) report("A Subrange is not covered by the main range", MF, LI); } } else if (LI.hasSubRanges()) { diff --git a/lib/CodeGen/RegisterCoalescer.cpp b/lib/CodeGen/RegisterCoalescer.cpp index afb579152a3..ecb224ab28e 100644 --- a/lib/CodeGen/RegisterCoalescer.cpp +++ b/lib/CodeGen/RegisterCoalescer.cpp @@ -514,13 +514,12 @@ bool RegisterCoalescer::adjustCopiesBackFrom(const CoalescerPair &CP, IntB.MergeValueNumberInto(BValNo, ValS->valno); // Do the same for the subregister segments. - for (LiveInterval::subrange_iterator S = IntB.subrange_begin(), - SE = IntB.subrange_end(); S != SE; ++S) { - VNInfo *SubBValNo = S->getVNInfoAt(CopyIdx); - S->addSegment(LiveInterval::Segment(FillerStart, FillerEnd, SubBValNo)); - VNInfo *SubValSNo = S->getVNInfoAt(AValNo->def.getPrevSlot()); + for (LiveInterval::SubRange &S : IntB.subranges()) { + VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx); + S.addSegment(LiveInterval::Segment(FillerStart, FillerEnd, SubBValNo)); + VNInfo *SubValSNo = S.getVNInfoAt(AValNo->def.getPrevSlot()); if (SubBValNo != SubValSNo) - S->MergeValueNumberInto(SubBValNo, SubValSNo); + S.MergeValueNumberInto(SubBValNo, SubValSNo); } DEBUG(dbgs() << " result = " << IntB << '\n'); @@ -745,13 +744,12 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP, DEBUG(dbgs() << "\t\tnoop: " << DefIdx << '\t' << *UseMI); assert(DVNI->def == DefIdx); BValNo = IntB.MergeValueNumberInto(BValNo, DVNI); - for (LiveInterval::subrange_iterator S = IntB.subrange_begin(), - SE = IntB.subrange_end(); S != SE; ++S) { - VNInfo *SubDVNI = S->getVNInfoAt(DefIdx); + for (LiveInterval::SubRange &S : IntB.subranges()) { + VNInfo *SubDVNI = S.getVNInfoAt(DefIdx); if (!SubDVNI) continue; - VNInfo *SubBValNo = S->getVNInfoAt(CopyIdx); - S->MergeValueNumberInto(SubBValNo, SubDVNI); + VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx); + S.MergeValueNumberInto(SubBValNo, SubDVNI); } ErasedInstrs.insert(UseMI); @@ -768,19 +766,17 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP, IntA.createSubRangeFrom(Allocator, Mask, IntA); } SlotIndex AIdx = CopyIdx.getRegSlot(true); - for (LiveInterval::subrange_iterator SA = IntA.subrange_begin(), - SAE = IntA.subrange_end(); SA != SAE; ++SA) { - VNInfo *ASubValNo = SA->getVNInfoAt(AIdx); + for (LiveInterval::SubRange &SA : IntA.subranges()) { + VNInfo *ASubValNo = SA.getVNInfoAt(AIdx); if (ASubValNo == nullptr) { DEBUG(dbgs() << "No A Range at " << AIdx << " with mask " - << format("%04X", SA->LaneMask) << "\n"); + << format("%04X", SA.LaneMask) << "\n"); continue; } - unsigned AMask = SA->LaneMask; - for (LiveInterval::subrange_iterator SB = IntB.subrange_begin(), - SBE = IntB.subrange_end(); SB != SBE; ++SB) { - unsigned BMask = SB->LaneMask; + unsigned AMask = SA.LaneMask; + for (LiveInterval::SubRange &SB : IntB.subranges()) { + unsigned BMask = SB.LaneMask; unsigned Common = BMask & AMask; if (Common == 0) continue; @@ -789,42 +785,41 @@ bool RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP, unsigned BRest = BMask & ~AMask; LiveInterval::SubRange *CommonRange; if (BRest != 0) { - SB->LaneMask = BRest; + SB.LaneMask = BRest; DEBUG(dbgs() << format("\t\tReduce Lane to %04X\n", BRest)); // Duplicate SubRange for newly merged common stuff. - CommonRange = IntB.createSubRangeFrom(Allocator, Common, *SB); + CommonRange = IntB.createSubRangeFrom(Allocator, Common, SB); } else { // We van reuse the L SubRange. - SB->LaneMask = Common; - CommonRange = &*SB; + SB.LaneMask = Common; + CommonRange = &SB; } - LiveRange RangeCopy(*SB, Allocator); + LiveRange RangeCopy(SB, Allocator); VNInfo *BSubValNo = CommonRange->getVNInfoAt(CopyIdx); assert(BSubValNo->def == CopyIdx); BSubValNo->def = ASubValNo->def; - addSegmentsWithValNo(*CommonRange, BSubValNo, *SA, ASubValNo); + addSegmentsWithValNo(*CommonRange, BSubValNo, SA, ASubValNo); AMask &= ~BMask; } if (AMask != 0) { DEBUG(dbgs() << format("\t\tNew Lane %04X\n", AMask)); LiveRange *NewRange = IntB.createSubRange(Allocator, AMask); 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()) { SlotIndex AIdx = CopyIdx.getRegSlot(true); - for (LiveInterval::subrange_iterator SA = IntA.subrange_begin(), - SAE = IntA.subrange_end(); SA != SAE; ++SA) { - VNInfo *ASubValNo = SA->getVNInfoAt(AIdx); + for (LiveInterval::SubRange &SA : IntA.subranges()) { + VNInfo *ASubValNo = SA.getVNInfoAt(AIdx); if (ASubValNo == nullptr) { DEBUG(dbgs() << "No A Range at " << AIdx << " with mask " - << format("%04X", SA->LaneMask) << "\n"); + << format("%04X", SA.LaneMask) << "\n"); continue; } - SA->removeValNo(ASubValNo); + SA.removeValNo(ASubValNo); } } @@ -1054,12 +1049,11 @@ bool RegisterCoalescer::eliminateUndefCopy(MachineInstr *CopyMI, assert(DeadVNI && "No value defined in DstInt"); DstInt->removeValNo(DeadVNI); // Eliminate the corresponding values in the subregister ranges. - for (LiveInterval::subrange_iterator S = DstInt->subrange_begin(), - E = DstInt->subrange_end(); S != E; ++S) { - VNInfo *DeadVNI = S->getVNInfoAt(RegIndex); + for (LiveInterval::SubRange &S : DstInt->subranges()) { + VNInfo *DeadVNI = S.getVNInfoAt(RegIndex); if (DeadVNI == nullptr) continue; - S->removeValNo(DeadVNI); + S.removeValNo(DeadVNI); } // Find new undef uses. @@ -1133,11 +1127,10 @@ void RegisterCoalescer::updateRegDefsUses(unsigned SrcReg, ? LIS->getSlotIndexes()->getIndexBefore(UseMI) : LIS->getInstructionIndex(UseMI); SlotIndex UseIdx = MIIdx.getRegSlot(true); - for (LiveInterval::subrange_iterator S = DstInt->subrange_begin(), - SE = DstInt->subrange_end(); S != SE; ++S) { - if ((S->LaneMask & Mask) == 0) + for (LiveInterval::SubRange &S : DstInt->subranges()) { + if ((S.LaneMask & Mask) == 0) continue; - if (S->liveAt(UseIdx)) { + if (S.liveAt(UseIdx)) { IsUndef = false; break; } @@ -1252,12 +1245,11 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) { LI.MergeValueNumberInto(DefVNI, ReadVNI); // Process subregister liveranges. - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { - LiveQueryResult SLRQ = S->Query(CopyIdx); + for (LiveInterval::SubRange &S : LI.subranges()) { + LiveQueryResult SLRQ = S.Query(CopyIdx); if (VNInfo *SDefVNI = SLRQ.valueDefined()) { VNInfo *SReadVNI = SLRQ.valueIn(); - S->MergeValueNumberInto(SDefVNI, SReadVNI); + S.MergeValueNumberInto(SDefVNI, SReadVNI); } } DEBUG(dbgs() << "\tMerged values: " << LI << '\n'); @@ -1362,13 +1354,12 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) { // Shrink subregister ranges if necessary. if (ShrinkMask != 0) { LiveInterval &LI = LIS->getInterval(CP.getDstReg()); - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { - if ((S->LaneMask & ShrinkMask) == 0) + for (LiveInterval::SubRange &S : LI.subranges()) { + if ((S.LaneMask & ShrinkMask) == 0) continue; DEBUG(dbgs() << "Shrink LaneUses (Lane " - << format("%04X", S->LaneMask) << ")\n"); - LIS->shrinkToUses(*S, LI.reg); + << format("%04X", S.LaneMask) << ")\n"); + LIS->shrinkToUses(S, LI.reg); } } if (ShrinkMainRange) { @@ -2216,17 +2207,16 @@ void JoinVals::pruneSubRegValues(LiveInterval &LI, unsigned &ShrinkMask) // Check subranges at the point where the copy will be removed. SlotIndex Def = LR.getValNumInfo(i)->def; - for (LiveInterval::subrange_iterator I = LI.subrange_begin(), - E = LI.subrange_end(); I != E; ++I) { - LiveQueryResult Q = I->Query(Def); + for (LiveInterval::SubRange &S : LI.subranges()) { + LiveQueryResult Q = S.Query(Def); // If a subrange starts at the copy then an undefined value has been // copied and we must remove that subrange value as well. VNInfo *ValueOut = Q.valueOutOrDead(); 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"); - LIS->pruneValue(*I, Def, nullptr); + LIS->pruneValue(S, Def, nullptr); DidPrune = true; // Mark value number as unused. ValueOut->markUnused(); @@ -2236,8 +2226,8 @@ void JoinVals::pruneSubRegValues(LiveInterval &LI, unsigned &ShrinkMask) // partially used later. Shrink the subregister range apropriately. if (Q.valueIn() != nullptr && Q.valueOut() == nullptr) { DEBUG(dbgs() << "\t\tDead uses at sublane " - << format("%04X", I->LaneMask) << " at " << Def << "\n"); - ShrinkMask |= I->LaneMask; + << format("%04X", S.LaneMask) << " at " << Def << "\n"); + ShrinkMask |= S.LaneMask; } } } @@ -2333,9 +2323,8 @@ void RegisterCoalescer::mergeSubRangeInto(LiveInterval &LI, unsigned LaneMask, CoalescerPair &CP) { BumpPtrAllocator &Allocator = LIS->getVNInfoAllocator(); - for (LiveInterval::subrange_iterator R = LI.subrange_begin(), - RE = LI.subrange_end(); R != RE; ++R) { - unsigned RMask = R->LaneMask; + for (LiveInterval::SubRange &R : LI.subranges()) { + unsigned RMask = R.LaneMask; // LaneMask of subregisters common to subrange R and ToMerge. unsigned Common = RMask & LaneMask; // There is nothing to do without common subregs. @@ -2348,14 +2337,14 @@ void RegisterCoalescer::mergeSubRangeInto(LiveInterval &LI, unsigned LRest = RMask & ~LaneMask; LiveInterval::SubRange *CommonRange; if (LRest != 0) { - R->LaneMask = LRest; + R.LaneMask = LRest; DEBUG(dbgs() << format("\t\tReduce Lane to %04X\n", LRest)); // Duplicate SubRange for newly merged common stuff. - CommonRange = LI.createSubRangeFrom(Allocator, Common, *R); + CommonRange = LI.createSubRangeFrom(Allocator, Common, R); } else { // Reuse the existing range. - R->LaneMask = Common; - CommonRange = &*R; + R.LaneMask = Common; + CommonRange = &R; } LiveRange RangeCopy(ToMerge, Allocator); joinSubRegRanges(*CommonRange, RangeCopy, CP); @@ -2405,10 +2394,9 @@ bool RegisterCoalescer::joinVirtRegs(CoalescerPair &CP) { << ' ' << LHS << '\n'); } else if (DstIdx != 0) { // Transform LHS lanemasks to new register class if necessary. - for (LiveInterval::subrange_iterator R = LHS.subrange_begin(), - RE = LHS.subrange_end(); R != RE; ++R) { - unsigned DstMask = TRI->composeSubRegIndexLaneMask(DstIdx, R->LaneMask); - R->LaneMask = DstMask; + for (LiveInterval::SubRange &R : LHS.subranges()) { + unsigned DstMask = TRI->composeSubRegIndexLaneMask(DstIdx, R.LaneMask); + R.LaneMask = DstMask; } DEBUG(dbgs() << "\t\tLHST = " << PrintReg(CP.getDstReg()) << ' ' << LHS << '\n'); @@ -2425,19 +2413,18 @@ bool RegisterCoalescer::joinVirtRegs(CoalescerPair &CP) { mergeSubRangeInto(LHS, RHS, Mask, CP); } else { // Pair up subranges and merge. - for (LiveInterval::subrange_iterator R = RHS.subrange_begin(), - RE = RHS.subrange_end(); R != RE; ++R) { - unsigned RMask = R->LaneMask; + for (LiveInterval::SubRange &R : RHS.subranges()) { + unsigned RMask = R.LaneMask; if (SrcIdx != 0) { // Transform LaneMask of RHS subranges to the ones on LHS. RMask = TRI->composeSubRegIndexLaneMask(SrcIdx, RMask); DEBUG(dbgs() << "\t\tTransform RHS Mask " - << format("%04X", R->LaneMask) << " to subreg " + << format("%04X", R.LaneMask) << " to subreg " << TRI->getSubRegIndexName(SrcIdx) << " => " << 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 // be supported. #ifndef NDEBUG - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - E = LI.subrange_end(); S != E; ++S) { - assert ((S->LaneMask & ~MaxMask) == 0); + for (LiveInterval::SubRange &S : LI.subranges()) { + assert ((S.LaneMask & ~MaxMask) == 0); } #endif } diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index e9fb913e86c..7d3b0cea1c1 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -253,16 +253,15 @@ void VirtRegRewriter::addMBBLiveIns() { assert(PhysReg != VirtRegMap::NO_PHYS_REG && "Unmapped virtual register."); if (LI.hasSubRanges()) { - for (LiveInterval::subrange_iterator S = LI.subrange_begin(), - SE = LI.subrange_end(); S != SE; ++S) { - for (const auto &Seg : S->segments) { + for (LiveInterval::SubRange &S : LI.subranges()) { + for (const auto &Seg : S.segments) { if (!Indexes->findLiveInMBBs(Seg.start, Seg.end, LiveIn)) continue; for (MCSubRegIndexIterator SR(PhysReg, TRI); SR.isValid(); ++SR) { unsigned SubReg = SR.getSubReg(); unsigned SubRegIndex = SR.getSubRegIndex(); unsigned SubRegLaneMask = TRI->getSubRegIndexLaneMask(SubRegIndex); - if ((SubRegLaneMask & S->LaneMask) == 0) + if ((SubRegLaneMask & S.LaneMask) == 0) continue; for (unsigned i = 0, e = LiveIn.size(); i != e; ++i) { if (!LiveIn[i]->isLiveIn(SubReg)) -- 2.34.1