mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-28 06:24:57 +00:00
Better handle instructions that re-def a scratch register
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84657 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -778,6 +778,8 @@ void PEI::scavengeFrameVirtualRegs(MachineFunction &Fn) {
|
|||||||
// directly.
|
// directly.
|
||||||
for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
|
for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
|
||||||
MachineInstr *MI = I;
|
MachineInstr *MI = I;
|
||||||
|
bool isDefInsn = false;
|
||||||
|
bool isKillInsn = false;
|
||||||
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
|
||||||
if (MI->getOperand(i).isReg()) {
|
if (MI->getOperand(i).isReg()) {
|
||||||
MachineOperand &MO = MI->getOperand(i);
|
MachineOperand &MO = MI->getOperand(i);
|
||||||
@ -802,6 +804,12 @@ void PEI::scavengeFrameVirtualRegs(MachineFunction &Fn) {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// If this is a def, remember that this insn defines the value.
|
||||||
|
// This lets us properly consider insns which re-use the scratch
|
||||||
|
// register, such as r2 = sub r2, #imm, in the middle of the
|
||||||
|
// scratch range.
|
||||||
|
if (MO.isDef())
|
||||||
|
isDefInsn = true;
|
||||||
|
|
||||||
// Have we already allocated a scratch register for this virtual?
|
// Have we already allocated a scratch register for this virtual?
|
||||||
if (Reg != CurrentVirtReg) {
|
if (Reg != CurrentVirtReg) {
|
||||||
@ -866,19 +874,20 @@ void PEI::scavengeFrameVirtualRegs(MachineFunction &Fn) {
|
|||||||
assert (CurrentScratchReg && "Missing scratch register!");
|
assert (CurrentScratchReg && "Missing scratch register!");
|
||||||
MI->getOperand(i).setReg(CurrentScratchReg);
|
MI->getOperand(i).setReg(CurrentScratchReg);
|
||||||
|
|
||||||
// If this is the last use of the register, stop tracking it.
|
|
||||||
if (MI->getOperand(i).isKill()) {
|
if (MI->getOperand(i).isKill()) {
|
||||||
PrevScratchReg = CurrentScratchReg;
|
isKillInsn = true;
|
||||||
PrevLastUseMI = MI;
|
|
||||||
PrevLastUseOp = i;
|
PrevLastUseOp = i;
|
||||||
CurrentScratchReg = CurrentVirtReg = 0;
|
PrevLastUseMI = MI;
|
||||||
havePrevValue = trackingCurrentValue;
|
|
||||||
// Re-scan the operands of this instruction to catch definitions
|
|
||||||
// of the scratch register we're using. This is to handle things
|
|
||||||
// like ldr "r2, [scratch]" where scratch is r2.
|
|
||||||
i = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If this is the last use of the scratch, stop tracking it. The
|
||||||
|
// last use will be a kill operand in an instruction that does
|
||||||
|
// not also define the scratch register.
|
||||||
|
if (isKillInsn && !isDefInsn) {
|
||||||
|
PrevScratchReg = CurrentScratchReg;
|
||||||
|
CurrentScratchReg = CurrentVirtReg = 0;
|
||||||
|
havePrevValue = trackingCurrentValue;
|
||||||
|
}
|
||||||
RS->forward(MI);
|
RS->forward(MI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user