summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2004-06-29 17:14:42 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2004-06-29 17:14:42 +0000
commit802403723b6c4176b8008797ed4523681e636474 (patch)
tree8608363adc8f10a0477d98725880fd49c215c612
parent811f5c2c4cf9be1059480c6be6769861cae43149 (diff)
downloadbcm5719-llvm-802403723b6c4176b8008797ed4523681e636474.tar.gz
bcm5719-llvm-802403723b6c4176b8008797ed4523681e636474.zip
* Fix saving LR in function prologue
* Adjust epilogue restore sequence to match the PowerPC documentation llvm-svn: 14480
-rw-r--r--llvm/lib/Target/PowerPC/PowerPCRegisterInfo.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Target/PowerPC/PowerPCRegisterInfo.cpp b/llvm/lib/Target/PowerPC/PowerPCRegisterInfo.cpp
index 30776dd2599..c7a1879e6d6 100644
--- a/llvm/lib/Target/PowerPC/PowerPCRegisterInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PowerPCRegisterInfo.cpp
@@ -167,7 +167,7 @@ PowerPCRegisterInfo::eliminateFrameIndex(MachineFunction &MF,
if (!hasFP(MF))
Offset += MF.getFrameInfo()->getStackSize();
- MI.SetMachineOperandConst(i-1, MachineOperand::MO_SignExtendedImmed, Offset);
+ MI.SetMachineOperandConst(i, MachineOperand::MO_SignExtendedImmed, Offset);
DEBUG(std::cerr << "offset = " << Offset << std::endl);
}
@@ -200,9 +200,10 @@ void PowerPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
NumBytes = ((NumBytes+4)+Align-1)/Align*Align - 4;
// Store the incoming LR so it is preserved across calls
- MI = BuildMI(PPC32::MovePCtoLR, 0, PPC32::LR).addReg(PPC32::LR);
+ MI = BuildMI(PPC32::MFLR, 0, PPC32::R0);
MBB.insert(MBBI, MI);
- MI = BuildMI(PPC32::MFSPR, 1, PPC32::R0).addImm(8);
+ MI = BuildMI(PPC32::STW, 3).addReg(PPC32::R31).addSImm(-4)
+ .addReg(PPC32::R1);
MBB.insert(MBBI, MI);
MI = BuildMI(PPC32::STW, 3).addReg(PPC32::R0).addSImm(8).addReg(PPC32::R1);
MBB.insert(MBBI, MI);
@@ -229,18 +230,22 @@ void PowerPCRegisterInfo::emitEpilogue(MachineFunction &MF,
// Get the number of bytes allocated from the FrameInfo...
unsigned NumBytes = MFI->getStackSize();
- // adjust stack pointer back: r1 += numbytes
+ // Read old LR from stack into R0
+ MI = BuildMI(PPC32::LWZ, 2, PPC32::R0).addSImm(8+NumBytes).addReg(PPC32::R1);
+ MBB.insert(MBBI, MI);
+
+ // Adjust stack pointer back: r1 += numbytes
if (NumBytes) {
- MI =BuildMI(PPC32::ADDI, 2, PPC32::R1).addReg(PPC32::R1).addSImm(NumBytes);
+ MI = BuildMI(PPC32::ADDI, 2, PPC32::R1).addReg(PPC32::R1).addSImm(NumBytes);
MBB.insert(MBBI, MI);
}
// If we have calls, restore the LR value before we branch to it
if (MFI->hasCalls()) {
- MI = BuildMI(PPC32::LWZ, 2, PPC32::R0).addSImm(8).addReg(PPC32::R1);
- MBB.insert(MBBI, MI);
MI = BuildMI(PPC32::MTLR, 1).addReg(PPC32::R0);
MBB.insert(MBBI, MI);
+ MI = BuildMI(PPC32::LWZ, 2, PPC32::R31).addSImm(-4).addReg(PPC32::R1);
+ MBB.insert(MBBI, MI);
}
}
OpenPOWER on IntegriCloud