1 //===- ARMBaseRegisterInfo.cpp - ARM Register Information -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the base ARM implementation of TargetRegisterInfo class.
12 //===----------------------------------------------------------------------===//
15 #include "ARMAddressingModes.h"
16 #include "ARMBaseInstrInfo.h"
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"
23 #include "llvm/Function.h"
24 #include "llvm/LLVMContext.h"
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"
32 #include "llvm/Support/Debug.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/raw_ostream.h"
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"
40 #include "llvm/Support/CommandLine.h"
44 ReuseFrameIndexVals("arm-reuse-frame-index-vals", cl::Hidden, cl::init(true),
45 cl::desc("Reuse repeated frame index values"));
48 ARMDynamicStackAlign("arm-dynamic-stack-alignment", cl::Hidden, cl::init(false),
49 cl::desc("Dynamically re-align the stack as needed"));
51 unsigned ARMBaseRegisterInfo::getRegisterNumbering(unsigned RegEnum,
59 llvm_unreachable("Unknown ARM register!");
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;
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:
101 case S28: case S29: case S30: case S31: {
105 default: return 0; // Avoid compile time warning.
143 ARMBaseRegisterInfo::ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
144 const ARMSubtarget &sti)
145 : ARMGenRegisterInfo(ARM::ADJCALLSTACKDOWN, ARM::ADJCALLSTACKUP),
147 FramePtr((STI.isTargetDarwin() || STI.isThumb()) ? ARM::R7 : ARM::R11) {
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,
156 ARM::D15, ARM::D14, ARM::D13, ARM::D12,
157 ARM::D11, ARM::D10, ARM::D9, ARM::D8,
161 static const unsigned DarwinCalleeSavedRegs[] = {
162 // Darwin ABI deviates from ARM standard ABI. R9 is not a callee-saved
164 ARM::LR, ARM::R7, ARM::R6, ARM::R5, ARM::R4,
165 ARM::R11, ARM::R10, ARM::R8,
167 ARM::D15, ARM::D14, ARM::D13, ARM::D12,
168 ARM::D11, ARM::D10, ARM::D9, ARM::D8,
171 return STI.isTargetDarwin() ? DarwinCalleeSavedRegs : CalleeSavedRegs;
174 const TargetRegisterClass* const *
175 ARMBaseRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const {
176 static const TargetRegisterClass * const CalleeSavedRegClasses[] = {
177 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
178 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
179 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
181 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
182 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
186 static const TargetRegisterClass * const ThumbCalleeSavedRegClasses[] = {
187 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
188 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::tGPRRegClass,
189 &ARM::tGPRRegClass,&ARM::tGPRRegClass,&ARM::tGPRRegClass,
191 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
192 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
196 static const TargetRegisterClass * const DarwinCalleeSavedRegClasses[] = {
197 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
198 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
199 &ARM::GPRRegClass, &ARM::GPRRegClass,
201 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
202 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
206 static const TargetRegisterClass * const DarwinThumbCalleeSavedRegClasses[] ={
207 &ARM::GPRRegClass, &ARM::tGPRRegClass, &ARM::tGPRRegClass,
208 &ARM::tGPRRegClass, &ARM::tGPRRegClass, &ARM::GPRRegClass,
209 &ARM::GPRRegClass, &ARM::GPRRegClass,
211 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
212 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
216 if (STI.isThumb1Only()) {
217 return STI.isTargetDarwin()
218 ? DarwinThumbCalleeSavedRegClasses : ThumbCalleeSavedRegClasses;
220 return STI.isTargetDarwin()
221 ? DarwinCalleeSavedRegClasses : CalleeSavedRegClasses;
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);
237 bool ARMBaseRegisterInfo::isReservedReg(const MachineFunction &MF,
238 unsigned Reg) const {
246 if (FramePtr == Reg && (STI.isTargetDarwin() || hasFP(MF)))
250 return STI.isR9Reserved();
256 const TargetRegisterClass *
257 ARMBaseRegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
258 const TargetRegisterClass *B,
259 unsigned SubIdx) const {
267 if (A->getSize() == 8) {
268 if (A == &ARM::DPR_8RegClass)
270 return &ARM::DPR_VFP2RegClass;
273 assert(A->getSize() == 16 && "Expecting a Q register class!");
274 return &ARM::QPR_VFP2RegClass;
283 const TargetRegisterClass *
284 ARMBaseRegisterInfo::getPointerRegClass(unsigned Kind) const {
285 return ARM::GPRRegisterClass;
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.
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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
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
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
372 return std::make_pair(RC->allocation_order_begin(MF),
373 RC->allocation_order_end(MF));
375 if (!STI.isTargetDarwin() && !hasFP(MF)) {
376 if (!STI.isR9Reserved())
377 return std::make_pair(GPREven1,
378 GPREven1 + (sizeof(GPREven1)/sizeof(unsigned)));
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)));
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)));
394 return std::make_pair(GPREven6,
395 GPREven6 + (sizeof(GPREven6)/sizeof(unsigned)));
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
401 return std::make_pair(RC->allocation_order_begin(MF),
402 RC->allocation_order_end(MF));
404 if (!STI.isTargetDarwin() && !hasFP(MF)) {
405 if (!STI.isR9Reserved())
406 return std::make_pair(GPROdd1,
407 GPROdd1 + (sizeof(GPROdd1)/sizeof(unsigned)));
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)));
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)));
423 return std::make_pair(GPROdd6,
424 GPROdd6 + (sizeof(GPROdd6)/sizeof(unsigned)));
427 return std::make_pair(RC->allocation_order_begin(MF),
428 RC->allocation_order_end(MF));
431 /// ResolveRegAllocHint - Resolves the specified register allocation hint
432 /// to a physical register. Returns the physical register if it is successful.
434 ARMBaseRegisterInfo::ResolveRegAllocHint(unsigned Type, unsigned Reg,
435 const MachineFunction &MF) const {
436 if (Reg == 0 || !isPhysicalRegister(Reg))
440 else if (Type == (unsigned)ARMRI::RegPairOdd)
442 return getRegisterPairOdd(Reg, MF);
443 else if (Type == (unsigned)ARMRI::RegPairEven)
445 return getRegisterPairEven(Reg, MF);
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
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);
469 static unsigned calculateMaxStackAlignment(const MachineFrameInfo *FFI) {
470 unsigned MaxAlign = 0;
472 for (int i = FFI->getObjectIndexBegin(),
473 e = FFI->getObjectIndexEnd(); i != e; ++i) {
474 if (FFI->isDeadObjectIndex(i))
477 unsigned Align = FFI->getObjectAlignment(i);
478 MaxAlign = std::max(MaxAlign, Align);
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.
488 bool ARMBaseRegisterInfo::hasFP(const MachineFunction &MF) const {
489 const MachineFrameInfo *MFI = MF.getFrameInfo();
490 return (NoFramePointerElim ||
491 needsStackRealignment(MF) ||
492 MFI->hasVarSizedObjects() ||
493 MFI->isFrameAddressTaken());
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)
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());
513 bool ARMBaseRegisterInfo::cannotEliminateFrame(const MachineFunction &MF) const {
514 const MachineFrameInfo *MFI = MF.getFrameInfo();
515 if (NoFramePointerElim && MFI->hasCalls())
517 return MFI->hasVarSizedObjects() || MFI->isFrameAddressTaken();
520 /// estimateStackSize - Estimate and return the size of the frame.
521 static unsigned estimateStackSize(MachineFunction &MF, MachineFrameInfo *MFI) {
522 const MachineFrameInfo *FFI = MF.getFrameInfo();
524 for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) {
525 int FixedOff = -FFI->getObjectOffset(i);
526 if (FixedOff > Offset) Offset = FixedOff;
528 for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
529 if (FFI->isDeadObjectIndex(i))
531 Offset += FFI->getObjectSize(i);
532 unsigned Align = FFI->getObjectAlignment(i);
533 // Adjust to alignment boundary
534 Offset = (Offset+Align-1)/Align*Align;
536 return (unsigned)Offset;
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.
543 ARMBaseRegisterInfo::estimateRSStackSizeLimit(MachineFunction &MF) const {
544 unsigned Limit = (1 << 12) - 1;
545 for (MachineFunction::iterator BB = MF.begin(),E = MF.end(); BB != E; ++BB) {
546 for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end();
548 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
549 if (!I->getOperand(i).isFI()) continue;
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)
557 if (AddrMode == ARMII::AddrMode5 ||
558 AddrMode == ARMII::AddrModeT2_i8s4)
559 Limit = std::min(Limit, ((1U << 8) - 1) * 4);
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.
565 break; // At most one FI per instruction
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>();
588 MachineFrameInfo *MFI = MF.getFrameInfo();
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);
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);
608 CanEliminateFrame = false;
610 // Check alias registers too.
611 for (const unsigned *Aliases = getAliasSet(Reg); *Aliases; ++Aliases) {
612 if (MF.getRegInfo().isPhysRegUsed(*Aliases)) {
614 CanEliminateFrame = false;
619 if (CSRegClasses[i] == ARM::GPRRegisterClass ||
620 CSRegClasses[i] == ARM::tGPRRegisterClass) {
624 if (!STI.isTargetDarwin()) {
631 // Keep track if LR and any of R4, R5, R6, and R7 is spilled.
646 if (!STI.isTargetDarwin()) {
647 UnspilledCS1GPRs.push_back(Reg);
657 UnspilledCS1GPRs.push_back(Reg);
660 UnspilledCS2GPRs.push_back(Reg);
667 bool ForceLRSpill = false;
668 if (!LRSpilled && AFI->isThumb1OnlyFunction()) {
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;
679 bool ExtraCSSpill = false;
680 if (!CanEliminateFrame || cannotEliminateFrame(MF)) {
681 AFI->setHasStackFrame(true);
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);
689 UnspilledCS1GPRs.erase(std::find(UnspilledCS1GPRs.begin(),
690 UnspilledCS1GPRs.end(), (unsigned)ARM::LR));
691 ForceLRSpill = false;
695 // Darwin ABI requires FP to point to the stack slot that contains the
697 if (STI.isTargetDarwin() || hasFP(MF)) {
698 MF.getRegInfo().setPhysRegUsed(FramePtr);
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];
710 // Don't spill high register if the function is thumb1
711 if (!AFI->isThumb1OnlyFunction() ||
712 isARMLowRegister(Reg) || Reg == ARM::LR) {
713 MF.getRegInfo().setPhysRegUsed(Reg);
714 AFI->setCSRegisterIsSpilled(Reg);
715 if (!isReservedReg(MF, Reg))
720 } else if (!UnspilledCS2GPRs.empty() &&
721 !AFI->isThumb1OnlyFunction()) {
722 unsigned Reg = UnspilledCS2GPRs.front();
723 MF.getRegInfo().setPhysRegUsed(Reg);
724 AFI->setCSRegisterIsSpilled(Reg);
725 if (!isReservedReg(MF, Reg))
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
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) {
736 MachineFrameInfo *MFI = MF.getFrameInfo();
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
741 // since the FP points to the stack slot of the previous FP.
742 if (estimateStackSize(MF, MFI) + (hasFP(MF) ? 4 : 0)
743 >= estimateRSStackSizeLimit(MF)) {
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);
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);
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]);
772 } else if (!AFI->isThumb1OnlyFunction()) {
773 // note: Thumb1 functions spill to R12, not the stack.
774 // Reserve a slot closest to SP or frame pointer.
775 const TargetRegisterClass *RC = ARM::GPRRegisterClass;
776 RS->setScavengingFrameIndex(MFI->CreateStackObject(RC->getSize(),
777 RC->getAlignment()));
784 MF.getRegInfo().setPhysRegUsed(ARM::LR);
785 AFI->setCSRegisterIsSpilled(ARM::LR);
786 AFI->setLRIsSpilledForFarJump(true);
790 unsigned ARMBaseRegisterInfo::getRARegister() const {
794 unsigned ARMBaseRegisterInfo::getFrameRegister(MachineFunction &MF) const {
795 if (STI.isTargetDarwin() || hasFP(MF))
800 unsigned ARMBaseRegisterInfo::getEHExceptionRegister() const {
801 llvm_unreachable("What is the exception register");
805 unsigned ARMBaseRegisterInfo::getEHHandlerRegister() const {
806 llvm_unreachable("What is the exception handler register");
810 int ARMBaseRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
811 return ARMGenRegisterInfo::getDwarfRegNumFull(RegNum, 0);
814 unsigned ARMBaseRegisterInfo::getRegisterPairEven(unsigned Reg,
815 const MachineFunction &MF) const {
818 // Return 0 if either register of the pair is a special register.
827 return isReservedReg(MF, ARM::R7) ? 0 : ARM::R6;
829 return isReservedReg(MF, ARM::R9) ? 0 :ARM::R8;
831 return isReservedReg(MF, ARM::R11) ? 0 : ARM::R10;
903 unsigned ARMBaseRegisterInfo::getRegisterPairOdd(unsigned Reg,
904 const MachineFunction &MF) const {
907 // Return 0 if either register of the pair is a special register.
916 return isReservedReg(MF, ARM::R7) ? 0 : ARM::R7;
918 return isReservedReg(MF, ARM::R9) ? 0 :ARM::R9;
920 return isReservedReg(MF, ARM::R11) ? 0 : ARM::R11;
992 /// emitLoadConstPool - Emits a load from constpool to materialize the
993 /// specified immediate.
994 void ARMBaseRegisterInfo::
995 emitLoadConstPool(MachineBasicBlock &MBB,
996 MachineBasicBlock::iterator &MBBI,
998 unsigned DestReg, unsigned SubIdx, int Val,
999 ARMCC::CondCodes Pred,
1000 unsigned PredReg) const {
1001 MachineFunction &MF = *MBB.getParent();
1002 MachineConstantPool *ConstantPool = MF.getConstantPool();
1004 ConstantInt::get(Type::getInt32Ty(MF.getFunction()->getContext()), Val);
1005 unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
1007 BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp))
1008 .addReg(DestReg, getDefRegState(true), SubIdx)
1009 .addConstantPoolIndex(Idx)
1010 .addReg(0).addImm(0).addImm(Pred).addReg(PredReg);
1013 bool ARMBaseRegisterInfo::
1014 requiresRegisterScavenging(const MachineFunction &MF) const {
1018 bool ARMBaseRegisterInfo::
1019 requiresFrameIndexScavenging(const MachineFunction &MF) const {
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
1039 return !MF.getFrameInfo()->hasVarSizedObjects();
1043 emitSPUpdate(bool isARM,
1044 MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
1045 DebugLoc dl, const ARMBaseInstrInfo &TII,
1047 ARMCC::CondCodes Pred = ARMCC::AL, unsigned PredReg = 0) {
1049 emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, ARM::SP, NumBytes,
1050 Pred, PredReg, TII);
1052 emitT2RegPlusImmediate(MBB, MBBI, dl, ARM::SP, ARM::SP, NumBytes,
1053 Pred, PredReg, TII);
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();
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;
1074 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1075 assert(!AFI->isThumb1OnlyFunction() &&
1076 "This eliminateCallFramePseudoInstr does not suppor Thumb1!");
1077 bool isARM = !AFI->isThumbFunction();
1079 // Replace the pseudo instruction with a new instruction...
1080 unsigned Opc = Old->getOpcode();
1081 ARMCC::CondCodes Pred = (ARMCC::CondCodes)Old->getOperand(1).getImm();
1082 // FIXME: Thumb2 version of ADJCALLSTACKUP and ADJCALLSTACKDOWN?
1083 if (Opc == ARM::ADJCALLSTACKDOWN || Opc == ARM::tADJCALLSTACKDOWN) {
1084 // Note: PredReg is operand 2 for ADJCALLSTACKDOWN.
1085 unsigned PredReg = Old->getOperand(2).getReg();
1086 emitSPUpdate(isARM, MBB, I, dl, TII, -Amount, Pred, PredReg);
1088 // Note: PredReg is operand 3 for ADJCALLSTACKUP.
1089 unsigned PredReg = Old->getOperand(3).getReg();
1090 assert(Opc == ARM::ADJCALLSTACKUP || Opc == ARM::tADJCALLSTACKUP);
1091 emitSPUpdate(isARM, MBB, I, dl, TII, Amount, Pred, PredReg);
1099 ARMBaseRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
1100 int SPAdj, int *Value,
1101 RegScavenger *RS) const {
1103 MachineInstr &MI = *II;
1104 MachineBasicBlock &MBB = *MI.getParent();
1105 MachineFunction &MF = *MBB.getParent();
1106 const MachineFrameInfo *MFI = MF.getFrameInfo();
1107 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1108 assert(!AFI->isThumb1OnlyFunction() &&
1109 "This eliminateFrameIndex does not support Thumb1!");
1111 while (!MI.getOperand(i).isFI()) {
1113 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
1116 unsigned FrameReg = ARM::SP;
1117 int FrameIndex = MI.getOperand(i).getIndex();
1118 int Offset = MFI->getObjectOffset(FrameIndex) + MFI->getStackSize() + SPAdj;
1120 // When doing dynamic stack realignment, all of these need to change(?)
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();
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
1138 } else if (hasFP(MF) && AFI->hasStackFrame()) {
1139 assert(SPAdj == 0 && "Unexpected stack offset!");
1140 // Use frame pointer to reference fixed objects unless this is a
1141 // frameless function.
1142 FrameReg = getFrameRegister(MF);
1143 Offset -= AFI->getFramePtrSpillOffset();
1146 // modify MI as necessary to handle as much of 'Offset' as possible
1148 if (!AFI->isThumbFunction())
1149 Done = rewriteARMFrameIndex(MI, i, FrameReg, Offset, TII);
1151 assert(AFI->isThumb2Function());
1152 Done = rewriteT2FrameIndex(MI, i, FrameReg, Offset, TII);
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
1161 (MI.getDesc().TSFlags & ARMII::AddrModeMask) == ARMII::AddrMode4) &&
1162 "This code isn't needed if offset already handled!");
1164 unsigned ScratchReg = 0;
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();
1170 // Must be addrmode4.
1171 MI.getOperand(i).ChangeToRegister(FrameReg, false, false, false);
1173 ScratchReg = MF.getRegInfo().createVirtualRegister(ARM::GPRRegisterClass);
1174 if (Value) *Value = Offset;
1175 if (!AFI->isThumbFunction())
1176 emitARMRegPlusImmediate(MBB, II, MI.getDebugLoc(), ScratchReg, FrameReg,
1177 Offset, Pred, PredReg, TII);
1179 assert(AFI->isThumb2Function());
1180 emitT2RegPlusImmediate(MBB, II, MI.getDebugLoc(), ScratchReg, FrameReg,
1181 Offset, Pred, PredReg, TII);
1183 MI.getOperand(i).ChangeToRegister(ScratchReg, false, false, true);
1184 if (!ReuseFrameIndexVals)
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,
1195 int Opc1, int Opc2, unsigned Area,
1196 const ARMSubtarget &STI) {
1197 while (MBBI != MBB.end() &&
1198 ((MBBI->getOpcode() == Opc1) || (MBBI->getOpcode() == Opc2)) &&
1199 MBBI->getOperand(1).isFI()) {
1202 unsigned Category = 0;
1203 switch (MBBI->getOperand(0).getReg()) {
1204 case ARM::R4: case ARM::R5: case ARM::R6: case ARM::R7:
1208 case ARM::R8: case ARM::R9: case ARM::R10: case ARM::R11:
1209 Category = STI.isTargetDarwin() ? 2 : 1;
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:
1219 if (Done || Category != Area)
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>();
1233 assert(!AFI->isThumb1OnlyFunction() &&
1234 "This emitPrologue does not suppor Thumb1!");
1235 bool isARM = !AFI->isThumbFunction();
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());
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;
1247 // Allocate the vararg register save area. This is not counted in NumBytes.
1249 emitSPUpdate(isARM, MBB, MBBI, dl, TII, -VARegSaveSize);
1251 if (!AFI->hasStackFrame()) {
1253 emitSPUpdate(isARM, MBB, MBBI, dl, TII, -NumBytes);
1257 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
1258 unsigned Reg = CSI[i].getReg();
1259 int FI = CSI[i].getFrameIdx();
1266 if (Reg == FramePtr)
1267 FramePtrSpillFI = FI;
1268 AFI->addGPRCalleeSavedArea1Frame(FI);
1275 if (Reg == FramePtr)
1276 FramePtrSpillFI = FI;
1277 if (STI.isTargetDarwin()) {
1278 AFI->addGPRCalleeSavedArea2Frame(FI);
1281 AFI->addGPRCalleeSavedArea1Frame(FI);
1286 AFI->addDPRCalleeSavedAreaFrame(FI);
1291 // Build the new SUBri to adjust SP for integer callee-save spill area 1.
1292 emitSPUpdate(isARM, MBB, MBBI, dl, TII, -GPRCS1Size);
1293 movePastCSLoadStoreOps(MBB, MBBI, ARM::STR, ARM::t2STRi12, 1, STI);
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.
1300 if (STI.isTargetDarwin() || hasFP(MF)) {
1301 unsigned ADDriOpc = !AFI->isThumbFunction() ? ARM::ADDri : ARM::t2ADDri;
1302 MachineInstrBuilder MIB =
1303 BuildMI(MBB, MBBI, dl, TII.get(ADDriOpc), FramePtr)
1304 .addFrameIndex(FramePtrSpillFI).addImm(0);
1305 AddDefaultCC(AddDefaultPred(MIB));
1308 // Build the new SUBri to adjust SP for integer callee-save spill area 2.
1309 emitSPUpdate(isARM, MBB, MBBI, dl, TII, -GPRCS2Size);
1311 // Build the new SUBri to adjust SP for FP callee-save spill area.
1312 movePastCSLoadStoreOps(MBB, MBBI, ARM::STR, ARM::t2STRi12, 2, STI);
1313 emitSPUpdate(isARM, MBB, MBBI, dl, TII, -DPRCSSize);
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);
1324 NumBytes = DPRCSOffset;
1326 // Insert it after all the callee-save spills.
1327 movePastCSLoadStoreOps(MBB, MBBI, ARM::FSTD, 0, 3, STI);
1328 emitSPUpdate(isARM, MBB, MBBI, dl, TII, -NumBytes);
1331 if (STI.isTargetELF() && hasFP(MF)) {
1332 MFI->setOffsetAdjustment(MFI->getOffsetAdjustment() -
1333 AFI->getFramePtrSpillOffset());
1336 AFI->setGPRCalleeSavedArea1Size(GPRCS1Size);
1337 AFI->setGPRCalleeSavedArea2Size(GPRCS2Size);
1338 AFI->setDPRCalleeSavedAreaSize(DPRCSSize);
1340 // If we need dynamic stack realignment, do it here.
1341 if (needsStackRealignment(MF)) {
1343 unsigned MaxAlign = MFI->getMaxAlignment();
1344 assert (!AFI->isThumb1OnlyFunction());
1345 Opc = AFI->isThumbFunction() ? ARM::t2BICri : ARM::BICri;
1347 AddDefaultCC(AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(Opc), ARM::SP)
1348 .addReg(ARM::SP, RegState::Kill)
1349 .addImm(MaxAlign-1)));
1353 static bool isCalleeSavedRegister(unsigned Reg, const unsigned *CSRegs) {
1354 for (unsigned i = 0; CSRegs[i]; ++i)
1355 if (Reg == CSRegs[i])
1360 static bool isCSRestore(MachineInstr *MI,
1361 const ARMBaseInstrInfo &TII,
1362 const unsigned *CSRegs) {
1363 return ((MI->getOpcode() == (int)ARM::FLDD ||
1364 MI->getOpcode() == (int)ARM::LDR ||
1365 MI->getOpcode() == (int)ARM::t2LDRi12) &&
1366 MI->getOperand(1).isFI() &&
1367 isCalleeSavedRegister(MI->getOperand(0).getReg(), CSRegs));
1370 void ARMBaseRegisterInfo::
1371 emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const {
1372 MachineBasicBlock::iterator MBBI = prior(MBB.end());
1373 assert(MBBI->getDesc().isReturn() &&
1374 "Can only insert epilog into returning blocks");
1375 DebugLoc dl = MBBI->getDebugLoc();
1376 MachineFrameInfo *MFI = MF.getFrameInfo();
1377 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1378 assert(!AFI->isThumb1OnlyFunction() &&
1379 "This emitEpilogue does not suppor Thumb1!");
1380 bool isARM = !AFI->isThumbFunction();
1382 unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
1383 int NumBytes = (int)MFI->getStackSize();
1385 if (!AFI->hasStackFrame()) {
1387 emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes);
1389 // Unwind MBBI to point to first LDR / FLDD.
1390 const unsigned *CSRegs = getCalleeSavedRegs();
1391 if (MBBI != MBB.begin()) {
1394 while (MBBI != MBB.begin() && isCSRestore(MBBI, TII, CSRegs));
1395 if (!isCSRestore(MBBI, TII, CSRegs))
1399 // Move SP to start of FP callee save spill area.
1400 NumBytes -= (AFI->getGPRCalleeSavedArea1Size() +
1401 AFI->getGPRCalleeSavedArea2Size() +
1402 AFI->getDPRCalleeSavedAreaSize());
1404 // Darwin ABI requires FP to point to the stack slot that contains the
1406 bool HasFP = hasFP(MF);
1407 if ((STI.isTargetDarwin() && NumBytes) || HasFP) {
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.
1412 AFI->getGPRCalleeSavedArea2Size() ||
1413 AFI->getDPRCalleeSavedAreaSize() ||
1414 AFI->getDPRCalleeSavedAreaOffset()) {
1417 emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes,
1420 emitT2RegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes,
1425 BuildMI(MBB, MBBI, dl, TII.get(ARM::MOVr), ARM::SP)
1427 .addImm((unsigned)ARMCC::AL).addReg(0).addReg(0);
1429 BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVgpr2gpr), ARM::SP)
1433 } else if (NumBytes)
1434 emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes);
1436 // Move SP to start of integer callee save spill area 2.
1437 movePastCSLoadStoreOps(MBB, MBBI, ARM::FLDD, 0, 3, STI);
1438 emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getDPRCalleeSavedAreaSize());
1440 // Move SP to start of integer callee save spill area 1.
1441 movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, ARM::t2LDRi12, 2, STI);
1442 emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getGPRCalleeSavedArea2Size());
1444 // Move SP to SP upon entry to the function.
1445 movePastCSLoadStoreOps(MBB, MBBI, ARM::LDR, ARM::t2LDRi12, 1, STI);
1446 emitSPUpdate(isARM, MBB, MBBI, dl, TII, AFI->getGPRCalleeSavedArea1Size());
1450 emitSPUpdate(isARM, MBB, MBBI, dl, TII, VARegSaveSize);
1453 #include "ARMGenRegisterInfo.inc"