2005-02-05 02:24:26 +00:00
|
|
|
//===- AlphaRegisterInfo.cpp - Alpha Register Information -------*- C++ -*-===//
|
2005-04-21 23:13:11 +00:00
|
|
|
//
|
2005-01-22 23:41:55 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:13:11 +00:00
|
|
|
//
|
2005-01-22 23:41:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2005-01-24 19:44:07 +00:00
|
|
|
// This file contains the Alpha implementation of the MRegisterInfo class.
|
2005-01-22 23:41:55 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "reginfo"
|
|
|
|
#include "Alpha.h"
|
|
|
|
#include "AlphaRegisterInfo.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/Type.h"
|
2005-04-13 17:17:28 +00:00
|
|
|
#include "llvm/Function.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2006-03-23 18:12:57 +00:00
|
|
|
#include "llvm/CodeGen/MachineLocation.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/Target/TargetFrameInfo.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2006-11-27 23:37:22 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2005-03-04 21:40:02 +00:00
|
|
|
//These describe LDAx
|
2005-03-29 19:24:04 +00:00
|
|
|
static const int IMM_LOW = -32768;
|
|
|
|
static const int IMM_HIGH = 32767;
|
2005-03-05 15:30:33 +00:00
|
|
|
static const int IMM_MULT = 65536;
|
2005-02-22 21:59:48 +00:00
|
|
|
|
|
|
|
static long getUpper16(long l)
|
|
|
|
{
|
2005-03-04 21:40:02 +00:00
|
|
|
long y = l / IMM_MULT;
|
|
|
|
if (l % IMM_MULT > IMM_HIGH)
|
2005-02-22 21:59:48 +00:00
|
|
|
++y;
|
|
|
|
return y;
|
|
|
|
}
|
2005-01-22 23:41:55 +00:00
|
|
|
|
2005-03-04 21:40:02 +00:00
|
|
|
static long getLower16(long l)
|
|
|
|
{
|
|
|
|
long h = getUpper16(l);
|
|
|
|
return l - h * IMM_MULT;
|
|
|
|
}
|
|
|
|
|
2006-11-13 23:36:35 +00:00
|
|
|
AlphaRegisterInfo::AlphaRegisterInfo(const TargetInstrInfo &tii)
|
|
|
|
: AlphaGenRegisterInfo(Alpha::ADJUSTSTACKDOWN, Alpha::ADJUSTSTACKUP),
|
|
|
|
TII(tii)
|
2005-01-22 23:41:55 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-04-21 23:13:11 +00:00
|
|
|
void
|
2005-01-22 23:41:55 +00:00
|
|
|
AlphaRegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
2005-09-30 01:29:42 +00:00
|
|
|
unsigned SrcReg, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2006-12-07 22:21:48 +00:00
|
|
|
//cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
|
|
|
|
// << FrameIdx << "\n";
|
2005-01-22 23:41:55 +00:00
|
|
|
//BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
|
2005-11-09 19:17:08 +00:00
|
|
|
if (RC == Alpha::F4RCRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::STS))
|
2006-09-05 02:31:13 +00:00
|
|
|
.addReg(SrcReg).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-11-09 19:17:08 +00:00
|
|
|
else if (RC == Alpha::F8RCRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::STT))
|
2006-09-05 02:31:13 +00:00
|
|
|
.addReg(SrcReg).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-11-09 19:17:08 +00:00
|
|
|
else if (RC == Alpha::GPRCRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::STQ))
|
2006-09-05 02:31:13 +00:00
|
|
|
.addReg(SrcReg).addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-02-01 20:35:57 +00:00
|
|
|
else
|
|
|
|
abort();
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AlphaRegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
2005-09-30 01:29:42 +00:00
|
|
|
unsigned DestReg, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2006-12-07 22:21:48 +00:00
|
|
|
//cerr << "Trying to load " << getPrettyName(DestReg) << " to "
|
|
|
|
// << FrameIdx << "\n";
|
2005-11-09 19:17:08 +00:00
|
|
|
if (RC == Alpha::F4RCRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::LDS), DestReg)
|
2006-09-05 02:31:13 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-11-09 19:17:08 +00:00
|
|
|
else if (RC == Alpha::F8RCRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::LDT), DestReg)
|
2006-09-05 02:31:13 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-11-09 19:17:08 +00:00
|
|
|
else if (RC == Alpha::GPRCRegisterClass)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::LDQ), DestReg)
|
2006-09-05 02:31:13 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
2005-02-01 20:35:57 +00:00
|
|
|
else
|
|
|
|
abort();
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
|
2005-11-09 19:17:08 +00:00
|
|
|
MachineInstr *AlphaRegisterInfo::foldMemoryOperand(MachineInstr *MI,
|
|
|
|
unsigned OpNum,
|
|
|
|
int FrameIndex) const {
|
2006-01-01 22:13:54 +00:00
|
|
|
// Make sure this is a reg-reg copy.
|
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
|
2006-11-15 20:58:11 +00:00
|
|
|
MachineInstr *NewMI = NULL;
|
2006-01-01 22:13:54 +00:00
|
|
|
switch(Opc) {
|
|
|
|
default:
|
|
|
|
break;
|
2006-10-31 23:46:56 +00:00
|
|
|
case Alpha::BISr:
|
2006-01-01 22:13:54 +00:00
|
|
|
case Alpha::CPYSS:
|
|
|
|
case Alpha::CPYST:
|
|
|
|
if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
|
|
|
|
if (OpNum == 0) { // move -> store
|
|
|
|
unsigned InReg = MI->getOperand(1).getReg();
|
2006-10-31 23:46:56 +00:00
|
|
|
Opc = (Opc == Alpha::BISr) ? Alpha::STQ :
|
2006-01-01 22:13:54 +00:00
|
|
|
((Opc == Alpha::CPYSS) ? Alpha::STS : Alpha::STT);
|
2006-11-27 23:37:22 +00:00
|
|
|
NewMI = BuildMI(TII.get(Opc)).addReg(InReg).addFrameIndex(FrameIndex)
|
2006-01-01 22:13:54 +00:00
|
|
|
.addReg(Alpha::F31);
|
|
|
|
} else { // load -> move
|
|
|
|
unsigned OutReg = MI->getOperand(0).getReg();
|
2006-10-31 23:46:56 +00:00
|
|
|
Opc = (Opc == Alpha::BISr) ? Alpha::LDQ :
|
2006-01-01 22:13:54 +00:00
|
|
|
((Opc == Alpha::CPYSS) ? Alpha::LDS : Alpha::LDT);
|
2006-11-27 23:37:22 +00:00
|
|
|
NewMI = BuildMI(TII.get(Opc), OutReg).addFrameIndex(FrameIndex)
|
2006-01-01 22:13:54 +00:00
|
|
|
.addReg(Alpha::F31);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-11-15 20:58:11 +00:00
|
|
|
if (NewMI)
|
|
|
|
NewMI->copyKillDeadInfo(MI);
|
2005-11-09 19:17:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
void AlphaRegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2006-12-07 22:21:48 +00:00
|
|
|
//cerr << "copyRegToReg " << DestReg << " <- " << SrcReg << "\n";
|
2005-01-22 23:41:55 +00:00
|
|
|
if (RC == Alpha::GPRCRegisterClass) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::BISr), DestReg).addReg(SrcReg).addReg(SrcReg);
|
2005-11-09 19:17:08 +00:00
|
|
|
} else if (RC == Alpha::F4RCRegisterClass) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::CPYSS), DestReg).addReg(SrcReg).addReg(SrcReg);
|
2005-11-09 19:17:08 +00:00
|
|
|
} else if (RC == Alpha::F8RCRegisterClass) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MI, TII.get(Alpha::CPYST), DestReg).addReg(SrcReg).addReg(SrcReg);
|
2005-04-21 23:13:11 +00:00
|
|
|
} else {
|
2006-12-07 22:21:48 +00:00
|
|
|
cerr << "Attempt to copy register that is not GPR or FPR";
|
|
|
|
abort();
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-02 21:33:40 +00:00
|
|
|
const unsigned* AlphaRegisterInfo::getCalleeSavedRegs() const {
|
|
|
|
static const unsigned CalleeSavedRegs[] = {
|
2006-05-18 00:12:58 +00:00
|
|
|
Alpha::R9, Alpha::R10,
|
|
|
|
Alpha::R11, Alpha::R12,
|
|
|
|
Alpha::R13, Alpha::R14,
|
|
|
|
Alpha::F2, Alpha::F3,
|
|
|
|
Alpha::F4, Alpha::F5,
|
|
|
|
Alpha::F6, Alpha::F7,
|
|
|
|
Alpha::F8, Alpha::F9, 0
|
|
|
|
};
|
2007-01-02 21:33:40 +00:00
|
|
|
return CalleeSavedRegs;
|
2006-05-18 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const TargetRegisterClass* const*
|
2007-01-02 21:33:40 +00:00
|
|
|
AlphaRegisterInfo::getCalleeSavedRegClasses() const {
|
|
|
|
static const TargetRegisterClass * const CalleeSavedRegClasses[] = {
|
2006-05-18 00:12:58 +00:00
|
|
|
&Alpha::GPRCRegClass, &Alpha::GPRCRegClass,
|
|
|
|
&Alpha::GPRCRegClass, &Alpha::GPRCRegClass,
|
|
|
|
&Alpha::GPRCRegClass, &Alpha::GPRCRegClass,
|
|
|
|
&Alpha::F8RCRegClass, &Alpha::F8RCRegClass,
|
|
|
|
&Alpha::F8RCRegClass, &Alpha::F8RCRegClass,
|
|
|
|
&Alpha::F8RCRegClass, &Alpha::F8RCRegClass,
|
|
|
|
&Alpha::F8RCRegClass, &Alpha::F8RCRegClass, 0
|
|
|
|
};
|
2007-01-02 21:33:40 +00:00
|
|
|
return CalleeSavedRegClasses;
|
2006-05-18 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stack Frame Processing methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
//
|
2006-08-17 22:00:08 +00:00
|
|
|
static bool hasFP(const MachineFunction &MF) {
|
2005-01-22 23:41:55 +00:00
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
return MFI->hasVarSizedObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaRegisterInfo::
|
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
|
|
|
if (hasFP(MF)) {
|
|
|
|
// If we have a frame pointer, turn the adjcallstackup instruction into a
|
|
|
|
// 'sub ESP, <amt>' and the adjcallstackdown instruction into 'add ESP,
|
|
|
|
// <amt>'
|
|
|
|
MachineInstr *Old = I;
|
2006-05-17 19:24:49 +00:00
|
|
|
uint64_t Amount = Old->getOperand(0).getImmedValue();
|
2005-01-22 23:41:55 +00:00
|
|
|
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 = MF.getTarget().getFrameInfo()->getStackAlignment();
|
|
|
|
Amount = (Amount+Align-1)/Align*Align;
|
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
MachineInstr *New;
|
|
|
|
if (Old->getOpcode() == Alpha::ADJUSTSTACKDOWN) {
|
2006-11-27 23:37:22 +00:00
|
|
|
New=BuildMI(TII.get(Alpha::LDA), Alpha::R30)
|
2005-02-22 21:59:48 +00:00
|
|
|
.addImm(-Amount).addReg(Alpha::R30);
|
|
|
|
} else {
|
2005-04-22 17:54:37 +00:00
|
|
|
assert(Old->getOpcode() == Alpha::ADJUSTSTACKUP);
|
2006-11-27 23:37:22 +00:00
|
|
|
New=BuildMI(TII.get(Alpha::LDA), Alpha::R30)
|
2005-02-22 21:59:48 +00:00
|
|
|
.addImm(Amount).addReg(Alpha::R30);
|
|
|
|
}
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// Replace the pseudo instruction with a new instruction...
|
2005-02-22 21:59:48 +00:00
|
|
|
MBB.insert(I, New);
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MBB.erase(I);
|
|
|
|
}
|
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
//Alpha has a slightly funny stack:
|
2005-04-21 23:13:11 +00:00
|
|
|
//Args
|
2005-02-22 21:59:48 +00:00
|
|
|
//<- incoming SP
|
|
|
|
//fixed locals (and spills, callee saved, etc)
|
|
|
|
//<- FP
|
|
|
|
//variable locals
|
|
|
|
//<- SP
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
void
|
|
|
|
AlphaRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
|
2005-01-30 00:35:27 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
MachineInstr &MI = *II;
|
|
|
|
MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
2005-02-22 21:59:48 +00:00
|
|
|
bool FP = hasFP(MF);
|
|
|
|
|
2005-01-30 00:35:27 +00:00
|
|
|
while (!MI.getOperand(i).isFrameIndex()) {
|
|
|
|
++i;
|
|
|
|
assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
|
|
|
|
}
|
2005-01-22 23:41:55 +00:00
|
|
|
|
2005-01-30 00:35:27 +00:00
|
|
|
int FrameIndex = MI.getOperand(i).getFrameIndex();
|
2005-01-22 23:41:55 +00:00
|
|
|
|
2005-01-30 00:35:27 +00:00
|
|
|
// Add the base register of R30 (SP) or R15 (FP).
|
2006-09-05 02:31:13 +00:00
|
|
|
MI.getOperand(i + 1).ChangeToRegister(FP ? Alpha::R15 : Alpha::R30, false);
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
// Now add the frame object offset to the offset from the virtual frame index.
|
2005-01-30 00:35:27 +00:00
|
|
|
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
|
|
|
|
|
2006-12-07 22:21:48 +00:00
|
|
|
DOUT << "FI: " << FrameIndex << " Offset: " << Offset << "\n";
|
2005-02-22 21:59:48 +00:00
|
|
|
|
2005-01-30 00:35:27 +00:00
|
|
|
Offset += MF.getFrameInfo()->getStackSize();
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2006-12-07 22:21:48 +00:00
|
|
|
DOUT << "Corrected Offset " << Offset
|
|
|
|
<< " for stack size: " << MF.getFrameInfo()->getStackSize() << "\n";
|
2005-01-30 00:35:27 +00:00
|
|
|
|
2005-03-04 21:40:02 +00:00
|
|
|
if (Offset > IMM_HIGH || Offset < IMM_LOW) {
|
2006-12-07 22:21:48 +00:00
|
|
|
DOUT << "Unconditionally using R28 for evil purposes Offset: "
|
|
|
|
<< Offset << "\n";
|
2006-09-05 02:31:13 +00:00
|
|
|
//so in this case, we need to use a temporary register, and move the
|
|
|
|
//original inst off the SP/FP
|
2005-02-22 21:59:48 +00:00
|
|
|
//fix up the old:
|
2006-09-05 02:31:13 +00:00
|
|
|
MI.getOperand(i + 1).ChangeToRegister(Alpha::R28, false);
|
2006-05-04 17:52:23 +00:00
|
|
|
MI.getOperand(i).ChangeToImmediate(getLower16(Offset));
|
2005-02-22 21:59:48 +00:00
|
|
|
//insert the new
|
2006-11-27 23:37:22 +00:00
|
|
|
MachineInstr* nMI=BuildMI(TII.get(Alpha::LDAH), Alpha::R28)
|
2005-02-22 21:59:48 +00:00
|
|
|
.addImm(getUpper16(Offset)).addReg(FP ? Alpha::R15 : Alpha::R30);
|
2005-03-13 00:43:20 +00:00
|
|
|
MBB.insert(II, nMI);
|
2005-02-22 21:59:48 +00:00
|
|
|
} else {
|
2006-05-04 17:52:23 +00:00
|
|
|
MI.getOperand(i).ChangeToImmediate(Offset);
|
2005-02-22 21:59:48 +00:00
|
|
|
}
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const {
|
|
|
|
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
|
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2005-02-22 21:59:48 +00:00
|
|
|
bool FP = hasFP(MF);
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2005-07-22 20:52:16 +00:00
|
|
|
static int curgpdist = 0;
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
//handle GOP offset
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDAHg), Alpha::R29)
|
2005-07-22 20:52:16 +00:00
|
|
|
.addGlobalAddress(const_cast<Function*>(MF.getFunction()))
|
|
|
|
.addReg(Alpha::R27).addImm(++curgpdist);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDAg), Alpha::R29)
|
2005-07-22 20:52:16 +00:00
|
|
|
.addGlobalAddress(const_cast<Function*>(MF.getFunction()))
|
|
|
|
.addReg(Alpha::R29).addImm(curgpdist);
|
|
|
|
|
2005-04-13 17:17:28 +00:00
|
|
|
//evil const_cast until MO stuff setup to handle const
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::ALTENT))
|
2006-05-04 01:15:02 +00:00
|
|
|
.addGlobalAddress(const_cast<Function*>(MF.getFunction()));
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// Get the number of bytes to allocate from the FrameInfo
|
2005-03-04 21:40:02 +00:00
|
|
|
long NumBytes = MFI->getStackSize();
|
2005-01-22 23:41:55 +00:00
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
if (MFI->hasCalls() && !FP) {
|
2005-04-21 23:13:11 +00:00
|
|
|
// We reserve argument space for call sites in the function immediately on
|
|
|
|
// entry to the current function. This eliminates the need for add/sub
|
2005-01-30 00:35:27 +00:00
|
|
|
// brackets around call sites.
|
2005-02-22 21:59:48 +00:00
|
|
|
//If there is a frame pointer, then we don't do this
|
2005-01-30 00:35:27 +00:00
|
|
|
NumBytes += MFI->getMaxCallFrameSize();
|
2006-12-07 22:21:48 +00:00
|
|
|
DOUT << "Added " << MFI->getMaxCallFrameSize()
|
|
|
|
<< " to the stack due to calls\n";
|
2005-01-30 00:35:27 +00:00
|
|
|
}
|
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
if (FP)
|
|
|
|
NumBytes += 8; //reserve space for the old FP
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// Do we need to allocate space on the stack?
|
|
|
|
if (NumBytes == 0) return;
|
|
|
|
|
2006-01-25 01:51:08 +00:00
|
|
|
unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
|
|
|
|
NumBytes = (NumBytes+Align-1)/Align*Align;
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// Update frame info to pretend that this is part of the stack...
|
|
|
|
MFI->setStackSize(NumBytes);
|
2005-02-22 21:59:48 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// adjust stack pointer: r30 -= numbytes
|
2005-03-04 21:40:02 +00:00
|
|
|
NumBytes = -NumBytes;
|
|
|
|
if (NumBytes >= IMM_LOW) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDA), Alpha::R30).addImm(NumBytes)
|
2005-07-07 19:52:58 +00:00
|
|
|
.addReg(Alpha::R30);
|
2005-03-04 21:40:02 +00:00
|
|
|
} else if (getUpper16(NumBytes) >= IMM_LOW) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDAH), Alpha::R30).addImm(getUpper16(NumBytes))
|
2005-07-07 19:52:58 +00:00
|
|
|
.addReg(Alpha::R30);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDA), Alpha::R30).addImm(getLower16(NumBytes))
|
2005-07-07 19:52:58 +00:00
|
|
|
.addReg(Alpha::R30);
|
2005-01-26 21:54:09 +00:00
|
|
|
} else {
|
2006-12-07 22:21:48 +00:00
|
|
|
cerr << "Too big a stack frame at " << NumBytes << "\n";
|
2005-01-26 21:54:09 +00:00
|
|
|
abort();
|
|
|
|
}
|
2005-02-22 21:59:48 +00:00
|
|
|
|
|
|
|
//now if we need to, save the old FP and set the new
|
|
|
|
if (FP)
|
|
|
|
{
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::STQ))
|
2006-09-05 02:31:13 +00:00
|
|
|
.addReg(Alpha::R15).addImm(0).addReg(Alpha::R30);
|
2005-02-22 21:59:48 +00:00
|
|
|
//this must be the last instr in the prolog
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::BISr), Alpha::R15)
|
2006-09-05 02:31:13 +00:00
|
|
|
.addReg(Alpha::R30).addReg(Alpha::R30);
|
2005-02-22 21:59:48 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB) const {
|
|
|
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
MachineBasicBlock::iterator MBBI = prior(MBB.end());
|
2006-09-05 02:31:13 +00:00
|
|
|
assert(MBBI->getOpcode() == Alpha::RETDAG ||
|
|
|
|
MBBI->getOpcode() == Alpha::RETDAGp
|
2005-04-22 17:54:37 +00:00
|
|
|
&& "Can only insert epilog into returning blocks");
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
bool FP = hasFP(MF);
|
2005-04-21 23:13:11 +00:00
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
// Get the number of bytes allocated from the FrameInfo...
|
2005-03-05 15:30:33 +00:00
|
|
|
long NumBytes = MFI->getStackSize();
|
2005-01-22 23:41:55 +00:00
|
|
|
|
2005-02-22 21:59:48 +00:00
|
|
|
//now if we need to, restore the old FP
|
|
|
|
if (FP)
|
|
|
|
{
|
2005-02-24 18:36:32 +00:00
|
|
|
//copy the FP into the SP (discards allocas)
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::BISr), Alpha::R30).addReg(Alpha::R15)
|
2005-07-07 19:52:58 +00:00
|
|
|
.addReg(Alpha::R15);
|
2005-02-24 18:36:32 +00:00
|
|
|
//restore the FP
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDQ), Alpha::R15).addImm(0).addReg(Alpha::R15);
|
2005-02-22 21:59:48 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 23:13:11 +00:00
|
|
|
if (NumBytes != 0)
|
2005-01-22 23:41:55 +00:00
|
|
|
{
|
2005-03-04 21:40:02 +00:00
|
|
|
if (NumBytes <= IMM_HIGH) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDA), Alpha::R30).addImm(NumBytes)
|
2005-07-07 19:52:58 +00:00
|
|
|
.addReg(Alpha::R30);
|
2005-03-04 21:40:02 +00:00
|
|
|
} else if (getUpper16(NumBytes) <= IMM_HIGH) {
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDAH), Alpha::R30)
|
2005-07-07 19:52:58 +00:00
|
|
|
.addImm(getUpper16(NumBytes)).addReg(Alpha::R30);
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(MBB, MBBI, TII.get(Alpha::LDA), Alpha::R30)
|
2005-07-07 19:52:58 +00:00
|
|
|
.addImm(getLower16(NumBytes)).addReg(Alpha::R30);
|
2005-01-27 08:31:19 +00:00
|
|
|
} else {
|
2006-12-07 22:21:48 +00:00
|
|
|
cerr << "Too big a stack frame at " << NumBytes << "\n";
|
2005-01-27 08:31:19 +00:00
|
|
|
abort();
|
|
|
|
}
|
2005-01-22 23:41:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-07 16:34:46 +00:00
|
|
|
unsigned AlphaRegisterInfo::getRARegister() const {
|
|
|
|
assert(0 && "What is the return address register");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-28 13:48:33 +00:00
|
|
|
unsigned AlphaRegisterInfo::getFrameRegister(MachineFunction &MF) const {
|
2006-04-07 16:34:46 +00:00
|
|
|
return hasFP(MF) ? Alpha::R15 : Alpha::R30;
|
2006-03-23 18:12:57 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "AlphaGenRegisterInfo.inc"
|
|
|
|
|
|
|
|
std::string AlphaRegisterInfo::getPrettyName(unsigned reg)
|
|
|
|
{
|
|
|
|
std::string s(RegisterDescriptors[reg].Name);
|
|
|
|
return s;
|
|
|
|
}
|