diff options
author | Chris Lattner <sabre@nondot.org> | 2006-01-11 23:03:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-01-11 23:03:54 +0000 |
commit | 64da172b1435d132ce867dcd5c652577664b55a3 (patch) | |
tree | 07bad74e766305367ed0e6c42955be3e5c243708 | |
parent | cfde3c19c76e554159aea74a57d752dc0dd5b5c7 (diff) | |
download | external_llvm-64da172b1435d132ce867dcd5c652577664b55a3.zip external_llvm-64da172b1435d132ce867dcd5c652577664b55a3.tar.gz external_llvm-64da172b1435d132ce867dcd5c652577664b55a3.tar.bz2 |
If a function has a non-zero sized frame, use an add to adjust the stack
pointer in the epilog, not a load.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25229 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/PowerPC/PPCRegisterInfo.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/Target/PowerPC/PPCRegisterInfo.cpp b/lib/Target/PowerPC/PPCRegisterInfo.cpp index ae136cb..febbb47 100644 --- a/lib/Target/PowerPC/PPCRegisterInfo.cpp +++ b/lib/Target/PowerPC/PPCRegisterInfo.cpp @@ -370,23 +370,34 @@ void PPCRegisterInfo::emitPrologue(MachineFunction &MF) const { void PPCRegisterInfo::emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const { - const MachineFrameInfo *MFI = MF.getFrameInfo(); MachineBasicBlock::iterator MBBI = prior(MBB.end()); - MachineInstr *MI; assert(MBBI->getOpcode() == PPC::BLR && "Can only insert epilog into returning blocks"); - // Get the number of bytes allocated from the FrameInfo... - unsigned NumBytes = MFI->getStackSize(); - unsigned GPRSize = 4; + // Get the number of bytes allocated from the FrameInfo. + unsigned NumBytes = MF.getFrameInfo()->getStackSize(); + unsigned GPRSize = 4; if (NumBytes != 0) { + // If this function has a frame pointer, load the saved stack pointer from + // its stack slot. if (hasFP(MF)) { - MI = BuildMI(PPC::LWZ, 2, PPC::R31).addSImm(GPRSize).addReg(PPC::R31); - MBB.insert(MBBI, MI); + BuildMI(MBB, MBBI, PPC::LWZ, 2, PPC::R31) + .addSImm(GPRSize).addReg(PPC::R31); + } + + // The loaded (or persistent) stack pointer value is offseted by the 'stwu' + // on entry to the function. Add this offset back now. + if (NumBytes <= 32768) { + BuildMI(MBB, MBBI, PPC::ADDI, 2, PPC::R1) + .addReg(PPC::R1).addSImm(NumBytes); + } else { + BuildMI(MBB, MBBI, PPC::LIS, 1, PPC::R0).addSImm(NumBytes >> 16); + BuildMI(MBB, MBBI, PPC::ORI, 2, PPC::R0) + .addReg(PPC::R0).addImm(NumBytes & 0xFFFF); + BuildMI(MBB, MBBI, PPC::ADD4, 2, PPC::R1) + .addReg(PPC::R0).addReg(PPC::R1); } - MI = BuildMI(PPC::LWZ, 2, PPC::R1).addSImm(0).addReg(PPC::R1); - MBB.insert(MBBI, MI); } } |