blob: 65f113e6fb9aff31490282eb820efd225acea542 [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:
Jim Laskey2f616bf2006-11-16 22:43:37 +000045 // Use the TOC save slot in the PowerPC linkage area for saving the frame
46 // pointer (if needed.) LLVM does not generate code that uses the TOC (R2
47 // is treated as a caller saved register.)
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000048 if (isDarwinABI)
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000049 return isPPC64 ? 40 : 20;
Chris Lattner9f0bc652007-02-25 05:34:32 +000050
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000051 // SVR4 ABI: First slot in the general register save area.
Reid Spencer6733a162007-04-04 22:07:24 +000052 return -4U;
Jim Laskey2f616bf2006-11-16 22:43:37 +000053 }
54
55 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
56 ///
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000057 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
58 if (isDarwinABI || isPPC64)
59 return 6 * (isPPC64 ? 8 : 4);
Chris Lattner9f0bc652007-02-25 05:34:32 +000060
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000061 // SVR4 ABI:
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000062 return 8;
Jim Laskey2f616bf2006-11-16 22:43:37 +000063 }
64
65 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
66 /// argument area.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000067 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
68 // For the Darwin ABI / 64-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000069 // The prolog code of the callee may store up to 8 GPR argument registers to
70 // the stack, allowing va_start to index over them in memory if its varargs.
71 // Because we cannot tell if this is needed on the caller side, we have to
72 // conservatively assume that it is needed. As such, make sure we have at
73 // least enough stack space for the caller to store the 8 GPRs.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000074 if (isDarwinABI || isPPC64)
75 return 8 * (isPPC64 ? 8 : 4);
Chris Lattner9f0bc652007-02-25 05:34:32 +000076
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000077 // 32-bit SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000078 // There is no default stack allocated for the 8 first GPR arguments.
79 return 0;
Jim Laskey2f616bf2006-11-16 22:43:37 +000080 }
81
82 /// getMinCallFrameSize - Return the minimum size a call frame can be using
83 /// the PowerPC ABI.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000084 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
Jim Laskey2f616bf2006-11-16 22:43:37 +000085 // The call frame needs to be at least big enough for linkage and 8 args.
Tilmann Scheller6b16eff2009-08-15 11:54:46 +000086 return getLinkageSize(isPPC64, isDarwinABI) +
87 getMinCallArgumentsSize(isPPC64, isDarwinABI);
Jim Laskey2f616bf2006-11-16 22:43:37 +000088 }
Tilmann Schellerffd02002009-07-03 06:45:56 +000089
90 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +000091 const SpillSlot *
Tilmann Schellerffd02002009-07-03 06:45:56 +000092 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
93 // Early exit if not using the SVR4 ABI.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000094 if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) {
Tilmann Schellerffd02002009-07-03 06:45:56 +000095 NumEntries = 0;
96 return 0;
97 }
Tilmann Scheller8ff95de2009-09-27 17:58:47 +000098
99 static const SpillSlot Offsets[] = {
Tilmann Schellerffd02002009-07-03 06:45:56 +0000100 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000101 {PPC::F31, -8},
102 {PPC::F30, -16},
103 {PPC::F29, -24},
104 {PPC::F28, -32},
105 {PPC::F27, -40},
106 {PPC::F26, -48},
107 {PPC::F25, -56},
108 {PPC::F24, -64},
109 {PPC::F23, -72},
110 {PPC::F22, -80},
111 {PPC::F21, -88},
112 {PPC::F20, -96},
113 {PPC::F19, -104},
114 {PPC::F18, -112},
115 {PPC::F17, -120},
116 {PPC::F16, -128},
117 {PPC::F15, -136},
118 {PPC::F14, -144},
119
Tilmann Schellerffd02002009-07-03 06:45:56 +0000120 // General register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000121 {PPC::R31, -4},
122 {PPC::R30, -8},
123 {PPC::R29, -12},
124 {PPC::R28, -16},
125 {PPC::R27, -20},
126 {PPC::R26, -24},
127 {PPC::R25, -28},
128 {PPC::R24, -32},
129 {PPC::R23, -36},
130 {PPC::R22, -40},
131 {PPC::R21, -44},
132 {PPC::R20, -48},
133 {PPC::R19, -52},
134 {PPC::R18, -56},
135 {PPC::R17, -60},
136 {PPC::R16, -64},
137 {PPC::R15, -68},
138 {PPC::R14, -72},
Tilmann Schellerffd02002009-07-03 06:45:56 +0000139
140 // CR save area offset.
Tilmann Scheller6a3a1ba2009-07-03 06:47:55 +0000141 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000142// {PPC::CR2, -4},
143// {PPC::CR3, -4},
144// {PPC::CR4, -4},
145// {PPC::CR2LT, -4},
146// {PPC::CR2GT, -4},
147// {PPC::CR2EQ, -4},
148// {PPC::CR2UN, -4},
149// {PPC::CR3LT, -4},
150// {PPC::CR3GT, -4},
151// {PPC::CR3EQ, -4},
152// {PPC::CR3UN, -4},
153// {PPC::CR4LT, -4},
154// {PPC::CR4GT, -4},
155// {PPC::CR4EQ, -4},
156// {PPC::CR4UN, -4},
Tilmann Schellerffd02002009-07-03 06:45:56 +0000157
158 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000159 {PPC::VRSAVE, -4},
160
Tilmann Schellerffd02002009-07-03 06:45:56 +0000161 // Vector register save area
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000162 {PPC::V31, -16},
163 {PPC::V30, -32},
164 {PPC::V29, -48},
165 {PPC::V28, -64},
166 {PPC::V27, -80},
167 {PPC::V26, -96},
168 {PPC::V25, -112},
169 {PPC::V24, -128},
170 {PPC::V23, -144},
171 {PPC::V22, -160},
172 {PPC::V21, -176},
173 {PPC::V20, -192}
Tilmann Schellerffd02002009-07-03 06:45:56 +0000174 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000175
176 static const SpillSlot Offsets64[] = {
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000177 // Floating-point register save area offsets.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000178 {PPC::F31, -8},
179 {PPC::F30, -16},
180 {PPC::F29, -24},
181 {PPC::F28, -32},
182 {PPC::F27, -40},
183 {PPC::F26, -48},
184 {PPC::F25, -56},
185 {PPC::F24, -64},
186 {PPC::F23, -72},
187 {PPC::F22, -80},
188 {PPC::F21, -88},
189 {PPC::F20, -96},
190 {PPC::F19, -104},
191 {PPC::F18, -112},
192 {PPC::F17, -120},
193 {PPC::F16, -128},
194 {PPC::F15, -136},
195 {PPC::F14, -144},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000196
197 // General register save area offsets.
198 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
199 // mode?
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000200 {PPC::R31, -4},
201 {PPC::R30, -12},
202 {PPC::R29, -20},
203 {PPC::R28, -28},
204 {PPC::R27, -36},
205 {PPC::R26, -44},
206 {PPC::R25, -52},
207 {PPC::R24, -60},
208 {PPC::R23, -68},
209 {PPC::R22, -76},
210 {PPC::R21, -84},
211 {PPC::R20, -92},
212 {PPC::R19, -100},
213 {PPC::R18, -108},
214 {PPC::R17, -116},
215 {PPC::R16, -124},
216 {PPC::R15, -132},
217 {PPC::R14, -140},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000218
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000219 {PPC::X31, -8},
220 {PPC::X30, -16},
221 {PPC::X29, -24},
222 {PPC::X28, -32},
223 {PPC::X27, -40},
224 {PPC::X26, -48},
225 {PPC::X25, -56},
226 {PPC::X24, -64},
227 {PPC::X23, -72},
228 {PPC::X22, -80},
229 {PPC::X21, -88},
230 {PPC::X20, -96},
231 {PPC::X19, -104},
232 {PPC::X18, -112},
233 {PPC::X17, -120},
234 {PPC::X16, -128},
235 {PPC::X15, -136},
236 {PPC::X14, -144},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000237
238 // CR save area offset.
239 // FIXME SVR4: Disable CR save area for now.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000240// {PPC::CR2, -4},
241// {PPC::CR3, -4},
242// {PPC::CR4, -4},
243// {PPC::CR2LT, -4},
244// {PPC::CR2GT, -4},
245// {PPC::CR2EQ, -4},
246// {PPC::CR2UN, -4},
247// {PPC::CR3LT, -4},
248// {PPC::CR3GT, -4},
249// {PPC::CR3EQ, -4},
250// {PPC::CR3UN, -4},
251// {PPC::CR4LT, -4},
252// {PPC::CR4GT, -4},
253// {PPC::CR4EQ, -4},
254// {PPC::CR4UN, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000255
256 // VRSAVE save area offset.
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000257 {PPC::VRSAVE, -4},
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000258
259 // Vector register save area
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000260 {PPC::V31, -16},
261 {PPC::V30, -32},
262 {PPC::V29, -48},
263 {PPC::V28, -64},
264 {PPC::V27, -80},
265 {PPC::V26, -96},
266 {PPC::V25, -112},
267 {PPC::V24, -128},
268 {PPC::V23, -144},
269 {PPC::V22, -160},
270 {PPC::V21, -176},
271 {PPC::V20, -192}
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000272 };
Tilmann Scheller8ff95de2009-09-27 17:58:47 +0000273
Tilmann Scheller6b16eff2009-08-15 11:54:46 +0000274 if (TM.getSubtarget<PPCSubtarget>().isPPC64()) {
275 NumEntries = array_lengthof(Offsets64);
276
277 return Offsets64;
278 } else {
279 NumEntries = array_lengthof(Offsets);
280
281 return Offsets;
282 }
Tilmann Schellerffd02002009-07-03 06:45:56 +0000283 }
Nate Begemanca068e82004-08-14 22:16:36 +0000284};
285
286} // End llvm namespace
287
288#endif