blob: 7587b0359816816539892548ba3f3e3b9ede0ad4 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef POWERPC_FRAMEINFO_H
14#define POWERPC_FRAMEINFO_H
15
16#include "PPC.h"
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +000017#include "PPCSubtarget.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018#include "llvm/Target/TargetFrameInfo.h"
19#include "llvm/Target/TargetMachine.h"
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +000020#include "llvm/ADT/STLExtras.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021
22namespace llvm {
23
24class PPCFrameInfo: public TargetFrameInfo {
25 const TargetMachine &TM;
26
27public:
28 PPCFrameInfo(const TargetMachine &tm, bool LP64)
29 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
30 }
31
32 /// getReturnSaveOffset - Return the previous frame offset to save the
33 /// return address.
Tilmann Scheller72cf2812009-08-15 11:54:46 +000034 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller386330d2009-07-03 06:47:08 +000035 if (isDarwinABI)
Tilmann Scheller72cf2812009-08-15 11:54:46 +000036 return isPPC64 ? 16 : 8;
Tilmann Scheller386330d2009-07-03 06:47:08 +000037 // SVR4 ABI:
Tilmann Scheller72cf2812009-08-15 11:54:46 +000038 return isPPC64 ? 16 : 4;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 }
40
41 /// getFramePointerSaveOffset - Return the previous frame offset to save the
42 /// frame pointer.
Tilmann Scheller72cf2812009-08-15 11:54:46 +000043 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller386330d2009-07-03 06:47:08 +000044 // For the Darwin ABI:
Dale Johannesen9902d092009-11-24 22:59:02 +000045 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
46 // for saving the frame pointer (if needed.) While the published ABI has
47 // not used this slot since at least MacOSX 10.2, there is older code
48 // around that does use it, and that needs to continue to work.
Tilmann Scheller386330d2009-07-03 06:47:08 +000049 if (isDarwinABI)
Dale Johannesen9902d092009-11-24 22:59:02 +000050 return isPPC64 ? -8U : -4U;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051
Tilmann Scheller72cf2812009-08-15 11:54:46 +000052 // SVR4 ABI: First slot in the general register save area.
Tilmann Scheller049162b2009-12-18 13:00:34 +000053 return isPPC64 ? -8U : -4U;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054 }
55
56 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
57 ///
Tilmann Scheller72cf2812009-08-15 11:54:46 +000058 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
59 if (isDarwinABI || isPPC64)
60 return 6 * (isPPC64 ? 8 : 4);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061
Tilmann Scheller386330d2009-07-03 06:47:08 +000062 // SVR4 ABI:
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 return 8;
64 }
65
66 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
67 /// argument area.
Tilmann Scheller72cf2812009-08-15 11:54:46 +000068 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
69 // For the Darwin ABI / 64-bit SVR4 ABI:
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070 // The prolog code of the callee may store up to 8 GPR argument registers to
71 // the stack, allowing va_start to index over them in memory if its varargs.
72 // Because we cannot tell if this is needed on the caller side, we have to
73 // conservatively assume that it is needed. As such, make sure we have at
74 // least enough stack space for the caller to store the 8 GPRs.
Tilmann Scheller72cf2812009-08-15 11:54:46 +000075 if (isDarwinABI || isPPC64)
76 return 8 * (isPPC64 ? 8 : 4);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077
Tilmann Scheller72cf2812009-08-15 11:54:46 +000078 // 32-bit SVR4 ABI:
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079 // There is no default stack allocated for the 8 first GPR arguments.
80 return 0;
81 }
82
83 /// getMinCallFrameSize - Return the minimum size a call frame can be using
84 /// the PowerPC ABI.
Tilmann Scheller72cf2812009-08-15 11:54:46 +000085 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086 // The call frame needs to be at least big enough for linkage and 8 args.
Tilmann Scheller72cf2812009-08-15 11:54:46 +000087 return getLinkageSize(isPPC64, isDarwinABI) +
88 getMinCallArgumentsSize(isPPC64, isDarwinABI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 }
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +000090
91 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +000092 const SpillSlot *
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +000093 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
Dale Johannesen9902d092009-11-24 22:59:02 +000094 if (TM.getSubtarget<PPCSubtarget>().isDarwinABI()) {
95 NumEntries = 1;
96 if (TM.getSubtarget<PPCSubtarget>().isPPC64()) {
Dale Johannesen65ee1912009-11-25 00:58:21 +000097 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
98 return &darwin64Offsets;
Dale Johannesen9902d092009-11-24 22:59:02 +000099 } else {
Dale Johannesen65ee1912009-11-25 00:58:21 +0000100 static const SpillSlot darwinOffsets = {PPC::R31, -4};
101 return &darwinOffsets;
Dale Johannesen9902d092009-11-24 22:59:02 +0000102 }
103 }
104
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000105 // Early exit if not using the SVR4 ABI.
Tilmann Scheller386330d2009-07-03 06:47:08 +0000106 if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) {
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000107 NumEntries = 0;
108 return 0;
109 }
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000110
111 static const SpillSlot Offsets[] = {
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000112 // Floating-point register save area offsets.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000113 {PPC::F31, -8},
114 {PPC::F30, -16},
115 {PPC::F29, -24},
116 {PPC::F28, -32},
117 {PPC::F27, -40},
118 {PPC::F26, -48},
119 {PPC::F25, -56},
120 {PPC::F24, -64},
121 {PPC::F23, -72},
122 {PPC::F22, -80},
123 {PPC::F21, -88},
124 {PPC::F20, -96},
125 {PPC::F19, -104},
126 {PPC::F18, -112},
127 {PPC::F17, -120},
128 {PPC::F16, -128},
129 {PPC::F15, -136},
130 {PPC::F14, -144},
131
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000132 // General register save area offsets.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000133 {PPC::R31, -4},
134 {PPC::R30, -8},
135 {PPC::R29, -12},
136 {PPC::R28, -16},
137 {PPC::R27, -20},
138 {PPC::R26, -24},
139 {PPC::R25, -28},
140 {PPC::R24, -32},
141 {PPC::R23, -36},
142 {PPC::R22, -40},
143 {PPC::R21, -44},
144 {PPC::R20, -48},
145 {PPC::R19, -52},
146 {PPC::R18, -56},
147 {PPC::R17, -60},
148 {PPC::R16, -64},
149 {PPC::R15, -68},
150 {PPC::R14, -72},
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000151
152 // CR save area offset.
Tilmann Schelleradb669f2009-07-03 06:47:55 +0000153 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000154// {PPC::CR2, -4},
155// {PPC::CR3, -4},
156// {PPC::CR4, -4},
157// {PPC::CR2LT, -4},
158// {PPC::CR2GT, -4},
159// {PPC::CR2EQ, -4},
160// {PPC::CR2UN, -4},
161// {PPC::CR3LT, -4},
162// {PPC::CR3GT, -4},
163// {PPC::CR3EQ, -4},
164// {PPC::CR3UN, -4},
165// {PPC::CR4LT, -4},
166// {PPC::CR4GT, -4},
167// {PPC::CR4EQ, -4},
168// {PPC::CR4UN, -4},
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000169
170 // VRSAVE save area offset.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000171 {PPC::VRSAVE, -4},
172
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000173 // Vector register save area
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000174 {PPC::V31, -16},
175 {PPC::V30, -32},
176 {PPC::V29, -48},
177 {PPC::V28, -64},
178 {PPC::V27, -80},
179 {PPC::V26, -96},
180 {PPC::V25, -112},
181 {PPC::V24, -128},
182 {PPC::V23, -144},
183 {PPC::V22, -160},
184 {PPC::V21, -176},
185 {PPC::V20, -192}
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000186 };
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000187
188 static const SpillSlot Offsets64[] = {
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000189 // Floating-point register save area offsets.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000190 {PPC::F31, -8},
191 {PPC::F30, -16},
192 {PPC::F29, -24},
193 {PPC::F28, -32},
194 {PPC::F27, -40},
195 {PPC::F26, -48},
196 {PPC::F25, -56},
197 {PPC::F24, -64},
198 {PPC::F23, -72},
199 {PPC::F22, -80},
200 {PPC::F21, -88},
201 {PPC::F20, -96},
202 {PPC::F19, -104},
203 {PPC::F18, -112},
204 {PPC::F17, -120},
205 {PPC::F16, -128},
206 {PPC::F15, -136},
207 {PPC::F14, -144},
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000208
209 // General register save area offsets.
210 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
211 // mode?
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000212 {PPC::R31, -4},
213 {PPC::R30, -12},
214 {PPC::R29, -20},
215 {PPC::R28, -28},
216 {PPC::R27, -36},
217 {PPC::R26, -44},
218 {PPC::R25, -52},
219 {PPC::R24, -60},
220 {PPC::R23, -68},
221 {PPC::R22, -76},
222 {PPC::R21, -84},
223 {PPC::R20, -92},
224 {PPC::R19, -100},
225 {PPC::R18, -108},
226 {PPC::R17, -116},
227 {PPC::R16, -124},
228 {PPC::R15, -132},
229 {PPC::R14, -140},
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000230
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000231 {PPC::X31, -8},
232 {PPC::X30, -16},
233 {PPC::X29, -24},
234 {PPC::X28, -32},
235 {PPC::X27, -40},
236 {PPC::X26, -48},
237 {PPC::X25, -56},
238 {PPC::X24, -64},
239 {PPC::X23, -72},
240 {PPC::X22, -80},
241 {PPC::X21, -88},
242 {PPC::X20, -96},
243 {PPC::X19, -104},
244 {PPC::X18, -112},
245 {PPC::X17, -120},
246 {PPC::X16, -128},
247 {PPC::X15, -136},
248 {PPC::X14, -144},
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000249
250 // CR save area offset.
251 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000252// {PPC::CR2, -4},
253// {PPC::CR3, -4},
254// {PPC::CR4, -4},
255// {PPC::CR2LT, -4},
256// {PPC::CR2GT, -4},
257// {PPC::CR2EQ, -4},
258// {PPC::CR2UN, -4},
259// {PPC::CR3LT, -4},
260// {PPC::CR3GT, -4},
261// {PPC::CR3EQ, -4},
262// {PPC::CR3UN, -4},
263// {PPC::CR4LT, -4},
264// {PPC::CR4GT, -4},
265// {PPC::CR4EQ, -4},
266// {PPC::CR4UN, -4},
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000267
268 // VRSAVE save area offset.
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000269 {PPC::VRSAVE, -4},
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000270
271 // Vector register save area
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000272 {PPC::V31, -16},
273 {PPC::V30, -32},
274 {PPC::V29, -48},
275 {PPC::V28, -64},
276 {PPC::V27, -80},
277 {PPC::V26, -96},
278 {PPC::V25, -112},
279 {PPC::V24, -128},
280 {PPC::V23, -144},
281 {PPC::V22, -160},
282 {PPC::V21, -176},
283 {PPC::V20, -192}
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000284 };
Tilmann Scheller4c2770b2009-09-27 17:58:47 +0000285
Tilmann Scheller72cf2812009-08-15 11:54:46 +0000286 if (TM.getSubtarget<PPCSubtarget>().isPPC64()) {
287 NumEntries = array_lengthof(Offsets64);
288
289 return Offsets64;
290 } else {
291 NumEntries = array_lengthof(Offsets);
292
293 return Offsets;
294 }
Tilmann Scheller1dd42ff2009-07-03 06:45:56 +0000295 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000296};
297
298} // End llvm namespace
299
300#endif