[llvm-commits] [llvm] r124799 - in /llvm/trunk/lib/CodeGen: RegAllocGreedy.cpp SplitKit.cpp SplitKit.h
Jakob Stoklund Olesen
stoklund at 2pi.dk
Thu Feb 3 09:04:16 PST 2011
Author: stoklund
Date: Thu Feb 3 11:04:16 2011
New Revision: 124799
URL: http://llvm.org/viewvc/llvm-project?rev=124799&view=rev
Log:
Return live range end points from SplitEditor::enter*/leave*.
These end points come from the inserted copies, and can be passed directly to
useIntv. This simplifies the coloring code.
Modified:
llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
llvm/trunk/lib/CodeGen/SplitKit.cpp
llvm/trunk/lib/CodeGen/SplitKit.h
Modified: llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp?rev=124799&r1=124798&r2=124799&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp Thu Feb 3 11:04:16 2011
@@ -680,16 +680,14 @@
}
if (!BI.LiveThrough) {
DEBUG(dbgs() << ", not live-through.\n");
- SE.enterIntvBefore(BI.Def);
- SE.useIntv(BI.Def, Stop);
+ SE.useIntv(SE.enterIntvBefore(BI.Def), Stop);
continue;
}
if (!RegIn) {
// Block is live-through, but entry bundle is on the stack.
// Reload just before the first use.
DEBUG(dbgs() << ", not live-in, enter before first use.\n");
- SE.enterIntvBefore(BI.FirstUse);
- SE.useIntv(BI.FirstUse, Stop);
+ SE.useIntv(SE.enterIntvBefore(BI.FirstUse), Stop);
continue;
}
DEBUG(dbgs() << ", live-through.\n");
@@ -713,8 +711,7 @@
SlotIndex Use = *UI;
DEBUG(dbgs() << ", free use at " << Use << ".\n");
assert(Use <= BI.LastUse && "Couldn't find last use");
- SE.enterIntvBefore(Use);
- SE.useIntv(Use, Stop);
+ SE.useIntv(SE.enterIntvBefore(Use), Stop);
continue;
}
@@ -759,16 +756,14 @@
}
if (!BI.LiveThrough) {
DEBUG(dbgs() << ", killed in block.\n");
- SE.useIntv(Start, BI.Kill.getBoundaryIndex());
- SE.leaveIntvAfter(BI.Kill);
+ SE.useIntv(Start, SE.leaveIntvAfter(BI.Kill));
continue;
}
if (!RegOut) {
// Block is live-through, but exit bundle is on the stack.
// Spill immediately after the last use.
DEBUG(dbgs() << ", uses, stack-out.\n");
- SE.useIntv(Start, BI.LastUse.getBoundaryIndex());
- SE.leaveIntvAfter(BI.LastUse);
+ SE.useIntv(Start, SE.leaveIntvAfter(BI.LastUse));
continue;
}
// Register is live-through.
@@ -794,8 +789,7 @@
SlotIndex Use = (--UI)->getBoundaryIndex();
DEBUG(dbgs() << ", free use at " << *UI << ".\n");
assert(Use >= BI.FirstUse && Use < IP.first);
- SE.useIntv(Start, Use);
- SE.leaveIntvAfter(Use);
+ SE.useIntv(Start, SE.leaveIntvAfter(Use));
continue;
}
@@ -875,6 +869,8 @@
SmallVector<LiveInterval*, 4> SpillRegs;
LiveRangeEdit LREdit(VirtReg, NewVRegs, SpillRegs);
SplitEditor(*SA, *LIS, *VRM, *DomTree, LREdit).splitSingleBlocks(Blocks);
+ if (VerifyEnabled)
+ MF->verify(this, "After splitting live range around basic blocks");
}
// Don't assign any physregs.
Modified: llvm/trunk/lib/CodeGen/SplitKit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SplitKit.cpp?rev=124799&r1=124798&r2=124799&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SplitKit.cpp (original)
+++ llvm/trunk/lib/CodeGen/SplitKit.cpp Thu Feb 3 11:04:16 2011
@@ -776,12 +776,6 @@
// Add minimal liveness for the new value.
Edit.get(RegIdx)->addRange(LiveRange(Def, Def.getNextSlot(), VNI));
-
- if (RegIdx) {
- if (UseIdx < Def)
- UseIdx = Def;
- RegAssign.insert(Def, UseIdx.getNextSlot(), RegIdx);
- }
return VNI;
}
@@ -803,38 +797,39 @@
LIMappers[OpenIdx].reset(Edit.get(OpenIdx));
}
-/// enterIntvBefore - Enter OpenLI before the instruction at Idx. If CurLI is
-/// not live before Idx, a COPY is not inserted.
-void SplitEditor::enterIntvBefore(SlotIndex Idx) {
+SlotIndex SplitEditor::enterIntvBefore(SlotIndex Idx) {
assert(OpenIdx && "openIntv not called before enterIntvBefore");
- Idx = Idx.getUseIndex();
DEBUG(dbgs() << " enterIntvBefore " << Idx);
+ Idx = Idx.getBaseIndex();
VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx);
if (!ParentVNI) {
DEBUG(dbgs() << ": not live\n");
- return;
+ return Idx;
}
- DEBUG(dbgs() << ": valno " << ParentVNI->id);
+ DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
MachineInstr *MI = LIS.getInstructionFromIndex(Idx);
assert(MI && "enterIntvBefore called with invalid index");
- defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI);
- DEBUG(dump());
+ VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Idx, *MI->getParent(), MI);
+ return VNI->def;
}
-/// enterIntvAtEnd - Enter OpenLI at the end of MBB.
-void SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
+SlotIndex SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
assert(OpenIdx && "openIntv not called before enterIntvAtEnd");
- SlotIndex End = LIS.getMBBEndIdx(&MBB).getPrevSlot();
- DEBUG(dbgs() << " enterIntvAtEnd BB#" << MBB.getNumber() << ", " << End);
- VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(End);
+ SlotIndex End = LIS.getMBBEndIdx(&MBB);
+ SlotIndex Last = End.getPrevSlot();
+ DEBUG(dbgs() << " enterIntvAtEnd BB#" << MBB.getNumber() << ", " << Last);
+ VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Last);
if (!ParentVNI) {
DEBUG(dbgs() << ": not live\n");
- return;
+ return End;
}
DEBUG(dbgs() << ": valno " << ParentVNI->id);
- defFromParent(OpenIdx, ParentVNI, End, MBB, MBB.getFirstTerminator());
+ VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB,
+ MBB.getFirstTerminator());
+ RegAssign.insert(VNI->def, End, OpenIdx);
DEBUG(dump());
+ return VNI->def;
}
/// useIntv - indicate that all instructions in MBB should use OpenLI.
@@ -849,8 +844,7 @@
DEBUG(dump());
}
-/// leaveIntvAfter - Leave OpenLI after the instruction at Idx.
-void SplitEditor::leaveIntvAfter(SlotIndex Idx) {
+SlotIndex SplitEditor::leaveIntvAfter(SlotIndex Idx) {
assert(OpenIdx && "openIntv not called before leaveIntvAfter");
DEBUG(dbgs() << " leaveIntvAfter " << Idx);
@@ -859,21 +853,17 @@
VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Idx);
if (!ParentVNI) {
DEBUG(dbgs() << ": not live\n");
- return;
+ return Idx.getNextSlot();
}
- DEBUG(dbgs() << ": valno " << ParentVNI->id);
+ DEBUG(dbgs() << ": valno " << ParentVNI->id << '\n');
MachineBasicBlock::iterator MII = LIS.getInstructionFromIndex(Idx);
VNInfo *VNI = defFromParent(0, ParentVNI, Idx,
*MII->getParent(), llvm::next(MII));
-
- RegAssign.insert(Idx, VNI->def, OpenIdx);
- DEBUG(dump());
+ return VNI->def;
}
-/// leaveIntvAtTop - Leave the interval at the top of MBB.
-/// Currently, only one value can leave the interval.
-void SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
+SlotIndex SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
assert(OpenIdx && "openIntv not called before leaveIntvAtTop");
SlotIndex Start = LIS.getMBBStartIdx(&MBB);
DEBUG(dbgs() << " leaveIntvAtTop BB#" << MBB.getNumber() << ", " << Start);
@@ -881,13 +871,14 @@
VNInfo *ParentVNI = Edit.getParent().getVNInfoAt(Start);
if (!ParentVNI) {
DEBUG(dbgs() << ": not live\n");
- return;
+ return Start;
}
VNInfo *VNI = defFromParent(0, ParentVNI, Start, MBB,
MBB.SkipPHIsAndLabels(MBB.begin()));
RegAssign.insert(Start, VNI->def, OpenIdx);
DEBUG(dump());
+ return VNI->def;
}
/// closeIntv - Indicate that we are done editing the currently open
@@ -1148,9 +1139,7 @@
assert(IP.first.isValid() && IP.second.isValid());
openIntv();
- enterIntvBefore(IP.first);
- useIntv(IP.first.getBaseIndex(), IP.second.getBoundaryIndex());
- leaveIntvAfter(IP.second);
+ useIntv(enterIntvBefore(IP.first), leaveIntvAfter(IP.second));
closeIntv();
}
finish();
@@ -1211,18 +1200,14 @@
// First interval before the gap. Don't create single-instr intervals.
if (bestPos > 1) {
openIntv();
- enterIntvBefore(Uses.front());
- useIntv(Uses.front().getBaseIndex(), Uses[bestPos-1].getBoundaryIndex());
- leaveIntvAfter(Uses[bestPos-1]);
+ useIntv(enterIntvBefore(Uses.front()), leaveIntvAfter(Uses[bestPos-1]));
closeIntv();
}
// Second interval after the gap.
if (bestPos < Uses.size()-1) {
openIntv();
- enterIntvBefore(Uses[bestPos]);
- useIntv(Uses[bestPos].getBaseIndex(), Uses.back().getBoundaryIndex());
- leaveIntvAfter(Uses.back());
+ useIntv(enterIntvBefore(Uses[bestPos]), leaveIntvAfter(Uses.back()));
closeIntv();
}
Modified: llvm/trunk/lib/CodeGen/SplitKit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SplitKit.h?rev=124799&r1=124798&r2=124799&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SplitKit.h (original)
+++ llvm/trunk/lib/CodeGen/SplitKit.h Thu Feb 3 11:04:16 2011
@@ -352,12 +352,15 @@
/// Create a new virtual register and live interval.
void openIntv();
- /// enterIntvBefore - Enter OpenLI before the instruction at Idx. If CurLI is
- /// not live before Idx, a COPY is not inserted.
- void enterIntvBefore(SlotIndex Idx);
-
- /// enterIntvAtEnd - Enter OpenLI at the end of MBB.
- void enterIntvAtEnd(MachineBasicBlock &MBB);
+ /// enterIntvBefore - Enter the open interval before the instruction at Idx.
+ /// If the parent interval is not live before Idx, a COPY is not inserted.
+ /// Return the beginning of the new live range.
+ SlotIndex enterIntvBefore(SlotIndex Idx);
+
+ /// enterIntvAtEnd - Enter the open interval at the end of MBB.
+ /// Use the open interval from he inserted copy to the MBB end.
+ /// Return the beginning of the new live range.
+ SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB);
/// useIntv - indicate that all instructions in MBB should use OpenLI.
void useIntv(const MachineBasicBlock &MBB);
@@ -365,12 +368,14 @@
/// useIntv - indicate that all instructions in range should use OpenLI.
void useIntv(SlotIndex Start, SlotIndex End);
- /// leaveIntvAfter - Leave OpenLI after the instruction at Idx.
- void leaveIntvAfter(SlotIndex Idx);
+ /// leaveIntvAfter - Leave the open interval after the instruction at Idx.
+ /// Return the end of the live range.
+ SlotIndex leaveIntvAfter(SlotIndex Idx);
/// leaveIntvAtTop - Leave the interval at the top of MBB.
- /// Currently, only one value can leave the interval.
- void leaveIntvAtTop(MachineBasicBlock &MBB);
+ /// Add liveness from the MBB top to the copy.
+ /// Return the end of the live range.
+ SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB);
/// closeIntv - Indicate that we are done editing the currently open
/// LiveInterval, and ranges can be trimmed.
More information about the llvm-commits
mailing list