Remove the "fast" cases for spill and restore point determination, as these were subtlely wrong in obscure cases. Patch the testcase

to account for this change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68093 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2009-03-31 08:27:09 +00:00
parent 8fe00540fc
commit 696a1307ba
2 changed files with 60 additions and 127 deletions

View File

@ -232,69 +232,39 @@ PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI,
unsigned &SpillIndex) { unsigned &SpillIndex) {
MachineBasicBlock::iterator Pt = MBB->begin(); MachineBasicBlock::iterator Pt = MBB->begin();
// Go top down if RefsInMBB is empty.
if (RefsInMBB.empty() && !DefMI) {
MachineBasicBlock::iterator MII = MBB->begin();
MachineBasicBlock::iterator EndPt = MI;
if (MII == EndPt) return Pt;
do {
++MII;
unsigned Index = LIs->getInstructionIndex(MII);
unsigned Gap = LIs->findGapBeforeInstr(Index);
// We can't insert the spill between the barrier (a call), and its
// corresponding call frame setup/teardown.
if (prior(MII)->getOpcode() == TRI->getCallFrameSetupOpcode()) {
bool reachedBarrier = false;
do {
if (MII == EndPt) {
reachedBarrier = true;
break;
}
++MII;
} while (MII->getOpcode() != TRI->getCallFrameDestroyOpcode());
if (reachedBarrier) break;
} else if (Gap) {
Pt = MII;
SpillIndex = Gap;
break;
}
} while (MII != EndPt);
} else {
MachineBasicBlock::iterator MII = MI; MachineBasicBlock::iterator MII = MI;
MachineBasicBlock::iterator EndPt = DefMI MachineBasicBlock::iterator EndPt = DefMI
? MachineBasicBlock::iterator(DefMI) : MBB->begin(); ? MachineBasicBlock::iterator(DefMI) : MBB->begin();
while (MII != EndPt && !RefsInMBB.count(MII) &&
MII->getOpcode() != TRI->getCallFrameSetupOpcode())
--MII;
if (MII == EndPt || RefsInMBB.count(MII)) return Pt;
while (MII != EndPt && !RefsInMBB.count(MII)) { while (MII != EndPt && !RefsInMBB.count(MII)) {
unsigned Index = LIs->getInstructionIndex(MII); unsigned Index = LIs->getInstructionIndex(MII);
// We can't insert the spill between the barrier (a call), and its // We can't insert the spill between the barrier (a call), and its
// corresponding call frame setup. // corresponding call frame setup.
if (prior(MII)->getOpcode() == TRI->getCallFrameSetupOpcode()) { if (MII->getOpcode() == TRI->getCallFrameDestroyOpcode()) {
--MII;
continue;
} if (MII->getOpcode() == TRI->getCallFrameDestroyOpcode()) {
bool reachedBarrier = false;
while (MII->getOpcode() != TRI->getCallFrameSetupOpcode()) { while (MII->getOpcode() != TRI->getCallFrameSetupOpcode()) {
--MII; --MII;
if (MII == EndPt) { if (MII == EndPt) {
reachedBarrier = true; return Pt;
break;
} }
} }
continue;
if (reachedBarrier) break;
else continue;
} else if (LIs->hasGapBeforeInstr(Index)) { } else if (LIs->hasGapBeforeInstr(Index)) {
Pt = MII; Pt = MII;
SpillIndex = LIs->findGapBeforeInstr(Index, true); SpillIndex = LIs->findGapBeforeInstr(Index, true);
} }
if (RefsInMBB.count(MII))
return Pt;
--MII; --MII;
} }
}
return Pt; return Pt;
} }
@ -311,50 +281,23 @@ PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
// FIXME: Allow spill to be inserted to the beginning of the mbb. Update mbb // FIXME: Allow spill to be inserted to the beginning of the mbb. Update mbb
// begin index accordingly. // begin index accordingly.
MachineBasicBlock::iterator Pt = MBB->end(); MachineBasicBlock::iterator Pt = MBB->end();
unsigned EndIdx = LIs->getMBBEndIdx(MBB); MachineBasicBlock::iterator EndPt = MBB->getFirstTerminator();
// Go bottom up if RefsInMBB is empty and the end of the mbb isn't beyond
// the last index in the live range.
if (RefsInMBB.empty() && LastIdx >= EndIdx) {
MachineBasicBlock::iterator MII = MBB->getFirstTerminator();
MachineBasicBlock::iterator EndPt = MI;
// We start at the call, so walk forward until we find the call frame teardown
// since we can't insert restores before that. Bail if we encounter a use
// during this time.
MachineBasicBlock::iterator MII = MI;
if (MII == EndPt) return Pt; if (MII == EndPt) return Pt;
--MII; while (MII != EndPt && !RefsInMBB.count(MII) &&
do { MII->getOpcode() != TRI->getCallFrameDestroyOpcode())
unsigned Index = LIs->getInstructionIndex(MII); ++MII;
unsigned Gap = LIs->findGapBeforeInstr(Index); if (MII == EndPt || RefsInMBB.count(MII)) return Pt;
++MII;
// We can't insert a restore between the barrier (a call) and its
// corresponding call frame teardown.
if (MII->getOpcode() == TRI->getCallFrameDestroyOpcode()) {
bool reachedBarrier = false;
while (MII->getOpcode() != TRI->getCallFrameSetupOpcode()) {
--MII;
if (MII == EndPt) {
reachedBarrier = true;
break;
}
}
if (reachedBarrier) break;
else continue;
} else if (Gap) {
Pt = MII;
RestoreIndex = Gap;
break;
}
--MII;
} while (MII != EndPt);
} else {
MachineBasicBlock::iterator MII = MI;
MII = ++MII;
// FIXME: Limit the number of instructions to examine to reduce // FIXME: Limit the number of instructions to examine to reduce
// compile time? // compile time?
while (MII != MBB->getFirstTerminator()) { while (MII != EndPt) {
unsigned Index = LIs->getInstructionIndex(MII); unsigned Index = LIs->getInstructionIndex(MII);
if (Index > LastIdx) if (Index > LastIdx)
break; break;
@ -362,31 +305,21 @@ PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI,
// We can't insert a restore between the barrier (a call) and its // We can't insert a restore between the barrier (a call) and its
// corresponding call frame teardown. // corresponding call frame teardown.
if (MII->getOpcode() == TRI->getCallFrameDestroyOpcode()) { if (MII->getOpcode() == TRI->getCallFrameSetupOpcode()) {
++MII;
continue;
} else if (prior(MII)->getOpcode() == TRI->getCallFrameSetupOpcode()) {
bool reachedBarrier = false;
do { do {
if (MII == MBB->getFirstTerminator() || RefsInMBB.count(MII)) { if (MII == EndPt || RefsInMBB.count(MII)) return Pt;
reachedBarrier = true;
break;
}
++MII; ++MII;
} while (MII->getOpcode() != TRI->getCallFrameDestroyOpcode()); } while (MII->getOpcode() != TRI->getCallFrameDestroyOpcode());
if (reachedBarrier) break;
} else if (Gap) { } else if (Gap) {
Pt = MII; Pt = MII;
RestoreIndex = Gap; RestoreIndex = Gap;
} }
if (RefsInMBB.count(MII)) if (RefsInMBB.count(MII))
break; return Pt;
++MII; ++MII;
} }
}
return Pt; return Pt;
} }

View File

@ -1,5 +1,5 @@
; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 -pre-alloc-split -stats |& \ ; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 -pre-alloc-split -stats |& \
; RUN: grep {pre-alloc-split} | grep {Number of intervals split} | grep 4 ; RUN: grep {pre-alloc-split} | grep {Number of intervals split} | grep 2
define i32 @main(i32 %argc, i8** %argv) nounwind { define i32 @main(i32 %argc, i8** %argv) nounwind {
entry: entry: