forked from OSchip/llvm-project
LiveInterval: Use more range based for loops for value numbers and segments.
llvm-svn: 223978
This commit is contained in:
parent
52276536f8
commit
96761959d4
|
@ -218,14 +218,12 @@ namespace llvm {
|
|||
/// another LiveRange.
|
||||
LiveRange(const LiveRange &Other, BumpPtrAllocator &Allocator) {
|
||||
// Duplicate valnos.
|
||||
for (LiveRange::const_vni_iterator I = Other.vni_begin(),
|
||||
E = Other.vni_end(); I != E; ++I) {
|
||||
createValueCopy(*I, Allocator);
|
||||
for (const VNInfo *VNI : Other.valnos) {
|
||||
createValueCopy(VNI, Allocator);
|
||||
}
|
||||
// Now we can copy segments and remap their valnos.
|
||||
for (LiveRange::const_iterator I = Other.begin(), E = Other.end();
|
||||
I != E; ++I) {
|
||||
segments.push_back(Segment(I->start, I->end, valnos[I->valno->id]));
|
||||
for (const Segment &S : Other.segments) {
|
||||
segments.push_back(Segment(S.start, S.end, valnos[S.valno->id]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -523,9 +521,9 @@ namespace llvm {
|
|||
/// Returns true if the live range is zero length, i.e. no live segments
|
||||
/// span instructions. It doesn't pay to spill such a range.
|
||||
bool isZeroLength(SlotIndexes *Indexes) const {
|
||||
for (const_iterator i = begin(), e = end(); i != e; ++i)
|
||||
if (Indexes->getNextNonNullIndex(i->start).getBaseIndex() <
|
||||
i->end.getBaseIndex())
|
||||
for (const Segment &S : segments)
|
||||
if (Indexes->getNextNonNullIndex(S.start).getBaseIndex() <
|
||||
S.end.getBaseIndex())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -191,13 +191,13 @@ bool LiveRange::covers(const LiveRange &Other) const {
|
|||
return Other.empty();
|
||||
|
||||
const_iterator I = begin();
|
||||
for (const_iterator O = Other.begin(), OE = Other.end(); O != OE; ++O) {
|
||||
I = advanceTo(I, O->start);
|
||||
if (I == end() || I->start > O->start)
|
||||
for (const Segment &O : Other.segments) {
|
||||
I = advanceTo(I, O.start);
|
||||
if (I == end() || I->start > O.start)
|
||||
return false;
|
||||
|
||||
// Check adjacent live segments and see if we can get behind O->end.
|
||||
while (I->end < O->end) {
|
||||
// Check adjacent live segments and see if we can get behind O.end.
|
||||
while (I->end < O.end) {
|
||||
const_iterator Last = I;
|
||||
// Get next segment and abort if it was not adjacent.
|
||||
++I;
|
||||
|
@ -226,8 +226,8 @@ void LiveRange::markValNoForDeletion(VNInfo *ValNo) {
|
|||
void LiveRange::RenumberValues() {
|
||||
SmallPtrSet<VNInfo*, 8> Seen;
|
||||
valnos.clear();
|
||||
for (const_iterator I = begin(), E = end(); I != E; ++I) {
|
||||
VNInfo *VNI = I->valno;
|
||||
for (const Segment &S : segments) {
|
||||
VNInfo *VNI = S.valno;
|
||||
if (!Seen.insert(VNI).second)
|
||||
continue;
|
||||
assert(!VNI->isUnused() && "Unused valno used by live segment");
|
||||
|
@ -483,8 +483,8 @@ void LiveRange::join(LiveRange &Other,
|
|||
// This can leave Other in an invalid state because we're not coalescing
|
||||
// touching segments that now have identical values. That's OK since Other is
|
||||
// not supposed to be valid after calling join();
|
||||
for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
|
||||
I->valno = NewVNInfo[RHSValNoAssignments[I->valno->id]];
|
||||
for (Segment &S : Other.segments)
|
||||
S.valno = NewVNInfo[RHSValNoAssignments[S.valno->id]];
|
||||
|
||||
// Update val# info. Renumber them and make sure they all belong to this
|
||||
// LiveRange now. Also remove dead val#'s.
|
||||
|
@ -504,8 +504,8 @@ void LiveRange::join(LiveRange &Other,
|
|||
|
||||
// Okay, now insert the RHS live segments into the LHS.
|
||||
LiveRangeUpdater Updater(this);
|
||||
for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
|
||||
Updater.add(*I);
|
||||
for (Segment &S : Other.segments)
|
||||
Updater.add(S);
|
||||
}
|
||||
|
||||
/// Merge all of the segments in RHS into this live range as the specified
|
||||
|
@ -515,8 +515,8 @@ void LiveRange::join(LiveRange &Other,
|
|||
void LiveRange::MergeSegmentsInAsValue(const LiveRange &RHS,
|
||||
VNInfo *LHSValNo) {
|
||||
LiveRangeUpdater Updater(this);
|
||||
for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I)
|
||||
Updater.add(I->start, I->end, LHSValNo);
|
||||
for (const Segment &S : RHS.segments)
|
||||
Updater.add(S.start, S.end, LHSValNo);
|
||||
}
|
||||
|
||||
/// MergeValueInAsValue - Merge all of the live segments of a specific val#
|
||||
|
@ -528,9 +528,9 @@ void LiveRange::MergeValueInAsValue(const LiveRange &RHS,
|
|||
const VNInfo *RHSValNo,
|
||||
VNInfo *LHSValNo) {
|
||||
LiveRangeUpdater Updater(this);
|
||||
for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I)
|
||||
if (I->valno == RHSValNo)
|
||||
Updater.add(I->start, I->end, LHSValNo);
|
||||
for (const Segment &S : RHS.segments)
|
||||
if (S.valno == RHSValNo)
|
||||
Updater.add(S.start, S.end, LHSValNo);
|
||||
}
|
||||
|
||||
/// MergeValueNumberInto - This method is called when two value nubmers
|
||||
|
@ -611,8 +611,8 @@ void LiveInterval::removeEmptySubRanges() {
|
|||
|
||||
unsigned LiveInterval::getSize() const {
|
||||
unsigned Sum = 0;
|
||||
for (const_iterator I = begin(), E = end(); I != E; ++I)
|
||||
Sum += I->start.distance(I->end);
|
||||
for (const Segment &S : segments)
|
||||
Sum += S.start.distance(S.end);
|
||||
return Sum;
|
||||
}
|
||||
|
||||
|
@ -630,9 +630,9 @@ void LiveRange::print(raw_ostream &OS) const {
|
|||
if (empty())
|
||||
OS << "EMPTY";
|
||||
else {
|
||||
for (const_iterator I = begin(), E = end(); I != E; ++I) {
|
||||
OS << *I;
|
||||
assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
|
||||
for (const Segment &S : segments) {
|
||||
OS << S;
|
||||
assert(S.valno == getValNumInfo(S.valno->id) && "Bad VNInfo");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -757,14 +757,14 @@ void LiveRangeUpdater::print(raw_ostream &OS) const {
|
|||
OS << " updater with gap = " << (ReadI - WriteI)
|
||||
<< ", last start = " << LastStart
|
||||
<< ":\n Area 1:";
|
||||
for (LiveRange::const_iterator I = LR->begin(); I != WriteI; ++I)
|
||||
OS << ' ' << *I;
|
||||
for (const auto &S : make_range(LR->begin(), WriteI))
|
||||
OS << ' ' << S;
|
||||
OS << "\n Spills:";
|
||||
for (unsigned I = 0, E = Spills.size(); I != E; ++I)
|
||||
OS << ' ' << Spills[I];
|
||||
OS << "\n Area 2:";
|
||||
for (LiveRange::const_iterator I = ReadI, E = LR->end(); I != E; ++I)
|
||||
OS << ' ' << *I;
|
||||
for (const auto &S : make_range(ReadI, LR->end()))
|
||||
OS << ' ' << S;
|
||||
OS << '\n';
|
||||
}
|
||||
|
||||
|
@ -925,9 +925,7 @@ unsigned ConnectedVNInfoEqClasses::Classify(const LiveInterval *LI) {
|
|||
const VNInfo *used = nullptr, *unused = nullptr;
|
||||
|
||||
// Determine connections.
|
||||
for (LiveInterval::const_vni_iterator I = LI->vni_begin(), E = LI->vni_end();
|
||||
I != E; ++I) {
|
||||
const VNInfo *VNI = *I;
|
||||
for (const VNInfo *VNI : LI->valnos) {
|
||||
// Group all unused values into one class.
|
||||
if (VNI->isUnused()) {
|
||||
if (unused)
|
||||
|
|
|
@ -449,7 +449,7 @@ void LiveIntervals::computeDeadValues(LiveRange &Segments, LiveRange &LR,
|
|||
bool *CanSeparateRes, unsigned Reg,
|
||||
SmallVectorImpl<MachineInstr*> *dead) {
|
||||
bool CanSeparate = false;
|
||||
for (auto VNI : make_range(LR.vni_begin(), LR.vni_end())) {
|
||||
for (auto VNI : LR.valnos) {
|
||||
if (VNI->isUnused())
|
||||
continue;
|
||||
LiveRange::iterator LRI = Segments.FindSegmentContaining(VNI->def);
|
||||
|
@ -729,9 +729,7 @@ LiveIntervals::intervalIsInOneMBB(const LiveInterval &LI) const {
|
|||
|
||||
bool
|
||||
LiveIntervals::hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const {
|
||||
for (LiveInterval::const_vni_iterator I = LI.vni_begin(), E = LI.vni_end();
|
||||
I != E; ++I) {
|
||||
const VNInfo *PHI = *I;
|
||||
for (const VNInfo *PHI : LI.valnos) {
|
||||
if (PHI->isUnused() || !PHI->isPHIDef())
|
||||
continue;
|
||||
const MachineBasicBlock *PHIMBB = getMBBFromIndex(PHI->def);
|
||||
|
|
|
@ -60,9 +60,7 @@ bool LiveRangeEdit::checkRematerializable(VNInfo *VNI,
|
|||
}
|
||||
|
||||
void LiveRangeEdit::scanRemattable(AliasAnalysis *aa) {
|
||||
for (LiveInterval::vni_iterator I = getParent().vni_begin(),
|
||||
E = getParent().vni_end(); I != E; ++I) {
|
||||
VNInfo *VNI = *I;
|
||||
for (VNInfo *VNI : getParent().valnos) {
|
||||
if (VNI->isUnused())
|
||||
continue;
|
||||
MachineInstr *DefMI = LIS.getInstructionFromIndex(VNI->def);
|
||||
|
|
|
@ -1643,9 +1643,8 @@ void MachineVerifier::verifyLiveRangeSegment(const LiveRange &LR,
|
|||
|
||||
void MachineVerifier::verifyLiveRange(const LiveRange &LR, unsigned Reg,
|
||||
unsigned LaneMask) {
|
||||
for (LiveRange::const_vni_iterator I = LR.vni_begin(), E = LR.vni_end();
|
||||
I != E; ++I)
|
||||
verifyLiveRangeValue(LR, *I, Reg, LaneMask);
|
||||
for (const VNInfo *VNI : LR.valnos)
|
||||
verifyLiveRangeValue(LR, VNI, Reg, LaneMask);
|
||||
|
||||
for (LiveRange::const_iterator I = LR.begin(), E = LR.end(); I != E; ++I)
|
||||
verifyLiveRangeSegment(LR, I, Reg, LaneMask);
|
||||
|
|
|
@ -554,19 +554,18 @@ bool RegisterCoalescer::hasOtherReachingDefs(LiveInterval &IntA,
|
|||
if (LIS->hasPHIKill(IntA, AValNo))
|
||||
return true;
|
||||
|
||||
for (LiveInterval::iterator AI = IntA.begin(), AE = IntA.end();
|
||||
AI != AE; ++AI) {
|
||||
if (AI->valno != AValNo) continue;
|
||||
for (LiveRange::Segment &ASeg : IntA.segments) {
|
||||
if (ASeg.valno != AValNo) continue;
|
||||
LiveInterval::iterator BI =
|
||||
std::upper_bound(IntB.begin(), IntB.end(), AI->start);
|
||||
std::upper_bound(IntB.begin(), IntB.end(), ASeg.start);
|
||||
if (BI != IntB.begin())
|
||||
--BI;
|
||||
for (; BI != IntB.end() && AI->end >= BI->start; ++BI) {
|
||||
for (; BI != IntB.end() && ASeg.end >= BI->start; ++BI) {
|
||||
if (BI->valno == BValNo)
|
||||
continue;
|
||||
if (BI->start <= AI->start && BI->end > AI->start)
|
||||
if (BI->start <= ASeg.start && BI->end > ASeg.start)
|
||||
return true;
|
||||
if (BI->start > AI->start && BI->start < AI->end)
|
||||
if (BI->start > ASeg.start && BI->start < ASeg.end)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -578,10 +577,10 @@ bool RegisterCoalescer::hasOtherReachingDefs(LiveInterval &IntA,
|
|||
static void addSegmentsWithValNo(LiveRange &Dst, VNInfo *DstValNo,
|
||||
const LiveRange &Src, const VNInfo *SrcValNo)
|
||||
{
|
||||
for (LiveRange::const_iterator I = Src.begin(), E = Src.end(); I != E; ++I) {
|
||||
if (I->valno != SrcValNo)
|
||||
for (const LiveRange::Segment &S : Src.segments) {
|
||||
if (S.valno != SrcValNo)
|
||||
continue;
|
||||
Dst.addSegment(LiveRange::Segment(I->start, I->end, DstValNo));
|
||||
Dst.addSegment(LiveRange::Segment(S.start, S.end, DstValNo));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,10 +120,9 @@ void SplitAnalysis::analyzeUses() {
|
|||
|
||||
// First get all the defs from the interval values. This provides the correct
|
||||
// slots for early clobbers.
|
||||
for (LiveInterval::const_vni_iterator I = CurLI->vni_begin(),
|
||||
E = CurLI->vni_end(); I != E; ++I)
|
||||
if (!(*I)->isPHIDef() && !(*I)->isUnused())
|
||||
UseSlots.push_back((*I)->def);
|
||||
for (const VNInfo *VNI : CurLI->valnos)
|
||||
if (!VNI->isPHIDef() && !VNI->isUnused())
|
||||
UseSlots.push_back(VNI->def);
|
||||
|
||||
// Get use slots form the use-def chain.
|
||||
const MachineRegisterInfo &MRI = MF.getRegInfo();
|
||||
|
@ -727,9 +726,7 @@ void SplitEditor::hoistCopiesForSize() {
|
|||
|
||||
// Find the nearest common dominator for parent values with multiple
|
||||
// back-copies. If a single back-copy dominates, put it in DomPair.second.
|
||||
for (LiveInterval::vni_iterator VI = LI->vni_begin(), VE = LI->vni_end();
|
||||
VI != VE; ++VI) {
|
||||
VNInfo *VNI = *VI;
|
||||
for (VNInfo *VNI : LI->valnos) {
|
||||
if (VNI->isUnused())
|
||||
continue;
|
||||
VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
|
||||
|
@ -802,9 +799,7 @@ void SplitEditor::hoistCopiesForSize() {
|
|||
// Remove redundant back-copies that are now known to be dominated by another
|
||||
// def with the same value.
|
||||
SmallVector<VNInfo*, 8> BackCopies;
|
||||
for (LiveInterval::vni_iterator VI = LI->vni_begin(), VE = LI->vni_end();
|
||||
VI != VE; ++VI) {
|
||||
VNInfo *VNI = *VI;
|
||||
for (VNInfo *VNI : LI->valnos) {
|
||||
if (VNI->isUnused())
|
||||
continue;
|
||||
VNInfo *ParentVNI = Edit->getParent().getVNInfoAt(VNI->def);
|
||||
|
@ -823,16 +818,15 @@ void SplitEditor::hoistCopiesForSize() {
|
|||
bool SplitEditor::transferValues() {
|
||||
bool Skipped = false;
|
||||
RegAssignMap::const_iterator AssignI = RegAssign.begin();
|
||||
for (LiveInterval::const_iterator ParentI = Edit->getParent().begin(),
|
||||
ParentE = Edit->getParent().end(); ParentI != ParentE; ++ParentI) {
|
||||
DEBUG(dbgs() << " blit " << *ParentI << ':');
|
||||
VNInfo *ParentVNI = ParentI->valno;
|
||||
for (const LiveRange::Segment &S : Edit->getParent()) {
|
||||
DEBUG(dbgs() << " blit " << S << ':');
|
||||
VNInfo *ParentVNI = S.valno;
|
||||
// RegAssign has holes where RegIdx 0 should be used.
|
||||
SlotIndex Start = ParentI->start;
|
||||
SlotIndex Start = S.start;
|
||||
AssignI.advanceTo(Start);
|
||||
do {
|
||||
unsigned RegIdx;
|
||||
SlotIndex End = ParentI->end;
|
||||
SlotIndex End = S.end;
|
||||
if (!AssignI.valid()) {
|
||||
RegIdx = 0;
|
||||
} else if (AssignI.start() <= Start) {
|
||||
|
@ -917,7 +911,7 @@ bool SplitEditor::transferValues() {
|
|||
++MBB;
|
||||
}
|
||||
Start = End;
|
||||
} while (Start != ParentI->end);
|
||||
} while (Start != S.end);
|
||||
DEBUG(dbgs() << '\n');
|
||||
}
|
||||
|
||||
|
@ -930,9 +924,7 @@ bool SplitEditor::transferValues() {
|
|||
|
||||
void SplitEditor::extendPHIKillRanges() {
|
||||
// Extend live ranges to be live-out for successor PHI values.
|
||||
for (LiveInterval::const_vni_iterator I = Edit->getParent().vni_begin(),
|
||||
E = Edit->getParent().vni_end(); I != E; ++I) {
|
||||
const VNInfo *PHIVNI = *I;
|
||||
for (const VNInfo *PHIVNI : Edit->getParent().valnos) {
|
||||
if (PHIVNI->isUnused() || !PHIVNI->isPHIDef())
|
||||
continue;
|
||||
unsigned RegIdx = RegAssign.lookup(PHIVNI->def);
|
||||
|
@ -1006,12 +998,11 @@ void SplitEditor::deleteRematVictims() {
|
|||
SmallVector<MachineInstr*, 8> Dead;
|
||||
for (LiveRangeEdit::iterator I = Edit->begin(), E = Edit->end(); I != E; ++I){
|
||||
LiveInterval *LI = &LIS.getInterval(*I);
|
||||
for (LiveInterval::const_iterator LII = LI->begin(), LIE = LI->end();
|
||||
LII != LIE; ++LII) {
|
||||
for (const LiveRange::Segment &S : LI->segments) {
|
||||
// Dead defs end at the dead slot.
|
||||
if (LII->end != LII->valno->def.getDeadSlot())
|
||||
if (S.end != S.valno->def.getDeadSlot())
|
||||
continue;
|
||||
MachineInstr *MI = LIS.getInstructionFromIndex(LII->valno->def);
|
||||
MachineInstr *MI = LIS.getInstructionFromIndex(S.valno->def);
|
||||
assert(MI && "Missing instruction for dead def");
|
||||
MI->addRegisterDead(LI->reg, &TRI);
|
||||
|
||||
|
@ -1036,9 +1027,7 @@ void SplitEditor::finish(SmallVectorImpl<unsigned> *LRMap) {
|
|||
// the inserted copies.
|
||||
|
||||
// Add the original defs from the parent interval.
|
||||
for (LiveInterval::const_vni_iterator I = Edit->getParent().vni_begin(),
|
||||
E = Edit->getParent().vni_end(); I != E; ++I) {
|
||||
const VNInfo *ParentVNI = *I;
|
||||
for (const VNInfo *ParentVNI : Edit->getParent().valnos) {
|
||||
if (ParentVNI->isUnused())
|
||||
continue;
|
||||
unsigned RegIdx = RegAssign.lookup(ParentVNI->def);
|
||||
|
|
|
@ -255,9 +255,8 @@ void VirtRegRewriter::addMBBLiveIns() {
|
|||
if (LI.hasSubRanges()) {
|
||||
for (LiveInterval::subrange_iterator S = LI.subrange_begin(),
|
||||
SE = LI.subrange_end(); S != SE; ++S) {
|
||||
for (LiveRange::const_iterator I = S->begin(), E = S->end(); I != E;
|
||||
++I) {
|
||||
if (!Indexes->findLiveInMBBs(I->start, I->end, LiveIn))
|
||||
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();
|
||||
|
@ -275,9 +274,8 @@ void VirtRegRewriter::addMBBLiveIns() {
|
|||
}
|
||||
} else {
|
||||
// Scan the segments of LI.
|
||||
for (LiveInterval::const_iterator I = LI.begin(), E = LI.end(); I != E;
|
||||
++I) {
|
||||
if (!Indexes->findLiveInMBBs(I->start, I->end, LiveIn))
|
||||
for (const auto &Seg : LI.segments) {
|
||||
if (!Indexes->findLiveInMBBs(Seg.start, Seg.end, LiveIn))
|
||||
continue;
|
||||
for (unsigned i = 0, e = LiveIn.size(); i != e; ++i)
|
||||
if (!LiveIn[i]->isLiveIn(PhysReg))
|
||||
|
|
Loading…
Reference in New Issue