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