2011-01-10 13:39:04 +01:00
|
|
|
//======- Thumb1FrameLowering.cpp - Thumb1 Frame Information ---*- C++ -*-====//
|
2010-11-15 01:06:54 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2011-01-10 13:39:04 +01:00
|
|
|
// This file contains the Thumb1 implementation of TargetFrameLowering class.
|
2010-11-15 01:06:54 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
#include "Thumb1FrameLowering.h"
|
2010-11-15 01:06:54 +01:00
|
|
|
#include "ARMBaseInstrInfo.h"
|
|
|
|
#include "ARMMachineFunctionInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
Fix epilogue codegen to avoid leaving the stack pointer in an invalid
state. Previously Thumb2 would restore sp from fp like this:
mov sp, r7
sub, sp, #4
If an interrupt is taken after the 'mov' but before the 'sub', callee-saved
registers might be clobbered by the interrupt handler. Instead, try
restoring directly from sp:
add sp, #4
Or, if necessary (with VLA, etc.) use a scratch register to compute sp and
then restore it:
sub.w r4, r7, #8
mov sp, r7
rdar://8465407
llvm-svn: 119977
2010-11-22 19:12:04 +01:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2010-11-15 01:06:54 +01:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
bool Thumb1FrameLowering::hasReservedCallFrame(const MachineFunction &MF) const {
|
2010-11-18 22:19:35 +01:00
|
|
|
const MachineFrameInfo *FFI = MF.getFrameInfo();
|
|
|
|
unsigned CFSize = FFI->getMaxCallFrameSize();
|
|
|
|
// It's not always a good idea to include the call frame as part of the
|
|
|
|
// stack frame. ARM (especially Thumb) has small immediate offset to
|
|
|
|
// address the stack frame. So a large call frame can cause poor codegen
|
|
|
|
// and may even makes it impossible to scavenge a register.
|
|
|
|
if (CFSize >= ((1 << 8) - 1) * 4 / 2) // Half of imm8 * 4
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !MF.getFrameInfo()->hasVarSizedObjects();
|
|
|
|
}
|
|
|
|
|
2011-03-05 19:43:50 +01:00
|
|
|
static void
|
|
|
|
emitSPUpdate(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator &MBBI,
|
|
|
|
const TargetInstrInfo &TII, DebugLoc dl,
|
|
|
|
const Thumb1RegisterInfo &MRI,
|
|
|
|
int NumBytes, unsigned MIFlags = MachineInstr::NoFlags) {
|
2011-03-05 19:43:32 +01:00
|
|
|
emitThumbRegPlusImmediate(MBB, MBBI, dl, ARM::SP, ARM::SP, NumBytes, TII,
|
2011-03-05 19:43:50 +01:00
|
|
|
MRI, MIFlags);
|
2010-11-15 01:06:54 +01:00
|
|
|
}
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
void Thumb1FrameLowering::emitPrologue(MachineFunction &MF) const {
|
2010-11-15 01:06:54 +01:00
|
|
|
MachineBasicBlock &MBB = MF.front();
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
|
|
|
const Thumb1RegisterInfo *RegInfo =
|
|
|
|
static_cast<const Thumb1RegisterInfo*>(MF.getTarget().getRegisterInfo());
|
|
|
|
const Thumb1InstrInfo &TII =
|
|
|
|
*static_cast<const Thumb1InstrInfo*>(MF.getTarget().getInstrInfo());
|
|
|
|
|
|
|
|
unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
|
|
|
|
unsigned NumBytes = MFI->getStackSize();
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
|
|
|
|
DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
|
|
|
|
unsigned FramePtr = RegInfo->getFrameRegister(MF);
|
|
|
|
unsigned BasePtr = RegInfo->getBaseRegister();
|
|
|
|
|
|
|
|
// Thumb add/sub sp, imm8 instructions implicitly multiply the offset by 4.
|
|
|
|
NumBytes = (NumBytes + 3) & ~3;
|
|
|
|
MFI->setStackSize(NumBytes);
|
|
|
|
|
|
|
|
// Determine the sizes of each callee-save spill areas and record which frame
|
|
|
|
// belongs to which callee-save spill areas.
|
|
|
|
unsigned GPRCS1Size = 0, GPRCS2Size = 0, DPRCSSize = 0;
|
|
|
|
int FramePtrSpillFI = 0;
|
|
|
|
|
|
|
|
if (VARegSaveSize)
|
2011-03-05 19:43:50 +01:00
|
|
|
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -VARegSaveSize,
|
|
|
|
MachineInstr::FrameSetup);
|
2010-11-15 01:06:54 +01:00
|
|
|
|
|
|
|
if (!AFI->hasStackFrame()) {
|
|
|
|
if (NumBytes != 0)
|
2011-03-05 19:43:50 +01:00
|
|
|
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -NumBytes,
|
|
|
|
MachineInstr::FrameSetup);
|
2010-11-15 01:06:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
|
|
|
|
unsigned Reg = CSI[i].getReg();
|
|
|
|
int FI = CSI[i].getFrameIdx();
|
|
|
|
switch (Reg) {
|
|
|
|
case ARM::R4:
|
|
|
|
case ARM::R5:
|
|
|
|
case ARM::R6:
|
|
|
|
case ARM::R7:
|
|
|
|
case ARM::LR:
|
|
|
|
if (Reg == FramePtr)
|
|
|
|
FramePtrSpillFI = FI;
|
|
|
|
AFI->addGPRCalleeSavedArea1Frame(FI);
|
|
|
|
GPRCS1Size += 4;
|
|
|
|
break;
|
|
|
|
case ARM::R8:
|
|
|
|
case ARM::R9:
|
|
|
|
case ARM::R10:
|
|
|
|
case ARM::R11:
|
|
|
|
if (Reg == FramePtr)
|
|
|
|
FramePtrSpillFI = FI;
|
|
|
|
if (STI.isTargetDarwin()) {
|
|
|
|
AFI->addGPRCalleeSavedArea2Frame(FI);
|
|
|
|
GPRCS2Size += 4;
|
|
|
|
} else {
|
|
|
|
AFI->addGPRCalleeSavedArea1Frame(FI);
|
|
|
|
GPRCS1Size += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AFI->addDPRCalleeSavedAreaFrame(FI);
|
|
|
|
DPRCSSize += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tPUSH) {
|
|
|
|
++MBBI;
|
|
|
|
if (MBBI != MBB.end())
|
|
|
|
dl = MBBI->getDebugLoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine starting offsets of spill areas.
|
|
|
|
unsigned DPRCSOffset = NumBytes - (GPRCS1Size + GPRCS2Size + DPRCSSize);
|
|
|
|
unsigned GPRCS2Offset = DPRCSOffset + DPRCSSize;
|
|
|
|
unsigned GPRCS1Offset = GPRCS2Offset + GPRCS2Size;
|
|
|
|
AFI->setFramePtrSpillOffset(MFI->getObjectOffset(FramePtrSpillFI) + NumBytes);
|
|
|
|
AFI->setGPRCalleeSavedArea1Offset(GPRCS1Offset);
|
|
|
|
AFI->setGPRCalleeSavedArea2Offset(GPRCS2Offset);
|
|
|
|
AFI->setDPRCalleeSavedAreaOffset(DPRCSOffset);
|
|
|
|
NumBytes = DPRCSOffset;
|
Fix epilogue codegen to avoid leaving the stack pointer in an invalid
state. Previously Thumb2 would restore sp from fp like this:
mov sp, r7
sub, sp, #4
If an interrupt is taken after the 'mov' but before the 'sub', callee-saved
registers might be clobbered by the interrupt handler. Instead, try
restoring directly from sp:
add sp, #4
Or, if necessary (with VLA, etc.) use a scratch register to compute sp and
then restore it:
sub.w r4, r7, #8
mov sp, r7
rdar://8465407
llvm-svn: 119977
2010-11-22 19:12:04 +01:00
|
|
|
|
|
|
|
// Adjust FP so it point to the stack slot that contains the previous FP.
|
|
|
|
if (hasFP(MF)) {
|
2011-08-24 19:46:13 +02:00
|
|
|
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tADDrSPi), FramePtr)
|
2011-03-05 19:43:50 +01:00
|
|
|
.addFrameIndex(FramePtrSpillFI).addImm(0)
|
2011-08-24 19:46:13 +02:00
|
|
|
.setMIFlags(MachineInstr::FrameSetup));
|
2011-06-13 23:18:25 +02:00
|
|
|
if (NumBytes > 508)
|
|
|
|
// If offset is > 508 then sp cannot be adjusted in a single instruction,
|
Fix epilogue codegen to avoid leaving the stack pointer in an invalid
state. Previously Thumb2 would restore sp from fp like this:
mov sp, r7
sub, sp, #4
If an interrupt is taken after the 'mov' but before the 'sub', callee-saved
registers might be clobbered by the interrupt handler. Instead, try
restoring directly from sp:
add sp, #4
Or, if necessary (with VLA, etc.) use a scratch register to compute sp and
then restore it:
sub.w r4, r7, #8
mov sp, r7
rdar://8465407
llvm-svn: 119977
2010-11-22 19:12:04 +01:00
|
|
|
// try restoring from fp instead.
|
|
|
|
AFI->setShouldRestoreSPFromFP(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NumBytes)
|
2010-11-15 01:06:54 +01:00
|
|
|
// Insert it after all the callee-save spills.
|
2011-03-05 19:43:50 +01:00
|
|
|
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -NumBytes,
|
|
|
|
MachineInstr::FrameSetup);
|
2010-11-15 01:06:54 +01:00
|
|
|
|
2010-11-18 22:19:35 +01:00
|
|
|
if (STI.isTargetELF() && hasFP(MF))
|
2010-11-15 01:06:54 +01:00
|
|
|
MFI->setOffsetAdjustment(MFI->getOffsetAdjustment() -
|
|
|
|
AFI->getFramePtrSpillOffset());
|
|
|
|
|
|
|
|
AFI->setGPRCalleeSavedArea1Size(GPRCS1Size);
|
|
|
|
AFI->setGPRCalleeSavedArea2Size(GPRCS2Size);
|
|
|
|
AFI->setDPRCalleeSavedAreaSize(DPRCSSize);
|
|
|
|
|
|
|
|
// If we need a base pointer, set it up here. It's whatever the value
|
|
|
|
// of the stack pointer is at this point. Any variable size objects
|
|
|
|
// will be allocated after this, so we can still use the base pointer
|
|
|
|
// to reference locals.
|
|
|
|
if (RegInfo->hasBasePointer(MF))
|
2011-07-01 01:38:17 +02:00
|
|
|
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr), BasePtr)
|
2011-07-01 00:10:46 +02:00
|
|
|
.addReg(ARM::SP));
|
2011-03-05 19:43:50 +01:00
|
|
|
|
2011-01-11 01:16:04 +01:00
|
|
|
// If the frame has variable sized objects then the epilogue must restore
|
|
|
|
// the sp from fp. We can assume there's an FP here since hasFP already
|
|
|
|
// checks for hasVarSizedObjects.
|
|
|
|
if (MFI->hasVarSizedObjects())
|
|
|
|
AFI->setShouldRestoreSPFromFP(true);
|
2010-11-15 01:06:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isCalleeSavedRegister(unsigned Reg, const unsigned *CSRegs) {
|
|
|
|
for (unsigned i = 0; CSRegs[i]; ++i)
|
|
|
|
if (Reg == CSRegs[i])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isCSRestore(MachineInstr *MI, const unsigned *CSRegs) {
|
2011-06-29 22:26:39 +02:00
|
|
|
if (MI->getOpcode() == ARM::tLDRspi &&
|
2010-11-15 01:06:54 +01:00
|
|
|
MI->getOperand(1).isFI() &&
|
|
|
|
isCalleeSavedRegister(MI->getOperand(0).getReg(), CSRegs))
|
|
|
|
return true;
|
|
|
|
else if (MI->getOpcode() == ARM::tPOP) {
|
|
|
|
// The first two operands are predicates. The last two are
|
|
|
|
// imp-def and imp-use of SP. Check everything in between.
|
|
|
|
for (int i = 2, e = MI->getNumOperands() - 2; i != e; ++i)
|
|
|
|
if (!isCalleeSavedRegister(MI->getOperand(i).getReg(), CSRegs))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
void Thumb1FrameLowering::emitEpilogue(MachineFunction &MF,
|
2010-11-15 01:06:54 +01:00
|
|
|
MachineBasicBlock &MBB) const {
|
2011-01-13 22:28:52 +01:00
|
|
|
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
|
2010-11-15 01:06:54 +01:00
|
|
|
assert((MBBI->getOpcode() == ARM::tBX_RET ||
|
|
|
|
MBBI->getOpcode() == ARM::tPOP_RET) &&
|
|
|
|
"Can only insert epilog into returning blocks");
|
|
|
|
DebugLoc dl = MBBI->getDebugLoc();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
|
|
|
const Thumb1RegisterInfo *RegInfo =
|
|
|
|
static_cast<const Thumb1RegisterInfo*>(MF.getTarget().getRegisterInfo());
|
|
|
|
const Thumb1InstrInfo &TII =
|
|
|
|
*static_cast<const Thumb1InstrInfo*>(MF.getTarget().getInstrInfo());
|
|
|
|
|
|
|
|
unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
|
|
|
|
int NumBytes = (int)MFI->getStackSize();
|
|
|
|
const unsigned *CSRegs = RegInfo->getCalleeSavedRegs();
|
|
|
|
unsigned FramePtr = RegInfo->getFrameRegister(MF);
|
|
|
|
|
|
|
|
if (!AFI->hasStackFrame()) {
|
|
|
|
if (NumBytes != 0)
|
|
|
|
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, NumBytes);
|
|
|
|
} else {
|
|
|
|
// Unwind MBBI to point to first LDR / VLDRD.
|
|
|
|
if (MBBI != MBB.begin()) {
|
|
|
|
do
|
|
|
|
--MBBI;
|
|
|
|
while (MBBI != MBB.begin() && isCSRestore(MBBI, CSRegs));
|
|
|
|
if (!isCSRestore(MBBI, CSRegs))
|
|
|
|
++MBBI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move SP to start of FP callee save spill area.
|
|
|
|
NumBytes -= (AFI->getGPRCalleeSavedArea1Size() +
|
|
|
|
AFI->getGPRCalleeSavedArea2Size() +
|
|
|
|
AFI->getDPRCalleeSavedAreaSize());
|
|
|
|
|
|
|
|
if (AFI->shouldRestoreSPFromFP()) {
|
|
|
|
NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
|
|
|
|
// Reset SP based on frame pointer only if the stack frame extends beyond
|
2011-01-11 01:16:04 +01:00
|
|
|
// frame pointer stack slot, the target is ELF and the function has FP, or
|
|
|
|
// the target uses var sized objects.
|
Fix epilogue codegen to avoid leaving the stack pointer in an invalid
state. Previously Thumb2 would restore sp from fp like this:
mov sp, r7
sub, sp, #4
If an interrupt is taken after the 'mov' but before the 'sub', callee-saved
registers might be clobbered by the interrupt handler. Instead, try
restoring directly from sp:
add sp, #4
Or, if necessary (with VLA, etc.) use a scratch register to compute sp and
then restore it:
sub.w r4, r7, #8
mov sp, r7
rdar://8465407
llvm-svn: 119977
2010-11-22 19:12:04 +01:00
|
|
|
if (NumBytes) {
|
|
|
|
assert(MF.getRegInfo().isPhysRegUsed(ARM::R4) &&
|
|
|
|
"No scratch register to restore SP from FP!");
|
2011-03-05 19:43:32 +01:00
|
|
|
emitThumbRegPlusImmediate(MBB, MBBI, dl, ARM::R4, FramePtr, -NumBytes,
|
|
|
|
TII, *RegInfo);
|
2011-07-01 01:38:17 +02:00
|
|
|
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr),
|
2011-07-01 00:10:46 +02:00
|
|
|
ARM::SP)
|
|
|
|
.addReg(ARM::R4));
|
Fix epilogue codegen to avoid leaving the stack pointer in an invalid
state. Previously Thumb2 would restore sp from fp like this:
mov sp, r7
sub, sp, #4
If an interrupt is taken after the 'mov' but before the 'sub', callee-saved
registers might be clobbered by the interrupt handler. Instead, try
restoring directly from sp:
add sp, #4
Or, if necessary (with VLA, etc.) use a scratch register to compute sp and
then restore it:
sub.w r4, r7, #8
mov sp, r7
rdar://8465407
llvm-svn: 119977
2010-11-22 19:12:04 +01:00
|
|
|
} else
|
2011-07-01 01:38:17 +02:00
|
|
|
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr),
|
2011-07-01 00:10:46 +02:00
|
|
|
ARM::SP)
|
|
|
|
.addReg(FramePtr));
|
2010-11-15 01:06:54 +01:00
|
|
|
} else {
|
|
|
|
if (MBBI->getOpcode() == ARM::tBX_RET &&
|
|
|
|
&MBB.front() != MBBI &&
|
|
|
|
prior(MBBI)->getOpcode() == ARM::tPOP) {
|
|
|
|
MachineBasicBlock::iterator PMBBI = prior(MBBI);
|
|
|
|
emitSPUpdate(MBB, PMBBI, TII, dl, *RegInfo, NumBytes);
|
|
|
|
} else
|
|
|
|
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, NumBytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VARegSaveSize) {
|
|
|
|
// Unlike T2 and ARM mode, the T1 pop instruction cannot restore
|
|
|
|
// to LR, and we can't pop the value directly to the PC since
|
|
|
|
// we need to update the SP after popping the value. Therefore, we
|
|
|
|
// pop the old LR into R3 as a temporary.
|
|
|
|
|
|
|
|
// Move back past the callee-saved register restoration
|
|
|
|
while (MBBI != MBB.end() && isCSRestore(MBBI, CSRegs))
|
|
|
|
++MBBI;
|
|
|
|
// Epilogue for vararg functions: pop LR to R3 and branch off it.
|
|
|
|
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tPOP)))
|
|
|
|
.addReg(ARM::R3, RegState::Define);
|
|
|
|
|
|
|
|
emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, VARegSaveSize);
|
|
|
|
|
2011-07-08 23:50:04 +02:00
|
|
|
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tBX_RET_vararg))
|
|
|
|
.addReg(ARM::R3, RegState::Kill));
|
2010-11-15 01:06:54 +01:00
|
|
|
// erase the old tBX_RET instruction
|
|
|
|
MBB.erase(MBBI);
|
|
|
|
}
|
|
|
|
}
|
2010-11-28 00:05:03 +01:00
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
bool Thumb1FrameLowering::
|
2010-11-28 00:05:03 +01:00
|
|
|
spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
|
|
|
if (CSI.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DebugLoc DL;
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
const TargetInstrInfo &TII = *MF.getTarget().getInstrInfo();
|
|
|
|
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, TII.get(ARM::tPUSH));
|
|
|
|
AddDefaultPred(MIB);
|
|
|
|
for (unsigned i = CSI.size(); i != 0; --i) {
|
|
|
|
unsigned Reg = CSI[i-1].getReg();
|
|
|
|
bool isKill = true;
|
|
|
|
|
|
|
|
// Add the callee-saved register as live-in unless it's LR and
|
|
|
|
// @llvm.returnaddress is called. If LR is returned for @llvm.returnaddress
|
|
|
|
// then it's already added to the function and entry block live-in sets.
|
|
|
|
if (Reg == ARM::LR) {
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
if (MF.getFrameInfo()->isReturnAddressTaken() &&
|
|
|
|
MF.getRegInfo().isLiveIn(Reg))
|
|
|
|
isKill = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isKill)
|
|
|
|
MBB.addLiveIn(Reg);
|
|
|
|
|
|
|
|
MIB.addReg(Reg, getKillRegState(isKill));
|
|
|
|
}
|
2011-03-05 19:43:50 +01:00
|
|
|
MIB.setMIFlags(MachineInstr::FrameSetup);
|
2010-11-28 00:05:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
bool Thumb1FrameLowering::
|
2010-11-28 00:05:03 +01:00
|
|
|
restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
|
|
|
if (CSI.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
|
|
|
const TargetInstrInfo &TII = *MF.getTarget().getInstrInfo();
|
|
|
|
|
|
|
|
bool isVarArg = AFI->getVarArgsRegSaveSize() > 0;
|
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, TII.get(ARM::tPOP));
|
|
|
|
AddDefaultPred(MIB);
|
|
|
|
|
|
|
|
bool NumRegs = false;
|
|
|
|
for (unsigned i = CSI.size(); i != 0; --i) {
|
|
|
|
unsigned Reg = CSI[i-1].getReg();
|
|
|
|
if (Reg == ARM::LR) {
|
|
|
|
// Special epilogue for vararg functions. See emitEpilogue
|
|
|
|
if (isVarArg)
|
|
|
|
continue;
|
|
|
|
Reg = ARM::PC;
|
|
|
|
(*MIB).setDesc(TII.get(ARM::tPOP_RET));
|
|
|
|
MI = MBB.erase(MI);
|
|
|
|
}
|
|
|
|
MIB.addReg(Reg, getDefRegState(true));
|
|
|
|
NumRegs = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's illegal to emit pop instruction without operands.
|
|
|
|
if (NumRegs)
|
|
|
|
MBB.insert(MI, &*MIB);
|
|
|
|
else
|
|
|
|
MF.DeleteMachineInstr(MIB);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|