blob: ce6d933f04fbf00c1ce199c8b96b1bbf956f8f9c [file] [log] [blame]
Akira Hatanakacdb3ba72012-07-31 22:50:19 +00001//===-- MipsSEFrameLowering.cpp - Mips32/64 Frame Information -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the Mips32/64 implementation of TargetFrameLowering class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MipsSEFrameLowering.h"
Akira Hatanakacdb3ba72012-07-31 22:50:19 +000015#include "MCTargetDesc/MipsBaseInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000016#include "MipsAnalyzeImmediate.h"
17#include "MipsMachineFunction.h"
18#include "MipsSEInstrInfo.h"
Akira Hatanakacdb3ba72012-07-31 22:50:19 +000019#include "llvm/CodeGen/MachineFrameInfo.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/CodeGen/MachineInstrBuilder.h"
22#include "llvm/CodeGen/MachineModuleInfo.h"
23#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanaka11a45c22012-11-03 00:05:43 +000024#include "llvm/CodeGen/RegisterScavenging.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000025#include "llvm/IR/DataLayout.h"
26#include "llvm/IR/Function.h"
Akira Hatanakacdb3ba72012-07-31 22:50:19 +000027#include "llvm/Support/CommandLine.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000028#include "llvm/Target/TargetOptions.h"
Akira Hatanakacdb3ba72012-07-31 22:50:19 +000029
30using namespace llvm;
31
Akira Hatanakad6a77822013-03-30 01:04:11 +000032namespace {
33typedef MachineBasicBlock::iterator Iter;
34
35/// Helper class to expand accumulator pseudos.
36class ExpandACCPseudo {
37public:
38 ExpandACCPseudo(MachineFunction &MF);
39 bool expand();
40
41private:
42 bool expandInstr(MachineBasicBlock &MBB, Iter I);
43 void expandLoad(MachineBasicBlock &MBB, Iter I, unsigned RegSize);
44 void expandStore(MachineBasicBlock &MBB, Iter I, unsigned RegSize);
Akira Hatanakac147c1b2013-04-30 23:22:09 +000045 bool expandCopy(MachineBasicBlock &MBB, Iter I);
Akira Hatanakad6a77822013-03-30 01:04:11 +000046
47 MachineFunction &MF;
48 const MipsSEInstrInfo &TII;
49 const MipsRegisterInfo &RegInfo;
50 MachineRegisterInfo &MRI;
51};
52}
53
54ExpandACCPseudo::ExpandACCPseudo(MachineFunction &MF_)
55 : MF(MF_),
56 TII(*static_cast<const MipsSEInstrInfo*>(MF.getTarget().getInstrInfo())),
57 RegInfo(TII.getRegisterInfo()), MRI(MF.getRegInfo()) {}
58
59bool ExpandACCPseudo::expand() {
60 bool Expanded = false;
61
62 for (MachineFunction::iterator BB = MF.begin(), BBEnd = MF.end();
63 BB != BBEnd; ++BB)
64 for (Iter I = BB->begin(), End = BB->end(); I != End;)
65 Expanded |= expandInstr(*BB, I++);
66
67 return Expanded;
68}
69
70bool ExpandACCPseudo::expandInstr(MachineBasicBlock &MBB, Iter I) {
71 switch(I->getOpcode()) {
72 case Mips::LOAD_AC64:
73 case Mips::LOAD_AC64_P8:
74 case Mips::LOAD_AC_DSP:
75 case Mips::LOAD_AC_DSP_P8:
76 expandLoad(MBB, I, 4);
77 break;
78 case Mips::LOAD_AC128:
79 case Mips::LOAD_AC128_P8:
80 expandLoad(MBB, I, 8);
81 break;
82 case Mips::STORE_AC64:
83 case Mips::STORE_AC64_P8:
84 case Mips::STORE_AC_DSP:
85 case Mips::STORE_AC_DSP_P8:
86 expandStore(MBB, I, 4);
87 break;
88 case Mips::STORE_AC128:
89 case Mips::STORE_AC128_P8:
90 expandStore(MBB, I, 8);
91 break;
Akira Hatanakac147c1b2013-04-30 23:22:09 +000092 case TargetOpcode::COPY:
93 if (!expandCopy(MBB, I))
94 return false;
Akira Hatanakad6a77822013-03-30 01:04:11 +000095 break;
96 default:
97 return false;
98 }
99
100 MBB.erase(I);
101 return true;
102}
103
104void ExpandACCPseudo::expandLoad(MachineBasicBlock &MBB, Iter I,
105 unsigned RegSize) {
106 // load $vr0, FI
107 // copy lo, $vr0
108 // load $vr1, FI + 4
109 // copy hi, $vr1
110
111 assert(I->getOperand(0).isReg() && I->getOperand(1).isFI());
112
113 const TargetRegisterClass *RC = RegInfo.intRegClass(RegSize);
114 unsigned VR0 = MRI.createVirtualRegister(RC);
115 unsigned VR1 = MRI.createVirtualRegister(RC);
116 unsigned Dst = I->getOperand(0).getReg(), FI = I->getOperand(1).getIndex();
117 unsigned Lo = RegInfo.getSubReg(Dst, Mips::sub_lo);
118 unsigned Hi = RegInfo.getSubReg(Dst, Mips::sub_hi);
119 DebugLoc DL = I->getDebugLoc();
120 const MCInstrDesc &Desc = TII.get(TargetOpcode::COPY);
121
122 TII.loadRegFromStack(MBB, I, VR0, FI, RC, &RegInfo, 0);
123 BuildMI(MBB, I, DL, Desc, Lo).addReg(VR0, RegState::Kill);
124 TII.loadRegFromStack(MBB, I, VR1, FI, RC, &RegInfo, RegSize);
125 BuildMI(MBB, I, DL, Desc, Hi).addReg(VR1, RegState::Kill);
126}
127
128void ExpandACCPseudo::expandStore(MachineBasicBlock &MBB, Iter I,
129 unsigned RegSize) {
130 // copy $vr0, lo
131 // store $vr0, FI
132 // copy $vr1, hi
133 // store $vr1, FI + 4
134
135 assert(I->getOperand(0).isReg() && I->getOperand(1).isFI());
136
137 const TargetRegisterClass *RC = RegInfo.intRegClass(RegSize);
138 unsigned VR0 = MRI.createVirtualRegister(RC);
139 unsigned VR1 = MRI.createVirtualRegister(RC);
140 unsigned Src = I->getOperand(0).getReg(), FI = I->getOperand(1).getIndex();
141 unsigned SrcKill = getKillRegState(I->getOperand(0).isKill());
142 unsigned Lo = RegInfo.getSubReg(Src, Mips::sub_lo);
143 unsigned Hi = RegInfo.getSubReg(Src, Mips::sub_hi);
144 DebugLoc DL = I->getDebugLoc();
145
146 BuildMI(MBB, I, DL, TII.get(TargetOpcode::COPY), VR0).addReg(Lo, SrcKill);
147 TII.storeRegToStack(MBB, I, VR0, true, FI, RC, &RegInfo, 0);
148 BuildMI(MBB, I, DL, TII.get(TargetOpcode::COPY), VR1).addReg(Hi, SrcKill);
149 TII.storeRegToStack(MBB, I, VR1, true, FI, RC, &RegInfo, RegSize);
150}
151
Akira Hatanakac147c1b2013-04-30 23:22:09 +0000152bool ExpandACCPseudo::expandCopy(MachineBasicBlock &MBB, Iter I) {
153 unsigned Dst = I->getOperand(0).getReg(), Src = I->getOperand(1).getReg();
154 unsigned RegSize;
155
156 if (Mips::ACRegsDSPRegClass.contains(Dst) &&
157 Mips::ACRegsDSPRegClass.contains(Src))
158 RegSize = 4;
159 else if (Mips::ACRegs128RegClass.contains(Dst) &&
160 Mips::ACRegs128RegClass.contains(Src))
161 RegSize = 8;
162 else
163 return false;
164
Akira Hatanakad6a77822013-03-30 01:04:11 +0000165 // copy $vr0, src_lo
166 // copy dst_lo, $vr0
167 // copy $vr1, src_hi
168 // copy dst_hi, $vr1
169
170 const TargetRegisterClass *RC = RegInfo.intRegClass(RegSize);
171 unsigned VR0 = MRI.createVirtualRegister(RC);
172 unsigned VR1 = MRI.createVirtualRegister(RC);
Akira Hatanakad6a77822013-03-30 01:04:11 +0000173 unsigned SrcKill = getKillRegState(I->getOperand(1).isKill());
174 unsigned DstLo = RegInfo.getSubReg(Dst, Mips::sub_lo);
175 unsigned DstHi = RegInfo.getSubReg(Dst, Mips::sub_hi);
176 unsigned SrcLo = RegInfo.getSubReg(Src, Mips::sub_lo);
177 unsigned SrcHi = RegInfo.getSubReg(Src, Mips::sub_hi);
178 DebugLoc DL = I->getDebugLoc();
179
180 BuildMI(MBB, I, DL, TII.get(TargetOpcode::COPY), VR0).addReg(SrcLo, SrcKill);
181 BuildMI(MBB, I, DL, TII.get(TargetOpcode::COPY), DstLo)
182 .addReg(VR0, RegState::Kill);
183 BuildMI(MBB, I, DL, TII.get(TargetOpcode::COPY), VR1).addReg(SrcHi, SrcKill);
184 BuildMI(MBB, I, DL, TII.get(TargetOpcode::COPY), DstHi)
185 .addReg(VR1, RegState::Kill);
Akira Hatanakac147c1b2013-04-30 23:22:09 +0000186 return true;
Akira Hatanakad6a77822013-03-30 01:04:11 +0000187}
188
Akira Hatanaka544cc212013-01-30 00:26:49 +0000189unsigned MipsSEFrameLowering::ehDataReg(unsigned I) const {
190 static const unsigned EhDataReg[] = {
191 Mips::A0, Mips::A1, Mips::A2, Mips::A3
192 };
193 static const unsigned EhDataReg64[] = {
194 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
195 };
196
197 return STI.isABI_N64() ? EhDataReg64[I] : EhDataReg[I];
198}
199
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000200void MipsSEFrameLowering::emitPrologue(MachineFunction &MF) const {
201 MachineBasicBlock &MBB = MF.front();
202 MachineFrameInfo *MFI = MF.getFrameInfo();
Akira Hatanaka544cc212013-01-30 00:26:49 +0000203 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000204 const MipsRegisterInfo *RegInfo =
205 static_cast<const MipsRegisterInfo*>(MF.getTarget().getRegisterInfo());
Akira Hatanaka71746222012-07-31 23:52:55 +0000206 const MipsSEInstrInfo &TII =
207 *static_cast<const MipsSEInstrInfo*>(MF.getTarget().getInstrInfo());
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000208 MachineBasicBlock::iterator MBBI = MBB.begin();
209 DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
210 unsigned SP = STI.isABI_N64() ? Mips::SP_64 : Mips::SP;
211 unsigned FP = STI.isABI_N64() ? Mips::FP_64 : Mips::FP;
212 unsigned ZERO = STI.isABI_N64() ? Mips::ZERO_64 : Mips::ZERO;
213 unsigned ADDu = STI.isABI_N64() ? Mips::DADDu : Mips::ADDu;
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000214
215 // First, compute final stack size.
216 uint64_t StackSize = MFI->getStackSize();
217
218 // No need to allocate space on the stack.
219 if (StackSize == 0 && !MFI->adjustsStack()) return;
220
221 MachineModuleInfo &MMI = MF.getMMI();
222 std::vector<MachineMove> &Moves = MMI.getFrameMoves();
223 MachineLocation DstML, SrcML;
224
225 // Adjust stack.
Akira Hatanaka71746222012-07-31 23:52:55 +0000226 TII.adjustStackPtr(SP, -StackSize, MBB, MBBI);
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000227
228 // emit ".cfi_def_cfa_offset StackSize"
229 MCSymbol *AdjustSPLabel = MMI.getContext().CreateTempSymbol();
230 BuildMI(MBB, MBBI, dl,
231 TII.get(TargetOpcode::PROLOG_LABEL)).addSym(AdjustSPLabel);
232 DstML = MachineLocation(MachineLocation::VirtualFP);
233 SrcML = MachineLocation(MachineLocation::VirtualFP, -StackSize);
234 Moves.push_back(MachineMove(AdjustSPLabel, DstML, SrcML));
235
236 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
237
238 if (CSI.size()) {
239 // Find the instruction past the last instruction that saves a callee-saved
240 // register to the stack.
241 for (unsigned i = 0; i < CSI.size(); ++i)
242 ++MBBI;
243
244 // Iterate over list of callee-saved registers and emit .cfi_offset
245 // directives.
246 MCSymbol *CSLabel = MMI.getContext().CreateTempSymbol();
247 BuildMI(MBB, MBBI, dl,
248 TII.get(TargetOpcode::PROLOG_LABEL)).addSym(CSLabel);
249
250 for (std::vector<CalleeSavedInfo>::const_iterator I = CSI.begin(),
251 E = CSI.end(); I != E; ++I) {
252 int64_t Offset = MFI->getObjectOffset(I->getFrameIdx());
253 unsigned Reg = I->getReg();
254
255 // If Reg is a double precision register, emit two cfa_offsets,
256 // one for each of the paired single precision registers.
257 if (Mips::AFGR64RegClass.contains(Reg)) {
258 MachineLocation DstML0(MachineLocation::VirtualFP, Offset);
259 MachineLocation DstML1(MachineLocation::VirtualFP, Offset + 4);
260 MachineLocation SrcML0(RegInfo->getSubReg(Reg, Mips::sub_fpeven));
261 MachineLocation SrcML1(RegInfo->getSubReg(Reg, Mips::sub_fpodd));
262
263 if (!STI.isLittle())
264 std::swap(SrcML0, SrcML1);
265
266 Moves.push_back(MachineMove(CSLabel, DstML0, SrcML0));
267 Moves.push_back(MachineMove(CSLabel, DstML1, SrcML1));
268 } else {
269 // Reg is either in CPURegs or FGR32.
270 DstML = MachineLocation(MachineLocation::VirtualFP, Offset);
271 SrcML = MachineLocation(Reg);
272 Moves.push_back(MachineMove(CSLabel, DstML, SrcML));
273 }
274 }
275 }
276
Akira Hatanaka544cc212013-01-30 00:26:49 +0000277 if (MipsFI->callsEhReturn()) {
278 const TargetRegisterClass *RC = STI.isABI_N64() ?
279 &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass;
280
281 // Insert instructions that spill eh data registers.
282 for (int I = 0; I < 4; ++I) {
283 if (!MBB.isLiveIn(ehDataReg(I)))
284 MBB.addLiveIn(ehDataReg(I));
285 TII.storeRegToStackSlot(MBB, MBBI, ehDataReg(I), false,
286 MipsFI->getEhDataRegFI(I), RC, RegInfo);
287 }
288
289 // Emit .cfi_offset directives for eh data registers.
290 MCSymbol *CSLabel2 = MMI.getContext().CreateTempSymbol();
291 BuildMI(MBB, MBBI, dl,
292 TII.get(TargetOpcode::PROLOG_LABEL)).addSym(CSLabel2);
293 for (int I = 0; I < 4; ++I) {
294 int64_t Offset = MFI->getObjectOffset(MipsFI->getEhDataRegFI(I));
295 DstML = MachineLocation(MachineLocation::VirtualFP, Offset);
296 SrcML = MachineLocation(ehDataReg(I));
297 Moves.push_back(MachineMove(CSLabel2, DstML, SrcML));
298 }
299 }
300
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000301 // if framepointer enabled, set it to point to the stack pointer.
302 if (hasFP(MF)) {
303 // Insert instruction "move $fp, $sp" at this location.
304 BuildMI(MBB, MBBI, dl, TII.get(ADDu), FP).addReg(SP).addReg(ZERO);
305
306 // emit ".cfi_def_cfa_register $fp"
307 MCSymbol *SetFPLabel = MMI.getContext().CreateTempSymbol();
308 BuildMI(MBB, MBBI, dl,
309 TII.get(TargetOpcode::PROLOG_LABEL)).addSym(SetFPLabel);
310 DstML = MachineLocation(FP);
311 SrcML = MachineLocation(MachineLocation::VirtualFP);
312 Moves.push_back(MachineMove(SetFPLabel, DstML, SrcML));
313 }
314}
315
316void MipsSEFrameLowering::emitEpilogue(MachineFunction &MF,
317 MachineBasicBlock &MBB) const {
318 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
319 MachineFrameInfo *MFI = MF.getFrameInfo();
Akira Hatanaka544cc212013-01-30 00:26:49 +0000320 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
321 const MipsRegisterInfo *RegInfo =
322 static_cast<const MipsRegisterInfo*>(MF.getTarget().getRegisterInfo());
Akira Hatanaka71746222012-07-31 23:52:55 +0000323 const MipsSEInstrInfo &TII =
324 *static_cast<const MipsSEInstrInfo*>(MF.getTarget().getInstrInfo());
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000325 DebugLoc dl = MBBI->getDebugLoc();
326 unsigned SP = STI.isABI_N64() ? Mips::SP_64 : Mips::SP;
327 unsigned FP = STI.isABI_N64() ? Mips::FP_64 : Mips::FP;
328 unsigned ZERO = STI.isABI_N64() ? Mips::ZERO_64 : Mips::ZERO;
329 unsigned ADDu = STI.isABI_N64() ? Mips::DADDu : Mips::ADDu;
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000330
331 // if framepointer enabled, restore the stack pointer.
332 if (hasFP(MF)) {
333 // Find the first instruction that restores a callee-saved register.
334 MachineBasicBlock::iterator I = MBBI;
335
336 for (unsigned i = 0; i < MFI->getCalleeSavedInfo().size(); ++i)
337 --I;
338
339 // Insert instruction "move $sp, $fp" at this location.
340 BuildMI(MBB, I, dl, TII.get(ADDu), SP).addReg(FP).addReg(ZERO);
341 }
342
Akira Hatanaka544cc212013-01-30 00:26:49 +0000343 if (MipsFI->callsEhReturn()) {
344 const TargetRegisterClass *RC = STI.isABI_N64() ?
345 &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass;
346
347 // Find first instruction that restores a callee-saved register.
348 MachineBasicBlock::iterator I = MBBI;
349 for (unsigned i = 0; i < MFI->getCalleeSavedInfo().size(); ++i)
350 --I;
351
352 // Insert instructions that restore eh data registers.
353 for (int J = 0; J < 4; ++J) {
354 TII.loadRegFromStackSlot(MBB, I, ehDataReg(J), MipsFI->getEhDataRegFI(J),
355 RC, RegInfo);
356 }
357 }
358
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000359 // Get the number of bytes from FrameInfo
360 uint64_t StackSize = MFI->getStackSize();
361
362 if (!StackSize)
363 return;
364
365 // Adjust stack.
Akira Hatanaka71746222012-07-31 23:52:55 +0000366 TII.adjustStackPtr(SP, StackSize, MBB, MBBI);
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000367}
368
369bool MipsSEFrameLowering::
370spillCalleeSavedRegisters(MachineBasicBlock &MBB,
371 MachineBasicBlock::iterator MI,
372 const std::vector<CalleeSavedInfo> &CSI,
373 const TargetRegisterInfo *TRI) const {
374 MachineFunction *MF = MBB.getParent();
375 MachineBasicBlock *EntryBlock = MF->begin();
376 const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
377
378 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
379 // Add the callee-saved register as live-in. Do not add if the register is
380 // RA and return address is taken, because it has already been added in
381 // method MipsTargetLowering::LowerRETURNADDR.
382 // It's killed at the spill, unless the register is RA and return address
383 // is taken.
384 unsigned Reg = CSI[i].getReg();
385 bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA || Reg == Mips::RA_64)
386 && MF->getFrameInfo()->isReturnAddressTaken();
387 if (!IsRAAndRetAddrIsTaken)
388 EntryBlock->addLiveIn(Reg);
389
390 // Insert the spill to the stack frame.
391 bool IsKill = !IsRAAndRetAddrIsTaken;
392 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
393 TII.storeRegToStackSlot(*EntryBlock, MI, Reg, IsKill,
394 CSI[i].getFrameIdx(), RC, TRI);
395 }
396
397 return true;
398}
399
400bool
401MipsSEFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
402 const MachineFrameInfo *MFI = MF.getFrameInfo();
403
404 // Reserve call frame if the size of the maximum call frame fits into 16-bit
405 // immediate field and there are no variable sized objects on the stack.
Akira Hatanakad6a77822013-03-30 01:04:11 +0000406 // Make sure the second register scavenger spill slot can be accessed with one
407 // instruction.
408 return isInt<16>(MFI->getMaxCallFrameSize() + getStackAlignment()) &&
409 !MFI->hasVarSizedObjects();
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000410}
411
Eli Bendersky700ed802013-02-21 20:05:00 +0000412// Eliminate ADJCALLSTACKDOWN, ADJCALLSTACKUP pseudo instructions
413void MipsSEFrameLowering::
414eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
415 MachineBasicBlock::iterator I) const {
416 const MipsSEInstrInfo &TII =
417 *static_cast<const MipsSEInstrInfo*>(MF.getTarget().getInstrInfo());
418
419 if (!hasReservedCallFrame(MF)) {
420 int64_t Amount = I->getOperand(0).getImm();
421
422 if (I->getOpcode() == Mips::ADJCALLSTACKDOWN)
423 Amount = -Amount;
424
425 unsigned SP = STI.isABI_N64() ? Mips::SP_64 : Mips::SP;
426 TII.adjustStackPtr(SP, Amount, MBB, I);
427 }
428
429 MBB.erase(I);
430}
431
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000432void MipsSEFrameLowering::
433processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
434 RegScavenger *RS) const {
435 MachineRegisterInfo &MRI = MF.getRegInfo();
Akira Hatanaka544cc212013-01-30 00:26:49 +0000436 MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000437 unsigned FP = STI.isABI_N64() ? Mips::FP_64 : Mips::FP;
438
439 // Mark $fp as used if function has dedicated frame pointer.
440 if (hasFP(MF))
441 MRI.setPhysRegUsed(FP);
Akira Hatanaka11a45c22012-11-03 00:05:43 +0000442
Akira Hatanaka544cc212013-01-30 00:26:49 +0000443 // Create spill slots for eh data registers if function calls eh_return.
444 if (MipsFI->callsEhReturn())
445 MipsFI->createEhDataRegsFI();
446
Akira Hatanakad6a77822013-03-30 01:04:11 +0000447 // Expand pseudo instructions which load, store or copy accumulators.
448 // Add an emergency spill slot if a pseudo was expanded.
449 if (ExpandACCPseudo(MF).expand()) {
450 // The spill slot should be half the size of the accumulator. If target is
451 // mips64, it should be 64-bit, otherwise it should be 32-bt.
452 const TargetRegisterClass *RC = STI.hasMips64() ?
453 &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass;
454 int FI = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
455 RC->getAlignment(), false);
456 RS->addScavengingFrameIndex(FI);
457 }
458
Akira Hatanaka11a45c22012-11-03 00:05:43 +0000459 // Set scavenging frame index if necessary.
460 uint64_t MaxSPOffset = MF.getInfo<MipsFunctionInfo>()->getIncomingArgSize() +
461 estimateStackSize(MF);
462
463 if (isInt<16>(MaxSPOffset))
464 return;
465
466 const TargetRegisterClass *RC = STI.isABI_N64() ?
467 &Mips::CPU64RegsRegClass : &Mips::CPURegsRegClass;
468 int FI = MF.getFrameInfo()->CreateStackObject(RC->getSize(),
469 RC->getAlignment(), false);
Hal Finkeldc3beb92013-03-22 23:32:27 +0000470 RS->addScavengingFrameIndex(FI);
Akira Hatanakacdb3ba72012-07-31 22:50:19 +0000471}
Akira Hatanakaaf266262012-08-02 18:21:47 +0000472
473const MipsFrameLowering *
474llvm::createMipsSEFrameLowering(const MipsSubtarget &ST) {
475 return new MipsSEFrameLowering(ST);
476}