1//===-- ARMFrameLowering.cpp - ARM Frame Information ----------------------===// 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//===----------------------------------------------------------------------===// --- 552 unchanged lines hidden (view full) --- 561 562 // If the frame has variable sized objects then the epilogue must restore 563 // the sp from fp. We can assume there's an FP here since hasFP already 564 // checks for hasVarSizedObjects. 565 if (MFI->hasVarSizedObjects()) 566 AFI->setShouldRestoreSPFromFP(true); 567} 568 |
569// Resolve TCReturn pseudo-instruction 570void ARMFrameLowering::fixTCReturn(MachineFunction &MF, 571 MachineBasicBlock &MBB) const { 572 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr(); 573 assert(MBBI->isReturn() && "Can only insert epilog into returning blocks"); 574 unsigned RetOpcode = MBBI->getOpcode(); 575 DebugLoc dl = MBBI->getDebugLoc(); 576 const ARMBaseInstrInfo &TII = 577 *MF.getTarget().getSubtarget<ARMSubtarget>().getInstrInfo(); 578 579 if (!(RetOpcode == ARM::TCRETURNdi || RetOpcode == ARM::TCRETURNri)) 580 return; 581 582 // Tail call return: adjust the stack pointer and jump to callee. 583 MBBI = MBB.getLastNonDebugInstr(); 584 MachineOperand &JumpTarget = MBBI->getOperand(0); 585 586 // Jump to label or value in register. 587 if (RetOpcode == ARM::TCRETURNdi) { 588 unsigned TCOpcode = STI.isThumb() ? 589 (STI.isTargetMachO() ? ARM::tTAILJMPd : ARM::tTAILJMPdND) : 590 ARM::TAILJMPd; 591 MachineInstrBuilder MIB = BuildMI(MBB, MBBI, dl, TII.get(TCOpcode)); 592 if (JumpTarget.isGlobal()) 593 MIB.addGlobalAddress(JumpTarget.getGlobal(), JumpTarget.getOffset(), 594 JumpTarget.getTargetFlags()); 595 else { 596 assert(JumpTarget.isSymbol()); 597 MIB.addExternalSymbol(JumpTarget.getSymbolName(), 598 JumpTarget.getTargetFlags()); 599 } 600 601 // Add the default predicate in Thumb mode. 602 if (STI.isThumb()) MIB.addImm(ARMCC::AL).addReg(0); 603 } else if (RetOpcode == ARM::TCRETURNri) { 604 BuildMI(MBB, MBBI, dl, 605 TII.get(STI.isThumb() ? ARM::tTAILJMPr : ARM::TAILJMPr)). 606 addReg(JumpTarget.getReg(), RegState::Kill); 607 } 608 609 MachineInstr *NewMI = std::prev(MBBI); 610 for (unsigned i = 1, e = MBBI->getNumOperands(); i != e; ++i) 611 NewMI->addOperand(MBBI->getOperand(i)); 612 613 // Delete the pseudo instruction TCRETURN. 614 MBB.erase(MBBI); 615 MBBI = NewMI; 616} 617 |
618void ARMFrameLowering::emitEpilogue(MachineFunction &MF, 619 MachineBasicBlock &MBB) const { 620 MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr(); 621 assert(MBBI->isReturn() && "Can only insert epilog into returning blocks"); |
622 DebugLoc dl = MBBI->getDebugLoc(); 623 MachineFrameInfo *MFI = MF.getFrameInfo(); 624 ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); 625 const TargetRegisterInfo *RegInfo = MF.getTarget().getRegisterInfo(); 626 const ARMBaseInstrInfo &TII = 627 *static_cast<const ARMBaseInstrInfo*>(MF.getTarget().getInstrInfo()); 628 assert(!AFI->isThumb1OnlyFunction() && 629 "This emitEpilogue does not support Thumb1!"); 630 bool isARM = !AFI->isThumbFunction(); 631 632 unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); 633 unsigned ArgRegsSaveSize = AFI->getArgRegsSaveSize(Align); 634 int NumBytes = (int)MFI->getStackSize(); 635 unsigned FramePtr = RegInfo->getFrameRegister(MF); 636 637 // All calls are tail calls in GHC calling conv, and functions have no 638 // prologue/epilogue. |
639 if (MF.getFunction()->getCallingConv() == CallingConv::GHC) { 640 fixTCReturn(MF, MBB); |
641 return; |
642 } |
643 644 if (!AFI->hasStackFrame()) { 645 if (NumBytes - ArgRegsSaveSize != 0) 646 emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes - ArgRegsSaveSize); 647 } else { 648 // Unwind MBBI to point to first LDR / VLDRD. 649 const MCPhysReg *CSRegs = RegInfo->getCalleeSavedRegs(&MF); 650 if (MBBI != MBB.begin()) { --- 55 unchanged lines hidden (view full) --- 706 // instructions in the epilogue. 707 while (MBBI->getOpcode() == ARM::VLDMDIA_UPD) 708 MBBI++; 709 } 710 if (AFI->getGPRCalleeSavedArea2Size()) MBBI++; 711 if (AFI->getGPRCalleeSavedArea1Size()) MBBI++; 712 } 713 |
714 fixTCReturn(MF, MBB); |
715 |
716 if (ArgRegsSaveSize) 717 emitSPUpdate(isARM, MBB, MBBI, dl, TII, ArgRegsSaveSize); 718} 719 720/// getFrameIndexReference - Provide a base+offset reference to an FI slot for 721/// debug info. It's the same as what we use for resolving the code-gen 722/// references for now. FIXME: This can go wrong when references are 723/// SP-relative and simple call frames aren't used. --- 1331 unchanged lines hidden --- |