LLVM API Documentation
00001 //===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // 00011 //===----------------------------------------------------------------------===// 00012 00013 #ifndef POWERPC_FRAMEINFO_H 00014 #define POWERPC_FRAMEINFO_H 00015 00016 #include "PPC.h" 00017 #include "PPCSubtarget.h" 00018 #include "llvm/Target/TargetFrameInfo.h" 00019 #include "llvm/Target/TargetMachine.h" 00020 #include "llvm/ADT/STLExtras.h" 00021 00022 namespace llvm { 00023 00024 class PPCFrameInfo: public TargetFrameInfo { 00025 const TargetMachine &TM; 00026 00027 public: 00028 PPCFrameInfo(const TargetMachine &tm, bool LP64) 00029 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) { 00030 } 00031 00032 /// getReturnSaveOffset - Return the previous frame offset to save the 00033 /// return address. 00034 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) { 00035 if (isDarwinABI) 00036 return isPPC64 ? 16 : 8; 00037 // SVR4 ABI: 00038 return isPPC64 ? 16 : 4; 00039 } 00040 00041 /// getFramePointerSaveOffset - Return the previous frame offset to save the 00042 /// frame pointer. 00043 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) { 00044 // For the Darwin ABI: 00045 // Use the TOC save slot in the PowerPC linkage area for saving the frame 00046 // pointer (if needed.) LLVM does not generate code that uses the TOC (R2 00047 // is treated as a caller saved register.) 00048 if (isDarwinABI) 00049 return isPPC64 ? 40 : 20; 00050 00051 // SVR4 ABI: First slot in the general register save area. 00052 return -4U; 00053 } 00054 00055 /// getLinkageSize - Return the size of the PowerPC ABI linkage area. 00056 /// 00057 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) { 00058 if (isDarwinABI || isPPC64) 00059 return 6 * (isPPC64 ? 8 : 4); 00060 00061 // SVR4 ABI: 00062 return 8; 00063 } 00064 00065 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI 00066 /// argument area. 00067 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) { 00068 // For the Darwin ABI / 64-bit SVR4 ABI: 00069 // The prolog code of the callee may store up to 8 GPR argument registers to 00070 // the stack, allowing va_start to index over them in memory if its varargs. 00071 // Because we cannot tell if this is needed on the caller side, we have to 00072 // conservatively assume that it is needed. As such, make sure we have at 00073 // least enough stack space for the caller to store the 8 GPRs. 00074 if (isDarwinABI || isPPC64) 00075 return 8 * (isPPC64 ? 8 : 4); 00076 00077 // 32-bit SVR4 ABI: 00078 // There is no default stack allocated for the 8 first GPR arguments. 00079 return 0; 00080 } 00081 00082 /// getMinCallFrameSize - Return the minimum size a call frame can be using 00083 /// the PowerPC ABI. 00084 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) { 00085 // The call frame needs to be at least big enough for linkage and 8 args. 00086 return getLinkageSize(isPPC64, isDarwinABI) + 00087 getMinCallArgumentsSize(isPPC64, isDarwinABI); 00088 } 00089 00090 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack. 00091 const std::pair<unsigned, int> * 00092 getCalleeSavedSpillSlots(unsigned &NumEntries) const { 00093 // Early exit if not using the SVR4 ABI. 00094 if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) { 00095 NumEntries = 0; 00096 return 0; 00097 } 00098 00099 static const std::pair<unsigned, int> Offsets[] = { 00100 // Floating-point register save area offsets. 00101 std::pair<unsigned, int>(PPC::F31, -8), 00102 std::pair<unsigned, int>(PPC::F30, -16), 00103 std::pair<unsigned, int>(PPC::F29, -24), 00104 std::pair<unsigned, int>(PPC::F28, -32), 00105 std::pair<unsigned, int>(PPC::F27, -40), 00106 std::pair<unsigned, int>(PPC::F26, -48), 00107 std::pair<unsigned, int>(PPC::F25, -56), 00108 std::pair<unsigned, int>(PPC::F24, -64), 00109 std::pair<unsigned, int>(PPC::F23, -72), 00110 std::pair<unsigned, int>(PPC::F22, -80), 00111 std::pair<unsigned, int>(PPC::F21, -88), 00112 std::pair<unsigned, int>(PPC::F20, -96), 00113 std::pair<unsigned, int>(PPC::F19, -104), 00114 std::pair<unsigned, int>(PPC::F18, -112), 00115 std::pair<unsigned, int>(PPC::F17, -120), 00116 std::pair<unsigned, int>(PPC::F16, -128), 00117 std::pair<unsigned, int>(PPC::F15, -136), 00118 std::pair<unsigned, int>(PPC::F14, -144), 00119 00120 // General register save area offsets. 00121 std::pair<unsigned, int>(PPC::R31, -4), 00122 std::pair<unsigned, int>(PPC::R30, -8), 00123 std::pair<unsigned, int>(PPC::R29, -12), 00124 std::pair<unsigned, int>(PPC::R28, -16), 00125 std::pair<unsigned, int>(PPC::R27, -20), 00126 std::pair<unsigned, int>(PPC::R26, -24), 00127 std::pair<unsigned, int>(PPC::R25, -28), 00128 std::pair<unsigned, int>(PPC::R24, -32), 00129 std::pair<unsigned, int>(PPC::R23, -36), 00130 std::pair<unsigned, int>(PPC::R22, -40), 00131 std::pair<unsigned, int>(PPC::R21, -44), 00132 std::pair<unsigned, int>(PPC::R20, -48), 00133 std::pair<unsigned, int>(PPC::R19, -52), 00134 std::pair<unsigned, int>(PPC::R18, -56), 00135 std::pair<unsigned, int>(PPC::R17, -60), 00136 std::pair<unsigned, int>(PPC::R16, -64), 00137 std::pair<unsigned, int>(PPC::R15, -68), 00138 std::pair<unsigned, int>(PPC::R14, -72), 00139 00140 // CR save area offset. 00141 // FIXME SVR4: Disable CR save area for now. 00142 // std::pair<unsigned, int>(PPC::CR2, -4), 00143 // std::pair<unsigned, int>(PPC::CR3, -4), 00144 // std::pair<unsigned, int>(PPC::CR4, -4), 00145 // std::pair<unsigned, int>(PPC::CR2LT, -4), 00146 // std::pair<unsigned, int>(PPC::CR2GT, -4), 00147 // std::pair<unsigned, int>(PPC::CR2EQ, -4), 00148 // std::pair<unsigned, int>(PPC::CR2UN, -4), 00149 // std::pair<unsigned, int>(PPC::CR3LT, -4), 00150 // std::pair<unsigned, int>(PPC::CR3GT, -4), 00151 // std::pair<unsigned, int>(PPC::CR3EQ, -4), 00152 // std::pair<unsigned, int>(PPC::CR3UN, -4), 00153 // std::pair<unsigned, int>(PPC::CR4LT, -4), 00154 // std::pair<unsigned, int>(PPC::CR4GT, -4), 00155 // std::pair<unsigned, int>(PPC::CR4EQ, -4), 00156 // std::pair<unsigned, int>(PPC::CR4UN, -4), 00157 00158 // VRSAVE save area offset. 00159 std::pair<unsigned, int>(PPC::VRSAVE, -4), 00160 00161 // Vector register save area 00162 std::pair<unsigned, int>(PPC::V31, -16), 00163 std::pair<unsigned, int>(PPC::V30, -32), 00164 std::pair<unsigned, int>(PPC::V29, -48), 00165 std::pair<unsigned, int>(PPC::V28, -64), 00166 std::pair<unsigned, int>(PPC::V27, -80), 00167 std::pair<unsigned, int>(PPC::V26, -96), 00168 std::pair<unsigned, int>(PPC::V25, -112), 00169 std::pair<unsigned, int>(PPC::V24, -128), 00170 std::pair<unsigned, int>(PPC::V23, -144), 00171 std::pair<unsigned, int>(PPC::V22, -160), 00172 std::pair<unsigned, int>(PPC::V21, -176), 00173 std::pair<unsigned, int>(PPC::V20, -192) 00174 }; 00175 00176 static const std::pair<unsigned, int> Offsets64[] = { 00177 // Floating-point register save area offsets. 00178 std::pair<unsigned, int>(PPC::F31, -8), 00179 std::pair<unsigned, int>(PPC::F30, -16), 00180 std::pair<unsigned, int>(PPC::F29, -24), 00181 std::pair<unsigned, int>(PPC::F28, -32), 00182 std::pair<unsigned, int>(PPC::F27, -40), 00183 std::pair<unsigned, int>(PPC::F26, -48), 00184 std::pair<unsigned, int>(PPC::F25, -56), 00185 std::pair<unsigned, int>(PPC::F24, -64), 00186 std::pair<unsigned, int>(PPC::F23, -72), 00187 std::pair<unsigned, int>(PPC::F22, -80), 00188 std::pair<unsigned, int>(PPC::F21, -88), 00189 std::pair<unsigned, int>(PPC::F20, -96), 00190 std::pair<unsigned, int>(PPC::F19, -104), 00191 std::pair<unsigned, int>(PPC::F18, -112), 00192 std::pair<unsigned, int>(PPC::F17, -120), 00193 std::pair<unsigned, int>(PPC::F16, -128), 00194 std::pair<unsigned, int>(PPC::F15, -136), 00195 std::pair<unsigned, int>(PPC::F14, -144), 00196 00197 // General register save area offsets. 00198 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit 00199 // mode? 00200 std::pair<unsigned, int>(PPC::R31, -4), 00201 std::pair<unsigned, int>(PPC::R30, -12), 00202 std::pair<unsigned, int>(PPC::R29, -20), 00203 std::pair<unsigned, int>(PPC::R28, -28), 00204 std::pair<unsigned, int>(PPC::R27, -36), 00205 std::pair<unsigned, int>(PPC::R26, -44), 00206 std::pair<unsigned, int>(PPC::R25, -52), 00207 std::pair<unsigned, int>(PPC::R24, -60), 00208 std::pair<unsigned, int>(PPC::R23, -68), 00209 std::pair<unsigned, int>(PPC::R22, -76), 00210 std::pair<unsigned, int>(PPC::R21, -84), 00211 std::pair<unsigned, int>(PPC::R20, -92), 00212 std::pair<unsigned, int>(PPC::R19, -100), 00213 std::pair<unsigned, int>(PPC::R18, -108), 00214 std::pair<unsigned, int>(PPC::R17, -116), 00215 std::pair<unsigned, int>(PPC::R16, -124), 00216 std::pair<unsigned, int>(PPC::R15, -132), 00217 std::pair<unsigned, int>(PPC::R14, -140), 00218 00219 std::pair<unsigned, int>(PPC::X31, -8), 00220 std::pair<unsigned, int>(PPC::X30, -16), 00221 std::pair<unsigned, int>(PPC::X29, -24), 00222 std::pair<unsigned, int>(PPC::X28, -32), 00223 std::pair<unsigned, int>(PPC::X27, -40), 00224 std::pair<unsigned, int>(PPC::X26, -48), 00225 std::pair<unsigned, int>(PPC::X25, -56), 00226 std::pair<unsigned, int>(PPC::X24, -64), 00227 std::pair<unsigned, int>(PPC::X23, -72), 00228 std::pair<unsigned, int>(PPC::X22, -80), 00229 std::pair<unsigned, int>(PPC::X21, -88), 00230 std::pair<unsigned, int>(PPC::X20, -96), 00231 std::pair<unsigned, int>(PPC::X19, -104), 00232 std::pair<unsigned, int>(PPC::X18, -112), 00233 std::pair<unsigned, int>(PPC::X17, -120), 00234 std::pair<unsigned, int>(PPC::X16, -128), 00235 std::pair<unsigned, int>(PPC::X15, -136), 00236 std::pair<unsigned, int>(PPC::X14, -144), 00237 00238 // CR save area offset. 00239 // FIXME SVR4: Disable CR save area for now. 00240 // std::pair<unsigned, int>(PPC::CR2, -4), 00241 // std::pair<unsigned, int>(PPC::CR3, -4), 00242 // std::pair<unsigned, int>(PPC::CR4, -4), 00243 // std::pair<unsigned, int>(PPC::CR2LT, -4), 00244 // std::pair<unsigned, int>(PPC::CR2GT, -4), 00245 // std::pair<unsigned, int>(PPC::CR2EQ, -4), 00246 // std::pair<unsigned, int>(PPC::CR2UN, -4), 00247 // std::pair<unsigned, int>(PPC::CR3LT, -4), 00248 // std::pair<unsigned, int>(PPC::CR3GT, -4), 00249 // std::pair<unsigned, int>(PPC::CR3EQ, -4), 00250 // std::pair<unsigned, int>(PPC::CR3UN, -4), 00251 // std::pair<unsigned, int>(PPC::CR4LT, -4), 00252 // std::pair<unsigned, int>(PPC::CR4GT, -4), 00253 // std::pair<unsigned, int>(PPC::CR4EQ, -4), 00254 // std::pair<unsigned, int>(PPC::CR4UN, -4), 00255 00256 // VRSAVE save area offset. 00257 std::pair<unsigned, int>(PPC::VRSAVE, -4), 00258 00259 // Vector register save area 00260 std::pair<unsigned, int>(PPC::V31, -16), 00261 std::pair<unsigned, int>(PPC::V30, -32), 00262 std::pair<unsigned, int>(PPC::V29, -48), 00263 std::pair<unsigned, int>(PPC::V28, -64), 00264 std::pair<unsigned, int>(PPC::V27, -80), 00265 std::pair<unsigned, int>(PPC::V26, -96), 00266 std::pair<unsigned, int>(PPC::V25, -112), 00267 std::pair<unsigned, int>(PPC::V24, -128), 00268 std::pair<unsigned, int>(PPC::V23, -144), 00269 std::pair<unsigned, int>(PPC::V22, -160), 00270 std::pair<unsigned, int>(PPC::V21, -176), 00271 std::pair<unsigned, int>(PPC::V20, -192) 00272 }; 00273 00274 if (TM.getSubtarget<PPCSubtarget>().isPPC64()) { 00275 NumEntries = array_lengthof(Offsets64); 00276 00277 return Offsets64; 00278 } else { 00279 NumEntries = array_lengthof(Offsets); 00280 00281 return Offsets; 00282 } 00283 } 00284 }; 00285 00286 } // End llvm namespace 00287 00288 #endif