blob: 2551d6fc2e16637299bd933205315e94dde4d65f [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 {
23
Nate Begeman21e463b2005-10-16 05:39:50 +000024class PPCFrameInfo: public TargetFrameInfo {
Nate Begemanca068e82004-08-14 22:16:36 +000025 const TargetMachine &TM;
Misha Brukmanb5f662f2005-04-21 23:30:14 +000026
Nate Begemanca068e82004-08-14 22:16:36 +000027public:
Nate Begeman21e463b2005-10-16 05:39:50 +000028 PPCFrameInfo(const TargetMachine &tm, bool LP64)
Misha Brukman63161812004-08-17 05:09:39 +000029 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
Nate Begemanca068e82004-08-14 22:16:36 +000030 }
31
Jim Laskey51fe9d92006-12-06 17:42:06 +000032 /// getReturnSaveOffset - Return the previous frame offset to save the
33 /// return address.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000034 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000035 if (isDarwinABI)
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000036 return isPPC64 ? 16 : 8;
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000037 // SVR4 ABI:
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000038 return isPPC64 ? 16 : 4;
Nate Begemanca068e82004-08-14 22:16:36 +000039 }
Jim Laskey51fe9d92006-12-06 17:42:06 +000040
Jim Laskey2f616bf2006-11-16 22:43:37 +000041 /// getFramePointerSaveOffset - Return the previous frame offset to save the
42 /// frame pointer.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000043 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000044 // For the Darwin ABI:
Dale Johannesenf7801b42009-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 Scheller2a9ddfb2009-07-03 06:47:08 +000049 if (isDarwinABI)
Dale Johannesenf7801b42009-11-24 22:59:02 +000050 return isPPC64 ? -8U : -4U;
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000051
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000052 // SVR4 ABI: First slot in the general register save area.
Tilmann Schellercfcb7992009-12-18 13:00:34 +000053 return isPPC64 ? -8U : -4U;
Jim Laskey2f616bf2006-11-16 22:43:37 +000054 }
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000055
Jim Laskey2f616bf2006-11-16 22:43:37 +000056 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
57 ///
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000058 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
59 if (isDarwinABI || isPPC64)
60 return 6 * (isPPC64 ? 8 : 4);
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000061
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000062 // SVR4 ABI:
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000063 return 8;
Jim Laskey2f616bf2006-11-16 22:43:37 +000064 }
65
66 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
67 /// argument area.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000068 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
69 // For the Darwin ABI / 64-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +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 Scheller6b16eff2009-08-15 11:54:46 +000075 if (isDarwinABI || isPPC64)
76 return 8 * (isPPC64 ? 8 : 4);
Anton Korobeynikov78b4fee2010-11-15 00:06:05 +000077
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000078 // 32-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000079 // There is no default stack allocated for the 8 first GPR arguments.
80 return 0;
Jim Laskey2f616bf2006-11-16 22:43:37 +000081 }
82
83 /// getMinCallFrameSize - Return the minimum size a call frame can be using
84 /// the PowerPC ABI.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000085 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
Jim Laskey2f616bf2006-11-16 22:43:37 +000086 // The call frame needs to be at least big enough for linkage and 8 args.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000087 return getLinkageSize(isPPC64, isDarwinABI) +
88 getMinCallArgumentsSize(isPPC64, isDarwinABI);
Jim Laskey2f616bf2006-11-16 22:43:37 +000089 }
Tilmann Schellerffd02002009-07-03 06:45:56 +000090
91 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +000092 const SpillSlot *
Tilmann Schellerffd02002009-07-03 06:45:56 +000093 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
Dale Johannesenf7801b42009-11-24 22:59:02 +000094 if (TM.getSubtarget<PPCSubtarget>().isDarwinABI()) {
95 NumEntries = 1;
96 if (TM.getSubtarget<PPCSubtarget>().isPPC64()) {
Dale Johannesen0106a0a2009-11-25 00:58:21 +000097 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
98 return &darwin64Offsets;
Dale Johannesenf7801b42009-11-24 22:59:02 +000099 } else {
Dale Johannesen0106a0a2009-11-25 00:58:21 +0000100 static const SpillSlot darwinOffsets = {PPC::R31, -4};
101 return &darwinOffsets;
Dale Johannesenf7801b42009-11-24 22:59:02 +0000102 }
103 }
104
Tilmann Schellerffd02002009-07-03 06:45:56 +0000105 // Early exit if not using the SVR4 ABI.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +0000106 if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000107 NumEntries = 0;
108 return 0;
109 }
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000110
111 static const SpillSlot Offsets[] = {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000112 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-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 Schellerffd02002009-07-03 06:45:56 +0000132 // General register save area offsets.
Tilmann Scheller8ff95de2009-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 Schellerffd02002009-07-03 06:45:56 +0000151
152 // CR save area offset.
Tilmann Scheller6a3a1ba2009-07-03 06:47:55 +0000153 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-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 Schellerffd02002009-07-03 06:45:56 +0000169
170 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000171 {PPC::VRSAVE, -4},
172
Tilmann Schellerffd02002009-07-03 06:45:56 +0000173 // Vector register save area
Tilmann Scheller8ff95de2009-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 Schellerffd02002009-07-03 06:45:56 +0000186 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000187
188 static const SpillSlot Offsets64[] = {
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000189 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-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 Scheller6b16eff2009-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 Scheller8ff95de2009-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 Scheller6b16eff2009-08-15 11:54:46 +0000230
Tilmann Scheller8ff95de2009-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 Scheller6b16eff2009-08-15 11:54:46 +0000249
250 // CR save area offset.
251 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-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 Scheller6b16eff2009-08-15 11:54:46 +0000267
268 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000269 {PPC::VRSAVE, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000270
271 // Vector register save area
Tilmann Scheller8ff95de2009-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 Scheller6b16eff2009-08-15 11:54:46 +0000284 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000285
Tilmann Scheller6b16eff2009-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 Schellerffd02002009-07-03 06:45:56 +0000295 }
Nate Begemanca068e82004-08-14 22:16:36 +0000296};
297
298} // End llvm namespace
299
300#endif