]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/lib/Target/PowerPC/PPCFrameLowering.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / lib / Target / PowerPC / PPCFrameLowering.h
1 //==-- PPCFrameLowering.h - Define frame lowering for PowerPC ----*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef POWERPC_FRAMEINFO_H
14 #define POWERPC_FRAMEINFO_H
15
16 #include "PPC.h"
17 #include "PPCSubtarget.h"
18 #include "llvm/Target/TargetFrameLowering.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/ADT/STLExtras.h"
21
22 namespace llvm {
23   class PPCSubtarget;
24
25 class PPCFrameLowering: public TargetFrameLowering {
26   const PPCSubtarget &Subtarget;
27
28 public:
29   PPCFrameLowering(const PPCSubtarget &sti)
30     : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 16, 0),
31       Subtarget(sti) {
32   }
33
34   void determineFrameLayout(MachineFunction &MF) const;
35
36   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
37   /// the function.
38   void emitPrologue(MachineFunction &MF) const;
39   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
40
41   bool hasFP(const MachineFunction &MF) const;
42   bool needsFP(const MachineFunction &MF) const;
43   void getInitialFrameState(std::vector<MachineMove> &Moves) const;
44
45   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
46                                             RegScavenger *RS = NULL) const;
47   void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
48
49   /// targetHandlesStackFrameRounding - Returns true if the target is
50   /// responsible for rounding up the stack frame (probably at emitPrologue
51   /// time).
52   bool targetHandlesStackFrameRounding() const { return true; }
53
54   /// getReturnSaveOffset - Return the previous frame offset to save the
55   /// return address.
56   static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
57     if (isDarwinABI)
58       return isPPC64 ? 16 : 8;
59     // SVR4 ABI:
60     return isPPC64 ? 16 : 4;
61   }
62
63   /// getFramePointerSaveOffset - Return the previous frame offset to save the
64   /// frame pointer.
65   static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
66     // For the Darwin ABI:
67     // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
68     // for saving the frame pointer (if needed.)  While the published ABI has
69     // not used this slot since at least MacOSX 10.2, there is older code
70     // around that does use it, and that needs to continue to work.
71     if (isDarwinABI)
72       return isPPC64 ? -8U : -4U;
73
74     // SVR4 ABI: First slot in the general register save area.
75     return isPPC64 ? -8U : -4U;
76   }
77
78   /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
79   ///
80   static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
81     if (isDarwinABI || isPPC64)
82       return 6 * (isPPC64 ? 8 : 4);
83
84     // SVR4 ABI:
85     return 8;
86   }
87
88   /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
89   /// argument area.
90   static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
91     // For the Darwin ABI / 64-bit SVR4 ABI:
92     // The prolog code of the callee may store up to 8 GPR argument registers to
93     // the stack, allowing va_start to index over them in memory if its varargs.
94     // Because we cannot tell if this is needed on the caller side, we have to
95     // conservatively assume that it is needed.  As such, make sure we have at
96     // least enough stack space for the caller to store the 8 GPRs.
97     if (isDarwinABI || isPPC64)
98       return 8 * (isPPC64 ? 8 : 4);
99
100     // 32-bit SVR4 ABI:
101     // There is no default stack allocated for the 8 first GPR arguments.
102     return 0;
103   }
104
105   /// getMinCallFrameSize - Return the minimum size a call frame can be using
106   /// the PowerPC ABI.
107   static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
108     // The call frame needs to be at least big enough for linkage and 8 args.
109     return getLinkageSize(isPPC64, isDarwinABI) +
110            getMinCallArgumentsSize(isPPC64, isDarwinABI);
111   }
112
113   // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
114   const SpillSlot *
115   getCalleeSavedSpillSlots(unsigned &NumEntries) const {
116     if (Subtarget.isDarwinABI()) {
117       NumEntries = 1;
118       if (Subtarget.isPPC64()) {
119         static const SpillSlot darwin64Offsets = {PPC::X31, -8};
120         return &darwin64Offsets;
121       } else {
122         static const SpillSlot darwinOffsets = {PPC::R31, -4};
123         return &darwinOffsets;
124       }
125     }
126
127     // Early exit if not using the SVR4 ABI.
128     if (!Subtarget.isSVR4ABI()) {
129       NumEntries = 0;
130       return 0;
131     }
132
133     static const SpillSlot Offsets[] = {
134       // Floating-point register save area offsets.
135       {PPC::F31, -8},
136       {PPC::F30, -16},
137       {PPC::F29, -24},
138       {PPC::F28, -32},
139       {PPC::F27, -40},
140       {PPC::F26, -48},
141       {PPC::F25, -56},
142       {PPC::F24, -64},
143       {PPC::F23, -72},
144       {PPC::F22, -80},
145       {PPC::F21, -88},
146       {PPC::F20, -96},
147       {PPC::F19, -104},
148       {PPC::F18, -112},
149       {PPC::F17, -120},
150       {PPC::F16, -128},
151       {PPC::F15, -136},
152       {PPC::F14, -144},
153
154       // General register save area offsets.
155       {PPC::R31, -4},
156       {PPC::R30, -8},
157       {PPC::R29, -12},
158       {PPC::R28, -16},
159       {PPC::R27, -20},
160       {PPC::R26, -24},
161       {PPC::R25, -28},
162       {PPC::R24, -32},
163       {PPC::R23, -36},
164       {PPC::R22, -40},
165       {PPC::R21, -44},
166       {PPC::R20, -48},
167       {PPC::R19, -52},
168       {PPC::R18, -56},
169       {PPC::R17, -60},
170       {PPC::R16, -64},
171       {PPC::R15, -68},
172       {PPC::R14, -72},
173
174       // CR save area offset.
175       // FIXME SVR4: Disable CR save area for now.
176 //      {PPC::CR2, -4},
177 //      {PPC::CR3, -4},
178 //      {PPC::CR4, -4},
179 //      {PPC::CR2LT, -4},
180 //      {PPC::CR2GT, -4},
181 //      {PPC::CR2EQ, -4},
182 //      {PPC::CR2UN, -4},
183 //      {PPC::CR3LT, -4},
184 //      {PPC::CR3GT, -4},
185 //      {PPC::CR3EQ, -4},
186 //      {PPC::CR3UN, -4},
187 //      {PPC::CR4LT, -4},
188 //      {PPC::CR4GT, -4},
189 //      {PPC::CR4EQ, -4},
190 //      {PPC::CR4UN, -4},
191
192       // VRSAVE save area offset.
193       {PPC::VRSAVE, -4},
194
195       // Vector register save area
196       {PPC::V31, -16},
197       {PPC::V30, -32},
198       {PPC::V29, -48},
199       {PPC::V28, -64},
200       {PPC::V27, -80},
201       {PPC::V26, -96},
202       {PPC::V25, -112},
203       {PPC::V24, -128},
204       {PPC::V23, -144},
205       {PPC::V22, -160},
206       {PPC::V21, -176},
207       {PPC::V20, -192}
208     };
209
210     static const SpillSlot Offsets64[] = {
211       // Floating-point register save area offsets.
212       {PPC::F31, -8},
213       {PPC::F30, -16},
214       {PPC::F29, -24},
215       {PPC::F28, -32},
216       {PPC::F27, -40},
217       {PPC::F26, -48},
218       {PPC::F25, -56},
219       {PPC::F24, -64},
220       {PPC::F23, -72},
221       {PPC::F22, -80},
222       {PPC::F21, -88},
223       {PPC::F20, -96},
224       {PPC::F19, -104},
225       {PPC::F18, -112},
226       {PPC::F17, -120},
227       {PPC::F16, -128},
228       {PPC::F15, -136},
229       {PPC::F14, -144},
230
231       // General register save area offsets.
232       // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
233       //                    mode?
234       {PPC::R31, -4},
235       {PPC::R30, -12},
236       {PPC::R29, -20},
237       {PPC::R28, -28},
238       {PPC::R27, -36},
239       {PPC::R26, -44},
240       {PPC::R25, -52},
241       {PPC::R24, -60},
242       {PPC::R23, -68},
243       {PPC::R22, -76},
244       {PPC::R21, -84},
245       {PPC::R20, -92},
246       {PPC::R19, -100},
247       {PPC::R18, -108},
248       {PPC::R17, -116},
249       {PPC::R16, -124},
250       {PPC::R15, -132},
251       {PPC::R14, -140},
252
253       {PPC::X31, -8},
254       {PPC::X30, -16},
255       {PPC::X29, -24},
256       {PPC::X28, -32},
257       {PPC::X27, -40},
258       {PPC::X26, -48},
259       {PPC::X25, -56},
260       {PPC::X24, -64},
261       {PPC::X23, -72},
262       {PPC::X22, -80},
263       {PPC::X21, -88},
264       {PPC::X20, -96},
265       {PPC::X19, -104},
266       {PPC::X18, -112},
267       {PPC::X17, -120},
268       {PPC::X16, -128},
269       {PPC::X15, -136},
270       {PPC::X14, -144},
271
272       // CR save area offset.
273       // FIXME SVR4: Disable CR save area for now.
274 //      {PPC::CR2, -4},
275 //      {PPC::CR3, -4},
276 //      {PPC::CR4, -4},
277 //      {PPC::CR2LT, -4},
278 //      {PPC::CR2GT, -4},
279 //      {PPC::CR2EQ, -4},
280 //      {PPC::CR2UN, -4},
281 //      {PPC::CR3LT, -4},
282 //      {PPC::CR3GT, -4},
283 //      {PPC::CR3EQ, -4},
284 //      {PPC::CR3UN, -4},
285 //      {PPC::CR4LT, -4},
286 //      {PPC::CR4GT, -4},
287 //      {PPC::CR4EQ, -4},
288 //      {PPC::CR4UN, -4},
289
290       // VRSAVE save area offset.
291       {PPC::VRSAVE, -4},
292
293       // Vector register save area
294       {PPC::V31, -16},
295       {PPC::V30, -32},
296       {PPC::V29, -48},
297       {PPC::V28, -64},
298       {PPC::V27, -80},
299       {PPC::V26, -96},
300       {PPC::V25, -112},
301       {PPC::V24, -128},
302       {PPC::V23, -144},
303       {PPC::V22, -160},
304       {PPC::V21, -176},
305       {PPC::V20, -192}
306     };
307
308     if (Subtarget.isPPC64()) {
309       NumEntries = array_lengthof(Offsets64);
310
311       return Offsets64;
312     } else {
313       NumEntries = array_lengthof(Offsets);
314
315       return Offsets;
316     }
317   }
318 };
319
320 } // End llvm namespace
321
322 #endif