Split EVT into MVT and EVT, the former representing _just_ a primitive type, while
[oota-llvm.git] / lib / Target / PowerPC / PPCFrameInfo.h
1 //===-- PPCFrameInfo.h - Define TargetFrameInfo 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/TargetFrameInfo.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/ADT/STLExtras.h"
21
22 namespace llvm {
23
24 class PPCFrameInfo: public TargetFrameInfo {
25   const TargetMachine &TM;
26
27 public:
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.
34   static unsigned getReturnSaveOffset(bool LP64, bool isDarwinABI) {
35     if (isDarwinABI)
36       return LP64 ? 16 : 8;
37     // SVR4 ABI:
38     return 4;
39   }
40
41   /// getFramePointerSaveOffset - Return the previous frame offset to save the
42   /// frame pointer.
43   static unsigned getFramePointerSaveOffset(bool LP64, bool isDarwinABI) {
44     // For the Darwin ABI:
45     // 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.)
48     if (isDarwinABI)
49       return LP64 ? 40 : 20;
50     
51     // SVR4 ABI:
52     // Save it right before the link register
53     return -4U;
54   }
55   
56   /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
57   ///
58   static unsigned getLinkageSize(bool LP64, bool isDarwinABI) {
59     if (isDarwinABI)
60       return 6 * (LP64 ? 8 : 4);
61     
62     // SVR4 ABI:
63     return 8;
64   }
65
66   /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
67   /// argument area.
68   static unsigned getMinCallArgumentsSize(bool LP64, bool isDarwinABI) {
69     // For the Darwin ABI:
70     // 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.
75     if (isDarwinABI)
76       return 8 * (LP64 ? 8 : 4);
77     
78     // SVR4 ABI:
79     // 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.
85   static unsigned getMinCallFrameSize(bool LP64, bool isDarwinABI) {
86     // The call frame needs to be at least big enough for linkage and 8 args.
87     return getLinkageSize(LP64, isDarwinABI) +
88            getMinCallArgumentsSize(LP64, isDarwinABI);
89   }
90
91   // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
92   const std::pair<unsigned, int> *
93   getCalleeSavedSpillSlots(unsigned &NumEntries) const {
94     // Early exit if not using the SVR4 ABI.
95     if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) {
96       NumEntries = 0;
97       return 0;
98     }
99     
100     static const std::pair<unsigned, int> Offsets[] = {
101       // Floating-point register save area offsets.
102       std::pair<unsigned, int>(PPC::F31, -8),
103       std::pair<unsigned, int>(PPC::F30, -16),
104       std::pair<unsigned, int>(PPC::F29, -24),
105       std::pair<unsigned, int>(PPC::F28, -32),
106       std::pair<unsigned, int>(PPC::F27, -40),
107       std::pair<unsigned, int>(PPC::F26, -48),
108       std::pair<unsigned, int>(PPC::F25, -56),
109       std::pair<unsigned, int>(PPC::F24, -64),
110       std::pair<unsigned, int>(PPC::F23, -72),
111       std::pair<unsigned, int>(PPC::F22, -80),
112       std::pair<unsigned, int>(PPC::F21, -88),
113       std::pair<unsigned, int>(PPC::F20, -96),
114       std::pair<unsigned, int>(PPC::F19, -104),
115       std::pair<unsigned, int>(PPC::F18, -112),
116       std::pair<unsigned, int>(PPC::F17, -120),
117       std::pair<unsigned, int>(PPC::F16, -128),
118       std::pair<unsigned, int>(PPC::F15, -136),
119       std::pair<unsigned, int>(PPC::F14, -144),
120         
121       // General register save area offsets.
122       std::pair<unsigned, int>(PPC::R31, -4),
123       std::pair<unsigned, int>(PPC::R30, -8),
124       std::pair<unsigned, int>(PPC::R29, -12),
125       std::pair<unsigned, int>(PPC::R28, -16),
126       std::pair<unsigned, int>(PPC::R27, -20),
127       std::pair<unsigned, int>(PPC::R26, -24),
128       std::pair<unsigned, int>(PPC::R25, -28),
129       std::pair<unsigned, int>(PPC::R24, -32),
130       std::pair<unsigned, int>(PPC::R23, -36),
131       std::pair<unsigned, int>(PPC::R22, -40),
132       std::pair<unsigned, int>(PPC::R21, -44),
133       std::pair<unsigned, int>(PPC::R20, -48),
134       std::pair<unsigned, int>(PPC::R19, -52),
135       std::pair<unsigned, int>(PPC::R18, -56),
136       std::pair<unsigned, int>(PPC::R17, -60),
137       std::pair<unsigned, int>(PPC::R16, -64),
138       std::pair<unsigned, int>(PPC::R15, -68),
139       std::pair<unsigned, int>(PPC::R14, -72),
140
141       // CR save area offset.
142       // FIXME SVR4: Disable CR save area for now.
143 //      std::pair<unsigned, int>(PPC::CR2, -4),
144 //      std::pair<unsigned, int>(PPC::CR3, -4),
145 //      std::pair<unsigned, int>(PPC::CR4, -4),
146 //      std::pair<unsigned, int>(PPC::CR2LT, -4),
147 //      std::pair<unsigned, int>(PPC::CR2GT, -4),
148 //      std::pair<unsigned, int>(PPC::CR2EQ, -4),
149 //      std::pair<unsigned, int>(PPC::CR2UN, -4),
150 //      std::pair<unsigned, int>(PPC::CR3LT, -4),
151 //      std::pair<unsigned, int>(PPC::CR3GT, -4),
152 //      std::pair<unsigned, int>(PPC::CR3EQ, -4),
153 //      std::pair<unsigned, int>(PPC::CR3UN, -4),
154 //      std::pair<unsigned, int>(PPC::CR4LT, -4),
155 //      std::pair<unsigned, int>(PPC::CR4GT, -4),
156 //      std::pair<unsigned, int>(PPC::CR4EQ, -4),
157 //      std::pair<unsigned, int>(PPC::CR4UN, -4),
158
159       // VRSAVE save area offset.
160       std::pair<unsigned, int>(PPC::VRSAVE, -4),
161       
162       // Vector register save area
163       std::pair<unsigned, int>(PPC::V31, -16),
164       std::pair<unsigned, int>(PPC::V30, -32),
165       std::pair<unsigned, int>(PPC::V29, -48),
166       std::pair<unsigned, int>(PPC::V28, -64),
167       std::pair<unsigned, int>(PPC::V27, -80),
168       std::pair<unsigned, int>(PPC::V26, -96),
169       std::pair<unsigned, int>(PPC::V25, -112),
170       std::pair<unsigned, int>(PPC::V24, -128),
171       std::pair<unsigned, int>(PPC::V23, -144),
172       std::pair<unsigned, int>(PPC::V22, -160),
173       std::pair<unsigned, int>(PPC::V21, -176),
174       std::pair<unsigned, int>(PPC::V20, -192)
175     };
176     
177     NumEntries = array_lengthof(Offsets);
178     
179     return Offsets;
180   }
181 };
182
183 } // End llvm namespace
184
185 #endif