2011-01-10 12:39:04 +00:00
|
|
|
//====- BlackfinFrameLowering.cpp - Blackfin Frame Information --*- C++ -*-===//
|
2010-11-15 00:06:54 +00: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 12:39:04 +00:00
|
|
|
// This file contains the Blackfin implementation of TargetFrameLowering class.
|
2010-11-15 00:06:54 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "BlackfinFrameLowering.h"
|
2010-11-15 00:06:54 +00:00
|
|
|
#include "BlackfinInstrInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2010-11-27 23:05:25 +00:00
|
|
|
#include "llvm/CodeGen/RegisterScavenging.h"
|
2010-11-18 21:19:35 +00:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2010-11-15 00:06:54 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
2010-11-18 21:19:35 +00:00
|
|
|
// hasFP - Return true if the specified function should have a dedicated frame
|
|
|
|
// pointer register. This is true if the function has variable sized allocas or
|
|
|
|
// if frame pointer elimination is disabled.
|
2011-01-10 12:39:04 +00:00
|
|
|
bool BlackfinFrameLowering::hasFP(const MachineFunction &MF) const {
|
2010-11-18 21:19:35 +00:00
|
|
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
return DisableFramePointerElim(MF) ||
|
|
|
|
MFI->adjustsStack() || MFI->hasVarSizedObjects();
|
|
|
|
}
|
|
|
|
|
2010-11-15 00:06:54 +00:00
|
|
|
// Emit a prologue that sets up a stack frame.
|
|
|
|
// On function entry, R0-R2 and P0 may hold arguments.
|
|
|
|
// R3, P1, and P2 may be used as scratch registers
|
2011-01-10 12:39:04 +00:00
|
|
|
void BlackfinFrameLowering::emitPrologue(MachineFunction &MF) const {
|
2010-11-15 00:06:54 +00:00
|
|
|
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
const BlackfinRegisterInfo *RegInfo =
|
|
|
|
static_cast<const BlackfinRegisterInfo*>(MF.getTarget().getRegisterInfo());
|
|
|
|
const BlackfinInstrInfo &TII =
|
|
|
|
*static_cast<const BlackfinInstrInfo*>(MF.getTarget().getInstrInfo());
|
|
|
|
|
|
|
|
DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
|
|
|
|
|
|
|
|
int FrameSize = MFI->getStackSize();
|
|
|
|
if (FrameSize%4) {
|
|
|
|
FrameSize = (FrameSize+3) & ~3;
|
|
|
|
MFI->setStackSize(FrameSize);
|
|
|
|
}
|
|
|
|
|
2010-11-18 21:19:35 +00:00
|
|
|
if (!hasFP(MF)) {
|
2010-11-15 00:06:54 +00:00
|
|
|
assert(!MFI->adjustsStack() &&
|
|
|
|
"FP elimination on a non-leaf function is not supported");
|
|
|
|
RegInfo->adjustRegister(MBB, MBBI, dl, BF::SP, BF::P1, -FrameSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// emit a LINK instruction
|
|
|
|
if (FrameSize <= 0x3ffff) {
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(BF::LINK)).addImm(FrameSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Frame is too big, do a manual LINK:
|
|
|
|
// [--SP] = RETS;
|
|
|
|
// [--SP] = FP;
|
|
|
|
// FP = SP;
|
|
|
|
// P1 = -FrameSize;
|
|
|
|
// SP = SP + P1;
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(BF::PUSH))
|
|
|
|
.addReg(BF::RETS, RegState::Kill);
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(BF::PUSH))
|
|
|
|
.addReg(BF::FP, RegState::Kill);
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(BF::MOVE), BF::FP)
|
|
|
|
.addReg(BF::SP);
|
|
|
|
RegInfo->loadConstant(MBB, MBBI, dl, BF::P1, -FrameSize);
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(BF::ADDpp), BF::SP)
|
|
|
|
.addReg(BF::SP, RegState::Kill)
|
|
|
|
.addReg(BF::P1, RegState::Kill);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
void BlackfinFrameLowering::emitEpilogue(MachineFunction &MF,
|
2010-11-15 00:06:54 +00:00
|
|
|
MachineBasicBlock &MBB) const {
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
const BlackfinRegisterInfo *RegInfo =
|
|
|
|
static_cast<const BlackfinRegisterInfo*>(MF.getTarget().getRegisterInfo());
|
|
|
|
const BlackfinInstrInfo &TII =
|
|
|
|
*static_cast<const BlackfinInstrInfo*>(MF.getTarget().getInstrInfo());
|
2011-01-13 21:28:52 +00:00
|
|
|
MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
|
2010-11-15 00:06:54 +00:00
|
|
|
DebugLoc dl = MBBI->getDebugLoc();
|
|
|
|
|
|
|
|
int FrameSize = MFI->getStackSize();
|
|
|
|
assert(FrameSize%4 == 0 && "Misaligned frame size");
|
|
|
|
|
2010-11-18 21:19:35 +00:00
|
|
|
if (!hasFP(MF)) {
|
2010-11-15 00:06:54 +00:00
|
|
|
assert(!MFI->adjustsStack() &&
|
|
|
|
"FP elimination on a non-leaf function is not supported");
|
|
|
|
RegInfo->adjustRegister(MBB, MBBI, dl, BF::SP, BF::P1, FrameSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// emit an UNLINK instruction
|
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(BF::UNLINK));
|
|
|
|
}
|
2010-11-27 23:05:25 +00:00
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
void BlackfinFrameLowering::
|
2010-11-27 23:05:25 +00:00
|
|
|
processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
|
|
|
|
RegScavenger *RS) const {
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
const BlackfinRegisterInfo *RegInfo =
|
|
|
|
static_cast<const BlackfinRegisterInfo*>(MF.getTarget().getRegisterInfo());
|
|
|
|
const TargetRegisterClass *RC = BF::DPRegisterClass;
|
|
|
|
|
|
|
|
if (RegInfo->requiresRegisterScavenging(MF)) {
|
|
|
|
// Reserve a slot close to SP or frame pointer.
|
|
|
|
RS->setScavengingFrameIndex(MFI->CreateStackObject(RC->getSize(),
|
|
|
|
RC->getAlignment(),
|
|
|
|
false));
|
|
|
|
}
|
|
|
|
}
|