summaryrefslogtreecommitdiff
path: root/lib/CodeGen/RegisterScavenging.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2009-10-25 00:45:07 +0000
committerJim Grosbach <grosbach@apple.com>2009-10-25 00:45:07 +0000
commit07d4964d1fc10a404f9bafd7c30b46322fe9293f (patch)
tree3f4fce2c00594d100462f7ea4f0b66d091406d5e /lib/CodeGen/RegisterScavenging.cpp
parent5639cb6b9e6fa5385c9dc6f877a062a136da5349 (diff)
downloadllvm-07d4964d1fc10a404f9bafd7c30b46322fe9293f.tar.gz
llvm-07d4964d1fc10a404f9bafd7c30b46322fe9293f.tar.bz2
llvm-07d4964d1fc10a404f9bafd7c30b46322fe9293f.tar.xz
When the scavenger is looking for a good candidate location to restore from a
spill, it should avoid doing so inside the live range of a virtual register. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85026 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/RegisterScavenging.cpp')
-rw-r--r--lib/CodeGen/RegisterScavenging.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/CodeGen/RegisterScavenging.cpp b/lib/CodeGen/RegisterScavenging.cpp
index 2518ce1520..1dca0a97da 100644
--- a/lib/CodeGen/RegisterScavenging.cpp
+++ b/lib/CodeGen/RegisterScavenging.cpp
@@ -227,7 +227,7 @@ unsigned RegScavenger::FindUnusedReg(const TargetRegisterClass *RC) const {
///
/// No more than InstrLimit instructions are inspected.
///
-unsigned RegScavenger::findSurvivorReg(MachineBasicBlock::iterator MI,
+unsigned RegScavenger::findSurvivorReg(MachineBasicBlock::iterator StartMI,
BitVector &Candidates,
unsigned InstrLimit,
MachineBasicBlock::iterator &UseMI) {
@@ -235,19 +235,37 @@ unsigned RegScavenger::findSurvivorReg(MachineBasicBlock::iterator MI,
assert(Survivor > 0 && "No candidates for scavenging");
MachineBasicBlock::iterator ME = MBB->getFirstTerminator();
- assert(MI != ME && "MI already at terminator");
+ assert(StartMI != ME && "MI already at terminator");
+ MachineBasicBlock::iterator RestorePointMI = StartMI;
+ MachineBasicBlock::iterator MI = StartMI;
+ bool inVirtLiveRange = false;
for (++MI; InstrLimit > 0 && MI != ME; ++MI, --InstrLimit) {
+ bool isVirtKillInsn = false;
+ bool isVirtDefInsn = false;
// Remove any candidates touched by instruction.
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
const MachineOperand &MO = MI->getOperand(i);
- if (!MO.isReg() || MO.isUndef() || !MO.getReg() ||
- TargetRegisterInfo::isVirtualRegister(MO.getReg()))
+ if (!MO.isReg() || MO.isUndef() || !MO.getReg())
continue;
+ if (TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
+ if (MO.isDef())
+ isVirtDefInsn = true;
+ else if (MO.isKill())
+ isVirtKillInsn = true;
+ continue;
+ }
Candidates.reset(MO.getReg());
for (const unsigned *R = TRI->getAliasSet(MO.getReg()); *R; R++)
Candidates.reset(*R);
}
+ // If we're not in a virtual reg's live range, this is a valid
+ // restore point.
+ if (!inVirtLiveRange) RestorePointMI = MI;
+
+ // Update whether we're in the live range of a virtual register
+ if (isVirtKillInsn) inVirtLiveRange = false;
+ if (isVirtDefInsn) inVirtLiveRange = true;
// Was our survivor untouched by this instruction?
if (Candidates.test(Survivor))
@@ -259,9 +277,13 @@ unsigned RegScavenger::findSurvivorReg(MachineBasicBlock::iterator MI,
Survivor = Candidates.find_first();
}
+ // If we ran off the end, that's where we want to restore.
+ if (MI == ME) RestorePointMI = ME;
+ assert (RestorePointMI != StartMI &&
+ "No available scavenger restore location!");
// We ran out of candidates, so stop the search.
- UseMI = MI;
+ UseMI = RestorePointMI;
return Survivor;
}