blob: 204aec8a8bbd263dea11b130f6b5a4de343177f5 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Nate Begemanca068e82004-08-14 22:16:36 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Nate Begemanca068e82004-08-14 22:16:36 +00008//===----------------------------------------------------------------------===//
9//
10//
Nate Begeman21e463b2005-10-16 05:39:50 +000011//===----------------------------------------------------------------------===//
Nate Begemanca068e82004-08-14 22:16:36 +000012
13#ifndef POWERPC_FRAMEINFO_H
14#define POWERPC_FRAMEINFO_H
15
Chris Lattner26689592005-10-14 23:51:18 +000016#include "PPC.h"
Tilmann Schellerffd02002009-07-03 06:45:56 +000017#include "PPCSubtarget.h"
Nate Begemanca068e82004-08-14 22:16:36 +000018#include "llvm/Target/TargetFrameInfo.h"
19#include "llvm/Target/TargetMachine.h"
Tilmann Schellerffd02002009-07-03 06:45:56 +000020#include "llvm/ADT/STLExtras.h"
Nate Begemanca068e82004-08-14 22:16:36 +000021
22namespace llvm {
Anton Korobeynikov33464912010-11-15 00:06:54 +000023 class PPCSubtarget;
Nate Begemanca068e82004-08-14 22:16:36 +000024
Nate Begeman21e463b2005-10-16 05:39:50 +000025class PPCFrameInfo: public TargetFrameInfo {
Anton Korobeynikov33464912010-11-15 00:06:54 +000026 const PPCSubtarget &Subtarget;
Misha Brukmanb5f662f2005-04-21 23:30:14 +000027
Nate Begemanca068e82004-08-14 22:16:36 +000028public:
Anton Korobeynikov33464912010-11-15 00:06:54 +000029 PPCFrameInfo(const PPCSubtarget &sti)
30 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), Subtarget(sti) {
Nate Begemanca068e82004-08-14 22:16:36 +000031 }
32
Anton Korobeynikov33464912010-11-15 00:06:54 +000033 void determineFrameLayout(MachineFunction &MF) const;
34
35 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
36 /// the function.
37 void emitPrologue(MachineFunction &MF) const;
38 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
39
Anton Korobeynikovd0c38172010-11-18 21:19:35 +000040 bool hasFP(const MachineFunction &MF) const;
Anton Korobeynikovd9e33852010-11-18 23:25:52 +000041 void getInitialFrameState(std::vector<MachineMove> &Moves) const;
Anton Korobeynikovd0c38172010-11-18 21:19:35 +000042
Anton Korobeynikov94c5ae02010-11-27 23:05:25 +000043 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
44 RegScavenger *RS = NULL) const;
45 void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
46
Anton Korobeynikov33464912010-11-15 00:06:54 +000047 /// targetHandlesStackFrameRounding - Returns true if the target is
48 /// responsible for rounding up the stack frame (probably at emitPrologue
49 /// time).
50 bool targetHandlesStackFrameRounding() const { return true; }
51
Jim Laskey51fe9d92006-12-06 17:42:06 +000052 /// getReturnSaveOffset - Return the previous frame offset to save the
53 /// return address.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000054 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000055 if (isDarwinABI)
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000056 return isPPC64 ? 16 : 8;
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000057 // SVR4 ABI:
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000058 return isPPC64 ? 16 : 4;
Nate Begemanca068e82004-08-14 22:16:36 +000059 }
Jim Laskey51fe9d92006-12-06 17:42:06 +000060
Jim Laskey2f616bf2006-11-16 22:43:37 +000061 /// getFramePointerSaveOffset - Return the previous frame offset to save the
62 /// frame pointer.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000063 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000064 // For the Darwin ABI:
Dale Johannesenf7801b42009-11-24 22:59:02 +000065 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
66 // for saving the frame pointer (if needed.) While the published ABI has
67 // not used this slot since at least MacOSX 10.2, there is older code
68 // around that does use it, and that needs to continue to work.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000069 if (isDarwinABI)
Dale Johannesenf7801b42009-11-24 22:59:02 +000070 return isPPC64 ? -8U : -4U;
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000071
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000072 // SVR4 ABI: First slot in the general register save area.
Tilmann Schellercfcb7992009-12-18 13:00:34 +000073 return isPPC64 ? -8U : -4U;
Jim Laskey2f616bf2006-11-16 22:43:37 +000074 }
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000075
Jim Laskey2f616bf2006-11-16 22:43:37 +000076 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
77 ///
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000078 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
79 if (isDarwinABI || isPPC64)
80 return 6 * (isPPC64 ? 8 : 4);
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000081
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000082 // SVR4 ABI:
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000083 return 8;
Jim Laskey2f616bf2006-11-16 22:43:37 +000084 }
85
86 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
87 /// argument area.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000088 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
89 // For the Darwin ABI / 64-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000090 // The prolog code of the callee may store up to 8 GPR argument registers to
91 // the stack, allowing va_start to index over them in memory if its varargs.
92 // Because we cannot tell if this is needed on the caller side, we have to
93 // conservatively assume that it is needed. As such, make sure we have at
94 // least enough stack space for the caller to store the 8 GPRs.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000095 if (isDarwinABI || isPPC64)
96 return 8 * (isPPC64 ? 8 : 4);
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000097
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000098 // 32-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000099 // There is no default stack allocated for the 8 first GPR arguments.
100 return 0;
Jim Laskey2f616bf2006-11-16 22:43:37 +0000101 }
102
103 /// getMinCallFrameSize - Return the minimum size a call frame can be using
104 /// the PowerPC ABI.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000105 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
Jim Laskey2f616bf2006-11-16 22:43:37 +0000106 // The call frame needs to be at least big enough for linkage and 8 args.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000107 return getLinkageSize(isPPC64, isDarwinABI) +
108 getMinCallArgumentsSize(isPPC64, isDarwinABI);
Jim Laskey2f616bf2006-11-16 22:43:37 +0000109 }
Tilmann Schellerffd02002009-07-03 06:45:56 +0000110
111 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000112 const SpillSlot *
Tilmann Schellerffd02002009-07-03 06:45:56 +0000113 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
Anton Korobeynikov33464912010-11-15 00:06:54 +0000114 if (Subtarget.isDarwinABI()) {
Dale Johannesenf7801b42009-11-24 22:59:02 +0000115 NumEntries = 1;
Anton Korobeynikov33464912010-11-15 00:06:54 +0000116 if (Subtarget.isPPC64()) {
Dale Johannesen0106a0a2009-11-25 00:58:21 +0000117 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
118 return &darwin64Offsets;
Dale Johannesenf7801b42009-11-24 22:59:02 +0000119 } else {
Dale Johannesen0106a0a2009-11-25 00:58:21 +0000120 static const SpillSlot darwinOffsets = {PPC::R31, -4};
121 return &darwinOffsets;
Dale Johannesenf7801b42009-11-24 22:59:02 +0000122 }
123 }
124
Tilmann Schellerffd02002009-07-03 06:45:56 +0000125 // Early exit if not using the SVR4 ABI.
Anton Korobeynikov33464912010-11-15 00:06:54 +0000126 if (!Subtarget.isSVR4ABI()) {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000127 NumEntries = 0;
128 return 0;
129 }
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000130
131 static const SpillSlot Offsets[] = {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000132 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000133 {PPC::F31, -8},
134 {PPC::F30, -16},
135 {PPC::F29, -24},
136 {PPC::F28, -32},
137 {PPC::F27, -40},
138 {PPC::F26, -48},
139 {PPC::F25, -56},
140 {PPC::F24, -64},
141 {PPC::F23, -72},
142 {PPC::F22, -80},
143 {PPC::F21, -88},
144 {PPC::F20, -96},
145 {PPC::F19, -104},
146 {PPC::F18, -112},
147 {PPC::F17, -120},
148 {PPC::F16, -128},
149 {PPC::F15, -136},
150 {PPC::F14, -144},
151
Tilmann Schellerffd02002009-07-03 06:45:56 +0000152 // General register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000153 {PPC::R31, -4},
154 {PPC::R30, -8},
155 {PPC::R29, -12},
156 {PPC::R28, -16},
157 {PPC::R27, -20},
158 {PPC::R26, -24},
159 {PPC::R25, -28},
160 {PPC::R24, -32},
161 {PPC::R23, -36},
162 {PPC::R22, -40},
163 {PPC::R21, -44},
164 {PPC::R20, -48},
165 {PPC::R19, -52},
166 {PPC::R18, -56},
167 {PPC::R17, -60},
168 {PPC::R16, -64},
169 {PPC::R15, -68},
170 {PPC::R14, -72},
Tilmann Schellerffd02002009-07-03 06:45:56 +0000171
172 // CR save area offset.
Tilmann Scheller6a3a1ba2009-07-03 06:47:55 +0000173 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000174// {PPC::CR2, -4},
175// {PPC::CR3, -4},
176// {PPC::CR4, -4},
177// {PPC::CR2LT, -4},
178// {PPC::CR2GT, -4},
179// {PPC::CR2EQ, -4},
180// {PPC::CR2UN, -4},
181// {PPC::CR3LT, -4},
182// {PPC::CR3GT, -4},
183// {PPC::CR3EQ, -4},
184// {PPC::CR3UN, -4},
185// {PPC::CR4LT, -4},
186// {PPC::CR4GT, -4},
187// {PPC::CR4EQ, -4},
188// {PPC::CR4UN, -4},
Tilmann Schellerffd02002009-07-03 06:45:56 +0000189
190 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000191 {PPC::VRSAVE, -4},
192
Tilmann Schellerffd02002009-07-03 06:45:56 +0000193 // Vector register save area
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000194 {PPC::V31, -16},
195 {PPC::V30, -32},
196 {PPC::V29, -48},
197 {PPC::V28, -64},
198 {PPC::V27, -80},
199 {PPC::V26, -96},
200 {PPC::V25, -112},
201 {PPC::V24, -128},
202 {PPC::V23, -144},
203 {PPC::V22, -160},
204 {PPC::V21, -176},
205 {PPC::V20, -192}
Tilmann Schellerffd02002009-07-03 06:45:56 +0000206 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000207
208 static const SpillSlot Offsets64[] = {
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000209 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000210 {PPC::F31, -8},
211 {PPC::F30, -16},
212 {PPC::F29, -24},
213 {PPC::F28, -32},
214 {PPC::F27, -40},
215 {PPC::F26, -48},
216 {PPC::F25, -56},
217 {PPC::F24, -64},
218 {PPC::F23, -72},
219 {PPC::F22, -80},
220 {PPC::F21, -88},
221 {PPC::F20, -96},
222 {PPC::F19, -104},
223 {PPC::F18, -112},
224 {PPC::F17, -120},
225 {PPC::F16, -128},
226 {PPC::F15, -136},
227 {PPC::F14, -144},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000228
229 // General register save area offsets.
230 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
231 // mode?
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000232 {PPC::R31, -4},
233 {PPC::R30, -12},
234 {PPC::R29, -20},
235 {PPC::R28, -28},
236 {PPC::R27, -36},
237 {PPC::R26, -44},
238 {PPC::R25, -52},
239 {PPC::R24, -60},
240 {PPC::R23, -68},
241 {PPC::R22, -76},
242 {PPC::R21, -84},
243 {PPC::R20, -92},
244 {PPC::R19, -100},
245 {PPC::R18, -108},
246 {PPC::R17, -116},
247 {PPC::R16, -124},
248 {PPC::R15, -132},
249 {PPC::R14, -140},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000250
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000251 {PPC::X31, -8},
252 {PPC::X30, -16},
253 {PPC::X29, -24},
254 {PPC::X28, -32},
255 {PPC::X27, -40},
256 {PPC::X26, -48},
257 {PPC::X25, -56},
258 {PPC::X24, -64},
259 {PPC::X23, -72},
260 {PPC::X22, -80},
261 {PPC::X21, -88},
262 {PPC::X20, -96},
263 {PPC::X19, -104},
264 {PPC::X18, -112},
265 {PPC::X17, -120},
266 {PPC::X16, -128},
267 {PPC::X15, -136},
268 {PPC::X14, -144},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000269
270 // CR save area offset.
271 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000272// {PPC::CR2, -4},
273// {PPC::CR3, -4},
274// {PPC::CR4, -4},
275// {PPC::CR2LT, -4},
276// {PPC::CR2GT, -4},
277// {PPC::CR2EQ, -4},
278// {PPC::CR2UN, -4},
279// {PPC::CR3LT, -4},
280// {PPC::CR3GT, -4},
281// {PPC::CR3EQ, -4},
282// {PPC::CR3UN, -4},
283// {PPC::CR4LT, -4},
284// {PPC::CR4GT, -4},
285// {PPC::CR4EQ, -4},
286// {PPC::CR4UN, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000287
288 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000289 {PPC::VRSAVE, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000290
291 // Vector register save area
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000292 {PPC::V31, -16},
293 {PPC::V30, -32},
294 {PPC::V29, -48},
295 {PPC::V28, -64},
296 {PPC::V27, -80},
297 {PPC::V26, -96},
298 {PPC::V25, -112},
299 {PPC::V24, -128},
300 {PPC::V23, -144},
301 {PPC::V22, -160},
302 {PPC::V21, -176},
303 {PPC::V20, -192}
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000304 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000305
Anton Korobeynikov33464912010-11-15 00:06:54 +0000306 if (Subtarget.isPPC64()) {
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000307 NumEntries = array_lengthof(Offsets64);
308
309 return Offsets64;
310 } else {
311 NumEntries = array_lengthof(Offsets);
312
313 return Offsets;
314 }
Tilmann Schellerffd02002009-07-03 06:45:56 +0000315 }
Nate Begemanca068e82004-08-14 22:16:36 +0000316};
317
318} // End llvm namespace
319
320#endif