Skip to content

Commit d3dd135

Browse files
committed
LiveIntervalAnalysis: Factor common code into splitSeparateComponents; NFC
llvm-svn: 248241
1 parent 927a11e commit d3dd135

File tree

7 files changed

+61
-64
lines changed

7 files changed

+61
-64
lines changed

llvm/include/llvm/CodeGen/LiveInterval.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,12 @@ namespace llvm {
853853
/// the equivalence class assigned the VNI.
854854
unsigned getEqClass(const VNInfo *VNI) const { return EqClass[VNI->id]; }
855855

856-
/// Distribute - Distribute values in LIV[0] into a separate LiveInterval
857-
/// for each connected component. LIV must have a LiveInterval for each
858-
/// connected component. The LiveIntervals in Liv[1..] must be empty.
859-
/// Instructions using LIV[0] are rewritten.
860-
void Distribute(LiveInterval *LIV[], MachineRegisterInfo &MRI);
861-
856+
/// Distribute values in \p LI into a separate LiveIntervals
857+
/// for each connected component. LIV must have an empty LiveInterval for
858+
/// each additional connected component. The first connected component is
859+
/// left in \p LI.
860+
void Distribute(LiveInterval &LI, LiveInterval *LIV[],
861+
MachineRegisterInfo &MRI);
862862
};
863863

864864
}

llvm/include/llvm/CodeGen/LiveIntervalAnalysis.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ extern cl::opt<bool> UseSegmentSetForPhysRegs;
402402
/// that start at position @p Pos.
403403
void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos);
404404

405+
/// Split separate components in LiveInterval \p LI into separate intervals.
406+
void splitSeparateComponents(LiveInterval &LI,
407+
SmallVectorImpl<LiveInterval*> &SplitLIs);
408+
405409
private:
406410
/// Compute live intervals for all virtual registers.
407411
void computeVirtRegs();

llvm/lib/CodeGen/LiveInterval.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,11 +1372,8 @@ unsigned ConnectedVNInfoEqClasses::Classify(const LiveInterval *LI) {
13721372
return EqClass.getNumClasses();
13731373
}
13741374

