blob: 658e294ec829db9f20daff17f0b5a91e84d4f84e [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===- PPCRegisterInfo.cpp - PowerPC Register Information -------*- C++ -*-===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Misha Brukmanf2ccb772004-08-17 04:55:41 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Misha Brukmanf2ccb772004-08-17 04:55:41 +00008//===----------------------------------------------------------------------===//
9//
Nate Begeman21e463b2005-10-16 05:39:50 +000010// This file contains the PowerPC implementation of the MRegisterInfo class.
Misha Brukmanf2ccb772004-08-17 04:55:41 +000011//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "reginfo"
Chris Lattner26689592005-10-14 23:51:18 +000015#include "PPC.h"
Chris Lattner26bd0d42005-10-14 23:45:43 +000016#include "PPCInstrBuilder.h"
Chris Lattner16e71f22005-10-14 23:59:06 +000017#include "PPCRegisterInfo.h"
Misha Brukmanf2ccb772004-08-17 04:55:41 +000018#include "llvm/Constants.h"
19#include "llvm/Type.h"
20#include "llvm/CodeGen/ValueTypes.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/MachineFrameInfo.h"
24#include "llvm/Target/TargetFrameInfo.h"
25#include "llvm/Target/TargetMachine.h"
26#include "llvm/Target/TargetOptions.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000027#include "llvm/Support/CommandLine.h"
28#include "llvm/Support/Debug.h"
29#include "llvm/ADT/STLExtras.h"
Misha Brukmanf2ccb772004-08-17 04:55:41 +000030#include <cstdlib>
31#include <iostream>
32using namespace llvm;
33
Nate Begeman21e463b2005-10-16 05:39:50 +000034PPCRegisterInfo::PPCRegisterInfo()
Chris Lattner4c7b43b2005-10-14 23:37:35 +000035 : PPCGenRegisterInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +000036 ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX;
Misha Brukmanf2ccb772004-08-17 04:55:41 +000037 ImmToIdxMap[PPC::LBZ] = PPC::LBZX; ImmToIdxMap[PPC::STB] = PPC::STBX;
38 ImmToIdxMap[PPC::LHZ] = PPC::LHZX; ImmToIdxMap[PPC::LHA] = PPC::LHAX;
39 ImmToIdxMap[PPC::LWZ] = PPC::LWZX; ImmToIdxMap[PPC::LWA] = PPC::LWAX;
40 ImmToIdxMap[PPC::LFS] = PPC::LFSX; ImmToIdxMap[PPC::LFD] = PPC::LFDX;
41 ImmToIdxMap[PPC::STH] = PPC::STHX; ImmToIdxMap[PPC::STW] = PPC::STWX;
42 ImmToIdxMap[PPC::STFS] = PPC::STFSX; ImmToIdxMap[PPC::STFD] = PPC::STFDX;
Nate Begeman1d9d7422005-10-18 00:28:58 +000043 ImmToIdxMap[PPC::ADDI] = PPC::ADD4;
Misha Brukmanf2ccb772004-08-17 04:55:41 +000044}
45
Misha Brukmanb5f662f2005-04-21 23:30:14 +000046void
Nate Begeman21e463b2005-10-16 05:39:50 +000047PPCRegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
48 MachineBasicBlock::iterator MI,
49 unsigned SrcReg, int FrameIdx,
50 const TargetRegisterClass *RC) const {
Misha Brukmanf2ccb772004-08-17 04:55:41 +000051 if (SrcReg == PPC::LR) {
Chris Lattner3f852b42005-08-18 23:24:50 +000052 BuildMI(MBB, MI, PPC::MFLR, 1, PPC::R11);
Chris Lattner919c0322005-10-01 01:35:02 +000053 addFrameReference(BuildMI(MBB, MI, PPC::STW, 3).addReg(PPC::R11), FrameIdx);
Nate Begeman1d9d7422005-10-18 00:28:58 +000054 } else if (RC == PPC::CRRCRegisterClass) {
Nate Begeman7af02482005-04-12 07:04:16 +000055 BuildMI(MBB, MI, PPC::MFCR, 0, PPC::R11);
Chris Lattner919c0322005-10-01 01:35:02 +000056 addFrameReference(BuildMI(MBB, MI, PPC::STW, 3).addReg(PPC::R11), FrameIdx);
Nate Begeman1d9d7422005-10-18 00:28:58 +000057 } else if (RC == PPC::GPRCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000058 addFrameReference(BuildMI(MBB, MI, PPC::STW, 3).addReg(SrcReg),FrameIdx);
Nate Begeman1d9d7422005-10-18 00:28:58 +000059 } else if (RC == PPC::G8RCRegisterClass) {
60 addFrameReference(BuildMI(MBB, MI, PPC::STD, 3).addReg(SrcReg),FrameIdx);
61 } else if (RC == PPC::F8RCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000062 addFrameReference(BuildMI(MBB, MI, PPC::STFD, 3).addReg(SrcReg),FrameIdx);
Nate Begeman1d9d7422005-10-18 00:28:58 +000063 } else if (RC == PPC::F4RCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000064 addFrameReference(BuildMI(MBB, MI, PPC::STFS, 3).addReg(SrcReg),FrameIdx);
Misha Brukmanf2ccb772004-08-17 04:55:41 +000065 } else {
Chris Lattner919c0322005-10-01 01:35:02 +000066 assert(0 && "Unknown regclass!");
67 abort();
Misha Brukmanf2ccb772004-08-17 04:55:41 +000068 }
69}
70
71void
Nate Begeman21e463b2005-10-16 05:39:50 +000072PPCRegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
Misha Brukmanf2ccb772004-08-17 04:55:41 +000073 MachineBasicBlock::iterator MI,
Chris Lattnerb48d2cf2005-09-30 01:31:52 +000074 unsigned DestReg, int FrameIdx,
75 const TargetRegisterClass *RC) const {
Misha Brukmanf2ccb772004-08-17 04:55:41 +000076 if (DestReg == PPC::LR) {
Chris Lattner919c0322005-10-01 01:35:02 +000077 addFrameReference(BuildMI(MBB, MI, PPC::LWZ, 2, PPC::R11), FrameIdx);
Misha Brukmanf2ccb772004-08-17 04:55:41 +000078 BuildMI(MBB, MI, PPC::MTLR, 1).addReg(PPC::R11);
Nate Begeman1d9d7422005-10-18 00:28:58 +000079 } else if (RC == PPC::CRRCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000080 addFrameReference(BuildMI(MBB, MI, PPC::LWZ, 2, PPC::R11), FrameIdx);
Nate Begeman7af02482005-04-12 07:04:16 +000081 BuildMI(MBB, MI, PPC::MTCRF, 1, DestReg).addReg(PPC::R11);
Nate Begeman1d9d7422005-10-18 00:28:58 +000082 } else if (RC == PPC::GPRCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000083 addFrameReference(BuildMI(MBB, MI, PPC::LWZ, 2, DestReg), FrameIdx);
Nate Begeman1d9d7422005-10-18 00:28:58 +000084 } else if (RC == PPC::G8RCRegisterClass) {
85 addFrameReference(BuildMI(MBB, MI, PPC::LD, 2, DestReg), FrameIdx);
86 } else if (RC == PPC::F8RCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000087 addFrameReference(BuildMI(MBB, MI, PPC::LFD, 2, DestReg), FrameIdx);
Nate Begeman1d9d7422005-10-18 00:28:58 +000088 } else if (RC == PPC::F4RCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +000089 addFrameReference(BuildMI(MBB, MI, PPC::LFS, 2, DestReg), FrameIdx);
Misha Brukmanf2ccb772004-08-17 04:55:41 +000090 } else {
Chris Lattner919c0322005-10-01 01:35:02 +000091 assert(0 && "Unknown regclass!");
92 abort();
Misha Brukmanf2ccb772004-08-17 04:55:41 +000093 }
94}
95
Nate Begeman21e463b2005-10-16 05:39:50 +000096void PPCRegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
97 MachineBasicBlock::iterator MI,
98 unsigned DestReg, unsigned SrcReg,
99 const TargetRegisterClass *RC) const {
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000100 MachineInstr *I;
101
Nate Begeman1d9d7422005-10-18 00:28:58 +0000102 if (RC == PPC::GPRCRegisterClass) {
103 BuildMI(MBB, MI, PPC::OR4, 2, DestReg).addReg(SrcReg).addReg(SrcReg);
104 } else if (RC == PPC::G8RCRegisterClass) {
105 BuildMI(MBB, MI, PPC::OR8, 2, DestReg).addReg(SrcReg).addReg(SrcReg);
106 } else if (RC == PPC::F4RCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +0000107 BuildMI(MBB, MI, PPC::FMRS, 1, DestReg).addReg(SrcReg);
Nate Begeman1d9d7422005-10-18 00:28:58 +0000108 } else if (RC == PPC::F8RCRegisterClass) {
Chris Lattner919c0322005-10-01 01:35:02 +0000109 BuildMI(MBB, MI, PPC::FMRD, 1, DestReg).addReg(SrcReg);
Nate Begeman1d9d7422005-10-18 00:28:58 +0000110 } else if (RC == PPC::CRRCRegisterClass) {
Nate Begeman7af02482005-04-12 07:04:16 +0000111 BuildMI(MBB, MI, PPC::MCRF, 1, DestReg).addReg(SrcReg);
112 } else {
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000113 std::cerr << "Attempt to copy register that is not GPR or FPR";
114 abort();
115 }
116}
117
Nate Begeman21e463b2005-10-16 05:39:50 +0000118unsigned PPCRegisterInfo::isLoadFromStackSlot(MachineInstr *MI,
119 int &FrameIndex) const {
Chris Lattner6a78c212005-09-17 01:03:26 +0000120 switch (MI->getOpcode()) {
121 default: break;
Nate Begeman1d9d7422005-10-18 00:28:58 +0000122 case PPC::LD:
Chris Lattner6a78c212005-09-17 01:03:26 +0000123 case PPC::LWZ:
Chris Lattnerb91956e2005-10-01 23:02:40 +0000124 case PPC::LFS:
Chris Lattner6a78c212005-09-17 01:03:26 +0000125 case PPC::LFD:
126 if (MI->getOperand(1).isImmediate() && !MI->getOperand(1).getImmedValue() &&
127 MI->getOperand(2).isFrameIndex()) {
128 FrameIndex = MI->getOperand(2).getFrameIndex();
129 return MI->getOperand(0).getReg();
130 }
131 break;
132 }
133 return 0;
134}
135
Chris Lattnerf38df042005-09-09 21:46:49 +0000136/// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
137/// copy instructions, turning them into load/store instructions.
Nate Begeman21e463b2005-10-16 05:39:50 +0000138MachineInstr *PPCRegisterInfo::foldMemoryOperand(MachineInstr *MI,
139 unsigned OpNum,
140 int FrameIndex) const {
Chris Lattnerf38df042005-09-09 21:46:49 +0000141 // Make sure this is a reg-reg copy. Note that we can't handle MCRF, because
142 // it takes more than one instruction to store it.
143 unsigned Opc = MI->getOpcode();
144
Nate Begeman1d9d7422005-10-18 00:28:58 +0000145 if ((Opc == PPC::OR4 &&
Chris Lattnerf38df042005-09-09 21:46:49 +0000146 MI->getOperand(1).getReg() == MI->getOperand(2).getReg())) {
147 if (OpNum == 0) { // move -> store
148 unsigned InReg = MI->getOperand(1).getReg();
149 return addFrameReference(BuildMI(PPC::STW,
150 3).addReg(InReg), FrameIndex);
Chris Lattnerc9fe7502005-09-09 21:59:44 +0000151 } else { // move -> load
Chris Lattnerf38df042005-09-09 21:46:49 +0000152 unsigned OutReg = MI->getOperand(0).getReg();
153 return addFrameReference(BuildMI(PPC::LWZ, 2, OutReg), FrameIndex);
154 }
Nate Begeman1d9d7422005-10-18 00:28:58 +0000155 } else if ((Opc == PPC::OR8 &&
156 MI->getOperand(1).getReg() == MI->getOperand(2).getReg())) {
157 if (OpNum == 0) { // move -> store
158 unsigned InReg = MI->getOperand(1).getReg();
159 return addFrameReference(BuildMI(PPC::STD,
160 3).addReg(InReg), FrameIndex);
161 } else { // move -> load
162 unsigned OutReg = MI->getOperand(0).getReg();
163 return addFrameReference(BuildMI(PPC::LD, 2, OutReg), FrameIndex);
164 }
Chris Lattner919c0322005-10-01 01:35:02 +0000165 } else if (Opc == PPC::FMRD) {
Chris Lattnerc9fe7502005-09-09 21:59:44 +0000166 if (OpNum == 0) { // move -> store
167 unsigned InReg = MI->getOperand(1).getReg();
168 return addFrameReference(BuildMI(PPC::STFD,
169 3).addReg(InReg), FrameIndex);
170 } else { // move -> load
171 unsigned OutReg = MI->getOperand(0).getReg();
172 return addFrameReference(BuildMI(PPC::LFD, 2, OutReg), FrameIndex);
173 }
Chris Lattner919c0322005-10-01 01:35:02 +0000174 } else if (Opc == PPC::FMRS) {
175 if (OpNum == 0) { // move -> store
176 unsigned InReg = MI->getOperand(1).getReg();
177 return addFrameReference(BuildMI(PPC::STFS,
178 3).addReg(InReg), FrameIndex);
179 } else { // move -> load
180 unsigned OutReg = MI->getOperand(0).getReg();
181 return addFrameReference(BuildMI(PPC::LFS, 2, OutReg), FrameIndex);
182 }
Chris Lattnerf38df042005-09-09 21:46:49 +0000183 }
184 return 0;
185}
186
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000187//===----------------------------------------------------------------------===//
188// Stack Frame Processing methods
189//===----------------------------------------------------------------------===//
190
191// hasFP - Return true if the specified function should have a dedicated frame
192// pointer register. This is true if the function has variable sized allocas or
193// if frame pointer elimination is disabled.
194//
195static bool hasFP(MachineFunction &MF) {
Chris Lattner5087daa2005-08-26 21:49:18 +0000196 return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000197}
198
Nate Begeman21e463b2005-10-16 05:39:50 +0000199void PPCRegisterInfo::
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000200eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
201 MachineBasicBlock::iterator I) const {
202 if (hasFP(MF)) {
203 // If we have a frame pointer, convert as follows:
204 // ADJCALLSTACKDOWN -> addi, r1, r1, -amount
205 // ADJCALLSTACKUP -> addi, r1, r1, amount
206 MachineInstr *Old = I;
207 unsigned Amount = Old->getOperand(0).getImmedValue();
208 if (Amount != 0) {
209 // We need to keep the stack aligned properly. To do this, we round the
210 // amount of space needed for the outgoing arguments up to the next
211 // alignment boundary.
212 unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
213 Amount = (Amount+Align-1)/Align*Align;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000214
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000215 // Replace the pseudo instruction with a new instruction...
216 if (Old->getOpcode() == PPC::ADJCALLSTACKDOWN) {
217 MBB.insert(I, BuildMI(PPC::ADDI, 2, PPC::R1).addReg(PPC::R1)
218 .addSImm(-Amount));
219 } else {
220 assert(Old->getOpcode() == PPC::ADJCALLSTACKUP);
221 MBB.insert(I, BuildMI(PPC::ADDI, 2, PPC::R1).addReg(PPC::R1)
222 .addSImm(Amount));
223 }
224 }
225 }
226 MBB.erase(I);
227}
228
229void
Nate Begeman21e463b2005-10-16 05:39:50 +0000230PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000231 unsigned i = 0;
232 MachineInstr &MI = *II;
233 MachineBasicBlock &MBB = *MI.getParent();
234 MachineFunction &MF = *MBB.getParent();
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000235
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000236 while (!MI.getOperand(i).isFrameIndex()) {
237 ++i;
238 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
239 }
240
241 int FrameIndex = MI.getOperand(i).getFrameIndex();
242
243 // Replace the FrameIndex with base register with GPR1 (SP) or GPR31 (FP).
244 MI.SetMachineOperandReg(i, hasFP(MF) ? PPC::R31 : PPC::R1);
245
246 // Take into account whether it's an add or mem instruction
247 unsigned OffIdx = (i == 2) ? 1 : 2;
248
249 // Now add the frame object offset to the offset from r1.
250 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
251 MI.getOperand(OffIdx).getImmedValue();
252
253 // If we're not using a Frame Pointer that has been set to the value of the
254 // SP before having the stack size subtracted from it, then add the stack size
255 // to Offset to get the correct offset.
256 Offset += MF.getFrameInfo()->getStackSize();
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000257
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000258 if (Offset > 32767 || Offset < -32768) {
259 // Insert a set of r0 with the full offset value before the ld, st, or add
260 MachineBasicBlock *MBB = MI.getParent();
261 MBB->insert(II, BuildMI(PPC::LIS, 1, PPC::R0).addSImm(Offset >> 16));
262 MBB->insert(II, BuildMI(PPC::ORI, 2, PPC::R0).addReg(PPC::R0)
263 .addImm(Offset));
264 // convert into indexed form of the instruction
265 // sth 0:rA, 1:imm 2:(rB) ==> sthx 0:rA, 2:rB, 1:r0
266 // addi 0:rA 1:rB, 2, imm ==> add 0:rA, 1:rB, 2:r0
Chris Lattner14630192005-09-09 20:51:08 +0000267 assert(ImmToIdxMap.count(MI.getOpcode()) &&
268 "No indexed form of load or store available!");
269 unsigned NewOpcode = ImmToIdxMap.find(MI.getOpcode())->second;
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000270 MI.setOpcode(NewOpcode);
271 MI.SetMachineOperandReg(1, MI.getOperand(i).getReg());
272 MI.SetMachineOperandReg(2, PPC::R0);
273 } else {
Chris Lattner841d12d2005-10-18 16:51:22 +0000274 switch (MI.getOpcode()) {
275 case PPC::LWA:
276 case PPC::LD:
277 case PPC::STD:
278 case PPC::STDU:
279 assert((Offset & 3) == 0 && "Invalid frame offset!");
280 Offset >>= 2; // The actual encoded value has the low two bits zero.
281 break;
282 }
Chris Lattner919c0322005-10-01 01:35:02 +0000283 MI.SetMachineOperandConst(OffIdx, MachineOperand::MO_SignExtendedImmed,
284 Offset);
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000285 }
286}
287
288
Nate Begeman21e463b2005-10-16 05:39:50 +0000289void PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000290 MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
291 MachineBasicBlock::iterator MBBI = MBB.begin();
292 MachineFrameInfo *MFI = MF.getFrameInfo();
293 MachineInstr *MI;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000294
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000295 // Get the number of bytes to allocate from the FrameInfo
296 unsigned NumBytes = MFI->getStackSize();
297
298 // If we have calls, we cannot use the red zone to store callee save registers
299 // and we must set up a stack frame, so calculate the necessary size here.
300 if (MFI->hasCalls()) {
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000301 // We reserve argument space for call sites in the function immediately on
302 // entry to the current function. This eliminates the need for add/sub
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000303 // brackets around call sites.
304 NumBytes += MFI->getMaxCallFrameSize();
305 }
306
Jeff Cohend29b6aa2005-07-30 18:33:25 +0000307 // If we are a leaf function, and use up to 224 bytes of stack space,
Nate Begeman54eed362005-07-27 06:06:29 +0000308 // and don't have a frame pointer, then we do not need to adjust the stack
309 // pointer (we fit in the Red Zone).
310 if ((NumBytes == 0) || (NumBytes <= 224 && !hasFP(MF) && !MFI->hasCalls())) {
311 MFI->setStackSize(0);
312 return;
313 }
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000314
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000315 // Add the size of R1 to NumBytes size for the store of R1 to the bottom
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000316 // of the stack and round the size to a multiple of the alignment.
317 unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
Chris Lattner5802be12005-09-30 17:16:59 +0000318 unsigned GPRSize = 4;
Chris Lattner8edcd842004-08-21 19:51:17 +0000319 unsigned Size = hasFP(MF) ? GPRSize + GPRSize : GPRSize;
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000320 NumBytes = (NumBytes+Size+Align-1)/Align*Align;
321
322 // Update frame info to pretend that this is part of the stack...
323 MFI->setStackSize(NumBytes);
324
Nate Begeman3dee1752005-07-27 23:11:27 +0000325 // Adjust stack pointer: r1 -= numbytes.
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000326 if (NumBytes <= 32768) {
327 MI=BuildMI(PPC::STWU,3).addReg(PPC::R1).addSImm(-NumBytes).addReg(PPC::R1);
328 MBB.insert(MBBI, MI);
329 } else {
330 int NegNumbytes = -NumBytes;
331 MI = BuildMI(PPC::LIS, 1, PPC::R0).addSImm(NegNumbytes >> 16);
332 MBB.insert(MBBI, MI);
333 MI = BuildMI(PPC::ORI, 2, PPC::R0).addReg(PPC::R0)
334 .addImm(NegNumbytes & 0xFFFF);
335 MBB.insert(MBBI, MI);
336 MI = BuildMI(PPC::STWUX, 3).addReg(PPC::R1).addReg(PPC::R1).addReg(PPC::R0);
337 MBB.insert(MBBI, MI);
338 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000339
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000340 if (hasFP(MF)) {
Chris Lattner8edcd842004-08-21 19:51:17 +0000341 MI = BuildMI(PPC::STW, 3).addReg(PPC::R31).addSImm(GPRSize).addReg(PPC::R1);
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000342 MBB.insert(MBBI, MI);
Nate Begeman1d9d7422005-10-18 00:28:58 +0000343 MI = BuildMI(PPC::OR4, 2, PPC::R31).addReg(PPC::R1).addReg(PPC::R1);
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000344 MBB.insert(MBBI, MI);
345 }
346}
347
Nate Begeman21e463b2005-10-16 05:39:50 +0000348void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
349 MachineBasicBlock &MBB) const {
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000350 const MachineFrameInfo *MFI = MF.getFrameInfo();
351 MachineBasicBlock::iterator MBBI = prior(MBB.end());
352 MachineInstr *MI;
353 assert(MBBI->getOpcode() == PPC::BLR &&
354 "Can only insert epilog into returning blocks");
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000355
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000356 // Get the number of bytes allocated from the FrameInfo...
357 unsigned NumBytes = MFI->getStackSize();
Chris Lattner5802be12005-09-30 17:16:59 +0000358 unsigned GPRSize = 4;
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000359
360 if (NumBytes != 0) {
361 if (hasFP(MF)) {
Nate Begeman1f4a1322004-08-22 08:09:17 +0000362 MI = BuildMI(PPC::LWZ, 2, PPC::R31).addSImm(GPRSize).addReg(PPC::R31);
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000363 MBB.insert(MBBI, MI);
364 }
365 MI = BuildMI(PPC::LWZ, 2, PPC::R1).addSImm(0).addReg(PPC::R1);
366 MBB.insert(MBBI, MI);
367 }
368}
369
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000370#include "PPCGenRegisterInfo.inc"
Misha Brukmanf2ccb772004-08-17 04:55:41 +0000371