blob: aeaa864e0ab6bb3edcafe41f7ce47b9b525ccb84 [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;
41
Anton Korobeynikov33464912010-11-15 00:06:54 +000042 /// targetHandlesStackFrameRounding - Returns true if the target is
43 /// responsible for rounding up the stack frame (probably at emitPrologue
44 /// time).
45 bool targetHandlesStackFrameRounding() const { return true; }
46
Jim Laskey51fe9d92006-12-06 17:42:06 +000047 /// getReturnSaveOffset - Return the previous frame offset to save the
48 /// return address.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000049 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000050 if (isDarwinABI)
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000051 return isPPC64 ? 16 : 8;
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000052 // SVR4 ABI:
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000053 return isPPC64 ? 16 : 4;
Nate Begemanca068e82004-08-14 22:16:36 +000054 }
Jim Laskey51fe9d92006-12-06 17:42:06 +000055
Jim Laskey2f616bf2006-11-16 22:43:37 +000056 /// getFramePointerSaveOffset - Return the previous frame offset to save the
57 /// frame pointer.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000058 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000059 // For the Darwin ABI:
Dale Johannesenf7801b42009-11-24 22:59:02 +000060 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
61 // for saving the frame pointer (if needed.) While the published ABI has
62 // not used this slot since at least MacOSX 10.2, there is older code
63 // around that does use it, and that needs to continue to work.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000064 if (isDarwinABI)
Dale Johannesenf7801b42009-11-24 22:59:02 +000065 return isPPC64 ? -8U : -4U;
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000066
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000067 // SVR4 ABI: First slot in the general register save area.
Tilmann Schellercfcb7992009-12-18 13:00:34 +000068 return isPPC64 ? -8U : -4U;
Jim Laskey2f616bf2006-11-16 22:43:37 +000069 }
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000070
Jim Laskey2f616bf2006-11-16 22:43:37 +000071 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
72 ///
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000073 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
74 if (isDarwinABI || isPPC64)
75 return 6 * (isPPC64 ? 8 : 4);
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000076
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000077 // SVR4 ABI:
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000078 return 8;
Jim Laskey2f616bf2006-11-16 22:43:37 +000079 }
80
81 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
82 /// argument area.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000083 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
84 // For the Darwin ABI / 64-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000085 // The prolog code of the callee may store up to 8 GPR argument registers to
86 // the stack, allowing va_start to index over them in memory if its varargs.
87 // Because we cannot tell if this is needed on the caller side, we have to
88 // conservatively assume that it is needed. As such, make sure we have at
89 // least enough stack space for the caller to store the 8 GPRs.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000090 if (isDarwinABI || isPPC64)
91 return 8 * (isPPC64 ? 8 : 4);
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000092
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000093 // 32-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000094 // There is no default stack allocated for the 8 first GPR arguments.
95 return 0;
Jim Laskey2f616bf2006-11-16 22:43:37 +000096 }
97
98 /// getMinCallFrameSize - Return the minimum size a call frame can be using
99 /// the PowerPC ABI.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000100 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
Jim Laskey2f616bf2006-11-16 22:43:37 +0000101 // The call frame needs to be at least big enough for linkage and 8 args.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000102 return getLinkageSize(isPPC64, isDarwinABI) +
103 getMinCallArgumentsSize(isPPC64, isDarwinABI);
Jim Laskey2f616bf2006-11-16 22:43:37 +0000104 }
Tilmann Schellerffd02002009-07-03 06:45:56 +0000105
106 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000107 const SpillSlot *
Tilmann Schellerffd02002009-07-03 06:45:56 +0000108 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
Anton Korobeynikov33464912010-11-15 00:06:54 +0000109 if (Subtarget.isDarwinABI()) {
Dale Johannesenf7801b42009-11-24 22:59:02 +0000110 NumEntries = 1;
Anton Korobeynikov33464912010-11-15 00:06:54 +0000111 if (Subtarget.isPPC64()) {
Dale Johannesen0106a0a2009-11-25 00:58:21 +0000112 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
113 return &darwin64Offsets;
Dale Johannesenf7801b42009-11-24 22:59:02 +0000114 } else {
Dale Johannesen0106a0a2009-11-25 00:58:21 +0000115 static const SpillSlot darwinOffsets = {PPC::R31, -4};
116 return &darwinOffsets;
Dale Johannesenf7801b42009-11-24 22:59:02 +0000117 }
118 }
119
Tilmann Schellerffd02002009-07-03 06:45:56 +0000120 // Early exit if not using the SVR4 ABI.
Anton Korobeynikov33464912010-11-15 00:06:54 +0000121 if (!Subtarget.isSVR4ABI()) {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000122 NumEntries = 0;
123 return 0;
124 }
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000125
126 static const SpillSlot Offsets[] = {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000127 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000128 {PPC::F31, -8},
129 {PPC::F30, -16},
130 {PPC::F29, -24},
131 {PPC::F28, -32},
132 {PPC::F27, -40},
133 {PPC::F26, -48},
134 {PPC::F25, -56},
135 {PPC::F24, -64},
136 {PPC::F23, -72},
137 {PPC::F22, -80},
138 {PPC::F21, -88},
139 {PPC::F20, -96},
140 {PPC::F19, -104},
141 {PPC::F18, -112},
142 {PPC::F17, -120},
143 {PPC::F16, -128},
144 {PPC::F15, -136},
145 {PPC::F14, -144},
146
Tilmann Schellerffd02002009-07-03 06:45:56 +0000147 // General register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000148 {PPC::R31, -4},
149 {PPC::R30, -8},
150 {PPC::R29, -12},
151 {PPC::R28, -16},
152 {PPC::R27, -20},
153 {PPC::R26, -24},
154 {PPC::R25, -28},
155 {PPC::R24, -32},
156 {PPC::R23, -36},
157 {PPC::R22, -40},
158 {PPC::R21, -44},
159 {PPC::R20, -48},
160 {PPC::R19, -52},
161 {PPC::R18, -56},
162 {PPC::R17, -60},
163 {PPC::R16, -64},
164 {PPC::R15, -68},
165 {PPC::R14, -72},
Tilmann Schellerffd02002009-07-03 06:45:56 +0000166
167 // CR save area offset.
Tilmann Scheller6a3a1ba2009-07-03 06:47:55 +0000168 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000169// {PPC::CR2, -4},
170// {PPC::CR3, -4},
171// {PPC::CR4, -4},
172// {PPC::CR2LT, -4},
173// {PPC::CR2GT, -4},
174// {PPC::CR2EQ, -4},
175// {PPC::CR2UN, -4},
176// {PPC::CR3LT, -4},
177// {PPC::CR3GT, -4},
178// {PPC::CR3EQ, -4},
179// {PPC::CR3UN, -4},
180// {PPC::CR4LT, -4},
181// {PPC::CR4GT, -4},
182// {PPC::CR4EQ, -4},
183// {PPC::CR4UN, -4},
Tilmann Schellerffd02002009-07-03 06:45:56 +0000184
185 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000186 {PPC::VRSAVE, -4},
187
Tilmann Schellerffd02002009-07-03 06:45:56 +0000188 // Vector register save area
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000189 {PPC::V31, -16},
190 {PPC::V30, -32},
191 {PPC::V29, -48},
192 {PPC::V28, -64},
193 {PPC::V27, -80},
194 {PPC::V26, -96},
195 {PPC::V25, -112},
196 {PPC::V24, -128},
197 {PPC::V23, -144},
198 {PPC::V22, -160},
199 {PPC::V21, -176},
200 {PPC::V20, -192}
Tilmann Schellerffd02002009-07-03 06:45:56 +0000201 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000202
203 static const SpillSlot Offsets64[] = {
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000204 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000205 {PPC::F31, -8},
206 {PPC::F30, -16},
207 {PPC::F29, -24},
208 {PPC::F28, -32},
209 {PPC::F27, -40},
210 {PPC::F26, -48},
211 {PPC::F25, -56},
212 {PPC::F24, -64},
213 {PPC::F23, -72},
214 {PPC::F22, -80},
215 {PPC::F21, -88},
216 {PPC::F20, -96},
217 {PPC::F19, -104},
218 {PPC::F18, -112},
219 {PPC::F17, -120},
220 {PPC::F16, -128},
221 {PPC::F15, -136},
222 {PPC::F14, -144},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000223
224 // General register save area offsets.
225 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
226 // mode?
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000227 {PPC::R31, -4},
228 {PPC::R30, -12},
229 {PPC::R29, -20},
230 {PPC::R28, -28},
231 {PPC::R27, -36},
232 {PPC::R26, -44},
233 {PPC::R25, -52},
234 {PPC::R24, -60},
235 {PPC::R23, -68},
236 {PPC::R22, -76},
237 {PPC::R21, -84},
238 {PPC::R20, -92},
239 {PPC::R19, -100},
240 {PPC::R18, -108},
241 {PPC::R17, -116},
242 {PPC::R16, -124},
243 {PPC::R15, -132},
244 {PPC::R14, -140},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000245
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000246 {PPC::X31, -8},
247 {PPC::X30, -16},
248 {PPC::X29, -24},
249 {PPC::X28, -32},
250 {PPC::X27, -40},
251 {PPC::X26, -48},
252 {PPC::X25, -56},
253 {PPC::X24, -64},
254 {PPC::X23, -72},
255 {PPC::X22, -80},
256 {PPC::X21, -88},
257 {PPC::X20, -96},
258 {PPC::X19, -104},
259 {PPC::X18, -112},
260 {PPC::X17, -120},
261 {PPC::X16, -128},
262 {PPC::X15, -136},
263 {PPC::X14, -144},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000264
265 // CR save area offset.
266 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000267// {PPC::CR2, -4},
268// {PPC::CR3, -4},
269// {PPC::CR4, -4},
270// {PPC::CR2LT, -4},
271// {PPC::CR2GT, -4},
272// {PPC::CR2EQ, -4},
273// {PPC::CR2UN, -4},
274// {PPC::CR3LT, -4},
275// {PPC::CR3GT, -4},
276// {PPC::CR3EQ, -4},
277// {PPC::CR3UN, -4},
278// {PPC::CR4LT, -4},
279// {PPC::CR4GT, -4},
280// {PPC::CR4EQ, -4},
281// {PPC::CR4UN, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000282
283 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000284 {PPC::VRSAVE, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000285
286 // Vector register save area
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000287 {PPC::V31, -16},
288 {PPC::V30, -32},
289 {PPC::V29, -48},
290 {PPC::V28, -64},
291 {PPC::V27, -80},
292 {PPC::V26, -96},
293 {PPC::V25, -112},
294 {PPC::V24, -128},
295 {PPC::V23, -144},
296 {PPC::V22, -160},
297 {PPC::V21, -176},
298 {PPC::V20, -192}
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000299 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000300
Anton Korobeynikov33464912010-11-15 00:06:54 +0000301 if (Subtarget.isPPC64()) {
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000302 NumEntries = array_lengthof(Offsets64);
303
304 return Offsets64;
305 } else {
306 NumEntries = array_lengthof(Offsets);
307
308 return Offsets;
309 }
Tilmann Schellerffd02002009-07-03 06:45:56 +0000310 }
Nate Begemanca068e82004-08-14 22:16:36 +0000311};
312
313} // End llvm namespace
314
315#endif