1375-
void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[],
1375+
void ConnectedVNInfoEqClasses::Distribute(LiveInterval &LI, LiveInterval *LIV[],
13761376
MachineRegisterInfo &MRI) {
1377-
assert(LIV[0] && "LIV[0] must be set");
1378-
LiveInterval &LI = *LIV[0];
1379-
13801377
// Rewrite instructions.
13811378
for (MachineRegisterInfo::reg_iterator RI = MRI.reg_begin(LI.reg),
13821379
RE = MRI.reg_end(); RI != RE;) {
@@ -1398,7 +1395,8 @@ void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[],
13981395
// NULL. If the use is tied to a def, VNI will be the defined value.
13991396
if (!VNI)
14001397
continue;
1401-
MO.setReg(LIV[getEqClass(VNI)]->reg);
1398+
if (unsigned EqClass = getEqClass(VNI))
1399+
MO.setReg(LIV[EqClass-1]->reg);
14021400
}
14031401

14041402
// Move runs to new intervals.
@@ -1407,9 +1405,9 @@ void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[],
14071405
++J;
14081406
for (LiveInterval::iterator I = J; I != E; ++I) {
14091407
if (unsigned eq = EqClass[I->valno->id]) {
1410-
assert((LIV[eq]->empty() || LIV[eq]->expiredAt(I->start)) &&
1408+
assert((LIV[eq-1]->empty() || LIV[eq-1]->expiredAt(I->start)) &&
14111409
"New intervals should be empty");
1412-
LIV[eq]->segments.push_back(*I);
1410+
LIV[eq-1]->segments.push_back(*I);
14131411
} else
14141412
*J++ = *I;
14151413
}
@@ -1424,8 +1422,8 @@ void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[],
14241422
for (unsigned i = j; i != e; ++i) {
14251423
VNInfo *VNI = LI.getValNumInfo(i);
14261424
if (unsigned eq = EqClass[i]) {
1427-
VNI->id = LIV[eq]->getNumValNums();
1428-
LIV[eq]->valnos.push_back(VNI);
1425+
VNI->id = LIV[eq-1]->getNumValNums();
1426+
LIV[eq-1]->valnos.push_back(VNI);
14291427
} else {
14301428
VNI->id = j;
14311429
LI.valnos[j++] = VNI;

llvm/lib/CodeGen/LiveIntervalAnalysis.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,3 +1413,20 @@ void LiveIntervals::removeVRegDefAt(LiveInterval &LI, SlotIndex Pos) {
14131413
}
14141414
LI.removeEmptySubRanges();
14151415
}
1416+
1417+
void LiveIntervals::splitSeparateComponents(LiveInterval &LI,
1418+
SmallVectorImpl<LiveInterval*> &SplitLIs) {
1419+
ConnectedVNInfoEqClasses ConEQ(*this);
1420+
unsigned NumComp = ConEQ.Classify(&LI);
1421+
if (NumComp <= 1)
1422+
return;
1423+
DEBUG(dbgs() << " Split " << NumComp << " components: " << LI << '\n');
1424+
unsigned Reg = LI.reg;
1425+
const TargetRegisterClass *RegClass = MRI->getRegClass(Reg);
1426+
for (unsigned I = 1; I < NumComp; ++I) {
1427+
unsigned NewVReg = MRI->createVirtualRegister(RegClass);
1428+
LiveInterval &NewLI = createEmptyInterval(NewVReg);
1429+
SplitLIs.push_back(&NewLI);
1430+
}
1431+
ConEQ.Distribute(LI, SplitLIs.data(), *MRI);
1432+
}

llvm/lib/CodeGen/LiveRangeEdit.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,9 @@ void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead,
349349
ToShrink.pop_back();
350350
if (foldAsLoad(LI, Dead))
351351
continue;
352+
unsigned VReg = LI->reg;
352353
if (TheDelegate)
353-
TheDelegate->LRE_WillShrinkVirtReg(LI->reg);
354+
TheDelegate->LRE_WillShrinkVirtReg(VReg);
354355
if (!LIS.shrinkToUses(LI, &Dead))
355356
continue;
356357

@@ -360,7 +361,7 @@ void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead,
360361
// them results in incorrect code.
361362
bool BeingSpilled = false;
362363
for (unsigned i = 0, e = RegsBeingSpilled.size(); i != e; ++i) {
363-
if (LI->reg == RegsBeingSpilled[i]) {
364+
if (VReg == RegsBeingSpilled[i]) {
364365
BeingSpilled = true;
365366
break;
366367
}
@@ -370,29 +371,21 @@ void LiveRangeEdit::eliminateDeadDefs(SmallVectorImpl<MachineInstr*> &Dead,
370371

371372
// LI may have been separated, create new intervals.
372373
LI->RenumberValues();
373-
ConnectedVNInfoEqClasses ConEQ(LIS);
374-
unsigned NumComp = ConEQ.Classify(LI);
375-
if (NumComp <= 1)
376-
continue;
377-
++NumFracRanges;
378-
bool IsOriginal = VRM && VRM->getOriginal(LI->reg) == LI->reg;
379-
DEBUG(dbgs() << NumComp << " components: " << *LI << '\n');
380-
SmallVector<LiveInterval*, 8> Dups(1, LI);
381-
for (unsigned i = 1; i != NumComp; ++i) {
382-
Dups.push_back(&createEmptyIntervalFrom(LI->reg));
374+
SmallVector<LiveInterval*, 8> SplitLIs;
375+
LIS.splitSeparateComponents(*LI, SplitLIs);
376+
if (!SplitLIs.empty())
377+
++NumFracRanges;
378+
379+
unsigned Original = VRM ? VRM->getOriginal(VReg) : 0;
380+
for (const LiveInterval *SplitLI : SplitLIs) {
383381
// If LI is an original interval that hasn't been split yet, make the new
384382
// intervals their own originals instead of referring to LI. The original
385383
// interval must contain all the split products, and LI doesn't.
386-
if (IsOriginal)
387-
VRM->setIsSplitFromReg(Dups.back()->reg, 0);
384+
if (Original != VReg && Original != 0)
385+
VRM->setIsSplitFromReg(SplitLI->reg, Original);
388386
if (TheDelegate)
389-
TheDelegate->LRE_DidCloneVirtReg(Dups.back()->reg, LI->reg);
387+
TheDelegate->LRE_DidCloneVirtReg(SplitLI->reg, VReg);
390388
}
391-
ConEQ.Distribute(&Dups[0], MRI);
392-
DEBUG({
393-
for (unsigned i = 0; i != NumComp; ++i)
394-
dbgs() << '\t' << *Dups[i] << '\n';
395-
});
396389
}
397390
}
398391

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -224,30 +224,17 @@ namespace {
224224
/// Dst, we can drop \p Copy.
225225
bool applyTerminalRule(const MachineInstr &Copy) const;
226226

227-
/// Check whether or not \p LI is composed by multiple connected
228-
/// components and if that is the case, fix that.
229-
void splitNewRanges(LiveInterval *LI) {
230-
ConnectedVNInfoEqClasses ConEQ(*LIS);
231-
unsigned NumComps = ConEQ.Classify(LI);
232-
if (NumComps <= 1)
233-
return;
234-
SmallVector<LiveInterval*, 8> NewComps(1, LI);
235-
for (unsigned i = 1; i != NumComps; ++i) {
236-
unsigned VReg = MRI->createVirtualRegister(MRI->getRegClass(LI->reg));
237-
NewComps.push_back(&LIS->createEmptyInterval(VReg));
238-
}
239-
240-
ConEQ.Distribute(&NewComps[0], *MRI);
241-
}
242-
243227
/// Wrapper method for \see LiveIntervals::shrinkToUses.
244228
/// This method does the proper fixing of the live-ranges when the afore
245229
/// mentioned method returns true.
246230
void shrinkToUses(LiveInterval *LI,
247231
SmallVectorImpl<MachineInstr * > *Dead = nullptr) {
248-
if (LIS->shrinkToUses(LI, Dead))
249-
// We may have created multiple connected components, split them.
250-
splitNewRanges(LI);
232+
if (LIS->shrinkToUses(LI, Dead)) {
233+
/// Check whether or not \p LI is composed by multiple connected
234+
/// components and if that is the case, fix that.
235+
SmallVector<LiveInterval*, 8> SplitLIs;
236+
LIS->splitSeparateComponents(*LI, SplitLIs);
237+
}
251238
}
252239

253240
public:

llvm/lib/CodeGen/SplitKit.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,16 +1082,14 @@ void SplitEditor::finish(SmallVectorImpl<unsigned> *LRMap) {
10821082
ConnectedVNInfoEqClasses ConEQ(LIS);
10831083
for (unsigned i = 0, e = Edit->size(); i != e; ++i) {
10841084
// Don't use iterators, they are invalidated by create() below.
1085-
LiveInterval *li = &LIS.getInterval(Edit->get(i));
1086-
unsigned NumComp = ConEQ.Classify(li);
1087-
if (NumComp <= 1)
1088-
continue;
1089-
DEBUG(dbgs() << " " << NumComp << " components: " << *li << '\n');
1090-
SmallVector<LiveInterval*, 8> dups;
1091-
dups.push_back(li);
1092-
for (unsigned j = 1; j != NumComp; ++j)
1093-
dups.push_back(&Edit->createEmptyInterval());
1094-
ConEQ.Distribute(&dups[0], MRI);
1085+
unsigned VReg = Edit->get(i);
1086+
LiveInterval &LI = LIS.getInterval(VReg);
1087+
SmallVector<LiveInterval*, 8> SplitLIs;
1088+
LIS.splitSeparateComponents(LI, SplitLIs);
1089+
unsigned Original = VRM.getOriginal(VReg);
1090+
for (LiveInterval *SplitLI : SplitLIs)
1091+
VRM.setIsSplitFromReg(SplitLI->reg, Original);
1092+
10951093
// The new intervals all map back to i.
10961094
if (LRMap)
10971095
LRMap->resize(Edit->size(), i);

0 commit comments

Comments
 (0)