2012-02-18 13:03:15 +01:00
|
|
|
//===-- XCoreFrameLowering.cpp - Frame info for XCore Target --------------===//
|
2008-11-07 11:59:00 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains XCore frame information that doesn't fit anywhere else
|
|
|
|
// cleanly...
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
#include "XCoreFrameLowering.h"
|
2012-03-17 19:46:09 +01:00
|
|
|
#include "XCore.h"
|
2010-11-15 01:06:54 +01:00
|
|
|
#include "XCoreInstrInfo.h"
|
|
|
|
#include "XCoreMachineFunctionInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2010-11-28 00:05:25 +01:00
|
|
|
#include "llvm/CodeGen/RegisterScavenging.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2010-11-15 01:06:54 +01:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2010-11-15 01:06:54 +01:00
|
|
|
|
2008-11-07 11:59:00 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-11-15 01:06:54 +01:00
|
|
|
// helper functions. FIXME: Eliminate.
|
|
|
|
static inline bool isImmUs(unsigned val) {
|
|
|
|
return val <= 11;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isImmU6(unsigned val) {
|
|
|
|
return val < (1 << 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isImmU16(unsigned val) {
|
|
|
|
return val < (1 << 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void loadFromStack(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DstReg, int Offset, DebugLoc dl,
|
|
|
|
const TargetInstrInfo &TII) {
|
|
|
|
assert(Offset%4 == 0 && "Misaligned stack offset");
|
|
|
|
Offset/=4;
|
|
|
|
bool isU6 = isImmU6(Offset);
|
|
|
|
if (!isU6 && !isImmU16(Offset))
|
|
|
|
report_fatal_error("loadFromStack offset too big " + Twine(Offset));
|
|
|
|
int Opcode = isU6 ? XCore::LDWSP_ru6 : XCore::LDWSP_lru6;
|
|
|
|
BuildMI(MBB, I, dl, TII.get(Opcode), DstReg)
|
|
|
|
.addImm(Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void storeToStack(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, int Offset, DebugLoc dl,
|
|
|
|
const TargetInstrInfo &TII) {
|
|
|
|
assert(Offset%4 == 0 && "Misaligned stack offset");
|
|
|
|
Offset/=4;
|
|
|
|
bool isU6 = isImmU6(Offset);
|
|
|
|
if (!isU6 && !isImmU16(Offset))
|
|
|
|
report_fatal_error("storeToStack offset too big " + Twine(Offset));
|
|
|
|
int Opcode = isU6 ? XCore::STWSP_ru6 : XCore::STWSP_lru6;
|
|
|
|
BuildMI(MBB, I, dl, TII.get(Opcode))
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addImm(Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-07 11:59:00 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2011-01-10 13:39:04 +01:00
|
|
|
// XCoreFrameLowering:
|
2008-11-07 11:59:00 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
XCoreFrameLowering::XCoreFrameLowering(const XCoreSubtarget &sti)
|
2012-06-06 21:47:08 +02:00
|
|
|
: TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 4, 0) {
|
2008-11-07 11:59:00 +01:00
|
|
|
// Do nothing
|
|
|
|
}
|
2010-11-15 01:06:54 +01:00
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
bool XCoreFrameLowering::hasFP(const MachineFunction &MF) const {
|
2011-12-02 23:16:29 +01:00
|
|
|
return MF.getTarget().Options.DisableFramePointerElim(MF) ||
|
|
|
|
MF.getFrameInfo()->hasVarSizedObjects();
|
2010-11-18 22:19:35 +01:00
|
|
|
}
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
void XCoreFrameLowering::emitPrologue(MachineFunction &MF) const {
|
2010-11-15 01:06:54 +01:00
|
|
|
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
MachineModuleInfo *MMI = &MF.getMMI();
|
|
|
|
const XCoreInstrInfo &TII =
|
|
|
|
*static_cast<const XCoreInstrInfo*>(MF.getTarget().getInstrInfo());
|
|
|
|
XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
|
|
|
|
DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
|
|
|
|
|
2010-11-18 22:19:35 +01:00
|
|
|
bool FP = hasFP(MF);
|
2012-12-08 00:16:57 +01:00
|
|
|
const AttributeSet &PAL = MF.getFunction()->getAttributes();
|
2011-02-02 15:57:41 +01:00
|
|
|
|
2012-12-31 01:49:59 +01:00
|
|
|
if (PAL.hasAttrSomewhere(Attribute::Nest))
|
|
|
|
loadFromStack(MBB, MBBI, XCore::R11, 0, dl, TII);
|
2010-11-15 01:06:54 +01:00
|
|
|
|
|
|
|
// Work out frame sizes.
|
|
|
|
int FrameSize = MFI->getStackSize();
|
|
|
|
assert(FrameSize%4 == 0 && "Misaligned frame size");
|
|
|
|
FrameSize/=4;
|
|
|
|
|
|
|
|
bool isU6 = isImmU6(FrameSize);
|
|
|
|
|
|
|
|
if (!isU6 && !isImmU16(FrameSize)) {
|
|
|
|
// FIXME could emit multiple instructions.
|
|
|
|
report_fatal_error("emitPrologue Frame size too big: " + Twine(FrameSize));
|
|
|
|
}
|
2012-02-24 12:49:08 +01:00
|
|
|
bool emitFrameMoves = XCoreRegisterInfo::needsFrameMoves(MF);
|
2010-11-15 01:06:54 +01:00
|
|
|
|
2013-05-09 18:43:42 +02:00
|
|
|
bool saveLR = XFI->getUsesLR();
|
2010-11-15 01:06:54 +01:00
|
|
|
// Do we need to allocate space on the stack?
|
|
|
|
if (FrameSize) {
|
|
|
|
int Opcode;
|
|
|
|
if (saveLR && (MFI->getObjectOffset(XFI->getLRSpillSlot()) == 0)) {
|
|
|
|
Opcode = (isU6) ? XCore::ENTSP_u6 : XCore::ENTSP_lu6;
|
|
|
|
MBB.addLiveIn(XCore::LR);
|
|
|
|
saveLR = false;
|
|
|
|
} else {
|
|
|
|
Opcode = (isU6) ? XCore::EXTSP_u6 : XCore::EXTSP_lu6;
|
|
|
|
}
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(Opcode)).addImm(FrameSize);
|
|
|
|
|
|
|
|
if (emitFrameMoves) {
|
|
|
|
|
|
|
|
// Show update of SP.
|
|
|
|
MCSymbol *FrameLabel = MMI->getContext().CreateTempSymbol();
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(XCore::PROLOG_LABEL)).addSym(FrameLabel);
|
|
|
|
}
|
2013-05-09 18:43:42 +02:00
|
|
|
}
|
|
|
|
if (saveLR) {
|
|
|
|
int LRSpillOffset = MFI->getObjectOffset(XFI->getLRSpillSlot());
|
|
|
|
storeToStack(MBB, MBBI, XCore::LR, LRSpillOffset + FrameSize*4, dl, TII);
|
|
|
|
MBB.addLiveIn(XCore::LR);
|
2010-11-15 01:06:54 +01:00
|
|
|
|
2013-05-09 18:43:42 +02:00
|
|
|
if (emitFrameMoves) {
|
|
|
|
MCSymbol *SaveLRLabel = MMI->getContext().CreateTempSymbol();
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(XCore::PROLOG_LABEL)).addSym(SaveLRLabel);
|
2010-11-15 01:06:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FP) {
|
|
|
|
// Save R10 to the stack.
|
|
|
|
int FPSpillOffset = MFI->getObjectOffset(XFI->getFPSpillSlot());
|
|
|
|
storeToStack(MBB, MBBI, XCore::R10, FPSpillOffset + FrameSize*4, dl, TII);
|
|
|
|
// R10 is live-in. It is killed at the spill.
|
|
|
|
MBB.addLiveIn(XCore::R10);
|
|
|
|
if (emitFrameMoves) {
|
|
|
|
MCSymbol *SaveR10Label = MMI->getContext().CreateTempSymbol();
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(XCore::PROLOG_LABEL)).addSym(SaveR10Label);
|
|
|
|
}
|
|
|
|
// Set the FP from the SP.
|
|
|
|
unsigned FramePtr = XCore::R10;
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(XCore::LDAWSP_ru6), FramePtr)
|
|
|
|
.addImm(0);
|
|
|
|
if (emitFrameMoves) {
|
|
|
|
// Show FP is now valid.
|
|
|
|
MCSymbol *FrameLabel = MMI->getContext().CreateTempSymbol();
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(XCore::PROLOG_LABEL)).addSym(FrameLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
void XCoreFrameLowering::emitEpilogue(MachineFunction &MF,
|
2010-11-15 01:06:54 +01:00
|
|
|
MachineBasicBlock &MBB) const {
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2011-01-13 23:47:43 +01:00
|
|
|
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
|
2010-11-15 01:06:54 +01:00
|
|
|
const XCoreInstrInfo &TII =
|
|
|
|
*static_cast<const XCoreInstrInfo*>(MF.getTarget().getInstrInfo());
|
2013-05-09 18:43:42 +02:00
|
|
|
XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
|
2010-11-15 01:06:54 +01:00
|
|
|
DebugLoc dl = MBBI->getDebugLoc();
|
|
|
|
|
2010-11-18 22:19:35 +01:00
|
|
|
bool FP = hasFP(MF);
|
2010-11-15 01:06:54 +01:00
|
|
|
if (FP) {
|
|
|
|
// Restore the stack pointer.
|
|
|
|
unsigned FramePtr = XCore::R10;
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(XCore::SETSP_1r))
|
|
|
|
.addReg(FramePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work out frame sizes.
|
|
|
|
int FrameSize = MFI->getStackSize();
|
|
|
|
|
|
|
|
assert(FrameSize%4 == 0 && "Misaligned frame size");
|
|
|
|
|
|
|
|
FrameSize/=4;
|
|
|
|
|
|
|
|
bool isU6 = isImmU6(FrameSize);
|
|
|
|
|
|
|
|
if (!isU6 && !isImmU16(FrameSize)) {
|
|
|
|
// FIXME could emit multiple instructions.
|
|
|
|
report_fatal_error("emitEpilogue Frame size too big: " + Twine(FrameSize));
|
|
|
|
}
|
|
|
|
|
2013-05-09 18:43:42 +02:00
|
|
|
if (FP) {
|
|
|
|
// Restore R10
|
|
|
|
int FPSpillOffset = MFI->getObjectOffset(XFI->getFPSpillSlot());
|
|
|
|
FPSpillOffset += FrameSize*4;
|
|
|
|
loadFromStack(MBB, MBBI, XCore::R10, FPSpillOffset, dl, TII);
|
|
|
|
}
|
2010-11-15 01:06:54 +01:00
|
|
|
|
2013-05-09 18:43:42 +02:00
|
|
|
bool restoreLR = XFI->getUsesLR();
|
|
|
|
if (restoreLR &&
|
|
|
|
(FrameSize == 0 || MFI->getObjectOffset(XFI->getLRSpillSlot()) != 0)) {
|
|
|
|
int LRSpillOffset = MFI->getObjectOffset(XFI->getLRSpillSlot());
|
|
|
|
LRSpillOffset += FrameSize*4;
|
|
|
|
loadFromStack(MBB, MBBI, XCore::LR, LRSpillOffset, dl, TII);
|
|
|
|
restoreLR = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FrameSize) {
|
2010-11-15 01:06:54 +01:00
|
|
|
if (restoreLR) {
|
|
|
|
// Fold prologue into return instruction
|
2013-05-09 18:43:42 +02:00
|
|
|
assert(MFI->getObjectOffset(XFI->getLRSpillSlot()) == 0);
|
2010-11-15 01:06:54 +01:00
|
|
|
assert(MBBI->getOpcode() == XCore::RETSP_u6
|
|
|
|
|| MBBI->getOpcode() == XCore::RETSP_lu6);
|
|
|
|
int Opcode = (isU6) ? XCore::RETSP_u6 : XCore::RETSP_lu6;
|
2013-07-17 12:58:37 +02:00
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MBBI, dl, TII.get(Opcode)).addImm(FrameSize);
|
|
|
|
for (unsigned i = 3, e = MBBI->getNumOperands(); i < e; ++i)
|
|
|
|
MIB->addOperand(MBBI->getOperand(i)); // copy any variadic operands
|
2010-11-15 01:06:54 +01:00
|
|
|
MBB.erase(MBBI);
|
|
|
|
} else {
|
2013-04-04 21:57:46 +02:00
|
|
|
int Opcode = (isU6) ? XCore::LDAWSP_ru6 : XCore::LDAWSP_lru6;
|
2010-11-15 01:06:54 +01:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(Opcode), XCore::SP).addImm(FrameSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-19 00:25:52 +01:00
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
bool XCoreFrameLowering::spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
2010-11-28 00:05:03 +01:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
|
|
|
if (CSI.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
MachineFunction *MF = MBB.getParent();
|
|
|
|
const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
|
|
|
|
|
|
|
|
XCoreFunctionInfo *XFI = MF->getInfo<XCoreFunctionInfo>();
|
|
|
|
bool emitFrameMoves = XCoreRegisterInfo::needsFrameMoves(*MF);
|
|
|
|
|
|
|
|
DebugLoc DL;
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
|
|
|
for (std::vector<CalleeSavedInfo>::const_iterator it = CSI.begin();
|
|
|
|
it != CSI.end(); ++it) {
|
|
|
|
// Add the callee-saved register as live-in. It's killed at the spill.
|
|
|
|
MBB.addLiveIn(it->getReg());
|
|
|
|
|
|
|
|
unsigned Reg = it->getReg();
|
|
|
|
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
|
|
|
|
TII.storeRegToStackSlot(MBB, MI, Reg, true,
|
|
|
|
it->getFrameIdx(), RC, TRI);
|
|
|
|
if (emitFrameMoves) {
|
|
|
|
MCSymbol *SaveLabel = MF->getContext().CreateTempSymbol();
|
|
|
|
BuildMI(MBB, MI, DL, TII.get(XCore::PROLOG_LABEL)).addSym(SaveLabel);
|
|
|
|
XFI->getSpillLabels().push_back(std::make_pair(SaveLabel, *it));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-10 13:39:04 +01:00
|
|
|
bool XCoreFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
2010-11-28 00:05:03 +01:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const{
|
|
|
|
MachineFunction *MF = MBB.getParent();
|
|
|
|
const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo();
|
|
|
|
|
|
|
|
bool AtStart = MI == MBB.begin();
|
|
|
|
MachineBasicBlock::iterator BeforeI = MI;
|
|
|
|
if (!AtStart)
|
|
|
|
--BeforeI;
|
|
|
|
for (std::vector<CalleeSavedInfo>::const_iterator it = CSI.begin();
|
|
|
|
it != CSI.end(); ++it) {
|
|
|
|
unsigned Reg = it->getReg();
|
|
|
|
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
|
|
|
|
TII.loadRegFromStackSlot(MBB, MI, it->getReg(), it->getFrameIdx(),
|
|
|
|
RC, TRI);
|
|
|
|
assert(MI != MBB.begin() &&
|
|
|
|
"loadRegFromStackSlot didn't insert any code!");
|
|
|
|
// Insert in reverse order. loadRegFromStackSlot can insert multiple
|
|
|
|
// instructions.
|
|
|
|
if (AtStart)
|
|
|
|
MI = MBB.begin();
|
|
|
|
else {
|
|
|
|
MI = BeforeI;
|
|
|
|
++MI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-28 00:05:25 +01:00
|
|
|
|
2013-02-21 21:05:00 +01:00
|
|
|
// This function eliminates ADJCALLSTACKDOWN,
|
|
|
|
// ADJCALLSTACKUP pseudo instructions
|
|
|
|
void XCoreFrameLowering::
|
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
|
|
|
const XCoreInstrInfo &TII =
|
|
|
|
*static_cast<const XCoreInstrInfo*>(MF.getTarget().getInstrInfo());
|
|
|
|
if (!hasReservedCallFrame(MF)) {
|
|
|
|
// Turn the adjcallstackdown instruction into 'extsp <amt>' and the
|
|
|
|
// adjcallstackup instruction into 'ldaw sp, sp[<amt>]'
|
|
|
|
MachineInstr *Old = I;
|
|
|
|
uint64_t Amount = Old->getOperand(0).getImm();
|
|
|
|
if (Amount != 0) {
|
|
|
|
// We need to keep the stack aligned properly. To do this, we round the
|
|
|
|
// amount of space needed for the outgoing arguments up to the next
|
|
|
|
// alignment boundary.
|
|
|
|
unsigned Align = getStackAlignment();
|
|
|
|
Amount = (Amount+Align-1)/Align*Align;
|
|
|
|
|
|
|
|
assert(Amount%4 == 0);
|
|
|
|
Amount /= 4;
|
|
|
|
|
|
|
|
bool isU6 = isImmU6(Amount);
|
|
|
|
if (!isU6 && !isImmU16(Amount)) {
|
|
|
|
// FIX could emit multiple instructions in this case.
|
|
|
|
#ifndef NDEBUG
|
|
|
|
errs() << "eliminateCallFramePseudoInstr size too big: "
|
|
|
|
<< Amount << "\n";
|
|
|
|
#endif
|
|
|
|
llvm_unreachable(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
MachineInstr *New;
|
|
|
|
if (Old->getOpcode() == XCore::ADJCALLSTACKDOWN) {
|
|
|
|
int Opcode = isU6 ? XCore::EXTSP_u6 : XCore::EXTSP_lu6;
|
|
|
|
New=BuildMI(MF, Old->getDebugLoc(), TII.get(Opcode))
|
|
|
|
.addImm(Amount);
|
|
|
|
} else {
|
|
|
|
assert(Old->getOpcode() == XCore::ADJCALLSTACKUP);
|
2013-04-04 21:57:46 +02:00
|
|
|
int Opcode = isU6 ? XCore::LDAWSP_ru6 : XCore::LDAWSP_lru6;
|
2013-02-21 21:05:00 +01:00
|
|
|
New=BuildMI(MF, Old->getDebugLoc(), TII.get(Opcode), XCore::SP)
|
|
|
|
.addImm(Amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace the pseudo instruction with a new instruction...
|
|
|
|
MBB.insert(I, New);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MBB.erase(I);
|
|
|
|
}
|
|
|
|
|
2010-11-28 00:05:25 +01:00
|
|
|
void
|
2011-01-10 13:39:04 +01:00
|
|
|
XCoreFrameLowering::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
|
2010-11-28 00:05:25 +01:00
|
|
|
RegScavenger *RS) const {
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
const TargetRegisterInfo *RegInfo = MF.getTarget().getRegisterInfo();
|
|
|
|
bool LRUsed = MF.getRegInfo().isPhysRegUsed(XCore::LR);
|
2012-04-20 09:30:17 +02:00
|
|
|
const TargetRegisterClass *RC = &XCore::GRRegsRegClass;
|
2010-11-28 00:05:25 +01:00
|
|
|
XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
|
|
|
|
if (LRUsed) {
|
|
|
|
MF.getRegInfo().setPhysRegUnused(XCore::LR);
|
|
|
|
|
|
|
|
bool isVarArg = MF.getFunction()->isVarArg();
|
|
|
|
int FrameIdx;
|
|
|
|
if (! isVarArg) {
|
|
|
|
// A fixed offset of 0 allows us to save / restore LR using entsp / retsp.
|
|
|
|
FrameIdx = MFI->CreateFixedObject(RC->getSize(), 0, true);
|
|
|
|
} else {
|
|
|
|
FrameIdx = MFI->CreateStackObject(RC->getSize(), RC->getAlignment(),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
XFI->setUsesLR(FrameIdx);
|
|
|
|
XFI->setLRSpillSlot(FrameIdx);
|
|
|
|
}
|
|
|
|
if (RegInfo->requiresRegisterScavenging(MF)) {
|
|
|
|
// Reserve a slot close to SP or frame pointer.
|
2013-03-23 00:32:27 +01:00
|
|
|
RS->addScavengingFrameIndex(MFI->CreateStackObject(RC->getSize(),
|
2010-11-28 00:05:25 +01:00
|
|
|
RC->getAlignment(),
|
|
|
|
false));
|
|
|
|
}
|
|
|
|
if (hasFP(MF)) {
|
|
|
|
// A callee save register is used to hold the FP.
|
|
|
|
// This needs saving / restoring in the epilogue / prologue.
|
|
|
|
XFI->setFPSpillSlot(MFI->CreateStackObject(RC->getSize(),
|
|
|
|
RC->getAlignment(),
|
|
|
|
false));
|
|
|
|
}
|
|
|
|
}
|