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/CodeGen/MachineConstantPool.h"
24 #include "llvm/CodeGen/MachineFrameInfo.h"
25 #include "llvm/CodeGen/MachineFunction.h"
26 #include "llvm/CodeGen/MachineInstrBuilder.h"
27 #include "llvm/CodeGen/MachineLocation.h"
28 #include "llvm/CodeGen/MachineRegisterInfo.h"
29 #include "llvm/CodeGen/RegisterScavenging.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/Target/TargetFrameInfo.h"
33 #include "llvm/Target/TargetMachine.h"
34 #include "llvm/Target/TargetOptions.h"
35 #include "llvm/ADT/BitVector.h"
36 #include "llvm/ADT/SmallVector.h"
39 unsigned ARMBaseRegisterInfo::getRegisterNumbering(unsigned RegEnum) {
42 case R0: case S0: case D0: return 0;
43 case R1: case S1: case D1: return 1;
44 case R2: case S2: case D2: return 2;
45 case R3: case S3: case D3: return 3;
46 case R4: case S4: case D4: return 4;
47 case R5: case S5: case D5: return 5;
48 case R6: case S6: case D6: return 6;
49 case R7: case S7: case D7: return 7;
50 case R8: case S8: case D8: return 8;
51 case R9: case S9: case D9: return 9;
52 case R10: case S10: case D10: return 10;
53 case R11: case S11: case D11: return 11;
54 case R12: case S12: case D12: return 12;
55 case SP: case S13: case D13: return 13;
56 case LR: case S14: case D14: return 14;
57 case PC: case S15: case D15: return 15;
75 LLVM_UNREACHABLE("Unknown ARM register!");
79 unsigned ARMBaseRegisterInfo::getRegisterNumbering(unsigned RegEnum,
86 LLVM_UNREACHABLE("Unknown ARM register!");
87 case R0: case D0: return 0;
88 case R1: case D1: return 1;
89 case R2: case D2: return 2;
90 case R3: case D3: return 3;
91 case R4: case D4: return 4;
92 case R5: case D5: return 5;
93 case R6: case D6: return 6;
94 case R7: case D7: return 7;
95 case R8: case D8: return 8;
96 case R9: case D9: return 9;
97 case R10: case D10: return 10;
98 case R11: case D11: return 11;
99 case R12: case D12: return 12;
100 case SP: case D13: return 13;
101 case LR: case D14: return 14;
102 case PC: case D15: return 15;
104 case S0: case S1: case S2: case S3:
105 case S4: case S5: case S6: case S7:
106 case S8: case S9: case S10: case S11:
107 case S12: case S13: case S14: case S15:
108 case S16: case S17: case S18: case S19:
109 case S20: case S21: case S22: case S23:
110 case S24: case S25: case S26: case S27:
111 case S28: case S29: case S30: case S31: {
114 default: return 0; // Avoid compile time warning.
152 ARMBaseRegisterInfo::ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
153 const ARMSubtarget &sti)
154 : ARMGenRegisterInfo(ARM::ADJCALLSTACKDOWN, ARM::ADJCALLSTACKUP),
156 FramePtr((STI.isTargetDarwin() || STI.isThumb()) ? ARM::R7 : ARM::R11) {
159 unsigned ARMBaseRegisterInfo::
160 getOpcode(int Op) const {
161 return TII.getOpcode((ARMII::Op)Op);
165 ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
166 static const unsigned CalleeSavedRegs[] = {
167 ARM::LR, ARM::R11, ARM::R10, ARM::R9, ARM::R8,
168 ARM::R7, ARM::R6, ARM::R5, ARM::R4,
170 ARM::D15, ARM::D14, ARM::D13, ARM::D12,
171 ARM::D11, ARM::D10, ARM::D9, ARM::D8,
175 static const unsigned DarwinCalleeSavedRegs[] = {
176 // Darwin ABI deviates from ARM standard ABI. R9 is not a callee-saved
178 ARM::LR, ARM::R7, ARM::R6, ARM::R5, ARM::R4,
179 ARM::R11, ARM::R10, ARM::R8,
181 ARM::D15, ARM::D14, ARM::D13, ARM::D12,
182 ARM::D11, ARM::D10, ARM::D9, ARM::D8,
185 return STI.isTargetDarwin() ? DarwinCalleeSavedRegs : CalleeSavedRegs;
188 const TargetRegisterClass* const *
189 ARMBaseRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const {
190 static const TargetRegisterClass * const CalleeSavedRegClasses[] = {
191 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
192 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
193 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
195 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
196 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
200 static const TargetRegisterClass * const ThumbCalleeSavedRegClasses[] = {
201 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
202 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::tGPRRegClass,
203 &ARM::tGPRRegClass,&ARM::tGPRRegClass,&ARM::tGPRRegClass,
205 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
206 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
210 static const TargetRegisterClass * const DarwinCalleeSavedRegClasses[] = {
211 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
212 &ARM::GPRRegClass, &ARM::GPRRegClass, &ARM::GPRRegClass,
213 &ARM::GPRRegClass, &ARM::GPRRegClass,
215 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
216 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
220 static const TargetRegisterClass * const DarwinThumbCalleeSavedRegClasses[] ={
221 &ARM::GPRRegClass, &ARM::tGPRRegClass, &ARM::tGPRRegClass,
222 &ARM::tGPRRegClass, &ARM::tGPRRegClass, &ARM::GPRRegClass,
223 &ARM::GPRRegClass, &ARM::GPRRegClass,
225 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
226 &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass, &ARM::DPRRegClass,
230 if (STI.isThumb1Only()) {
231 return STI.isTargetDarwin()
232 ? DarwinThumbCalleeSavedRegClasses : ThumbCalleeSavedRegClasses;
234 return STI.isTargetDarwin()
235 ? DarwinCalleeSavedRegClasses : CalleeSavedRegClasses;
238 BitVector ARMBaseRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
239 // FIXME: avoid re-calculating this everytime.
240 BitVector Reserved(getNumRegs());
241 Reserved.set(ARM::SP);
242 Reserved.set(ARM::PC);
243 if (STI.isTargetDarwin() || hasFP(MF))
244 Reserved.set(FramePtr);
245 // Some targets reserve R9.
246 if (STI.isR9Reserved())
247 Reserved.set(ARM::R9);
252 ARMBaseRegisterInfo::isReservedReg(const MachineFunction &MF, unsigned Reg) const {
260 if (FramePtr == Reg && (STI.isTargetDarwin() || hasFP(MF)))
264 return STI.isR9Reserved();
270 const TargetRegisterClass *ARMBaseRegisterInfo::getPointerRegClass() const {
271 return &ARM::GPRRegClass;
274 /// getAllocationOrder - Returns the register allocation order for a specified
275 /// register class in the form of a pair of TargetRegisterClass iterators.
276 std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator>
277 ARMBaseRegisterInfo::getAllocationOrder(const TargetRegisterClass *RC,
278 unsigned HintType, unsigned HintReg,
279 const MachineFunction &MF) const {
280 // Alternative register allocation orders when favoring even / odd registers
281 // of register pairs.
283 // No FP, R9 is available.
284 static const unsigned GPREven1[] = {
285 ARM::R0, ARM::R2, ARM::R4, ARM::R6, ARM::R8, ARM::R10,
286 ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R7,
289 static const unsigned GPROdd1[] = {
290 ARM::R1, ARM::R3, ARM::R5, ARM::R7, ARM::R9, ARM::R11,
291 ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6,
295 // FP is R7, R9 is available.
296 static const unsigned GPREven2[] = {
297 ARM::R0, ARM::R2, ARM::R4, ARM::R8, ARM::R10,
298 ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R6,
301 static const unsigned GPROdd2[] = {
302 ARM::R1, ARM::R3, ARM::R5, ARM::R9, ARM::R11,
303 ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6,
307 // FP is R11, R9 is available.
308 static const unsigned GPREven3[] = {
309 ARM::R0, ARM::R2, ARM::R4, ARM::R6, ARM::R8,
310 ARM::R1, ARM::R3, ARM::R10,ARM::R12,ARM::LR, ARM::R5, ARM::R7,
313 static const unsigned GPROdd3[] = {
314 ARM::R1, ARM::R3, ARM::R5, ARM::R6, ARM::R9,
315 ARM::R0, ARM::R2, ARM::R10,ARM::R12,ARM::LR, ARM::R4, ARM::R7,
319 // No FP, R9 is not available.
320 static const unsigned GPREven4[] = {
321 ARM::R0, ARM::R2, ARM::R4, ARM::R6, ARM::R10,
322 ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R7, ARM::R8,
325 static const unsigned GPROdd4[] = {
326 ARM::R1, ARM::R3, ARM::R5, ARM::R7, ARM::R11,
327 ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6, ARM::R8,
331 // FP is R7, R9 is not available.
332 static const unsigned GPREven5[] = {
333 ARM::R0, ARM::R2, ARM::R4, ARM::R10,
334 ARM::R1, ARM::R3, ARM::R12,ARM::LR, ARM::R5, ARM::R6, ARM::R8,
337 static const unsigned GPROdd5[] = {
338 ARM::R1, ARM::R3, ARM::R5, ARM::R11,
339 ARM::R0, ARM::R2, ARM::R12,ARM::LR, ARM::R4, ARM::R6, ARM::R8,
343 // FP is R11, R9 is not available.
344 static const unsigned GPREven6[] = {
345 ARM::R0, ARM::R2, ARM::R4, ARM::R6,
346 ARM::R1, ARM::R3, ARM::R10,ARM::R12,ARM::LR, ARM::R5, ARM::R7, ARM::R8
348 static const unsigned GPROdd6[] = {
349 ARM::R1, ARM::R3, ARM::R5, ARM::R7,
350 ARM::R0, ARM::R2, ARM::R10,ARM::R12,ARM::LR, ARM::R4, ARM::R6, ARM::R8
354 if (HintType == ARMRI::RegPairEven) {
355 if (isPhysicalRegister(HintReg) && getRegisterPairEven(HintReg, MF) == 0)
356 // It's no longer possible to fulfill this hint. Return the default
358 return std::make_pair(RC->allocation_order_begin(MF),
359 RC->allocation_order_end(MF));
361 if (!STI.isTargetDarwin() && !hasFP(MF)) {
362 if (!STI.isR9Reserved())
363 return std::make_pair(GPREven1,
364 GPREven1 + (sizeof(GPREven1)/sizeof(unsigned)));
366 return std::make_pair(GPREven4,
367 GPREven4 + (sizeof(GPREven4)/sizeof(unsigned)));
368 } else if (FramePtr == ARM::R7) {
369 if (!STI.isR9Reserved())
370 return std::make_pair(GPREven2,
371 GPREven2 + (sizeof(GPREven2)/sizeof(unsigned)));
373 return std::make_pair(GPREven5,
374 GPREven5 + (sizeof(GPREven5)/sizeof(unsigned)));
375 } else { // FramePtr == ARM::R11
376 if (!STI.isR9Reserved())
377 return std::make_pair(GPREven3,
378 GPREven3 + (sizeof(GPREven3)/sizeof(unsigned)));
380 return std::make_pair(GPREven6,
381 GPREven6 + (sizeof(GPREven6)/sizeof(unsigned)));
383 } else if (HintType == ARMRI::RegPairOdd) {
384 if (isPhysicalRegister(HintReg) && getRegisterPairOdd(HintReg, MF) == 0)
385 // It's no longer possible to fulfill this hint. Return the default
387 return std::make_pair(RC->allocation_order_begin(MF),
388 RC->allocation_order_end(MF));
390 if (!STI.isTargetDarwin() && !hasFP(MF)) {
391 if (!STI.isR9Reserved())
392 return std::make_pair(GPROdd1,
393 GPROdd1 + (sizeof(GPROdd1)/sizeof(unsigned)));
395 return std::make_pair(GPROdd4,
396 GPROdd4 + (sizeof(GPROdd4)/sizeof(unsigned)));
397 } else if (FramePtr == ARM::R7) {
398 if (!STI.isR9Reserved())
399 return std::make_pair(GPROdd2,
400 GPROdd2 + (sizeof(GPROdd2)/sizeof(unsigned)));
402 return std::make_pair(GPROdd5,
403 GPROdd5 + (sizeof(GPROdd5)/sizeof(unsigned)));
404 } else { // FramePtr == ARM::R11
405 if (!STI.isR9Reserved())
406 return std::make_pair(GPROdd3,
407 GPROdd3 + (sizeof(GPROdd3)/sizeof(unsigned)));
409 return std::make_pair(GPROdd6,
410 GPROdd6 + (sizeof(GPROdd6)/sizeof(unsigned)));
413 return std::make_pair(RC->allocation_order_begin(MF),
414 RC->allocation_order_end(MF));
417 /// ResolveRegAllocHint - Resolves the specified register allocation hint
418 /// to a physical register. Returns the physical register if it is successful.
420 ARMBaseRegisterInfo::ResolveRegAllocHint(unsigned Type, unsigned Reg,
421 const MachineFunction &MF) const {
422 if (Reg == 0 || !isPhysicalRegister(Reg))
426 else if (Type == (unsigned)ARMRI::RegPairOdd)
428 return getRegisterPairOdd(Reg, MF);
429 else if (Type == (unsigned)ARMRI::RegPairEven)
431 return getRegisterPairEven(Reg, MF);
436 ARMBaseRegisterInfo::UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
437 MachineFunction &MF) const {
438 MachineRegisterInfo *MRI = &MF.getRegInfo();
439 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(Reg);
440 if ((Hint.first == (unsigned)ARMRI::RegPairOdd ||
441 Hint.first == (unsigned)ARMRI::RegPairEven) &&
442 Hint.second && TargetRegisterInfo::isVirtualRegister(Hint.second)) {
443 // If 'Reg' is one of the even / odd register pair and it's now changed
444 // (e.g. coalesced) into a different register. The other register of the
445 // pair allocation hint must be updated to reflect the relationship
447 unsigned OtherReg = Hint.second;
448 Hint = MRI->getRegAllocationHint(OtherReg);
449 if (Hint.second == Reg)
450 // Make sure the pair has not already divorced.
451 MRI->setRegAllocationHint(OtherReg, Hint.first, NewReg);
455 /// hasFP - Return true if the specified function should have a dedicated frame
456 /// pointer register. This is true if the function has variable sized allocas
457 /// or if frame pointer elimination is disabled.
459 bool ARMBaseRegisterInfo::hasFP(const MachineFunction &MF) const {
460 const MachineFrameInfo *MFI = MF.getFrameInfo();
461 return (NoFramePointerElim ||
462 MFI->hasVarSizedObjects() ||
463 MFI->isFrameAddressTaken());
466 static unsigned estimateStackSize(MachineFunction &MF, MachineFrameInfo *MFI) {
467 const MachineFrameInfo *FFI = MF.getFrameInfo();
469 for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) {
470 int FixedOff = -FFI->getObjectOffset(i);
471 if (FixedOff > Offset) Offset = FixedOff;
473 for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
474 if (FFI->isDeadObjectIndex(i))
476 Offset += FFI->getObjectSize(i);
477 unsigned Align = FFI->getObjectAlignment(i);
478 // Adjust to alignment boundary
479 Offset = (Offset+Align-1)/Align*Align;
481 return (unsigned)Offset;
485 ARMBaseRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
486 RegScavenger *RS) const {
487 // This tells PEI to spill the FP as if it is any other callee-save register
488 // to take advantage the eliminateFrameIndex machinery. This also ensures it
489 // is spilled in the order specified by getCalleeSavedRegs() to make it easier
490 // to combine multiple loads / stores.
491 bool CanEliminateFrame = true;
492 bool CS1Spilled = false;
493 bool LRSpilled = false;
494 unsigned NumGPRSpills = 0;
495 SmallVector<unsigned, 4> UnspilledCS1GPRs;
496 SmallVector<unsigned, 4> UnspilledCS2GPRs;
497 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
499 // Don't spill FP if the frame can be eliminated. This is determined
500 // by scanning the callee-save registers to see if any is used.
501 const unsigned *CSRegs = getCalleeSavedRegs();
502 const TargetRegisterClass* const *CSRegClasses = getCalleeSavedRegClasses();
503 for (unsigned i = 0; CSRegs[i]; ++i) {
504 unsigned Reg = CSRegs[i];
505 bool Spilled = false;
506 if (MF.getRegInfo().isPhysRegUsed(Reg)) {
507 AFI->setCSRegisterIsSpilled(Reg);
509 CanEliminateFrame = false;
511 // Check alias registers too.
512 for (const unsigned *Aliases = getAliasSet(Reg); *Aliases; ++Aliases) {
513 if (MF.getRegInfo().isPhysRegUsed(*Aliases)) {
515 CanEliminateFrame = false;
520 if (CSRegClasses[i] == &ARM::GPRRegClass) {
524 if (!STI.isTargetDarwin()) {
531 // Keep track if LR and any of R4, R5, R6, and R7 is spilled.
546 if (!STI.isTargetDarwin()) {
547 UnspilledCS1GPRs.push_back(Reg);
557 UnspilledCS1GPRs.push_back(Reg);
560 UnspilledCS2GPRs.push_back(Reg);
567 bool ForceLRSpill = false;
568 if (!LRSpilled && AFI->isThumb1OnlyFunction()) {
569 unsigned FnSize = TII.GetFunctionSizeInBytes(MF);
570 // Force LR to be spilled if the Thumb function size is > 2048. This enables
571 // use of BL to implement far jump. If it turns out that it's not needed
572 // then the branch fix up path will undo it.
573 if (FnSize >= (1 << 11)) {
574 CanEliminateFrame = false;
579 bool ExtraCSSpill = false;
580 if (!CanEliminateFrame || hasFP(MF)) {
581 AFI->setHasStackFrame(true);
583 // If LR is not spilled, but at least one of R4, R5, R6, and R7 is spilled.
584 // Spill LR as well so we can fold BX_RET to the registers restore (LDM).
585 if (!LRSpilled && CS1Spilled) {
586 MF.getRegInfo().setPhysRegUsed(ARM::LR);
587 AFI->setCSRegisterIsSpilled(ARM::LR);
589 UnspilledCS1GPRs.erase(std::find(UnspilledCS1GPRs.begin(),
590 UnspilledCS1GPRs.end(), (unsigned)ARM::LR));
591 ForceLRSpill = false;
595 // Darwin ABI requires FP to point to the stack slot that contains the
597 if (STI.isTargetDarwin() || hasFP(MF)) {
598 MF.getRegInfo().setPhysRegUsed(FramePtr);
602 // If stack and double are 8-byte aligned and we are spilling an odd number
603 // of GPRs. Spill one extra callee save GPR so we won't have to pad between
604 // the integer and double callee save areas.
605 unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment();
606 if (TargetAlign == 8 && (NumGPRSpills & 1)) {
607 if (CS1Spilled && !UnspilledCS1GPRs.empty()) {
608 for (unsigned i = 0, e = UnspilledCS1GPRs.size(); i != e; ++i) {
609 unsigned Reg = UnspilledCS1GPRs[i];
610 // Don't spill high register if the function is thumb1
611 if (!AFI->isThumb1OnlyFunction() ||
612 isARMLowRegister(Reg) || Reg == ARM::LR) {
613 MF.getRegInfo().setPhysRegUsed(Reg);
614 AFI->setCSRegisterIsSpilled(Reg);
615 if (!isReservedReg(MF, Reg))
620 } else if (!UnspilledCS2GPRs.empty() &&
621 !AFI->isThumb1OnlyFunction()) {
622 unsigned Reg = UnspilledCS2GPRs.front();
623 MF.getRegInfo().setPhysRegUsed(Reg);
624 AFI->setCSRegisterIsSpilled(Reg);
625 if (!isReservedReg(MF, Reg))
630 // Estimate if we might need to scavenge a register at some point in order
631 // to materialize a stack offset. If so, either spill one additional
632 // callee-saved register or reserve a special spill slot to facilitate
633 // register scavenging.
634 if (RS && !ExtraCSSpill && !AFI->isThumb1OnlyFunction()) {
635 MachineFrameInfo *MFI = MF.getFrameInfo();
636 unsigned Size = estimateStackSize(MF, MFI);
637 unsigned Limit = (1 << 12) - 1;
638 for (MachineFunction::iterator BB = MF.begin(),E = MF.end();BB != E; ++BB)
639 for (MachineBasicBlock::iterator I= BB->begin(); I != BB->end(); ++I) {
640 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
641 if (I->getOperand(i).isFI()) {
642 unsigned Opcode = I->getOpcode();
643 const TargetInstrDesc &Desc = TII.get(Opcode);
644 unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask);
645 if (AddrMode == ARMII::AddrMode3) {
646 Limit = (1 << 8) - 1;
648 } else if (AddrMode == ARMII::AddrMode5) {
649 unsigned ThisLimit = ((1 << 8) - 1) * 4;
650 if (ThisLimit < Limit)
657 // If any non-reserved CS register isn't spilled, just spill one or two
658 // extra. That should take care of it!
659 unsigned NumExtras = TargetAlign / 4;
660 SmallVector<unsigned, 2> Extras;
661 while (NumExtras && !UnspilledCS1GPRs.empty()) {
662 unsigned Reg = UnspilledCS1GPRs.back();
663 UnspilledCS1GPRs.pop_back();
664 if (!isReservedReg(MF, Reg)) {
665 Extras.push_back(Reg);
669 while (NumExtras && !UnspilledCS2GPRs.empty()) {
670 unsigned Reg = UnspilledCS2GPRs.back();
671 UnspilledCS2GPRs.pop_back();
672 if (!isReservedReg(MF, Reg)) {
673 Extras.push_back(Reg);
677 if (Extras.size() && NumExtras == 0) {
678 for (unsigned i = 0, e = Extras.size(); i != e; ++i) {
679 MF.getRegInfo().setPhysRegUsed(Extras[i]);
680 AFI->setCSRegisterIsSpilled(Extras[i]);
683 // Reserve a slot closest to SP or frame pointer.
684 const TargetRegisterClass *RC = &ARM::GPRRegClass;
685 RS->setScavengingFrameIndex(MFI->CreateStackObject(RC->getSize(),
686 RC->getAlignment()));
693 MF.getRegInfo().setPhysRegUsed(ARM::LR);
694 AFI->setCSRegisterIsSpilled(ARM::LR);
695 AFI->setLRIsSpilledForFarJump(true);
699 unsigned ARMBaseRegisterInfo::getRARegister() const {
703 unsigned ARMBaseRegisterInfo::getFrameRegister(MachineFunction &MF) const {
704 if (STI.isTargetDarwin() || hasFP(MF))
709 unsigned ARMBaseRegisterInfo::getEHExceptionRegister() const {
710 LLVM_UNREACHABLE("What is the exception register");
714 unsigned ARMBaseRegisterInfo::getEHHandlerRegister() const {
715 LLVM_UNREACHABLE("What is the exception handler register");
719 int ARMBaseRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
720 return ARMGenRegisterInfo::getDwarfRegNumFull(RegNum, 0);
723 unsigned ARMBaseRegisterInfo::getRegisterPairEven(unsigned Reg,
724 const MachineFunction &MF) const {
727 // Return 0 if either register of the pair is a special register.
733 return STI.isThumb1Only() ? 0 : ARM::R2;
737 return isReservedReg(MF, ARM::R7) ? 0 : ARM::R6;
739 return isReservedReg(MF, ARM::R9) ? 0 :ARM::R8;
741 return isReservedReg(MF, ARM::R11) ? 0 : ARM::R10;
797 unsigned ARMBaseRegisterInfo::getRegisterPairOdd(unsigned Reg,
798 const MachineFunction &MF) const {
801 // Return 0 if either register of the pair is a special register.
807 return STI.isThumb1Only() ? 0 : ARM::R3;
811 return isReservedReg(MF, ARM::R7) ? 0 : ARM::R7;
813 return isReservedReg(MF, ARM::R9) ? 0 :ARM::R9;
815 return isReservedReg(MF, ARM::R11) ? 0 : ARM::R11;
871 // FIXME: Dup in ARMBaseInstrInfo.cpp
873 const MachineInstrBuilder &AddDefaultPred(const MachineInstrBuilder &MIB) {
874 return MIB.addImm((int64_t)ARMCC::AL).addReg(0);
878 const MachineInstrBuilder &AddDefaultCC(const MachineInstrBuilder &MIB) {
879 return MIB.addReg(0);
882 /// emitLoadConstPool - Emits a load from constpool to materialize the
883 /// specified immediate.
884 void ARMBaseRegisterInfo::
885 emitLoadConstPool(MachineBasicBlock &MBB,
886 MachineBasicBlock::iterator &MBBI,
888 unsigned DestReg, int Val,
889 ARMCC::CondCodes Pred,
890 unsigned PredReg) const {
891 MachineFunction &MF = *MBB.getParent();
892 MachineConstantPool *ConstantPool = MF.getConstantPool();
893 Constant *C = ConstantInt::get(Type::Int32Ty, Val);
894 unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4);
896 BuildMI(MBB, MBBI, dl, TII.get(ARM::LDRcp), DestReg)
897 .addConstantPoolIndex(Idx)
898 .addReg(0).addImm(0).addImm(Pred).addReg(PredReg);
901 bool ARMBaseRegisterInfo::
902 requiresRegisterScavenging(const MachineFunction &MF) const {
906 // hasReservedCallFrame - Under normal circumstances, when a frame pointer is
907 // not required, we reserve argument space for call sites in the function
908 // immediately on entry to the current function. This eliminates the need for
909 // add/sub sp brackets around call sites. Returns true if the call frame is
910 // included as part of the stack frame.
911 bool ARMBaseRegisterInfo::
912 hasReservedCallFrame(MachineFunction &MF) const {
913 const MachineFrameInfo *FFI = MF.getFrameInfo();
914 unsigned CFSize = FFI->getMaxCallFrameSize();
915 // It's not always a good idea to include the call frame as part of the
916 // stack frame. ARM (especially Thumb) has small immediate offset to
917 // address the stack frame. So a large call frame can cause poor codegen
918 // and may even makes it impossible to scavenge a register.
919 if (CFSize >= ((1 << 12) - 1) / 2) // Half of imm12
922 return !MF.getFrameInfo()->hasVarSizedObjects();
925 /// emitARMRegPlusImmediate - Emits a series of instructions to materialize
926 /// a destreg = basereg + immediate in ARM code.
928 void emitARMRegPlusImmediate(MachineBasicBlock &MBB,
929 MachineBasicBlock::iterator &MBBI,
930 unsigned DestReg, unsigned BaseReg, int NumBytes,
931 ARMCC::CondCodes Pred, unsigned PredReg,
932 const ARMBaseInstrInfo &TII,
934 bool isSub = NumBytes < 0;
935 if (isSub) NumBytes = -NumBytes;
938 unsigned RotAmt = ARM_AM::getSOImmValRotate(NumBytes);
939 unsigned ThisVal = NumBytes & ARM_AM::rotr32(0xFF, RotAmt);
940 assert(ThisVal && "Didn't extract field correctly");
942 // We will handle these bits from offset, clear them.
943 NumBytes &= ~ThisVal;
945 assert(ARM_AM::getSOImmVal(ThisVal) != -1 && "Bit extraction didn't work?");
947 // Build the new ADD / SUB.
948 BuildMI(MBB, MBBI, dl, TII.get(TII.getOpcode(isSub ? ARMII::SUBri : ARMII::ADDri)), DestReg)
949 .addReg(BaseReg, RegState::Kill).addImm(ThisVal)
950 .addImm((unsigned)Pred).addReg(PredReg).addReg(0);
956 emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
957 const ARMBaseInstrInfo &TII, DebugLoc dl,
959 ARMCC::CondCodes Pred = ARMCC::AL, unsigned PredReg = 0) {
960 emitARMRegPlusImmediate(MBB, MBBI, ARM::SP, ARM::SP, NumBytes,
961 Pred, PredReg, TII, dl);
964 void ARMBaseRegisterInfo::
965 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
966 MachineBasicBlock::iterator I) const {
967 if (!hasReservedCallFrame(MF)) {
968 // If we have alloca, convert as follows:
969 // ADJCALLSTACKDOWN -> sub, sp, sp, amount
970 // ADJCALLSTACKUP -> add, sp, sp, amount
971 MachineInstr *Old = I;
972 DebugLoc dl = Old->getDebugLoc();
973 unsigned Amount = Old->getOperand(0).getImm();
975 // We need to keep the stack aligned properly. To do this, we round the
976 // amount of space needed for the outgoing arguments up to the next
977 // alignment boundary.
978 unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
979 Amount = (Amount+Align-1)/Align*Align;
981 // Replace the pseudo instruction with a new instruction...
982 unsigned Opc = Old->getOpcode();
983 ARMCC::CondCodes Pred = (ARMCC::CondCodes)Old->getOperand(1).getImm();
984 if (Opc == ARM::ADJCALLSTACKDOWN || Opc == ARM::tADJCALLSTACKDOWN) {
985 // Note: PredReg is operand 2 for ADJCALLSTACKDOWN.
986 unsigned PredReg = Old->getOperand(2).getReg();
987 emitSPUpdate(MBB, I, TII, dl, -Amount, Pred, PredReg);
989 // Note: PredReg is operand 3 for ADJCALLSTACKUP.
990 unsigned PredReg = Old->getOperand(3).getReg();
991 assert(Opc == ARM::ADJCALLSTACKUP || Opc == ARM::tADJCALLSTACKUP);
992 emitSPUpdate(MBB, I, TII, dl, Amount, Pred, PredReg);
999 /// findScratchRegister - Find a 'free' ARM register. If register scavenger
1000 /// is not being used, R12 is available. Otherwise, try for a call-clobbered
1001 /// register first and then a spilled callee-saved register if that fails.
1003 unsigned findScratchRegister(RegScavenger *RS, const TargetRegisterClass *RC,
1004 ARMFunctionInfo *AFI) {
1005 unsigned Reg = RS ? RS->FindUnusedReg(RC, true) : (unsigned) ARM::R12;
1006 assert (!AFI->isThumb1OnlyFunction());
1008 // Try a already spilled CS register.
1009 Reg = RS->FindUnusedReg(RC, AFI->getSpilledCSRegisters());
1014 void ARMBaseRegisterInfo::
1015 eliminateFrameIndex(MachineBasicBlock::iterator II,
1016 int SPAdj, RegScavenger *RS) const{
1018 MachineInstr &MI = *II;
1019 MachineBasicBlock &MBB = *MI.getParent();
1020 MachineFunction &MF = *MBB.getParent();
1021 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1022 DebugLoc dl = MI.getDebugLoc();
1024 while (!MI.getOperand(i).isFI()) {
1026 assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
1029 unsigned FrameReg = ARM::SP;
1030 int FrameIndex = MI.getOperand(i).getIndex();
1031 int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
1032 MF.getFrameInfo()->getStackSize() + SPAdj;
1034 if (AFI->isGPRCalleeSavedArea1Frame(FrameIndex))
1035 Offset -= AFI->getGPRCalleeSavedArea1Offset();
1036 else if (AFI->isGPRCalleeSavedArea2Frame(FrameIndex))
1037 Offset -= AFI->getGPRCalleeSavedArea2Offset();
1038 else if (AFI->isDPRCalleeSavedAreaFrame(FrameIndex))
1039 Offset -= AFI->getDPRCalleeSavedAreaOffset();
1040 else if (hasFP(MF)) {
1041 assert(SPAdj == 0 && "Unexpected");
1042 // There is alloca()'s in this function, must reference off the frame
1044 FrameReg = getFrameRegister(MF);
1045 Offset -= AFI->getFramePtrSpillOffset();
1048 unsigned Opcode = MI.getOpcode();
1049 const TargetInstrDesc &Desc = MI.getDesc();
1050 unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask);
1053 // Memory operands in inline assembly always use AddrMode2.
1054 if (Opcode == ARM::INLINEASM)
1055 AddrMode = ARMII::AddrMode2;
1057 if (Opcode == getOpcode(ARMII::ADDri)) {
1058 Offset += MI.getOperand(i+1).getImm();
1060 // Turn it into a move.
1061 MI.setDesc(TII.get(getOpcode(ARMII::MOVr)));
1062 MI.getOperand(i).ChangeToRegister(FrameReg, false);
1063 MI.RemoveOperand(i+1);
1065 } else if (Offset < 0) {
1068 MI.setDesc(TII.get(getOpcode(ARMII::SUBri)));
1071 // Common case: small offset, fits into instruction.
1072 if (ARM_AM::getSOImmVal(Offset) != -1) {
1073 // Replace the FrameIndex with sp / fp
1074 MI.getOperand(i).ChangeToRegister(FrameReg, false);
1075 MI.getOperand(i+1).ChangeToImmediate(Offset);
1079 // Otherwise, we fallback to common code below to form the imm offset with
1080 // a sequence of ADDri instructions. First though, pull as much of the imm
1081 // into this ADDri as possible.
1082 unsigned RotAmt = ARM_AM::getSOImmValRotate(Offset);
1083 unsigned ThisImmVal = Offset & ARM_AM::rotr32(0xFF, RotAmt);
1085 // We will handle these bits from offset, clear them.
1086 Offset &= ~ThisImmVal;
1088 // Get the properly encoded SOImmVal field.
1089 assert(ARM_AM::getSOImmVal(ThisImmVal) != -1 &&
1090 "Bit extraction didn't work?");
1091 MI.getOperand(i+1).ChangeToImmediate(ThisImmVal);
1093 unsigned ImmIdx = 0;
1095 unsigned NumBits = 0;
1098 case ARMII::AddrMode2: {
1100 InstrOffs = ARM_AM::getAM2Offset(MI.getOperand(ImmIdx).getImm());
1101 if (ARM_AM::getAM2Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub)
1106 case ARMII::AddrMode3: {
1108 InstrOffs = ARM_AM::getAM3Offset(MI.getOperand(ImmIdx).getImm());
1109 if (ARM_AM::getAM3Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub)
1114 case ARMII::AddrMode5: {
1116 InstrOffs = ARM_AM::getAM5Offset(MI.getOperand(ImmIdx).getImm());
1117 if (ARM_AM::getAM5Op(MI.getOperand(ImmIdx).getImm()) == ARM_AM::sub)
1123 case ARMII::AddrModeT2_i12: {
1125 InstrOffs = MI.getOperand(ImmIdx).getImm();
1129 case ARMII::AddrModeT2_so:
1130 case ARMII::AddrModeT2_i8: {
1132 InstrOffs = MI.getOperand(ImmIdx).getImm();
1137 LLVM_UNREACHABLE("Unsupported addressing mode!");
1141 Offset += InstrOffs * Scale;
1142 assert((Offset & (Scale-1)) == 0 && "Can't encode this offset!");
1148 // Common case: small offset, fits into instruction.
1149 MachineOperand &ImmOp = MI.getOperand(ImmIdx);
1150 int ImmedOffset = Offset / Scale;
1151 unsigned Mask = (1 << NumBits) - 1;
1152 if ((unsigned)Offset <= Mask * Scale) {
1153 // Replace the FrameIndex with sp
1154 MI.getOperand(i).ChangeToRegister(FrameReg, false);
1156 ImmedOffset |= 1 << NumBits;
1157 ImmOp.ChangeToImmediate(ImmedOffset);
1161 // Otherwise, it didn't fit. Pull in what we can to simplify the immed.
1162 ImmedOffset = ImmedOffset & Mask;
1164 ImmedOffset |= 1 << NumBits;
1165 ImmOp.ChangeToImmediate(ImmedOffset);
1166 Offset &= ~(Mask*Scale);
1169 // If we get here, the immediate doesn't fit into the instruction. We folded
1170 // as much as possible above, handle the rest, providing a register that is
1172 assert(Offset && "This code isn't needed if offset already handled!");
1174 // Insert a set of r12 with the full address: r12 = sp + offset
1175 // If the offset we have is too large to fit into the instruction, we need
1176 // to form it with a series of ADDri's. Do this by taking 8-bit chunks
1178 unsigned ScratchReg = findScratchRegister(RS, &ARM::GPRRegClass, AFI);
1179 if (ScratchReg == 0)
1180 // No register is "free". Scavenge a register.
1181 ScratchReg = RS->scavengeRegister(&ARM::GPRRegClass, II, SPAdj);
1182 int PIdx = MI.findFirstPredOperandIdx();
1183 ARMCC::CondCodes Pred = (PIdx == -1)
1184 ? ARMCC::AL : (ARMCC::CondCodes)MI.getOperand(PIdx).getImm();
1185 unsigned PredReg = (PIdx == -1) ? 0 : MI.getOperand(PIdx+1).getReg();
1186 emitARMRegPlusImmediate(MBB, II, ScratchReg, FrameReg,
1187 isSub ? -Offset : Offset, Pred, PredReg, TII, dl);
1188 MI.getOperand(i).ChangeToRegister(ScratchReg, false, false, true);
1191 /// Move iterator pass the next bunch of callee save load / store ops for
1192 /// the particular spill area (1: integer area 1, 2: integer area 2,
1193 /// 3: fp area, 0: don't care).
1194 static void movePastCSLoadStoreOps(MachineBasicBlock &MBB,
1195 MachineBasicBlock::iterator &MBBI,
1196 int Opc, unsigned Area,
1197 const ARMSubtarget &STI) {
1198 while (MBBI != MBB.end() &&
1199 MBBI->getOpcode() == Opc && 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 unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
1234 unsigned NumBytes = MFI->getStackSize();
1235 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
1236 DebugLoc dl = (MBBI != MBB.end() ?
1237 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
1239 // Determine the sizes of each callee-save spill areas and record which frame
1240 // belongs to which callee-save spill areas.
1241 unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0;
1242 int FramePtrSpillFI = 0;
1245 emitSPUpdate(MBB, MBBI, TII, dl, -VARegSaveSize);
1247 if (!AFI->hasStackFrame()) {
1249 emitSPUpdate(MBB, MBBI, TII, dl, -NumBytes);
1253 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
1254 unsigned Reg = CSI[i].getReg();
1255 int FI = CSI[i].getFrameIdx();
1262 if (Reg == FramePtr)
1263 FramePtrSpillFI = FI;
1264 AFI->addGPRCalleeSavedArea1Frame(FI);
1271 if (Reg == FramePtr)
1272 FramePtrSpillFI = FI;
1273 if (STI.isTargetDarwin()) {
1274 AFI->addGPRCalleeSavedArea2Frame(FI);
1277 AFI->addGPRCalleeSavedArea1Frame(FI);
1282 AFI->addDPRCalleeSavedAreaFrame(FI);
1287 // Build the new SUBri to adjust SP for integer callee-save spill area 1.
1288 emitSPUpdate(MBB, MBBI, TII, dl, -GPRCS1Size);
1289 movePastCSLoadStoreOps(MBB, MBBI, getOpcode(ARMII::STR), 1, STI);
1291 // Darwin ABI requires FP to point to the stack slot that contains the
1293 if (STI.isTargetDarwin() || hasFP(MF)) {
1294 MachineInstrBuilder MIB =
1295 BuildMI(MBB, MBBI, dl, TII.get(getOpcode(ARMII::ADDri)), FramePtr)
1296 .addFrameIndex(FramePtrSpillFI).addImm(0);
1297 AddDefaultCC(AddDefaultPred(MIB));
1300 // Build the new SUBri to adjust SP for integer callee-save spill area 2.
1301 emitSPUpdate(MBB, MBBI, TII, dl, -GPRCS2Size);
1303 // Build the new SUBri to adjust SP for FP callee-save spill area.
1304 movePastCSLoadStoreOps(MBB, MBBI, getOpcode(ARMII::STR), 2, STI);
1305 emitSPUpdate(MBB, MBBI, TII, dl, -DPRCSSize);
1307 // Determine starting offsets of spill areas.
1308 unsigned DPRCSOffset = NumBytes - (GPRCS1Size + GPRCS2Size + DPRCSSize);
1309 unsigned GPRCS2Offset = DPRCSOffset + DPRCSSize;
1310 unsigned GPRCS1Offset = GPRCS2Offset + GPRCS2Size;
1311 AFI->setFramePtrSpillOffset(MFI->getObjectOffset(FramePtrSpillFI) + NumBytes);
1312 AFI->setGPRCalleeSavedArea1Offset(GPRCS1Offset);
1313 AFI->setGPRCalleeSavedArea2Offset(GPRCS2Offset);
1314 AFI->setDPRCalleeSavedAreaOffset(DPRCSOffset);
1316 NumBytes = DPRCSOffset;
1318 // Insert it after all the callee-save spills.
1319 movePastCSLoadStoreOps(MBB, MBBI, getOpcode(ARMII::FSTD), 3, STI);
1320 emitSPUpdate(MBB, MBBI, TII, dl, -NumBytes);
1323 if (STI.isTargetELF() && hasFP(MF)) {
1324 MFI->setOffsetAdjustment(MFI->getOffsetAdjustment() -
1325 AFI->getFramePtrSpillOffset());
1328 AFI->setGPRCalleeSavedArea1Size(GPRCS1Size);
1329 AFI->setGPRCalleeSavedArea2Size(GPRCS2Size);
1330 AFI->setDPRCalleeSavedAreaSize(DPRCSSize);
1333 static bool isCalleeSavedRegister(unsigned Reg, const unsigned *CSRegs) {
1334 for (unsigned i = 0; CSRegs[i]; ++i)
1335 if (Reg == CSRegs[i])
1340 static bool isCSRestore(MachineInstr *MI,
1341 const ARMBaseInstrInfo &TII,
1342 const unsigned *CSRegs) {
1343 return ((MI->getOpcode() == (int)TII.getOpcode(ARMII::FLDD) ||
1344 MI->getOpcode() == (int)TII.getOpcode(ARMII::LDR)) &&
1345 MI->getOperand(1).isFI() &&
1346 isCalleeSavedRegister(MI->getOperand(0).getReg(), CSRegs));
1349 void ARMBaseRegisterInfo::
1350 emitEpilogue(MachineFunction &MF,
1351 MachineBasicBlock &MBB) const {
1352 MachineBasicBlock::iterator MBBI = prior(MBB.end());
1353 assert(MBBI->getOpcode() == (int)getOpcode(ARMII::BX_RET) &&
1354 "Can only insert epilog into returning blocks");
1355 DebugLoc dl = MBBI->getDebugLoc();
1356 MachineFrameInfo *MFI = MF.getFrameInfo();
1357 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
1358 unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
1359 int NumBytes = (int)MFI->getStackSize();
1361 if (!AFI->hasStackFrame()) {
1363 emitSPUpdate(MBB, MBBI, TII, dl, NumBytes);
1365 // Unwind MBBI to point to first LDR / FLDD.
1366 const unsigned *CSRegs = getCalleeSavedRegs();
1367 if (MBBI != MBB.begin()) {
1370 while (MBBI != MBB.begin() && isCSRestore(MBBI, TII, CSRegs));
1371 if (!isCSRestore(MBBI, TII, CSRegs))
1375 // Move SP to start of FP callee save spill area.
1376 NumBytes -= (AFI->getGPRCalleeSavedArea1Size() +
1377 AFI->getGPRCalleeSavedArea2Size() +
1378 AFI->getDPRCalleeSavedAreaSize());
1380 // Darwin ABI requires FP to point to the stack slot that contains the
1382 if ((STI.isTargetDarwin() && NumBytes) || hasFP(MF)) {
1383 NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
1384 // Reset SP based on frame pointer only if the stack frame extends beyond
1385 // frame pointer stack slot or target is ELF and the function has FP.
1386 if (AFI->getGPRCalleeSavedArea2Size() ||
1387 AFI->getDPRCalleeSavedAreaSize() ||
1388 AFI->getDPRCalleeSavedAreaOffset()||
1391 BuildMI(MBB, MBBI, dl, TII.get(getOpcode(ARMII::SUBri)), ARM::SP).addReg(FramePtr)
1393 .addImm((unsigned)ARMCC::AL).addReg(0).addReg(0);
1395 BuildMI(MBB, MBBI, dl, TII.get(getOpcode(ARMII::MOVr)), ARM::SP).addReg(FramePtr)
1396 .addImm((unsigned)ARMCC::AL).addReg(0).addReg(0);
1398 } else if (NumBytes) {
1399 emitSPUpdate(MBB, MBBI, TII, dl, NumBytes);
1402 // Move SP to start of integer callee save spill area 2.
1403 movePastCSLoadStoreOps(MBB, MBBI, getOpcode(ARMII::FLDD), 3, STI);
1404 emitSPUpdate(MBB, MBBI, TII, dl, AFI->getDPRCalleeSavedAreaSize());
1406 // Move SP to start of integer callee save spill area 1.
1407 movePastCSLoadStoreOps(MBB, MBBI, getOpcode(ARMII::LDR), 2, STI);
1408 emitSPUpdate(MBB, MBBI, TII, dl, AFI->getGPRCalleeSavedArea2Size());
1410 // Move SP to SP upon entry to the function.
1411 movePastCSLoadStoreOps(MBB, MBBI, getOpcode(ARMII::LDR), 1, STI);
1412 emitSPUpdate(MBB, MBBI, TII, dl, AFI->getGPRCalleeSavedArea1Size());
1416 emitSPUpdate(MBB, MBBI, TII, dl, VARegSaveSize);
1420 #include "ARMGenRegisterInfo.inc"