Chris Lattner | 2cfd52c | 2009-07-29 20:31:52 +0000 | [diff] [blame] | 1 | //===- ARMBaseRegisterInfo.cpp - ARM Register Information -------*- C++ -*-===// |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 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 | // This file contains the base ARM implementation of TargetRegisterInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ARM.h" |
| 15 | #include "ARMAddressingModes.h" |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 16 | #include "ARMBaseInstrInfo.h" |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 17 | #include "ARMBaseRegisterInfo.h" |
| 18 | #include "ARMInstrInfo.h" |
| 19 | #include "ARMMachineFunctionInfo.h" |
| 20 | #include "ARMSubtarget.h" |
| 21 | #include "llvm/Constants.h" |
| 22 | #include "llvm/DerivedTypes.h" |
Owen Anderson | 9adc0ab | 2009-07-14 23:09:55 +0000 | [diff] [blame] | 23 | #include "llvm/Function.h" |
| 24 | #include "llvm/LLVMContext.h" |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 26 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 27 | #include "llvm/CodeGen/MachineFunction.h" |
| 28 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 29 | #include "llvm/CodeGen/MachineLocation.h" |
| 30 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 31 | #include "llvm/CodeGen/RegisterScavenging.h" |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Debug.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Torok Edwin | dac237e | 2009-07-08 20:53:28 +0000 | [diff] [blame] | 34 | #include "llvm/Support/raw_ostream.h" |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetFrameInfo.h" |
| 36 | #include "llvm/Target/TargetMachine.h" |
| 37 | #include "llvm/Target/TargetOptions.h" |
| 38 | #include "llvm/ADT/BitVector.h" |
| 39 | #include "llvm/ADT/SmallVector.h" |
Jim Grosbach | 18ed9c9 | 2009-10-20 20:19:50 +0000 | [diff] [blame] | 40 | #include "llvm/Support/CommandLine.h" |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 41 | using namespace llvm; |
| 42 | |
Jim Grosbach | 18ed9c9 | 2009-10-20 20:19:50 +0000 | [diff] [blame] | 43 | static cl::opt<bool> |
Jim Grosbach | a6a99b4 | 2009-10-27 22:52:29 +0000 | [diff] [blame] | 44 | ReuseFrameIndexVals("arm-reuse-frame-index-vals", cl::Hidden, cl::init(true), |
Jim Grosbach | 18ed9c9 | 2009-10-20 20:19:50 +0000 | [diff] [blame] | 45 | cl::desc("Reuse repeated frame index values")); |
| 46 | |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 47 | static cl::opt<bool> |
| 48 | ARMDynamicStackAlign("arm-dynamic-stack-alignment", cl::Hidden, cl::init(false), |
| 49 | cl::desc("Dynamically re-align the stack as needed")); |
| 50 | |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 51 | unsigned ARMBaseRegisterInfo::getRegisterNumbering(unsigned RegEnum, |
Evan Cheng | 8295d99 | 2009-07-22 05:55:18 +0000 | [diff] [blame] | 52 | bool *isSPVFP) { |
| 53 | if (isSPVFP) |
| 54 | *isSPVFP = false; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 55 | |
| 56 | using namespace ARM; |
| 57 | switch (RegEnum) { |
| 58 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 59 | llvm_unreachable("Unknown ARM register!"); |
Evan Cheng | 8295d99 | 2009-07-22 05:55:18 +0000 | [diff] [blame] | 60 | case R0: case D0: case Q0: return 0; |
| 61 | case R1: case D1: case Q1: return 1; |
| 62 | case R2: case D2: case Q2: return 2; |
| 63 | case R3: case D3: case Q3: return 3; |
| 64 | case R4: case D4: case Q4: return 4; |
| 65 | case R5: case D5: case Q5: return 5; |
| 66 | case R6: case D6: case Q6: return 6; |
| 67 | case R7: case D7: case Q7: return 7; |
| 68 | case R8: case D8: case Q8: return 8; |
| 69 | case R9: case D9: case Q9: return 9; |
| 70 | case R10: case D10: case Q10: return 10; |
| 71 | case R11: case D11: case Q11: return 11; |
| 72 | case R12: case D12: case Q12: return 12; |
| 73 | case SP: case D13: case Q13: return 13; |
| 74 | case LR: case D14: case Q14: return 14; |
| 75 | case PC: case D15: case Q15: return 15; |
| 76 | |
| 77 | case D16: return 16; |
| 78 | case D17: return 17; |
| 79 | case D18: return 18; |
| 80 | case D19: return 19; |
| 81 | case D20: return 20; |
| 82 | case D21: return 21; |
| 83 | case D22: return 22; |
| 84 | case D23: return 23; |
| 85 | case D24: return 24; |
| 86 | case D25: return 25; |
| 87 | case D26: return 27; |
| 88 | case D27: return 27; |
| 89 | case D28: return 28; |
| 90 | case D29: return 29; |
| 91 | case D30: return 30; |
| 92 | case D31: return 31; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 93 | |
| 94 | case S0: case S1: case S2: case S3: |
| 95 | case S4: case S5: case S6: case S7: |
| 96 | case S8: case S9: case S10: case S11: |
| 97 | case S12: case S13: case S14: case S15: |
| 98 | case S16: case S17: case S18: case S19: |
| 99 | case S20: case S21: case S22: case S23: |
| 100 | case S24: case S25: case S26: case S27: |
Evan Cheng | 8295d99 | 2009-07-22 05:55:18 +0000 | [diff] [blame] | 101 | case S28: case S29: case S30: case S31: { |
| 102 | if (isSPVFP) |
| 103 | *isSPVFP = true; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 104 | switch (RegEnum) { |
| 105 | default: return 0; // Avoid compile time warning. |
| 106 | case S0: return 0; |
| 107 | case S1: return 1; |
| 108 | case S2: return 2; |
| 109 | case S3: return 3; |
| 110 | case S4: return 4; |
| 111 | case S5: return 5; |
| 112 | case S6: return 6; |
| 113 | case S7: return 7; |
| 114 | case S8: return 8; |
| 115 | case S9: return 9; |
| 116 | case S10: return 10; |
| 117 | case S11: return 11; |
| 118 | case S12: return 12; |
| 119 | case S13: return 13; |
| 120 | case S14: return 14; |
| 121 | case S15: return 15; |
| 122 | case S16: return 16; |
| 123 | case S17: return 17; |
| 124 | case S18: return 18; |
| 125 | case S19: return 19; |
| 126 | case S20: return 20; |
| 127 | case S21: return 21; |
| 128 | case S22: return 22; |
| 129 | case S23: return 23; |
| 130 | case S24: return 24; |
| 131 | case S25: return 25; |
| 132 | case S26: return 26; |
| 133 | case S27: return 27; |
| 134 | case S28: return 28; |
| 135 | case S29: return 29; |
| 136 | case S30: return 30; |
| 137 | case S31: return 31; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 143 | ARMBaseRegisterInfo::ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 144 | const ARMSubtarget &sti) |
| 145 | : ARMGenRegisterInfo(ARM::ADJCALLSTACKDOWN, ARM::ADJCALLSTACKUP), |
| 146 | TII(tii), STI(sti), |
| 147 | FramePtr((STI.isTargetDarwin() || STI.isThumb()) ? ARM::R7 : ARM::R11) { |
| 148 | } |
| 149 | |
| 150 | const unsigned* |
| 151 | ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { |
| 152 | static const unsigned CalleeSavedRegs[] = { |
| 153 | ARM::LR, ARM::R11, ARM::R10, ARM::R9, ARM::R8, |
| 154 | ARM::R7, ARM::R6, ARM::R5, ARM::R4, |
| 155 | |
| 156 | ARM::D15, ARM::D14, ARM::D13, ARM::D12, |
| 157 | ARM::D11, ARM::D10, ARM::D9, ARM::D8, |
| 158 | 0 |
| 159 | }; |
| 160 | |
| 161 | static const unsigned DarwinCalleeSavedRegs[] = { |
| 162 | // Darwin ABI deviates from ARM standard ABI. R9 is not a callee-saved |
| 163 | // register. |
| 164 | ARM::LR, ARM::R7, ARM::R6, ARM::R5, ARM::R4, |
| 165 | ARM::R11, ARM::R10, ARM::R8, |
| 166 | |
| 167 | ARM::D15, ARM::D14, ARM::D13, ARM::D12, |
| 168 | ARM::D11, ARM::D10, ARM::D9, ARM::D8, |
| 169 | 0 |
| 170 | }; |
| 171 | return STI.isTargetDarwin() ? DarwinCalleeSavedRegs : CalleeSavedRegs; |
| 172 | } |
| 173 | |
| 174 | const TargetRegisterClass* const * |
| 175 | ARMBaseRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const { |
| 176 | static const TargetRegisterClass * const CalleeSavedRegClasses[] = { |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 177 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass, |
| 178 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass, |
| 179 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 180 | |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 181 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
| 182 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 183 | 0 |
| 184 | }; |
| 185 | |
| 186 | static const TargetRegisterClass * const ThumbCalleeSavedRegClasses[] = { |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 187 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass, |
| 188 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::tGPRRegClass, |
| 189 | &ARM::tGPRRegClass,&ARM::tGPRRegClass,&ARM::tGPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 190 | |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 191 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
| 192 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 193 | 0 |
| 194 | }; |
| 195 | |
| 196 | static const TargetRegisterClass * const DarwinCalleeSavedRegClasses[] = { |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 197 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass, |
| 198 | &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass, |
| 199 | &ARM::GPRRegClass, &ARM::GPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 200 | |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 201 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
| 202 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 203 | 0 |
| 204 | }; |
| 205 | |
| 206 | static const TargetRegisterClass * const DarwinThumbCalleeSavedRegClasses[] ={ |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 207 | &ARM::GPRRegClass, &ARM::tGPRRegClass, &ARM::tGPRRegClass, |
| 208 | &ARM::tGPRRegClass, &ARM::tGPRRegClass, &ARM::GPRRegClass, |
| 209 | &ARM::GPRRegClass, &ARM::GPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 210 | |
Jim Grosbach | 82b3c2e | 2009-09-11 20:13:17 +0000 | [diff] [blame] | 211 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
| 212 | &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 213 | 0 |
| 214 | }; |
| 215 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 216 | if (STI.isThumb1Only()) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 217 | return STI.isTargetDarwin() |
| 218 | ? DarwinThumbCalleeSavedRegClasses : ThumbCalleeSavedRegClasses; |
| 219 | } |
| 220 | return STI.isTargetDarwin() |
| 221 | ? DarwinCalleeSavedRegClasses : CalleeSavedRegClasses; |
| 222 | } |
| 223 | |
| 224 | BitVector ARMBaseRegisterInfo::getReservedRegs(const MachineFunction &MF) const { |
| 225 | // FIXME: avoid re-calculating this everytime. |
| 226 | BitVector Reserved(getNumRegs()); |
| 227 | Reserved.set(ARM::SP); |
| 228 | Reserved.set(ARM::PC); |
| 229 | if (STI.isTargetDarwin() || hasFP(MF)) |
| 230 | Reserved.set(FramePtr); |
| 231 | // Some targets reserve R9. |
| 232 | if (STI.isR9Reserved()) |
| 233 | Reserved.set(ARM::R9); |
| 234 | return Reserved; |
| 235 | } |
| 236 | |
Chris Lattner | 2cfd52c | 2009-07-29 20:31:52 +0000 | [diff] [blame] | 237 | bool ARMBaseRegisterInfo::isReservedReg(const MachineFunction &MF, |
| 238 | unsigned Reg) const { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 239 | switch (Reg) { |
| 240 | default: break; |
| 241 | case ARM::SP: |
| 242 | case ARM::PC: |
| 243 | return true; |
| 244 | case ARM::R7: |
| 245 | case ARM::R11: |
| 246 | if (FramePtr == Reg && (STI.isTargetDarwin() || hasFP(MF))) |
| 247 | return true; |
| 248 | break; |
| 249 | case ARM::R9: |
| 250 | return STI.isR9Reserved(); |
| 251 | } |
| 252 | |
| 253 | return false; |
| 254 | } |
| 255 | |
Chris Lattner | 2cfd52c | 2009-07-29 20:31:52 +0000 | [diff] [blame] | 256 | const TargetRegisterClass * |
Evan Cheng | 4f54c12 | 2009-10-25 07:53:28 +0000 | [diff] [blame] | 257 | ARMBaseRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A, |
| 258 | const TargetRegisterClass *B, |
| 259 | unsigned SubIdx) const { |
| 260 | switch (SubIdx) { |
| 261 | default: return 0; |
| 262 | case 1: |
| 263 | case 2: |
| 264 | case 3: |
| 265 | case 4: |
| 266 | // S sub-registers. |
| 267 | if (A->getSize() == 8) { |
| 268 | if (A == &ARM::DPR_8RegClass) |
| 269 | return A; |
| 270 | return &ARM::DPR_VFP2RegClass; |
| 271 | } |
| 272 | |
| 273 | assert(A->getSize() == 16 && "Expecting a Q register class!"); |
| 274 | return &ARM::QPR_VFP2RegClass; |
| 275 | case 5: |
| 276 | case 6: |
| 277 | // D sub-registers. |
| 278 | return A; |
| 279 | } |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | const TargetRegisterClass * |
Chris Lattner | 2cfd52c | 2009-07-29 20:31:52 +0000 | [diff] [blame] | 284 | ARMBaseRegisterInfo::getPointerRegClass(unsigned Kind) const { |
Jim Grosbach | e11a8f5 | 2009-09-11 19:49:06 +0000 | [diff] [blame] | 285 | return ARM::GPRRegisterClass; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /// getAllocationOrder - Returns the register allocation order for a specified |
| 289 | /// register class in the form of a pair of TargetRegisterClass iterators. |
| 290 | std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator> |
| 291 | ARMBaseRegisterInfo::getAllocationOrder(const TargetRegisterClass *RC, |
| 292 | unsigned HintType, unsigned HintReg, |
| 293 | const MachineFunction &MF) const { |
| 294 | // Alternative register allocation orders when favoring even / odd registers |
| 295 | // of register pairs. |
| 296 | |
| 297 | // No FP, R9 is available. |
| 298 | static const unsigned GPREven1[] = { |
| 299 | ARM::R0, ARM::R2, ARM::R4, ARM::R6, ARM::R8, ARM::R10, |
| 300 | ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R7, |
| 301 | ARM::R9, ARM::R11 |
| 302 | }; |
| 303 | static const unsigned GPROdd1[] = { |
| 304 | ARM::R1, ARM::R3, ARM::R5, ARM::R7, ARM::R9, ARM::R11, |
| 305 | ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6, |
| 306 | ARM::R8, ARM::R10 |
| 307 | }; |
| 308 | |
| 309 | // FP is R7, R9 is available. |
| 310 | static const unsigned GPREven2[] = { |
| 311 | ARM::R0, ARM::R2, ARM::R4, ARM::R8, ARM::R10, |
| 312 | ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R6, |
| 313 | ARM::R9, ARM::R11 |
| 314 | }; |
| 315 | static const unsigned GPROdd2[] = { |
| 316 | ARM::R1, ARM::R3, ARM::R5, ARM::R9, ARM::R11, |
| 317 | ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6, |
| 318 | ARM::R8, ARM::R10 |
| 319 | }; |
| 320 | |
| 321 | // FP is R11, R9 is available. |
| 322 | static const unsigned GPREven3[] = { |
| 323 | ARM::R0, ARM::R2, ARM::R4, ARM::R6, ARM::R8, |
| 324 | ARM::R1, ARM::R3, ARM::R10,ARM::R12,ARM::LR, ARM::R5, ARM::R7, |
| 325 | ARM::R9 |
| 326 | }; |
| 327 | static const unsigned GPROdd3[] = { |
| 328 | ARM::R1, ARM::R3, ARM::R5, ARM::R6, ARM::R9, |
| 329 | ARM::R0, ARM::R2, ARM::R10,ARM::R12,ARM::LR, ARM::R4, ARM::R7, |
| 330 | ARM::R8 |
| 331 | }; |
| 332 | |
| 333 | // No FP, R9 is not available. |
| 334 | static const unsigned GPREven4[] = { |
| 335 | ARM::R0, ARM::R2, ARM::R4, ARM::R6, ARM::R10, |
| 336 | ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R7, ARM::R8, |
| 337 | ARM::R11 |
| 338 | }; |
| 339 | static const unsigned GPROdd4[] = { |
| 340 | ARM::R1, ARM::R3, ARM::R5, ARM::R7, ARM::R11, |
| 341 | ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6, ARM::R8, |
| 342 | ARM::R10 |
| 343 | }; |
| 344 | |
| 345 | // FP is R7, R9 is not available. |
| 346 | static const unsigned GPREven5[] = { |
| 347 | ARM::R0, ARM::R2, ARM::R4, ARM::R10, |
| 348 | ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R6, ARM::R8, |
| 349 | ARM::R11 |
| 350 | }; |
| 351 | static const unsigned GPROdd5[] = { |
| 352 | ARM::R1, ARM::R3, ARM::R5, ARM::R11, |
| 353 | ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6, ARM::R8, |
| 354 | ARM::R10 |
| 355 | }; |
| 356 | |
| 357 | // FP is R11, R9 is not available. |
| 358 | static const unsigned GPREven6[] = { |
| 359 | ARM::R0, ARM::R2, ARM::R4, ARM::R6, |
| 360 | ARM::R1, ARM::R3, ARM::R10,ARM::R12,ARM::LR, ARM::R5, ARM::R7, ARM::R8 |
| 361 | }; |
| 362 | static const unsigned GPROdd6[] = { |
| 363 | ARM::R1, ARM::R3, ARM::R5, ARM::R7, |
| 364 | ARM::R0, ARM::R2, ARM::R10,ARM::R12,ARM::LR, ARM::R4, ARM::R6, ARM::R8 |
| 365 | }; |
| 366 | |
| 367 | |
| 368 | if (HintType == ARMRI::RegPairEven) { |
| 369 | if (isPhysicalRegister(HintReg) && getRegisterPairEven(HintReg, MF) == 0) |
| 370 | // It's no longer possible to fulfill this hint. Return the default |
| 371 | // allocation order. |
| 372 | return std::make_pair(RC->allocation_order_begin(MF), |
| 373 | RC->allocation_order_end(MF)); |
| 374 | |
| 375 | if (!STI.isTargetDarwin() && !hasFP(MF)) { |
| 376 | if (!STI.isR9Reserved()) |
| 377 | return std::make_pair(GPREven1, |
| 378 | GPREven1 + (sizeof(GPREven1)/sizeof(unsigned))); |
| 379 | else |
| 380 | return std::make_pair(GPREven4, |
| 381 | GPREven4 + (sizeof(GPREven4)/sizeof(unsigned))); |
| 382 | } else if (FramePtr == ARM::R7) { |
| 383 | if (!STI.isR9Reserved()) |
| 384 | return std::make_pair(GPREven2, |
| 385 | GPREven2 + (sizeof(GPREven2)/sizeof(unsigned))); |
| 386 | else |
| 387 | return std::make_pair(GPREven5, |
| 388 | GPREven5 + (sizeof(GPREven5)/sizeof(unsigned))); |
| 389 | } else { // FramePtr == ARM::R11 |
| 390 | if (!STI.isR9Reserved()) |
| 391 | return std::make_pair(GPREven3, |
| 392 | GPREven3 + (sizeof(GPREven3)/sizeof(unsigned))); |
| 393 | else |
| 394 | return std::make_pair(GPREven6, |
| 395 | GPREven6 + (sizeof(GPREven6)/sizeof(unsigned))); |
| 396 | } |
| 397 | } else if (HintType == ARMRI::RegPairOdd) { |
| 398 | if (isPhysicalRegister(HintReg) && getRegisterPairOdd(HintReg, MF) == 0) |
| 399 | // It's no longer possible to fulfill this hint. Return the default |
| 400 | // allocation order. |
| 401 | return std::make_pair(RC->allocation_order_begin(MF), |
| 402 | RC->allocation_order_end(MF)); |
| 403 | |
| 404 | if (!STI.isTargetDarwin() && !hasFP(MF)) { |
| 405 | if (!STI.isR9Reserved()) |
| 406 | return std::make_pair(GPROdd1, |
| 407 | GPROdd1 + (sizeof(GPROdd1)/sizeof(unsigned))); |
| 408 | else |
| 409 | return std::make_pair(GPROdd4, |
| 410 | GPROdd4 + (sizeof(GPROdd4)/sizeof(unsigned))); |
| 411 | } else if (FramePtr == ARM::R7) { |
| 412 | if (!STI.isR9Reserved()) |
| 413 | return std::make_pair(GPROdd2, |
| 414 | GPROdd2 + (sizeof(GPROdd2)/sizeof(unsigned))); |
| 415 | else |
| 416 | return std::make_pair(GPROdd5, |
| 417 | GPROdd5 + (sizeof(GPROdd5)/sizeof(unsigned))); |
| 418 | } else { // FramePtr == ARM::R11 |
| 419 | if (!STI.isR9Reserved()) |
| 420 | return std::make_pair(GPROdd3, |
| 421 | GPROdd3 + (sizeof(GPROdd3)/sizeof(unsigned))); |
| 422 | else |
| 423 | return std::make_pair(GPROdd6, |
| 424 | GPROdd6 + (sizeof(GPROdd6)/sizeof(unsigned))); |
| 425 | } |
| 426 | } |
| 427 | return std::make_pair(RC->allocation_order_begin(MF), |
| 428 | RC->allocation_order_end(MF)); |
| 429 | } |
| 430 | |
| 431 | /// ResolveRegAllocHint - Resolves the specified register allocation hint |
| 432 | /// to a physical register. Returns the physical register if it is successful. |
| 433 | unsigned |
| 434 | ARMBaseRegisterInfo::ResolveRegAllocHint(unsigned Type, unsigned Reg, |
| 435 | const MachineFunction &MF) const { |
| 436 | if (Reg == 0 || !isPhysicalRegister(Reg)) |
| 437 | return 0; |
| 438 | if (Type == 0) |
| 439 | return Reg; |
| 440 | else if (Type == (unsigned)ARMRI::RegPairOdd) |
| 441 | // Odd register. |
| 442 | return getRegisterPairOdd(Reg, MF); |
| 443 | else if (Type == (unsigned)ARMRI::RegPairEven) |
| 444 | // Even register. |
| 445 | return getRegisterPairEven(Reg, MF); |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | void |
| 450 | ARMBaseRegisterInfo::UpdateRegAllocHint(unsigned Reg, unsigned NewReg, |
| 451 | MachineFunction &MF) const { |
| 452 | MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 453 | std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(Reg); |
| 454 | if ((Hint.first == (unsigned)ARMRI::RegPairOdd || |
| 455 | Hint.first == (unsigned)ARMRI::RegPairEven) && |
| 456 | Hint.second && TargetRegisterInfo::isVirtualRegister(Hint.second)) { |
| 457 | // If 'Reg' is one of the even / odd register pair and it's now changed |
| 458 | // (e.g. coalesced) into a different register. The other register of the |
| 459 | // pair allocation hint must be updated to reflect the relationship |
| 460 | // change. |
| 461 | unsigned OtherReg = Hint.second; |
| 462 | Hint = MRI->getRegAllocationHint(OtherReg); |
| 463 | if (Hint.second == Reg) |
| 464 | // Make sure the pair has not already divorced. |
| 465 | MRI->setRegAllocationHint(OtherReg, Hint.first, NewReg); |
| 466 | } |
| 467 | } |
| 468 | |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 469 | static unsigned calculateMaxStackAlignment(const MachineFrameInfo *FFI) { |
| 470 | unsigned MaxAlign = 0; |
| 471 | |
| 472 | for (int i = FFI->getObjectIndexBegin(), |
| 473 | e = FFI->getObjectIndexEnd(); i != e; ++i) { |
| 474 | if (FFI->isDeadObjectIndex(i)) |
| 475 | continue; |
| 476 | |
| 477 | unsigned Align = FFI->getObjectAlignment(i); |
| 478 | MaxAlign = std::max(MaxAlign, Align); |
| 479 | } |
| 480 | |
| 481 | return MaxAlign; |
| 482 | } |
| 483 | |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 484 | /// hasFP - Return true if the specified function should have a dedicated frame |
| 485 | /// pointer register. This is true if the function has variable sized allocas |
| 486 | /// or if frame pointer elimination is disabled. |
| 487 | /// |
| 488 | bool ARMBaseRegisterInfo::hasFP(const MachineFunction &MF) const { |
| 489 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 490 | return (NoFramePointerElim || |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 491 | needsStackRealignment(MF) || |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 492 | MFI->hasVarSizedObjects() || |
| 493 | MFI->isFrameAddressTaken()); |
| 494 | } |
| 495 | |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 496 | bool ARMBaseRegisterInfo:: |
| 497 | needsStackRealignment(const MachineFunction &MF) const { |
| 498 | // Only do this for ARM if explicitly enabled |
| 499 | // FIXME: Once it's passing all the tests, enable by default |
| 500 | if (!ARMDynamicStackAlign) |
| 501 | return false; |
| 502 | |
| 503 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 504 | const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 505 | unsigned StackAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 506 | return (RealignStack && |
| 507 | !AFI->isThumb1OnlyFunction() && |
| 508 | (MFI->getMaxAlignment() > StackAlign) && |
| 509 | !MFI->hasVarSizedObjects()); |
| 510 | |
| 511 | } |
| 512 | |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 513 | bool ARMBaseRegisterInfo::cannotEliminateFrame(const MachineFunction &MF) const { |
Evan Cheng | 98a0104 | 2009-08-14 20:48:13 +0000 | [diff] [blame] | 514 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 515 | if (NoFramePointerElim && MFI->hasCalls()) |
| 516 | return true; |
| 517 | return MFI->hasVarSizedObjects() || MFI->isFrameAddressTaken(); |
| 518 | } |
| 519 | |
Evan Cheng | 542383d | 2009-07-28 06:24:12 +0000 | [diff] [blame] | 520 | /// estimateStackSize - Estimate and return the size of the frame. |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 521 | static unsigned estimateStackSize(MachineFunction &MF, MachineFrameInfo *MFI) { |
| 522 | const MachineFrameInfo *FFI = MF.getFrameInfo(); |
| 523 | int Offset = 0; |
| 524 | for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) { |
| 525 | int FixedOff = -FFI->getObjectOffset(i); |
| 526 | if (FixedOff > Offset) Offset = FixedOff; |
| 527 | } |
| 528 | for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) { |
| 529 | if (FFI->isDeadObjectIndex(i)) |
| 530 | continue; |
| 531 | Offset += FFI->getObjectSize(i); |
| 532 | unsigned Align = FFI->getObjectAlignment(i); |
| 533 | // Adjust to alignment boundary |
| 534 | Offset = (Offset+Align-1)/Align*Align; |
| 535 | } |
| 536 | return (unsigned)Offset; |
| 537 | } |
| 538 | |
Evan Cheng | 542383d | 2009-07-28 06:24:12 +0000 | [diff] [blame] | 539 | /// estimateRSStackSizeLimit - Look at each instruction that references stack |
| 540 | /// frames and return the stack size limit beyond which some of these |
| 541 | /// instructions will require scratch register during their expansion later. |
Evan Cheng | ee42fd3 | 2009-07-30 23:29:25 +0000 | [diff] [blame] | 542 | unsigned |
| 543 | ARMBaseRegisterInfo::estimateRSStackSizeLimit(MachineFunction &MF) const { |
Evan Cheng | 542383d | 2009-07-28 06:24:12 +0000 | [diff] [blame] | 544 | unsigned Limit = (1 << 12) - 1; |
Chris Lattner | b180d99 | 2009-07-28 18:48:43 +0000 | [diff] [blame] | 545 | for (MachineFunction::iterator BB = MF.begin(),E = MF.end(); BB != E; ++BB) { |
| 546 | for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end(); |
| 547 | I != E; ++I) { |
| 548 | for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) { |
| 549 | if (!I->getOperand(i).isFI()) continue; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 550 | |
Chris Lattner | b180d99 | 2009-07-28 18:48:43 +0000 | [diff] [blame] | 551 | const TargetInstrDesc &Desc = TII.get(I->getOpcode()); |
| 552 | unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask); |
| 553 | if (AddrMode == ARMII::AddrMode3 || |
| 554 | AddrMode == ARMII::AddrModeT2_i8) |
| 555 | return (1 << 8) - 1; |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 556 | |
Chris Lattner | b180d99 | 2009-07-28 18:48:43 +0000 | [diff] [blame] | 557 | if (AddrMode == ARMII::AddrMode5 || |
| 558 | AddrMode == ARMII::AddrModeT2_i8s4) |
| 559 | Limit = std::min(Limit, ((1U << 8) - 1) * 4); |
Evan Cheng | ee42fd3 | 2009-07-30 23:29:25 +0000 | [diff] [blame] | 560 | |
| 561 | if (AddrMode == ARMII::AddrModeT2_i12 && hasFP(MF)) |
| 562 | // When the stack offset is negative, we will end up using |
| 563 | // the i8 instructions instead. |
| 564 | return (1 << 8) - 1; |
Chris Lattner | b180d99 | 2009-07-28 18:48:43 +0000 | [diff] [blame] | 565 | break; // At most one FI per instruction |
| 566 | } |
Evan Cheng | 542383d | 2009-07-28 06:24:12 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | return Limit; |
| 571 | } |
| 572 | |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 573 | void |
| 574 | ARMBaseRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF, |
| 575 | RegScavenger *RS) const { |
| 576 | // This tells PEI to spill the FP as if it is any other callee-save register |
| 577 | // to take advantage the eliminateFrameIndex machinery. This also ensures it |
| 578 | // is spilled in the order specified by getCalleeSavedRegs() to make it easier |
| 579 | // to combine multiple loads / stores. |
| 580 | bool CanEliminateFrame = true; |
| 581 | bool CS1Spilled = false; |
| 582 | bool LRSpilled = false; |
| 583 | unsigned NumGPRSpills = 0; |
| 584 | SmallVector<unsigned, 4> UnspilledCS1GPRs; |
| 585 | SmallVector<unsigned, 4> UnspilledCS2GPRs; |
| 586 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 587 | |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 588 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 589 | |
| 590 | // Calculate and set max stack object alignment early, so we can decide |
| 591 | // whether we will need stack realignment (and thus FP). |
| 592 | if (ARMDynamicStackAlign) { |
| 593 | unsigned MaxAlign = std::max(MFI->getMaxAlignment(), |
| 594 | calculateMaxStackAlignment(MFI)); |
| 595 | MFI->setMaxAlignment(MaxAlign); |
| 596 | } |
| 597 | |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 598 | // Don't spill FP if the frame can be eliminated. This is determined |
| 599 | // by scanning the callee-save registers to see if any is used. |
| 600 | const unsigned *CSRegs = getCalleeSavedRegs(); |
| 601 | const TargetRegisterClass* const *CSRegClasses = getCalleeSavedRegClasses(); |
| 602 | for (unsigned i = 0; CSRegs[i]; ++i) { |
| 603 | unsigned Reg = CSRegs[i]; |
| 604 | bool Spilled = false; |
| 605 | if (MF.getRegInfo().isPhysRegUsed(Reg)) { |
| 606 | AFI->setCSRegisterIsSpilled(Reg); |
| 607 | Spilled = true; |
| 608 | CanEliminateFrame = false; |
| 609 | } else { |
| 610 | // Check alias registers too. |
| 611 | for (const unsigned *Aliases = getAliasSet(Reg); *Aliases; ++Aliases) { |
| 612 | if (MF.getRegInfo().isPhysRegUsed(*Aliases)) { |
| 613 | Spilled = true; |
| 614 | CanEliminateFrame = false; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
Jim Grosbach | ec9eef4 | 2009-09-28 22:08:06 +0000 | [diff] [blame] | 619 | if (CSRegClasses[i] == ARM::GPRRegisterClass || |
| 620 | CSRegClasses[i] == ARM::tGPRRegisterClass) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 621 | if (Spilled) { |
| 622 | NumGPRSpills++; |
| 623 | |
| 624 | if (!STI.isTargetDarwin()) { |
| 625 | if (Reg == ARM::LR) |
| 626 | LRSpilled = true; |
| 627 | CS1Spilled = true; |
| 628 | continue; |
| 629 | } |
| 630 | |
| 631 | // Keep track if LR and any of R4, R5, R6, and R7 is spilled. |
| 632 | switch (Reg) { |
| 633 | case ARM::LR: |
| 634 | LRSpilled = true; |
| 635 | // Fallthrough |
| 636 | case ARM::R4: |
| 637 | case ARM::R5: |
| 638 | case ARM::R6: |
| 639 | case ARM::R7: |
| 640 | CS1Spilled = true; |
| 641 | break; |
| 642 | default: |
| 643 | break; |
| 644 | } |
| 645 | } else { |
| 646 | if (!STI.isTargetDarwin()) { |
| 647 | UnspilledCS1GPRs.push_back(Reg); |
| 648 | continue; |
| 649 | } |
| 650 | |
| 651 | switch (Reg) { |
| 652 | case ARM::R4: |
| 653 | case ARM::R5: |
| 654 | case ARM::R6: |
| 655 | case ARM::R7: |
| 656 | case ARM::LR: |
| 657 | UnspilledCS1GPRs.push_back(Reg); |
| 658 | break; |
| 659 | default: |
| 660 | UnspilledCS2GPRs.push_back(Reg); |
| 661 | break; |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | bool ForceLRSpill = false; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 668 | if (!LRSpilled && AFI->isThumb1OnlyFunction()) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 669 | unsigned FnSize = TII.GetFunctionSizeInBytes(MF); |
| 670 | // Force LR to be spilled if the Thumb function size is > 2048. This enables |
| 671 | // use of BL to implement far jump. If it turns out that it's not needed |
| 672 | // then the branch fix up path will undo it. |
| 673 | if (FnSize >= (1 << 11)) { |
| 674 | CanEliminateFrame = false; |
| 675 | ForceLRSpill = true; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | bool ExtraCSSpill = false; |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 680 | if (!CanEliminateFrame || cannotEliminateFrame(MF)) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 681 | AFI->setHasStackFrame(true); |
| 682 | |
| 683 | // If LR is not spilled, but at least one of R4, R5, R6, and R7 is spilled. |
| 684 | // Spill LR as well so we can fold BX_RET to the registers restore (LDM). |
| 685 | if (!LRSpilled && CS1Spilled) { |
| 686 | MF.getRegInfo().setPhysRegUsed(ARM::LR); |
| 687 | AFI->setCSRegisterIsSpilled(ARM::LR); |
| 688 | NumGPRSpills++; |
| 689 | UnspilledCS1GPRs.erase(std::find(UnspilledCS1GPRs.begin(), |
| 690 | UnspilledCS1GPRs.end(), (unsigned)ARM::LR)); |
| 691 | ForceLRSpill = false; |
| 692 | ExtraCSSpill = true; |
| 693 | } |
| 694 | |
| 695 | // Darwin ABI requires FP to point to the stack slot that contains the |
| 696 | // previous FP. |
| 697 | if (STI.isTargetDarwin() || hasFP(MF)) { |
| 698 | MF.getRegInfo().setPhysRegUsed(FramePtr); |
| 699 | NumGPRSpills++; |
| 700 | } |
| 701 | |
| 702 | // If stack and double are 8-byte aligned and we are spilling an odd number |
| 703 | // of GPRs. Spill one extra callee save GPR so we won't have to pad between |
| 704 | // the integer and double callee save areas. |
| 705 | unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 706 | if (TargetAlign == 8 && (NumGPRSpills & 1)) { |
| 707 | if (CS1Spilled && !UnspilledCS1GPRs.empty()) { |
| 708 | for (unsigned i = 0, e = UnspilledCS1GPRs.size(); i != e; ++i) { |
| 709 | unsigned Reg = UnspilledCS1GPRs[i]; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 710 | // Don't spill high register if the function is thumb1 |
| 711 | if (!AFI->isThumb1OnlyFunction() || |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 712 | isARMLowRegister(Reg) || Reg == ARM::LR) { |
| 713 | MF.getRegInfo().setPhysRegUsed(Reg); |
| 714 | AFI->setCSRegisterIsSpilled(Reg); |
| 715 | if (!isReservedReg(MF, Reg)) |
| 716 | ExtraCSSpill = true; |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | } else if (!UnspilledCS2GPRs.empty() && |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 721 | !AFI->isThumb1OnlyFunction()) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 722 | unsigned Reg = UnspilledCS2GPRs.front(); |
| 723 | MF.getRegInfo().setPhysRegUsed(Reg); |
| 724 | AFI->setCSRegisterIsSpilled(Reg); |
| 725 | if (!isReservedReg(MF, Reg)) |
| 726 | ExtraCSSpill = true; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | // Estimate if we might need to scavenge a register at some point in order |
| 731 | // to materialize a stack offset. If so, either spill one additional |
| 732 | // callee-saved register or reserve a special spill slot to facilitate |
Jim Grosbach | 3d6cb88 | 2009-09-24 23:52:18 +0000 | [diff] [blame] | 733 | // register scavenging. Thumb1 needs a spill slot for stack pointer |
| 734 | // adjustments also, even when the frame itself is small. |
| 735 | if (RS && !ExtraCSSpill) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 736 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Jim Grosbach | d1a5ca6 | 2009-09-30 01:43:29 +0000 | [diff] [blame] | 737 | // If any of the stack slot references may be out of range of an |
| 738 | // immediate offset, make sure a register (or a spill slot) is |
| 739 | // available for the register scavenger. Note that if we're indexing |
| 740 | // off the frame pointer, the effective stack size is 4 bytes larger |
Jim Grosbach | 460c482 | 2009-09-30 15:23:38 +0000 | [diff] [blame] | 741 | // since the FP points to the stack slot of the previous FP. |
Jim Grosbach | d1a5ca6 | 2009-09-30 01:43:29 +0000 | [diff] [blame] | 742 | if (estimateStackSize(MF, MFI) + (hasFP(MF) ? 4 : 0) |
Jim Grosbach | 540b05d | 2009-10-05 22:30:23 +0000 | [diff] [blame] | 743 | >= estimateRSStackSizeLimit(MF)) { |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 744 | // If any non-reserved CS register isn't spilled, just spill one or two |
| 745 | // extra. That should take care of it! |
| 746 | unsigned NumExtras = TargetAlign / 4; |
| 747 | SmallVector<unsigned, 2> Extras; |
| 748 | while (NumExtras && !UnspilledCS1GPRs.empty()) { |
| 749 | unsigned Reg = UnspilledCS1GPRs.back(); |
| 750 | UnspilledCS1GPRs.pop_back(); |
| 751 | if (!isReservedReg(MF, Reg)) { |
| 752 | Extras.push_back(Reg); |
| 753 | NumExtras--; |
| 754 | } |
| 755 | } |
Jim Grosbach | 17487ba | 2009-09-29 23:17:20 +0000 | [diff] [blame] | 756 | // For non-Thumb1 functions, also check for hi-reg CS registers |
| 757 | if (!AFI->isThumb1OnlyFunction()) { |
| 758 | while (NumExtras && !UnspilledCS2GPRs.empty()) { |
| 759 | unsigned Reg = UnspilledCS2GPRs.back(); |
| 760 | UnspilledCS2GPRs.pop_back(); |
| 761 | if (!isReservedReg(MF, Reg)) { |
| 762 | Extras.push_back(Reg); |
| 763 | NumExtras--; |
| 764 | } |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | if (Extras.size() && NumExtras == 0) { |
| 768 | for (unsigned i = 0, e = Extras.size(); i != e; ++i) { |
| 769 | MF.getRegInfo().setPhysRegUsed(Extras[i]); |
| 770 | AFI->setCSRegisterIsSpilled(Extras[i]); |
| 771 | } |
Jim Grosbach | 540b05d | 2009-10-05 22:30:23 +0000 | [diff] [blame] | 772 | } else if (!AFI->isThumb1OnlyFunction()) { |
| 773 | // note: Thumb1 functions spill to R12, not the stack. |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 774 | // Reserve a slot closest to SP or frame pointer. |
Jim Grosbach | e11a8f5 | 2009-09-11 19:49:06 +0000 | [diff] [blame] | 775 | const TargetRegisterClass *RC = ARM::GPRRegisterClass; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 776 | RS->setScavengingFrameIndex(MFI->CreateStackObject(RC->getSize(), |
| 777 | RC->getAlignment())); |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | if (ForceLRSpill) { |
| 784 | MF.getRegInfo().setPhysRegUsed(ARM::LR); |
| 785 | AFI->setCSRegisterIsSpilled(ARM::LR); |
| 786 | AFI->setLRIsSpilledForFarJump(true); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | unsigned ARMBaseRegisterInfo::getRARegister() const { |
| 791 | return ARM::LR; |
| 792 | } |
| 793 | |
| 794 | unsigned ARMBaseRegisterInfo::getFrameRegister(MachineFunction &MF) const { |
| 795 | if (STI.isTargetDarwin() || hasFP(MF)) |
| 796 | return FramePtr; |
| 797 | return ARM::SP; |
| 798 | } |
| 799 | |
| 800 | unsigned ARMBaseRegisterInfo::getEHExceptionRegister() const { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 801 | llvm_unreachable("What is the exception register"); |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 802 | return 0; |
| 803 | } |
| 804 | |
| 805 | unsigned ARMBaseRegisterInfo::getEHHandlerRegister() const { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 806 | llvm_unreachable("What is the exception handler register"); |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | int ARMBaseRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const { |
| 811 | return ARMGenRegisterInfo::getDwarfRegNumFull(RegNum, 0); |
| 812 | } |
| 813 | |
| 814 | unsigned ARMBaseRegisterInfo::getRegisterPairEven(unsigned Reg, |
| 815 | const MachineFunction &MF) const { |
| 816 | switch (Reg) { |
| 817 | default: break; |
| 818 | // Return 0 if either register of the pair is a special register. |
| 819 | // So no R12, etc. |
| 820 | case ARM::R1: |
| 821 | return ARM::R0; |
| 822 | case ARM::R3: |
Jim Grosbach | 6009751 | 2009-10-19 22:57:03 +0000 | [diff] [blame] | 823 | return ARM::R2; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 824 | case ARM::R5: |
| 825 | return ARM::R4; |
| 826 | case ARM::R7: |
| 827 | return isReservedReg(MF, ARM::R7) ? 0 : ARM::R6; |
| 828 | case ARM::R9: |
| 829 | return isReservedReg(MF, ARM::R9) ? 0 :ARM::R8; |
| 830 | case ARM::R11: |
| 831 | return isReservedReg(MF, ARM::R11) ? 0 : ARM::R10; |
| 832 | |
| 833 | case ARM::S1: |
| 834 | return ARM::S0; |
| 835 | case ARM::S3: |
| 836 | return ARM::S2; |
| 837 | case ARM::S5: |
| 838 | return ARM::S4; |
| 839 | case ARM::S7: |
| 840 | return ARM::S6; |
| 841 | case ARM::S9: |
| 842 | return ARM::S8; |
| 843 | case ARM::S11: |
| 844 | return ARM::S10; |
| 845 | case ARM::S13: |
| 846 | return ARM::S12; |
| 847 | case ARM::S15: |
| 848 | return ARM::S14; |
| 849 | case ARM::S17: |
| 850 | return ARM::S16; |
| 851 | case ARM::S19: |
| 852 | return ARM::S18; |
| 853 | case ARM::S21: |
| 854 | return ARM::S20; |
| 855 | case ARM::S23: |
| 856 | return ARM::S22; |
| 857 | case ARM::S25: |
| 858 | return ARM::S24; |
| 859 | case ARM::S27: |
| 860 | return ARM::S26; |
| 861 | case ARM::S29: |
| 862 | return ARM::S28; |
| 863 | case ARM::S31: |
| 864 | return ARM::S30; |
| 865 | |
| 866 | case ARM::D1: |
| 867 | return ARM::D0; |
| 868 | case ARM::D3: |
| 869 | return ARM::D2; |
| 870 | case ARM::D5: |
| 871 | return ARM::D4; |
| 872 | case ARM::D7: |
| 873 | return ARM::D6; |
| 874 | case ARM::D9: |
| 875 | return ARM::D8; |
| 876 | case ARM::D11: |
| 877 | return ARM::D10; |
| 878 | case ARM::D13: |
| 879 | return ARM::D12; |
| 880 | case ARM::D15: |
| 881 | return ARM::D14; |
Evan Cheng | 8295d99 | 2009-07-22 05:55:18 +0000 | [diff] [blame] | 882 | case ARM::D17: |
| 883 | return ARM::D16; |
| 884 | case ARM::D19: |
| 885 | return ARM::D18; |
| 886 | case ARM::D21: |
| 887 | return ARM::D20; |
| 888 | case ARM::D23: |
| 889 | return ARM::D22; |
| 890 | case ARM::D25: |
| 891 | return ARM::D24; |
| 892 | case ARM::D27: |
| 893 | return ARM::D26; |
| 894 | case ARM::D29: |
| 895 | return ARM::D28; |
| 896 | case ARM::D31: |
| 897 | return ARM::D30; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | unsigned ARMBaseRegisterInfo::getRegisterPairOdd(unsigned Reg, |
| 904 | const MachineFunction &MF) const { |
| 905 | switch (Reg) { |
| 906 | default: break; |
| 907 | // Return 0 if either register of the pair is a special register. |
| 908 | // So no R12, etc. |
| 909 | case ARM::R0: |
| 910 | return ARM::R1; |
| 911 | case ARM::R2: |
Jim Grosbach | 6009751 | 2009-10-19 22:57:03 +0000 | [diff] [blame] | 912 | return ARM::R3; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 913 | case ARM::R4: |
| 914 | return ARM::R5; |
| 915 | case ARM::R6: |
| 916 | return isReservedReg(MF, ARM::R7) ? 0 : ARM::R7; |
| 917 | case ARM::R8: |
| 918 | return isReservedReg(MF, ARM::R9) ? 0 :ARM::R9; |
| 919 | case ARM::R10: |
| 920 | return isReservedReg(MF, ARM::R11) ? 0 : ARM::R11; |
| 921 | |
| 922 | case ARM::S0: |
| 923 | return ARM::S1; |
| 924 | case ARM::S2: |
| 925 | return ARM::S3; |
| 926 | case ARM::S4: |
| 927 | return ARM::S5; |
| 928 | case ARM::S6: |
| 929 | return ARM::S7; |
| 930 | case ARM::S8: |
| 931 | return ARM::S9; |
| 932 | case ARM::S10: |
| 933 | return ARM::S11; |
| 934 | case ARM::S12: |
| 935 | return ARM::S13; |
| 936 | case ARM::S14: |
| 937 | return ARM::S15; |
| 938 | case ARM::S16: |
| 939 | return ARM::S17; |
| 940 | case ARM::S18: |
| 941 | return ARM::S19; |
| 942 | case ARM::S20: |
| 943 | return ARM::S21; |
| 944 | case ARM::S22: |
| 945 | return ARM::S23; |
| 946 | case ARM::S24: |
| 947 | return ARM::S25; |
| 948 | case ARM::S26: |
| 949 | return ARM::S27; |
| 950 | case ARM::S28: |
| 951 | return ARM::S29; |
| 952 | case ARM::S30: |
| 953 | return ARM::S31; |
| 954 | |
| 955 | case ARM::D0: |
| 956 | return ARM::D1; |
| 957 | case ARM::D2: |
| 958 | return ARM::D3; |
| 959 | case ARM::D4: |
| 960 | return ARM::D5; |
| 961 | case ARM::D6: |
| 962 | return ARM::D7; |
| 963 | case ARM::D8: |
| 964 | return ARM::D9; |
| 965 | case ARM::D10: |
| 966 | return ARM::D11; |
| 967 | case ARM::D12: |
| 968 | return ARM::D13; |
| 969 | case ARM::D14: |
| 970 | return ARM::D15; |
Evan Cheng | 8295d99 | 2009-07-22 05:55:18 +0000 | [diff] [blame] | 971 | case ARM::D16: |
| 972 | return ARM::D17; |
| 973 | case ARM::D18: |
| 974 | return ARM::D19; |
| 975 | case ARM::D20: |
| 976 | return ARM::D21; |
| 977 | case ARM::D22: |
| 978 | return ARM::D23; |
| 979 | case ARM::D24: |
| 980 | return ARM::D25; |
| 981 | case ARM::D26: |
| 982 | return ARM::D27; |
| 983 | case ARM::D28: |
| 984 | return ARM::D29; |
| 985 | case ARM::D30: |
| 986 | return ARM::D31; |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | return 0; |
| 990 | } |
| 991 | |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 992 | /// emitLoadConstPool - Emits a load from constpool to materialize the |
| 993 | /// specified immediate. |
| 994 | void ARMBaseRegisterInfo:: |
| 995 | emitLoadConstPool(MachineBasicBlock &MBB, |
| 996 | MachineBasicBlock::iterator &MBBI, |
David Goodwin | 77521f5 | 2009-07-08 20:28:28 +0000 | [diff] [blame] | 997 | DebugLoc dl, |
Evan Cheng | 3784453 | 2009-07-16 09:20:10 +0000 | [diff] [blame] | 998 | unsigned DestReg, unsigned SubIdx, int Val, |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 999 | ARMCC::CondCodes Pred, |
| 1000 | unsigned PredReg) const { |
| 1001 | MachineFunction &MF = *MBB.getParent(); |
| 1002 | MachineConstantPool *ConstantPool = MF.getConstantPool(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1003 | Constant *C = |
| 1004 | ConstantInt::get(Type::getInt32Ty(MF.getFunction()->getContext()), Val); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1005 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); |
| 1006 | |
Evan Cheng | 3784453 | 2009-07-16 09:20:10 +0000 | [diff] [blame] | 1007 | BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp)) |
| 1008 | .addReg(DestReg, getDefRegState(true), SubIdx) |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1009 | .addConstantPoolIndex(Idx) |
| 1010 | .addReg(0).addImm(0).addImm(Pred).addReg(PredReg); |
| 1011 | } |
| 1012 | |
| 1013 | bool ARMBaseRegisterInfo:: |
| 1014 | requiresRegisterScavenging(const MachineFunction &MF) const { |
| 1015 | return true; |
| 1016 | } |
Jim Grosbach | 41fff8c | 2009-10-21 23:40:56 +0000 | [diff] [blame] | 1017 | |
Jim Grosbach | 7e831db | 2009-10-20 01:26:58 +0000 | [diff] [blame] | 1018 | bool ARMBaseRegisterInfo:: |
| 1019 | requiresFrameIndexScavenging(const MachineFunction &MF) const { |
Jim Grosbach | ca5dfb7 | 2009-10-28 17:33:28 +0000 | [diff] [blame^] | 1020 | return true; |
Jim Grosbach | 7e831db | 2009-10-20 01:26:58 +0000 | [diff] [blame] | 1021 | } |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1022 | |
| 1023 | // hasReservedCallFrame - Under normal circumstances, when a frame pointer is |
| 1024 | // not required, we reserve argument space for call sites in the function |
| 1025 | // immediately on entry to the current function. This eliminates the need for |
| 1026 | // add/sub sp brackets around call sites. Returns true if the call frame is |
| 1027 | // included as part of the stack frame. |
| 1028 | bool ARMBaseRegisterInfo:: |
| 1029 | hasReservedCallFrame(MachineFunction &MF) const { |
| 1030 | const MachineFrameInfo *FFI = MF.getFrameInfo(); |
| 1031 | unsigned CFSize = FFI->getMaxCallFrameSize(); |
| 1032 | // It's not always a good idea to include the call frame as part of the |
| 1033 | // stack frame. ARM (especially Thumb) has small immediate offset to |
| 1034 | // address the stack frame. So a large call frame can cause poor codegen |
| 1035 | // and may even makes it impossible to scavenge a register. |
| 1036 | if (CFSize >= ((1 << 12) - 1) / 2) // Half of imm12 |
| 1037 | return false; |
| 1038 | |
| 1039 | return !MF.getFrameInfo()->hasVarSizedObjects(); |
| 1040 | } |
| 1041 | |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1042 | static void |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1043 | emitSPUpdate(bool isARM, |
| 1044 | MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, |
| 1045 | DebugLoc dl, const ARMBaseInstrInfo &TII, |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1046 | int NumBytes, |
| 1047 | ARMCC::CondCodes Pred = ARMCC::AL, unsigned PredReg = 0) { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1048 | if (isARM) |
| 1049 | emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, ARM::SP, NumBytes, |
| 1050 | Pred, PredReg, TII); |
| 1051 | else |
| 1052 | emitT2RegPlusImmediate(MBB, MBBI, dl, ARM::SP, ARM::SP, NumBytes, |
| 1053 | Pred, PredReg, TII); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1056 | |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1057 | void ARMBaseRegisterInfo:: |
| 1058 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, |
| 1059 | MachineBasicBlock::iterator I) const { |
| 1060 | if (!hasReservedCallFrame(MF)) { |
| 1061 | // If we have alloca, convert as follows: |
| 1062 | // ADJCALLSTACKDOWN -> sub, sp, sp, amount |
| 1063 | // ADJCALLSTACKUP -> add, sp, sp, amount |
| 1064 | MachineInstr *Old = I; |
| 1065 | DebugLoc dl = Old->getDebugLoc(); |
| 1066 | unsigned Amount = Old->getOperand(0).getImm(); |
| 1067 | if (Amount != 0) { |
| 1068 | // We need to keep the stack aligned properly. To do this, we round the |
| 1069 | // amount of space needed for the outgoing arguments up to the next |
| 1070 | // alignment boundary. |
| 1071 | unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment(); |
| 1072 | Amount = (Amount+Align-1)/Align*Align; |
| 1073 | |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1074 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1075 | assert(!AFI->isThumb1OnlyFunction() && |
| 1076 | "This eliminateCallFramePseudoInstr does not suppor Thumb1!"); |
| 1077 | bool isARM = !AFI->isThumbFunction(); |
| 1078 | |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1079 | // Replace the pseudo instruction with a new instruction... |
| 1080 | unsigned Opc = Old->getOpcode(); |
| 1081 | ARMCC::CondCodes Pred = (ARMCC::CondCodes)Old->getOperand(1).getImm(); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1082 | // FIXME: Thumb2 version of ADJCALLSTACKUP and ADJCALLSTACKDOWN? |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1083 | if (Opc == ARM::ADJCALLSTACKDOWN || Opc == ARM::tADJCALLSTACKDOWN) { |
| 1084 | // Note: PredReg is operand 2 for ADJCALLSTACKDOWN. |
| 1085 | unsigned PredReg = Old->getOperand(2).getReg(); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1086 | emitSPUpdate(isARM, MBB, I, dl, TII, -Amount, Pred, PredReg); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1087 | } else { |
| 1088 | // Note: PredReg is operand 3 for ADJCALLSTACKUP. |
| 1089 | unsigned PredReg = Old->getOperand(3).getReg(); |
| 1090 | assert(Opc == ARM::ADJCALLSTACKUP || Opc == ARM::tADJCALLSTACKUP); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1091 | emitSPUpdate(isARM, MBB, I, dl, TII, Amount, Pred, PredReg); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | MBB.erase(I); |
| 1096 | } |
| 1097 | |
Jim Grosbach | b58f498 | 2009-10-07 17:12:56 +0000 | [diff] [blame] | 1098 | unsigned |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1099 | ARMBaseRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II, |
Jim Grosbach | b58f498 | 2009-10-07 17:12:56 +0000 | [diff] [blame] | 1100 | int SPAdj, int *Value, |
| 1101 | RegScavenger *RS) const { |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1102 | unsigned i = 0; |
| 1103 | MachineInstr &MI = *II; |
| 1104 | MachineBasicBlock &MBB = *MI.getParent(); |
| 1105 | MachineFunction &MF = *MBB.getParent(); |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 1106 | const MachineFrameInfo *MFI = MF.getFrameInfo(); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1107 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1108 | assert(!AFI->isThumb1OnlyFunction() && |
Bob Wilson | a15de00 | 2009-09-18 21:42:44 +0000 | [diff] [blame] | 1109 | "This eliminateFrameIndex does not support Thumb1!"); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1110 | |
| 1111 | while (!MI.getOperand(i).isFI()) { |
| 1112 | ++i; |
| 1113 | assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!"); |
| 1114 | } |
| 1115 | |
| 1116 | unsigned FrameReg = ARM::SP; |
| 1117 | int FrameIndex = MI.getOperand(i).getIndex(); |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 1118 | int Offset = MFI->getObjectOffset(FrameIndex) + MFI->getStackSize() + SPAdj; |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1119 | |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 1120 | // When doing dynamic stack realignment, all of these need to change(?) |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1121 | if (AFI->isGPRCalleeSavedArea1Frame(FrameIndex)) |
| 1122 | Offset -= AFI->getGPRCalleeSavedArea1Offset(); |
| 1123 | else if (AFI->isGPRCalleeSavedArea2Frame(FrameIndex)) |
| 1124 | Offset -= AFI->getGPRCalleeSavedArea2Offset(); |
| 1125 | else if (AFI->isDPRCalleeSavedAreaFrame(FrameIndex)) |
| 1126 | Offset -= AFI->getDPRCalleeSavedAreaOffset(); |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 1127 | else if (needsStackRealignment(MF)) { |
| 1128 | // When dynamically realigning the stack, use the frame pointer for |
| 1129 | // parameters, and the stack pointer for locals. |
| 1130 | assert (hasFP(MF) && "dynamic stack realignment without a FP!"); |
| 1131 | if (FrameIndex < 0) { |
| 1132 | FrameReg = getFrameRegister(MF); |
| 1133 | Offset -= AFI->getFramePtrSpillOffset(); |
| 1134 | // When referencing from the frame pointer, stack pointer adjustments |
| 1135 | // don't matter. |
| 1136 | SPAdj = 0; |
| 1137 | } |
| 1138 | } else if (hasFP(MF) && AFI->hasStackFrame()) { |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 1139 | assert(SPAdj == 0 && "Unexpected stack offset!"); |
| 1140 | // Use frame pointer to reference fixed objects unless this is a |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 1141 | // frameless function. |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1142 | FrameReg = getFrameRegister(MF); |
| 1143 | Offset -= AFI->getFramePtrSpillOffset(); |
| 1144 | } |
| 1145 | |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 1146 | // modify MI as necessary to handle as much of 'Offset' as possible |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1147 | bool Done = false; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1148 | if (!AFI->isThumbFunction()) |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1149 | Done = rewriteARMFrameIndex(MI, i, FrameReg, Offset, TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1150 | else { |
| 1151 | assert(AFI->isThumb2Function()); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1152 | Done = rewriteT2FrameIndex(MI, i, FrameReg, Offset, TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1153 | } |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1154 | if (Done) |
Jim Grosbach | b58f498 | 2009-10-07 17:12:56 +0000 | [diff] [blame] | 1155 | return 0; |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1156 | |
| 1157 | // If we get here, the immediate doesn't fit into the instruction. We folded |
| 1158 | // as much as possible above, handle the rest, providing a register that is |
| 1159 | // SP+LargeImm. |
Daniel Dunbar | 19bb87d | 2009-08-28 08:08:22 +0000 | [diff] [blame] | 1160 | assert((Offset || |
| 1161 | (MI.getDesc().TSFlags & ARMII::AddrModeMask) == ARMII::AddrMode4) && |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1162 | "This code isn't needed if offset already handled!"); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1163 | |
Jim Grosbach | 7e831db | 2009-10-20 01:26:58 +0000 | [diff] [blame] | 1164 | unsigned ScratchReg = 0; |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1165 | int PIdx = MI.findFirstPredOperandIdx(); |
| 1166 | ARMCC::CondCodes Pred = (PIdx == -1) |
| 1167 | ? ARMCC::AL : (ARMCC::CondCodes)MI.getOperand(PIdx).getImm(); |
| 1168 | unsigned PredReg = (PIdx == -1) ? 0 : MI.getOperand(PIdx+1).getReg(); |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1169 | if (Offset == 0) |
| 1170 | // Must be addrmode4. |
| 1171 | MI.getOperand(i).ChangeToRegister(FrameReg, false, false, false); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1172 | else { |
Jim Grosbach | ca5dfb7 | 2009-10-28 17:33:28 +0000 | [diff] [blame^] | 1173 | ScratchReg = MF.getRegInfo().createVirtualRegister(ARM::GPRRegisterClass); |
| 1174 | if (Value) *Value = Offset; |
Evan Cheng | cdbb3f5 | 2009-08-27 01:23:50 +0000 | [diff] [blame] | 1175 | if (!AFI->isThumbFunction()) |
| 1176 | emitARMRegPlusImmediate(MBB, II, MI.getDebugLoc(), ScratchReg, FrameReg, |
| 1177 | Offset, Pred, PredReg, TII); |
| 1178 | else { |
| 1179 | assert(AFI->isThumb2Function()); |
| 1180 | emitT2RegPlusImmediate(MBB, II, MI.getDebugLoc(), ScratchReg, FrameReg, |
| 1181 | Offset, Pred, PredReg, TII); |
| 1182 | } |
| 1183 | MI.getOperand(i).ChangeToRegister(ScratchReg, false, false, true); |
Jim Grosbach | ca5dfb7 | 2009-10-28 17:33:28 +0000 | [diff] [blame^] | 1184 | if (!ReuseFrameIndexVals) |
Jim Grosbach | 18ed9c9 | 2009-10-20 20:19:50 +0000 | [diff] [blame] | 1185 | ScratchReg = 0; |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1186 | } |
Jim Grosbach | 7e831db | 2009-10-20 01:26:58 +0000 | [diff] [blame] | 1187 | return ScratchReg; |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /// Move iterator pass the next bunch of callee save load / store ops for |
| 1191 | /// the particular spill area (1: integer area 1, 2: integer area 2, |
| 1192 | /// 3: fp area, 0: don't care). |
| 1193 | static void movePastCSLoadStoreOps(MachineBasicBlock &MBB, |
| 1194 | MachineBasicBlock::iterator &MBBI, |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 1195 | int Opc1, int Opc2, unsigned Area, |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1196 | const ARMSubtarget &STI) { |
| 1197 | while (MBBI != MBB.end() && |
David Goodwin | 5ff58b5 | 2009-07-24 00:16:18 +0000 | [diff] [blame] | 1198 | ((MBBI->getOpcode() == Opc1) || (MBBI->getOpcode() == Opc2)) && |
| 1199 | MBBI->getOperand(1).isFI()) { |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1200 | if (Area != 0) { |
| 1201 | bool Done = false; |
| 1202 | unsigned Category = 0; |
| 1203 | switch (MBBI->getOperand(0).getReg()) { |
| 1204 | case ARM::R4: case ARM::R5: case ARM::R6: case ARM::R7: |
| 1205 | case ARM::LR: |
| 1206 | Category = 1; |
| 1207 | break; |
| 1208 | case ARM::R8: case ARM::R9: case ARM::R10: case ARM::R11: |
| 1209 | Category = STI.isTargetDarwin() ? 2 : 1; |
| 1210 | break; |
| 1211 | case ARM::D8: case ARM::D9: case ARM::D10: case ARM::D11: |
| 1212 | case ARM::D12: case ARM::D13: case ARM::D14: case ARM::D15: |
| 1213 | Category = 3; |
| 1214 | break; |
| 1215 | default: |
| 1216 | Done = true; |
| 1217 | break; |
| 1218 | } |
| 1219 | if (Done || Category != Area) |
| 1220 | break; |
| 1221 | } |
| 1222 | |
| 1223 | ++MBBI; |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | void ARMBaseRegisterInfo:: |
| 1228 | emitPrologue(MachineFunction &MF) const { |
| 1229 | MachineBasicBlock &MBB = MF.front(); |
| 1230 | MachineBasicBlock::iterator MBBI = MBB.begin(); |
| 1231 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1232 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1233 | assert(!AFI->isThumb1OnlyFunction() && |
| 1234 | "This emitPrologue does not suppor Thumb1!"); |
| 1235 | bool isARM = !AFI->isThumbFunction(); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1236 | unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize(); |
| 1237 | unsigned NumBytes = MFI->getStackSize(); |
| 1238 | const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo(); |
| 1239 | DebugLoc dl = (MBBI != MBB.end() ? |
| 1240 | MBBI->getDebugLoc() : DebugLoc::getUnknownLoc()); |
| 1241 | |
| 1242 | // Determine the sizes of each callee-save spill areas and record which frame |
| 1243 | // belongs to which callee-save spill areas. |
| 1244 | unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0; |
| 1245 | int FramePtrSpillFI = 0; |
| 1246 | |
Bob Wilson | c8ce2d4 | 2009-09-25 16:34:46 +0000 | [diff] [blame] | 1247 | // Allocate the vararg register save area. This is not counted in NumBytes. |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1248 | if (VARegSaveSize) |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1249 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -VARegSaveSize); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1250 | |
| 1251 | if (!AFI->hasStackFrame()) { |
| 1252 | if (NumBytes != 0) |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1253 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -NumBytes); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1254 | return; |
| 1255 | } |
| 1256 | |
| 1257 | for (unsigned i = 0, e = CSI.size(); i != e; ++i) { |
| 1258 | unsigned Reg = CSI[i].getReg(); |
| 1259 | int FI = CSI[i].getFrameIdx(); |
| 1260 | switch (Reg) { |
| 1261 | case ARM::R4: |
| 1262 | case ARM::R5: |
| 1263 | case ARM::R6: |
| 1264 | case ARM::R7: |
| 1265 | case ARM::LR: |
| 1266 | if (Reg == FramePtr) |
| 1267 | FramePtrSpillFI = FI; |
| 1268 | AFI->addGPRCalleeSavedArea1Frame(FI); |
| 1269 | GPRCS1Size += 4; |
| 1270 | break; |
| 1271 | case ARM::R8: |
| 1272 | case ARM::R9: |
| 1273 | case ARM::R10: |
| 1274 | case ARM::R11: |
| 1275 | if (Reg == FramePtr) |
| 1276 | FramePtrSpillFI = FI; |
| 1277 | if (STI.isTargetDarwin()) { |
| 1278 | AFI->addGPRCalleeSavedArea2Frame(FI); |
| 1279 | GPRCS2Size += 4; |
| 1280 | } else { |
| 1281 | AFI->addGPRCalleeSavedArea1Frame(FI); |
| 1282 | GPRCS1Size += 4; |
| 1283 | } |
| 1284 | break; |
| 1285 | default: |
| 1286 | AFI->addDPRCalleeSavedAreaFrame(FI); |
| 1287 | DPRCSSize += 8; |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | // Build the new SUBri to adjust SP for integer callee-save spill area 1. |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1292 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -GPRCS1Size); |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1293 | movePastCSLoadStoreOps(MBB, MBBI, ARM::STR, ARM::t2STRi12, 1, STI); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1294 | |
Bob Wilson | c8ce2d4 | 2009-09-25 16:34:46 +0000 | [diff] [blame] | 1295 | // Set FP to point to the stack slot that contains the previous FP. |
| 1296 | // For Darwin, FP is R7, which has now been stored in spill area 1. |
| 1297 | // Otherwise, if this is not Darwin, all the callee-saved registers go |
| 1298 | // into spill area 1, including the FP in R11. In either case, it is |
| 1299 | // now safe to emit this assignment. |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1300 | if (STI.isTargetDarwin() || hasFP(MF)) { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1301 | unsigned ADDriOpc = !AFI->isThumbFunction() ? ARM::ADDri : ARM::t2ADDri; |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1302 | MachineInstrBuilder MIB = |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1303 | BuildMI(MBB, MBBI, dl, TII.get(ADDriOpc), FramePtr) |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1304 | .addFrameIndex(FramePtrSpillFI).addImm(0); |
| 1305 | AddDefaultCC(AddDefaultPred(MIB)); |
| 1306 | } |
| 1307 | |
| 1308 | // Build the new SUBri to adjust SP for integer callee-save spill area 2. |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1309 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -GPRCS2Size); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1310 | |
| 1311 | // Build the new SUBri to adjust SP for FP callee-save spill area. |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1312 | movePastCSLoadStoreOps(MBB, MBBI, ARM::STR, ARM::t2STRi12, 2, STI); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1313 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -DPRCSSize); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1314 | |
| 1315 | // Determine starting offsets of spill areas. |
| 1316 | unsigned DPRCSOffset = NumBytes - (GPRCS1Size + GPRCS2Size + DPRCSSize); |
| 1317 | unsigned GPRCS2Offset = DPRCSOffset + DPRCSSize; |
| 1318 | unsigned GPRCS1Offset = GPRCS2Offset + GPRCS2Size; |
| 1319 | AFI->setFramePtrSpillOffset(MFI->getObjectOffset(FramePtrSpillFI) + NumBytes); |
| 1320 | AFI->setGPRCalleeSavedArea1Offset(GPRCS1Offset); |
| 1321 | AFI->setGPRCalleeSavedArea2Offset(GPRCS2Offset); |
| 1322 | AFI->setDPRCalleeSavedAreaOffset(DPRCSOffset); |
| 1323 | |
| 1324 | NumBytes = DPRCSOffset; |
| 1325 | if (NumBytes) { |
| 1326 | // Insert it after all the callee-save spills. |
Evan Cheng | b74bb1a | 2009-07-24 00:53:56 +0000 | [diff] [blame] | 1327 | movePastCSLoadStoreOps(MBB, MBBI, ARM::FSTD, 0, 3, STI); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1328 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, -NumBytes); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | if (STI.isTargetELF() && hasFP(MF)) { |
| 1332 | MFI->setOffsetAdjustment(MFI->getOffsetAdjustment() - |
| 1333 | AFI->getFramePtrSpillOffset()); |
| 1334 | } |
| 1335 | |
| 1336 | AFI->setGPRCalleeSavedArea1Size(GPRCS1Size); |
| 1337 | AFI->setGPRCalleeSavedArea2Size(GPRCS2Size); |
| 1338 | AFI->setDPRCalleeSavedAreaSize(DPRCSSize); |
Jim Grosbach | 3dab277 | 2009-10-27 22:45:39 +0000 | [diff] [blame] | 1339 | |
| 1340 | // If we need dynamic stack realignment, do it here. |
| 1341 | if (needsStackRealignment(MF)) { |
| 1342 | unsigned Opc; |
| 1343 | unsigned MaxAlign = MFI->getMaxAlignment(); |
| 1344 | assert (!AFI->isThumb1OnlyFunction()); |
| 1345 | Opc = AFI->isThumbFunction() ? ARM::t2BICri : ARM::BICri; |
| 1346 | |
| 1347 | AddDefaultCC(AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(Opc), ARM::SP) |
| 1348 | .addReg(ARM::SP, RegState::Kill) |
| 1349 | .addImm(MaxAlign-1))); |
| 1350 | } |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static bool isCalleeSavedRegister(unsigned Reg, const unsigned *CSRegs) { |
| 1354 | for (unsigned i = 0; CSRegs[i]; ++i) |
| 1355 | if (Reg == CSRegs[i]) |
| 1356 | return true; |
| 1357 | return false; |
| 1358 | } |
| 1359 | |
David Goodwin | 77521f5 | 2009-07-08 20:28:28 +0000 | [diff] [blame] | 1360 | static bool isCSRestore(MachineInstr *MI, |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1361 | const ARMBaseInstrInfo &TII, |
David Goodwin | 77521f5 | 2009-07-08 20:28:28 +0000 | [diff] [blame] | 1362 | const unsigned *CSRegs) { |
Evan Cheng | b74bb1a | 2009-07-24 00:53:56 +0000 | [diff] [blame] | 1363 | return ((MI->getOpcode() == (int)ARM::FLDD || |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1364 | MI->getOpcode() == (int)ARM::LDR || |
| 1365 | MI->getOpcode() == (int)ARM::t2LDRi12) && |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1366 | MI->getOperand(1).isFI() && |
| 1367 | isCalleeSavedRegister(MI->getOperand(0).getReg(), CSRegs)); |
| 1368 | } |
| 1369 | |
| 1370 | void ARMBaseRegisterInfo:: |
Evan Cheng | 293f8d9 | 2009-07-27 18:31:40 +0000 | [diff] [blame] | 1371 | emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const { |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1372 | MachineBasicBlock::iterator MBBI = prior(MBB.end()); |
Evan Cheng | 5ca53a7 | 2009-07-27 18:20:05 +0000 | [diff] [blame] | 1373 | assert(MBBI->getDesc().isReturn() && |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1374 | "Can only insert epilog into returning blocks"); |
| 1375 | DebugLoc dl = MBBI->getDebugLoc(); |
| 1376 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1377 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1378 | assert(!AFI->isThumb1OnlyFunction() && |
| 1379 | "This emitEpilogue does not suppor Thumb1!"); |
| 1380 | bool isARM = !AFI->isThumbFunction(); |
| 1381 | |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1382 | unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize(); |
| 1383 | int NumBytes = (int)MFI->getStackSize(); |
| 1384 | |
| 1385 | if (!AFI->hasStackFrame()) { |
| 1386 | if (NumBytes != 0) |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1387 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1388 | } else { |
| 1389 | // Unwind MBBI to point to first LDR / FLDD. |
| 1390 | const unsigned *CSRegs = getCalleeSavedRegs(); |
| 1391 | if (MBBI != MBB.begin()) { |
| 1392 | do |
| 1393 | --MBBI; |
David Goodwin | 77521f5 | 2009-07-08 20:28:28 +0000 | [diff] [blame] | 1394 | while (MBBI != MBB.begin() && isCSRestore(MBBI, TII, CSRegs)); |
| 1395 | if (!isCSRestore(MBBI, TII, CSRegs)) |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1396 | ++MBBI; |
| 1397 | } |
| 1398 | |
| 1399 | // Move SP to start of FP callee save spill area. |
| 1400 | NumBytes -= (AFI->getGPRCalleeSavedArea1Size() + |
| 1401 | AFI->getGPRCalleeSavedArea2Size() + |
| 1402 | AFI->getDPRCalleeSavedAreaSize()); |
| 1403 | |
| 1404 | // Darwin ABI requires FP to point to the stack slot that contains the |
| 1405 | // previous FP. |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 1406 | bool HasFP = hasFP(MF); |
| 1407 | if ((STI.isTargetDarwin() && NumBytes) || HasFP) { |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1408 | NumBytes = AFI->getFramePtrSpillOffset() - NumBytes; |
| 1409 | // Reset SP based on frame pointer only if the stack frame extends beyond |
| 1410 | // frame pointer stack slot or target is ELF and the function has FP. |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 1411 | if (HasFP || |
| 1412 | AFI->getGPRCalleeSavedArea2Size() || |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1413 | AFI->getDPRCalleeSavedAreaSize() || |
Evan Cheng | 010b1b9 | 2009-08-15 02:05:35 +0000 | [diff] [blame] | 1414 | AFI->getDPRCalleeSavedAreaOffset()) { |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1415 | if (NumBytes) { |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1416 | if (isARM) |
| 1417 | emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes, |
| 1418 | ARMCC::AL, 0, TII); |
| 1419 | else |
| 1420 | emitT2RegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes, |
| 1421 | ARMCC::AL, 0, TII); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1422 | } else { |
| 1423 | // Thumb2 or ARM. |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 1424 | if (isARM) |
Evan Cheng | 052053b | 2009-08-10 05:49:43 +0000 | [diff] [blame] | 1425 | BuildMI(MBB, MBBI, dl, TII.get(ARM::MOVr), ARM::SP) |
| 1426 | .addReg(FramePtr) |
| 1427 | .addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 1428 | else |
| 1429 | BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVgpr2gpr), ARM::SP) |
| 1430 | .addReg(FramePtr); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1431 | } |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1432 | } |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1433 | } else if (NumBytes) |
| 1434 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1435 | |
| 1436 | // Move SP to start of integer callee save spill area 2. |
Evan Cheng | b74bb1a | 2009-07-24 00:53:56 +0000 | [diff] [blame] | 1437 | movePastCSLoadStoreOps(MBB, MBBI, ARM::FLDD, 0, 3, STI); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1438 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getDPRCalleeSavedAreaSize()); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1439 | |
| 1440 | // Move SP to start of integer callee save spill area 1. |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1441 | movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, ARM::t2LDRi12, 2, STI); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1442 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getGPRCalleeSavedArea2Size()); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1443 | |
| 1444 | // Move SP to SP upon entry to the function. |
Evan Cheng | 5732ca0 | 2009-07-27 03:14:20 +0000 | [diff] [blame] | 1445 | movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, ARM::t2LDRi12, 1, STI); |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1446 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getGPRCalleeSavedArea1Size()); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
| 1449 | if (VARegSaveSize) |
Evan Cheng | 6495f63 | 2009-07-28 05:48:47 +0000 | [diff] [blame] | 1450 | emitSPUpdate(isARM, MBB, MBBI, dl, TII, VARegSaveSize); |
David Goodwin | db5a71a | 2009-07-08 18:31:39 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
David Goodwin | c140c48 | 2009-07-08 17:28:55 +0000 | [diff] [blame] | 1453 | #include "ARMGenRegisterInfo.inc" |