mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-13 17:38:39 +00:00
dynamic stack allocas
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20273 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
84734ce8ef
commit
032f235f02
@ -26,6 +26,7 @@
|
|||||||
#include "llvm/Target/TargetLowering.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
|
#include "llvm/Support/Debug.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -180,7 +181,6 @@ AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
|
|||||||
DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), newroot);
|
DAG.getNode(ISD::TRUNCATE, getValueType(I->getType()), newroot);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++count;
|
|
||||||
} else { //more args
|
} else { //more args
|
||||||
// Create the frame index object for this incoming parameter...
|
// Create the frame index object for this incoming parameter...
|
||||||
int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
|
int FI = MFI->CreateFixedObject(8, 8 * (count - 6));
|
||||||
@ -191,19 +191,14 @@ AlphaTargetLowering::LowerArguments(Function &F, SelectionDAG &DAG)
|
|||||||
argt = newroot = DAG.getLoad(getValueType(I->getType()),
|
argt = newroot = DAG.getLoad(getValueType(I->getType()),
|
||||||
DAG.getEntryNode(), FIN);
|
DAG.getEntryNode(), FIN);
|
||||||
}
|
}
|
||||||
|
++count;
|
||||||
DAG.setRoot(newroot.getValue(1));
|
DAG.setRoot(newroot.getValue(1));
|
||||||
ArgValues.push_back(argt);
|
ArgValues.push_back(argt);
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildMI(&BB, Alpha::IDEF, 0, Alpha::R29);
|
BuildMI(&BB, Alpha::IDEF, 0, Alpha::R29);
|
||||||
BuildMI(&BB, Alpha::BIS, 2, GP).addReg(Alpha::R29).addReg(Alpha::R29);
|
BuildMI(&BB, Alpha::BIS, 2, GP).addReg(Alpha::R29).addReg(Alpha::R29);
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count && i < 6; ++i) {
|
||||||
if (argPreg[i] == Alpha::F16 || argPreg[i] == Alpha::F17 ||
|
|
||||||
argPreg[i] == Alpha::F18 || argPreg[i] == Alpha::F19 ||
|
|
||||||
argPreg[i] == Alpha::F20 || argPreg[i] == Alpha::F21)
|
|
||||||
{
|
|
||||||
assert(argOpc[i] == Alpha::CPYS && "Using BIS for a float??");
|
|
||||||
}
|
|
||||||
BuildMI(&BB, argOpc[i], 2,
|
BuildMI(&BB, argOpc[i], 2,
|
||||||
argVreg[i]).addReg(argPreg[i]).addReg(argPreg[i]);
|
argVreg[i]).addReg(argPreg[i]).addReg(argPreg[i]);
|
||||||
}
|
}
|
||||||
@ -311,6 +306,7 @@ public:
|
|||||||
/// InstructionSelectBasicBlock - This callback is invoked by
|
/// InstructionSelectBasicBlock - This callback is invoked by
|
||||||
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
/// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
|
||||||
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
virtual void InstructionSelectBasicBlock(SelectionDAG &DAG) {
|
||||||
|
DEBUG(BB->dump());
|
||||||
// Codegen the basic block.
|
// Codegen the basic block.
|
||||||
Select(DAG.getRoot());
|
Select(DAG.getRoot());
|
||||||
|
|
||||||
@ -570,8 +566,9 @@ unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
|
|||||||
BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
|
BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
|
||||||
}
|
}
|
||||||
else if(Address.getOpcode() == ISD::FrameIndex) {
|
else if(Address.getOpcode() == ISD::FrameIndex) {
|
||||||
Tmp1 = cast<FrameIndexSDNode>(Address)->getIndex();
|
BuildMI(BB, Opc, 2, Result)
|
||||||
BuildMI(BB, Opc, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31);
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
||||||
|
.addReg(Alpha::F31);
|
||||||
} else {
|
} else {
|
||||||
long offset;
|
long offset;
|
||||||
SelectAddr(Address, Tmp1, offset);
|
SelectAddr(Address, Tmp1, offset);
|
||||||
@ -636,7 +633,9 @@ unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
|
|||||||
}
|
}
|
||||||
else if(Address.getOpcode() == ISD::FrameIndex) {
|
else if(Address.getOpcode() == ISD::FrameIndex) {
|
||||||
Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
|
Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
|
||||||
BuildMI(BB, Alpha::LDS, 2, Tmp1).addFrameIndex(Tmp2).addReg(Alpha::F31);
|
BuildMI(BB, Alpha::LDS, 2, Tmp1)
|
||||||
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
||||||
|
.addReg(Alpha::F31);
|
||||||
} else {
|
} else {
|
||||||
long offset;
|
long offset;
|
||||||
SelectAddr(Address, Tmp2, offset);
|
SelectAddr(Address, Tmp2, offset);
|
||||||
@ -723,6 +722,47 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
|||||||
Node->dump();
|
Node->dump();
|
||||||
assert(0 && "Node not handled!\n");
|
assert(0 && "Node not handled!\n");
|
||||||
|
|
||||||
|
case ISD::DYNAMIC_STACKALLOC:
|
||||||
|
// Generate both result values.
|
||||||
|
if (Result != 1)
|
||||||
|
ExprMap[N.getValue(1)] = 1; // Generate the token
|
||||||
|
else
|
||||||
|
Result = ExprMap[N.getValue(0)] = MakeReg(N.getValue(0).getValueType());
|
||||||
|
|
||||||
|
// FIXME: We are currently ignoring the requested alignment for handling
|
||||||
|
// greater than the stack alignment. This will need to be revisited at some
|
||||||
|
// point. Align = N.getOperand(2);
|
||||||
|
|
||||||
|
if (!isa<ConstantSDNode>(N.getOperand(2)) ||
|
||||||
|
cast<ConstantSDNode>(N.getOperand(2))->getValue() != 0) {
|
||||||
|
std::cerr << "Cannot allocate stack object with greater alignment than"
|
||||||
|
<< " the stack alignment yet!";
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
Select(N.getOperand(0));
|
||||||
|
if (ConstantSDNode* CN = dyn_cast<ConstantSDNode>(N.getOperand(1)))
|
||||||
|
{
|
||||||
|
if (CN->getValue() < 32000)
|
||||||
|
{
|
||||||
|
BuildMI(BB, Alpha::LDA, 2, Alpha::R30)
|
||||||
|
.addImm(-CN->getValue()).addReg(Alpha::R30);
|
||||||
|
} else {
|
||||||
|
Tmp1 = SelectExpr(N.getOperand(1));
|
||||||
|
// Subtract size from stack pointer, thereby allocating some space.
|
||||||
|
BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Tmp1 = SelectExpr(N.getOperand(1));
|
||||||
|
// Subtract size from stack pointer, thereby allocating some space.
|
||||||
|
BuildMI(BB, Alpha::SUBQ, 2, Alpha::R30).addReg(Alpha::R30).addReg(Tmp1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put a pointer to the space into the result register, by copying the stack
|
||||||
|
// pointer.
|
||||||
|
BuildMI(BB, Alpha::BIS, 1, Result).addReg(Alpha::R30).addReg(Alpha::R30);
|
||||||
|
return Result;
|
||||||
|
|
||||||
case ISD::ConstantPool:
|
case ISD::ConstantPool:
|
||||||
Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
|
Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
|
||||||
AlphaLowering.restoreGP(BB);
|
AlphaLowering.restoreGP(BB);
|
||||||
@ -730,8 +770,9 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
|||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
case ISD::FrameIndex:
|
case ISD::FrameIndex:
|
||||||
Tmp1 = cast<FrameIndexSDNode>(N)->getIndex();
|
BuildMI(BB, Alpha::LDA, 2, Result)
|
||||||
BuildMI(BB, Alpha::LDA, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31);
|
.addFrameIndex(cast<FrameIndexSDNode>(N)->getIndex())
|
||||||
|
.addReg(Alpha::F31);
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
case ISD::EXTLOAD:
|
case ISD::EXTLOAD:
|
||||||
@ -776,8 +817,9 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
|||||||
BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
|
BuildMI(BB, Opc, 1, Result).addConstantPoolIndex(CP->getIndex());
|
||||||
}
|
}
|
||||||
else if(Address.getOpcode() == ISD::FrameIndex) {
|
else if(Address.getOpcode() == ISD::FrameIndex) {
|
||||||
Tmp1 = cast<FrameIndexSDNode>(Address)->getIndex();
|
BuildMI(BB, Opc, 2, Result)
|
||||||
BuildMI(BB, Opc, 2, Result).addFrameIndex(Tmp1).addReg(Alpha::F31);
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
||||||
|
.addReg(Alpha::F31);
|
||||||
} else {
|
} else {
|
||||||
long offset;
|
long offset;
|
||||||
SelectAddr(Address, Tmp1, offset);
|
SelectAddr(Address, Tmp1, offset);
|
||||||
@ -1111,14 +1153,16 @@ unsigned ISel::SelectExpr(SDOperand N) {
|
|||||||
//Can only compare doubles, and dag won't promote for me
|
//Can only compare doubles, and dag won't promote for me
|
||||||
if (SetCC->getOperand(0).getValueType() == MVT::f32)
|
if (SetCC->getOperand(0).getValueType() == MVT::f32)
|
||||||
{
|
{
|
||||||
std::cerr << "Setcc On float?\n";
|
//assert(0 && "Setcc On float?\n");
|
||||||
|
std::cerr << "Setcc on float!\n";
|
||||||
Tmp3 = MakeReg(MVT::f64);
|
Tmp3 = MakeReg(MVT::f64);
|
||||||
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
|
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp1);
|
||||||
Tmp1 = Tmp3;
|
Tmp1 = Tmp3;
|
||||||
}
|
}
|
||||||
if (SetCC->getOperand(1).getValueType() == MVT::f32)
|
if (SetCC->getOperand(1).getValueType() == MVT::f32)
|
||||||
{
|
{
|
||||||
std::cerr << "Setcc On float?\n";
|
//assert (0 && "Setcc On float?\n");
|
||||||
|
std::cerr << "Setcc on float!\n";
|
||||||
Tmp3 = MakeReg(MVT::f64);
|
Tmp3 = MakeReg(MVT::f64);
|
||||||
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
|
BuildMI(BB, Alpha::CVTST, 1, Tmp3).addReg(Tmp2);
|
||||||
Tmp2 = Tmp3;
|
Tmp2 = Tmp3;
|
||||||
@ -1338,7 +1382,6 @@ void ISel::Select(SDOperand N) {
|
|||||||
|
|
||||||
SDNode *Node = N.Val;
|
SDNode *Node = N.Val;
|
||||||
|
|
||||||
|
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1457,8 +1500,9 @@ void ISel::Select(SDOperand N) {
|
|||||||
}
|
}
|
||||||
else if(Address.getOpcode() == ISD::FrameIndex)
|
else if(Address.getOpcode() == ISD::FrameIndex)
|
||||||
{
|
{
|
||||||
Tmp2 = cast<FrameIndexSDNode>(Address)->getIndex();
|
BuildMI(BB, Opc, 3).addReg(Tmp1)
|
||||||
BuildMI(BB, Opc, 3).addReg(Tmp1).addFrameIndex(Tmp2).addReg(Alpha::F31);
|
.addFrameIndex(cast<FrameIndexSDNode>(Address)->getIndex())
|
||||||
|
.addReg(Alpha::F31);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1475,7 +1519,7 @@ void ISel::Select(SDOperand N) {
|
|||||||
case ISD::LOAD:
|
case ISD::LOAD:
|
||||||
case ISD::CopyFromReg:
|
case ISD::CopyFromReg:
|
||||||
case ISD::CALL:
|
case ISD::CALL:
|
||||||
// case ISD::DYNAMIC_STACKALLOC:
|
case ISD::DYNAMIC_STACKALLOC:
|
||||||
ExprMap.erase(N);
|
ExprMap.erase(N);
|
||||||
SelectExpr(N);
|
SelectExpr(N);
|
||||||
return;
|
return;
|
||||||
|
@ -30,6 +30,21 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
static long getLower16(long l)
|
||||||
|
{
|
||||||
|
long y = l / 65536;
|
||||||
|
if (l % 65536 > 32767)
|
||||||
|
++y;
|
||||||
|
return l - y * 65536;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long getUpper16(long l)
|
||||||
|
{
|
||||||
|
long y = l / 65536;
|
||||||
|
if (l % 65536 > 32767)
|
||||||
|
++y;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
AlphaRegisterInfo::AlphaRegisterInfo()
|
AlphaRegisterInfo::AlphaRegisterInfo()
|
||||||
: AlphaGenRegisterInfo(Alpha::ADJUSTSTACKDOWN, Alpha::ADJUSTSTACKUP)
|
: AlphaGenRegisterInfo(Alpha::ADJUSTSTACKDOWN, Alpha::ADJUSTSTACKUP)
|
||||||
@ -102,7 +117,6 @@ void AlphaRegisterInfo::
|
|||||||
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator I) const {
|
MachineBasicBlock::iterator I) const {
|
||||||
if (hasFP(MF)) {
|
if (hasFP(MF)) {
|
||||||
assert(0 && "TODO");
|
|
||||||
// If we have a frame pointer, turn the adjcallstackup instruction into a
|
// If we have a frame pointer, turn the adjcallstackup instruction into a
|
||||||
// 'sub ESP, <amt>' and the adjcallstackdown instruction into 'add ESP,
|
// 'sub ESP, <amt>' and the adjcallstackdown instruction into 'add ESP,
|
||||||
// <amt>'
|
// <amt>'
|
||||||
@ -115,31 +129,39 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|||||||
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
|
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
|
||||||
Amount = (Amount+Align-1)/Align*Align;
|
Amount = (Amount+Align-1)/Align*Align;
|
||||||
|
|
||||||
// MachineInstr *New;
|
MachineInstr *New;
|
||||||
// if (Old->getOpcode() == X86::ADJCALLSTACKDOWN) {
|
if (Old->getOpcode() == Alpha::ADJUSTSTACKDOWN) {
|
||||||
// New=BuildMI(X86::SUB32ri, 1, X86::ESP, MachineOperand::UseAndDef)
|
New=BuildMI(Alpha::LDA, 2, Alpha::R30)
|
||||||
// .addZImm(Amount);
|
.addImm(-Amount).addReg(Alpha::R30);
|
||||||
// } else {
|
} else {
|
||||||
// assert(Old->getOpcode() == X86::ADJCALLSTACKUP);
|
assert(Old->getOpcode() == Alpha::ADJUSTSTACKUP);
|
||||||
// New=BuildMI(X86::ADD32ri, 1, X86::ESP, MachineOperand::UseAndDef)
|
New=BuildMI(Alpha::LDA, 2, Alpha::R30)
|
||||||
// .addZImm(Amount);
|
.addImm(Amount).addReg(Alpha::R30);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Replace the pseudo instruction with a new instruction...
|
// Replace the pseudo instruction with a new instruction...
|
||||||
//MBB.insert(I, New);
|
MBB.insert(I, New);
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MBB.erase(I);
|
MBB.erase(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Alpha has a slightly funny stack:
|
||||||
|
//Args
|
||||||
|
//<- incoming SP
|
||||||
|
//fixed locals (and spills, callee saved, etc)
|
||||||
|
//<- FP
|
||||||
|
//variable locals
|
||||||
|
//<- SP
|
||||||
|
|
||||||
void
|
void
|
||||||
AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
|
AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
MachineInstr &MI = *II;
|
MachineInstr &MI = *II;
|
||||||
MachineBasicBlock &MBB = *MI.getParent();
|
MachineBasicBlock &MBB = *MI.getParent();
|
||||||
MachineFunction &MF = *MBB.getParent();
|
MachineFunction &MF = *MBB.getParent();
|
||||||
|
bool FP = hasFP(MF);
|
||||||
|
|
||||||
while (!MI.getOperand(i).isFrameIndex()) {
|
while (!MI.getOperand(i).isFrameIndex()) {
|
||||||
++i;
|
++i;
|
||||||
@ -149,19 +171,29 @@ AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
|
|||||||
int FrameIndex = MI.getOperand(i).getFrameIndex();
|
int FrameIndex = MI.getOperand(i).getFrameIndex();
|
||||||
|
|
||||||
// Add the base register of R30 (SP) or R15 (FP).
|
// Add the base register of R30 (SP) or R15 (FP).
|
||||||
MI.SetMachineOperandReg(i + 1, hasFP(MF) ? Alpha::R15 : Alpha::R30);
|
MI.SetMachineOperandReg(i + 1, FP ? Alpha::R15 : Alpha::R30);
|
||||||
|
|
||||||
// Now add the frame object offset to the offset from r1.
|
// Now add the frame object offset to the offset from the virtual frame index.
|
||||||
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
|
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
|
||||||
|
|
||||||
// If we're not using a Frame Pointer that has been set to the value of the
|
DEBUG(std::cerr << "FI: " << FrameIndex << " Offset: " << Offset << "\n");
|
||||||
// SP before having the stack size subtracted from it, then add the stack size
|
|
||||||
// to Offset to get the correct offset.
|
|
||||||
Offset += MF.getFrameInfo()->getStackSize();
|
Offset += MF.getFrameInfo()->getStackSize();
|
||||||
|
|
||||||
|
DEBUG(std::cerr << "Corrected Offset " << Offset <<
|
||||||
|
" for stack size: " << MF.getFrameInfo()->getStackSize() << "\n");
|
||||||
|
|
||||||
if (Offset > 32767 || Offset < -32768) {
|
if (Offset > 32767 || Offset < -32768) {
|
||||||
std::cerr << "Offset needs to be " << Offset << "\n";
|
//so in this case, we need to use a temporary register, and move the original
|
||||||
assert(0 && "stack too big");
|
//inst off the SP/FP
|
||||||
|
//fix up the old:
|
||||||
|
MI.SetMachineOperandReg(i + 1, Alpha::R28);
|
||||||
|
MI.SetMachineOperandConst(i, MachineOperand::MO_SignExtendedImmed,
|
||||||
|
getLower16(Offset));
|
||||||
|
//insert the new
|
||||||
|
MachineInstr* nMI=BuildMI(Alpha::LDAH, 2, Alpha::R28)
|
||||||
|
.addImm(getUpper16(Offset)).addReg(FP ? Alpha::R15 : Alpha::R30);
|
||||||
|
MBB.insert(--II, nMI);
|
||||||
} else {
|
} else {
|
||||||
MI.SetMachineOperandConst(i, MachineOperand::MO_SignExtendedImmed, Offset);
|
MI.SetMachineOperandConst(i, MachineOperand::MO_SignExtendedImmed, Offset);
|
||||||
}
|
}
|
||||||
@ -173,6 +205,7 @@ void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const {
|
|||||||
MachineBasicBlock::iterator MBBI = MBB.begin();
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
||||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
MachineInstr *MI;
|
MachineInstr *MI;
|
||||||
|
bool FP = hasFP(MF);
|
||||||
|
|
||||||
//handle GOP offset
|
//handle GOP offset
|
||||||
MI = BuildMI(Alpha::LDGP, 0);
|
MI = BuildMI(Alpha::LDGP, 0);
|
||||||
@ -181,42 +214,48 @@ void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const {
|
|||||||
// Get the number of bytes to allocate from the FrameInfo
|
// Get the number of bytes to allocate from the FrameInfo
|
||||||
unsigned NumBytes = MFI->getStackSize();
|
unsigned NumBytes = MFI->getStackSize();
|
||||||
|
|
||||||
if (MFI->hasCalls()) {
|
if (MFI->hasCalls() && !FP) {
|
||||||
// We reserve argument space for call sites in the function immediately on
|
// We reserve argument space for call sites in the function immediately on
|
||||||
// entry to the current function. This eliminates the need for add/sub
|
// entry to the current function. This eliminates the need for add/sub
|
||||||
// brackets around call sites.
|
// brackets around call sites.
|
||||||
|
//If there is a frame pointer, then we don't do this
|
||||||
NumBytes += MFI->getMaxCallFrameSize();
|
NumBytes += MFI->getMaxCallFrameSize();
|
||||||
std::cerr << "Added " << MFI->getMaxCallFrameSize() << " to the stack due to calls\n";
|
std::cerr << "Added " << MFI->getMaxCallFrameSize() << " to the stack due to calls\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FP)
|
||||||
|
NumBytes += 8; //reserve space for the old FP
|
||||||
|
|
||||||
// Do we need to allocate space on the stack?
|
// Do we need to allocate space on the stack?
|
||||||
if (NumBytes == 0) return;
|
if (NumBytes == 0) return;
|
||||||
|
|
||||||
// Add the size of R30 to NumBytes size for the store of R30 to the
|
|
||||||
// stack
|
|
||||||
// std::cerr << "Spillsize of R30 is " << getSpillSize(Alpha::R30) << "\n";
|
|
||||||
// NumBytes = NumBytes + getSpillSize(Alpha::R30)/8;
|
|
||||||
|
|
||||||
// Update frame info to pretend that this is part of the stack...
|
// Update frame info to pretend that this is part of the stack...
|
||||||
MFI->setStackSize(NumBytes);
|
MFI->setStackSize(NumBytes);
|
||||||
|
|
||||||
// adjust stack pointer: r30 -= numbytes
|
// adjust stack pointer: r30 -= numbytes
|
||||||
|
|
||||||
if (NumBytes <= 32767) {
|
if (NumBytes <= 32767) {
|
||||||
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(-NumBytes).addReg(Alpha::R30);
|
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(-NumBytes).addReg(Alpha::R30);
|
||||||
MBB.insert(MBBI, MI);
|
MBB.insert(MBBI, MI);
|
||||||
} else if ((unsigned long)NumBytes <= (unsigned long)32767 * (unsigned long)65536) {
|
} else if ((unsigned long)NumBytes <= (unsigned long)32767 * (unsigned long)65536) {
|
||||||
long y = NumBytes / 65536;
|
MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(getUpper16(-NumBytes)).addReg(Alpha::R30);
|
||||||
if (NumBytes % 65536 > 32767)
|
|
||||||
++y;
|
|
||||||
MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(-y).addReg(Alpha::R30);
|
|
||||||
MBB.insert(MBBI, MI);
|
MBB.insert(MBBI, MI);
|
||||||
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(-(NumBytes - y * 65536)).addReg(Alpha::R30);
|
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(getLower16(-NumBytes)).addReg(Alpha::R30);
|
||||||
MBB.insert(MBBI, MI);
|
MBB.insert(MBBI, MI);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Too big a stack frame at " << NumBytes << "\n";
|
std::cerr << "Too big a stack frame at " << NumBytes << "\n";
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//now if we need to, save the old FP and set the new
|
||||||
|
if (FP)
|
||||||
|
{
|
||||||
|
MI=BuildMI(Alpha::STQ, 3).addReg(Alpha::R15).addImm(0).addReg(Alpha::R30);
|
||||||
|
MBB.insert(MBBI, MI);
|
||||||
|
//this must be the last instr in the prolog
|
||||||
|
MI=BuildMI(Alpha::BIS, 2, Alpha::R15).addReg(Alpha::R30).addReg(Alpha::R30);
|
||||||
|
MBB.insert(MBBI, MI);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF,
|
void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||||
@ -227,21 +266,27 @@ void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF,
|
|||||||
assert((MBBI->getOpcode() == Alpha::RET || MBBI->getOpcode() == Alpha::RETURN) &&
|
assert((MBBI->getOpcode() == Alpha::RET || MBBI->getOpcode() == Alpha::RETURN) &&
|
||||||
"Can only insert epilog into returning blocks");
|
"Can only insert epilog into returning blocks");
|
||||||
|
|
||||||
|
bool FP = hasFP(MF);
|
||||||
|
|
||||||
// Get the number of bytes allocated from the FrameInfo...
|
// Get the number of bytes allocated from the FrameInfo...
|
||||||
unsigned NumBytes = MFI->getStackSize();
|
unsigned NumBytes = MFI->getStackSize();
|
||||||
|
|
||||||
|
//now if we need to, restore the old FP
|
||||||
|
if (FP)
|
||||||
|
{
|
||||||
|
MI=BuildMI(Alpha::LDQ, 2, Alpha::R15).addImm(0).addReg(Alpha::R15);
|
||||||
|
MBB.insert(MBBI, MI);
|
||||||
|
}
|
||||||
|
|
||||||
if (NumBytes != 0)
|
if (NumBytes != 0)
|
||||||
{
|
{
|
||||||
if (NumBytes <= 32767) {
|
if (NumBytes <= 32767) {
|
||||||
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(NumBytes).addReg(Alpha::R30);
|
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(NumBytes).addReg(Alpha::R30);
|
||||||
MBB.insert(MBBI, MI);
|
MBB.insert(MBBI, MI);
|
||||||
} else if ((unsigned long)NumBytes <= (unsigned long)32767 * (unsigned long)65536) {
|
} else if ((unsigned long)NumBytes <= (unsigned long)32767 * (unsigned long)65536) {
|
||||||
long y = NumBytes / 65536;
|
MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(getUpper16(NumBytes)).addReg(Alpha::R30);
|
||||||
if (NumBytes % 65536 > 32767)
|
|
||||||
++y;
|
|
||||||
MI=BuildMI(Alpha::LDAH, 2, Alpha::R30).addImm(y).addReg(Alpha::R30);
|
|
||||||
MBB.insert(MBBI, MI);
|
MBB.insert(MBBI, MI);
|
||||||
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(NumBytes - y * 65536).addReg(Alpha::R30);
|
MI=BuildMI(Alpha::LDA, 2, Alpha::R30).addImm(getLower16(NumBytes)).addReg(Alpha::R30);
|
||||||
MBB.insert(MBBI, MI);
|
MBB.insert(MBBI, MI);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Too big a stack frame at " << NumBytes << "\n";
|
std::cerr << "Too big a stack frame at " << NumBytes << "\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user