[llvm-commits] [llvm] r61158 - /llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
Owen Anderson
resistor at mac.com
Wed Dec 17 14:07:01 PST 2008
Author: resistor
Date: Wed Dec 17 16:06:59 2008
New Revision: 61158
URL: http://llvm.org/viewvc/llvm-project?rev=61158&view=rev
Log:
Fix miscompilations caused by renumbering, and enable it as part of prealloc splitting.
Modified:
llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
Modified: llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp?rev=61158&r1=61157&r2=61158&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp (original)
+++ llvm/trunk/lib/CodeGen/PreAllocSplitting.cpp Wed Dec 17 16:06:59 2008
@@ -41,6 +41,7 @@
STATISTIC(NumSplits, "Number of intervals split");
STATISTIC(NumRemats, "Number of intervals split by rematerialization");
STATISTIC(NumFolds, "Number of intervals split with spill folding");
+STATISTIC(NumRenumbers, "Number of intervals renumbered into new registers");
namespace {
class VISIBILITY_HIDDEN PreAllocSplitting : public MachineFunctionPass {
@@ -137,7 +138,7 @@
void UpdateSpillSlotInterval(VNInfo*, unsigned, unsigned);
- void UpdateRegisterInterval(VNInfo*, unsigned, unsigned);
+ VNInfo* UpdateRegisterInterval(VNInfo*, unsigned, unsigned);
bool ShrinkWrapToLastUse(MachineBasicBlock*, VNInfo*,
SmallVector<MachineOperand*, 4>&,
@@ -409,7 +410,7 @@
/// UpdateRegisterInterval - Given the specified val# of the current live
/// interval is being split, and the spill and restore indices, update the live
/// interval accordingly.
-void
+VNInfo*
PreAllocSplitting::UpdateRegisterInterval(VNInfo *ValNo, unsigned SpillIndex,
unsigned RestoreIndex) {
assert(LIs->getMBBFromIndex(RestoreIndex) == BarrierMBB &&
@@ -512,6 +513,8 @@
unsigned End = After[i].second;
CurrLI->addRange(LiveRange(Start, End, AValNo));
}
+
+ return AValNo;
}
/// ShrinkWrapToLastUse - There are uses of the current live interval in the
@@ -700,17 +703,14 @@
ShrinkWrapLiveInterval(ValNo, BarrierMBB, NULL, DefMI->getParent(), Visited,
Uses, UseMIs, UseMBBs);
-#if 0
- if (!ValNo->hasPHIKill)
- RenumberValno();
-#endif
- // FIXME: If ValNo->hasPHIKill is false, then renumber the val# by
- // the restore.
-
// Remove live range from barrier to the restore. FIXME: Find a better
// point to re-start the live interval.
- UpdateRegisterInterval(ValNo, LIs->getUseIndex(BarrierIdx)+1,
- LIs->getDefIndex(RestoreIdx));
+ VNInfo* AfterValNo = UpdateRegisterInterval(ValNo,
+ LIs->getUseIndex(BarrierIdx)+1,
+ LIs->getDefIndex(RestoreIdx));
+ // Attempt to renumber the new valno into a new vreg.
+ if (!AfterValNo->hasPHIKill)
+ RenumberValno(AfterValNo);
}
/// RenumberValno - Split the given valno out into a new vreg, allowing it to
@@ -722,15 +722,41 @@
// Create the new vreg
unsigned NewVReg = MRI->createVirtualRegister(MRI->getRegClass(CurrLI->reg));
- // Copy over the valno and ranges
+ // Create the new live interval
LiveInterval& NewLI = LIs->getOrCreateInterval(NewVReg);
- VNInfo* NewVN = NewLI.getNextValue(VN->def, VN->copy,
- LIs->getVNInfoAllocator());
- NewLI.copyValNumInfo(NewVN, VN);
- NewLI.MergeValueInAsValue(*CurrLI, VN, NewVN);
+ SmallVector<VNInfo*, 4> VNsToCopy;
+ VNsToCopy.push_back(VN);
+
+ // Walk through and copy the valno we care about, and any other valnos
+ // that are two-address redefinitions of the one we care about. These
+ // will need to be rewritten as well.
+ while (!VNsToCopy.empty()) {
+ VNInfo* OldVN = VNsToCopy.back();
+ VNsToCopy.pop_back();
+
+ // Copy the valno over
+ VNInfo* NewVN = NewLI.getNextValue(OldVN->def, OldVN->copy,
+ LIs->getVNInfoAllocator());
+ NewLI.copyValNumInfo(NewVN, OldVN);
+ NewLI.MergeValueInAsValue(*CurrLI, OldVN, NewVN);
+
+ // Locate two-address redefinitions
+ for (SmallVector<unsigned, 4>::iterator KI = NewVN->kills.begin(),
+ KE = NewVN->kills.end(); KI != KE; ++KI) {
+ MachineInstr* MI = LIs->getInstructionFromIndex(*KI);
+ unsigned DefIdx = MI->findRegisterDefOperandIdx(CurrLI->reg);
+ if (DefIdx == ~0U) continue;
+ if (MI->isRegReDefinedByTwoAddr(DefIdx)) {
+ VNInfo* NextVN =
+ CurrLI->findDefinedVNInfo(LiveIntervals::getDefIndex(*KI));
+ VNsToCopy.push_back(NextVN);
+ }
+ }
+
+ // Remove the valno from the old interval
+ CurrLI->removeValNo(OldVN);
+ }
- // Remove the valno from the old interval
- CurrLI->removeValNo(VN);
// Rewrite defs and uses. This is done in two stages to avoid invalidating
// the reg_iterator.
@@ -753,6 +779,8 @@
MachineOperand& MO = Inst->getOperand(OpIdx);
MO.setReg(NewVReg);
}
+
+ NumRenumbers++;
}
bool PreAllocSplitting::Rematerialize(unsigned vreg, VNInfo* ValNo,
@@ -1097,8 +1125,6 @@
// Make sure blocks are numbered in order.
MF.RenumberBlocks();
-#if 1
- // FIXME: Go top down.
MachineBasicBlock *Entry = MF.begin();
SmallPtrSet<MachineBasicBlock*,16> Visited;
@@ -1117,22 +1143,6 @@
MadeChange |= SplitRegLiveIntervals(BarrierRCs);
}
}
-#else
- for (MachineFunction::reverse_iterator I = MF.rbegin(), E = MF.rend();
- I != E; ++I) {
- BarrierMBB = &*I;
- for (MachineBasicBlock::reverse_iterator II = BarrierMBB->rbegin(),
- EE = BarrierMBB->rend(); II != EE; ++II) {
- Barrier = &*II;
- const TargetRegisterClass **BarrierRCs =
- Barrier->getDesc().getRegClassBarriers();
- if (!BarrierRCs)
- continue;
- BarrierIdx = LIs->getInstructionIndex(Barrier);
- MadeChange |= SplitRegLiveIntervals(BarrierRCs);
- }
- }
-#endif
return MadeChange;
}
More information about the llvm-commits
mailing list