2004-02-25 19:28:19 +00:00
|
|
|
//===- SparcV8RegisterInfo.cpp - SparcV8 Register Information ---*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +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:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the SparcV8 implementation of the MRegisterInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SparcV8.h"
|
|
|
|
#include "SparcV8RegisterInfo.h"
|
2004-02-29 05:18:30 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2004-04-02 20:53:37 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2004-02-25 19:28:19 +00:00
|
|
|
#include "llvm/Type.h"
|
2004-09-02 02:37:43 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2004-07-04 17:19:21 +00:00
|
|
|
#include <iostream>
|
2004-02-25 19:28:19 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
SparcV8RegisterInfo::SparcV8RegisterInfo()
|
2004-02-28 19:37:18 +00:00
|
|
|
: SparcV8GenRegisterInfo(V8::ADJCALLSTACKDOWN,
|
|
|
|
V8::ADJCALLSTACKUP) {}
|
2004-02-25 19:28:19 +00:00
|
|
|
|
2004-08-15 22:15:11 +00:00
|
|
|
void SparcV8RegisterInfo::
|
2004-08-15 21:56:44 +00:00
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
2005-09-30 01:29:42 +00:00
|
|
|
unsigned SrcReg, int FrameIdx,
|
2005-12-17 20:18:49 +00:00
|
|
|
const TargetRegisterClass *RC) const {
|
2004-06-17 22:34:48 +00:00
|
|
|
// On the order of operands here: think "[FrameIdx + 0] = SrcReg".
|
2005-08-19 18:50:11 +00:00
|
|
|
if (RC == V8::IntRegsRegisterClass)
|
2005-12-17 20:18:49 +00:00
|
|
|
BuildMI (MBB, I, V8::STri, 3).addFrameIndex (FrameIdx).addSImm (0)
|
2004-06-27 22:59:56 +00:00
|
|
|
.addReg (SrcReg);
|
2005-08-19 18:50:11 +00:00
|
|
|
else if (RC == V8::FPRegsRegisterClass)
|
2004-06-27 22:59:56 +00:00
|
|
|
BuildMI (MBB, I, V8::STFri, 3).addFrameIndex (FrameIdx).addSImm (0)
|
|
|
|
.addReg (SrcReg);
|
2005-08-19 18:50:11 +00:00
|
|
|
else if (RC == V8::DFPRegsRegisterClass)
|
2004-06-27 22:59:56 +00:00
|
|
|
BuildMI (MBB, I, V8::STDFri, 3).addFrameIndex (FrameIdx).addSImm (0)
|
|
|
|
.addReg (SrcReg);
|
|
|
|
else
|
|
|
|
assert (0 && "Can't store this register to stack slot");
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2004-08-15 22:15:11 +00:00
|
|
|
void SparcV8RegisterInfo::
|
2004-08-15 21:56:44 +00:00
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
2005-09-30 01:29:42 +00:00
|
|
|
unsigned DestReg, int FrameIdx,
|
2005-12-17 20:18:49 +00:00
|
|
|
const TargetRegisterClass *RC) const {
|
2005-08-19 18:50:11 +00:00
|
|
|
if (RC == V8::IntRegsRegisterClass)
|
2005-12-17 20:18:49 +00:00
|
|
|
BuildMI (MBB, I, V8::LDri, 2, DestReg).addFrameIndex (FrameIdx).addSImm (0);
|
2005-08-19 18:50:11 +00:00
|
|
|
else if (RC == V8::FPRegsRegisterClass)
|
2004-06-27 22:59:56 +00:00
|
|
|
BuildMI (MBB, I, V8::LDFri, 2, DestReg).addFrameIndex (FrameIdx)
|
|
|
|
.addSImm (0);
|
2005-08-19 18:50:11 +00:00
|
|
|
else if (RC == V8::DFPRegsRegisterClass)
|
2004-06-27 22:59:56 +00:00
|
|
|
BuildMI (MBB, I, V8::LDDFri, 2, DestReg).addFrameIndex (FrameIdx)
|
|
|
|
.addSImm (0);
|
|
|
|
else
|
2004-08-15 22:15:11 +00:00
|
|
|
assert(0 && "Can't load this register from stack slot");
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2004-08-15 22:15:11 +00:00
|
|
|
void SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2005-08-19 18:50:11 +00:00
|
|
|
if (RC == V8::IntRegsRegisterClass)
|
2004-06-27 22:59:56 +00:00
|
|
|
BuildMI (MBB, I, V8::ORrr, 2, DestReg).addReg (V8::G0).addReg (SrcReg);
|
2005-08-19 18:50:11 +00:00
|
|
|
else if (RC == V8::FPRegsRegisterClass)
|
2004-06-27 22:59:56 +00:00
|
|
|
BuildMI (MBB, I, V8::FMOVS, 1, DestReg).addReg (SrcReg);
|
2005-08-19 18:50:11 +00:00
|
|
|
else if (RC == V8::DFPRegsRegisterClass)
|
2004-09-29 03:27:30 +00:00
|
|
|
BuildMI (MBB, I, V8::FpMOVD, 1, DestReg).addReg (SrcReg);
|
2004-06-27 22:59:56 +00:00
|
|
|
else
|
|
|
|
assert (0 && "Can't copy this register");
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SparcV8RegisterInfo::
|
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2004-10-10 19:57:21 +00:00
|
|
|
MachineInstr &MI = *I;
|
2005-12-19 02:51:12 +00:00
|
|
|
int Size = MI.getOperand(0).getImmedValue();
|
|
|
|
if (MI.getOpcode() == V8::ADJCALLSTACKDOWN)
|
|
|
|
Size = -Size;
|
|
|
|
if (Size)
|
|
|
|
BuildMI(MBB, I, V8::ADDri, 2, V8::O6).addReg(V8::O6).addSImm(Size);
|
|
|
|
MBB.erase(I);
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-14 22:57:22 +00:00
|
|
|
SparcV8RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II) const {
|
2004-04-02 20:53:37 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
MachineInstr &MI = *II;
|
|
|
|
while (!MI.getOperand(i).isFrameIndex()) {
|
|
|
|
++i;
|
|
|
|
assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
|
|
|
|
}
|
|
|
|
|
|
|
|
int FrameIndex = MI.getOperand(i).getFrameIndex();
|
|
|
|
|
2004-04-06 22:10:22 +00:00
|
|
|
// Addressable stack objects are accessed using neg. offsets from %fp
|
2004-08-14 22:57:22 +00:00
|
|
|
MachineFunction &MF = *MI.getParent()->getParent();
|
2004-04-06 22:10:22 +00:00
|
|
|
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
|
|
|
|
MI.getOperand(i+1).getImmedValue();
|
Reserve G1 for frame offset stuff and use it to handle large stack frames.
For example, instead of emitting this:
test:
save -40112, %o6, %o6 ;; imm too large
add %i6, -40016, %o0 ;; imm too large
call caller
nop
restore %g0, %g0, %g0
retl
nop
emit this:
test:
sethi 4194264, %g1
or %g1, 848, %g1
save %o6, %g1, %o6
sethi 4194264, %g1
add %g1, %i6, %g1
add %i1, 944, %o0
call caller
nop
restore %g0, %g0, %g0
retl
nop
which doesn't cause the assembler to barf.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24880 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-20 07:56:31 +00:00
|
|
|
|
|
|
|
// Replace frame index with a frame pointer reference.
|
|
|
|
if (Offset >= -4096 && Offset <= 4095) {
|
|
|
|
// If the offset is small enough to fit in the immediate field, directly
|
|
|
|
// encode it.
|
|
|
|
MI.SetMachineOperandReg(i, V8::I6);
|
|
|
|
MI.SetMachineOperandConst(i+1, MachineOperand::MO_SignExtendedImmed,Offset);
|
|
|
|
} else {
|
|
|
|
// Otherwise, emit a G1 = SETHI %hi(offset). FIXME: it would be better to
|
|
|
|
// scavenge a register here instead of reserving G1 all of the time.
|
|
|
|
unsigned OffHi = (unsigned)Offset >> 10U;
|
|
|
|
BuildMI(*MI.getParent(), II, V8::SETHIi, 1, V8::G1).addImm(OffHi);
|
|
|
|
// Emit G1 = G1 + I6
|
|
|
|
BuildMI(*MI.getParent(), II, V8::ADDrr, 2,
|
|
|
|
V8::G1).addReg(V8::G1).addReg(V8::I6);
|
|
|
|
// Insert: G1+%lo(offset) into the user.
|
|
|
|
MI.SetMachineOperandReg(i, V8::I1);
|
|
|
|
MI.SetMachineOperandConst(i+1, MachineOperand::MO_SignExtendedImmed,
|
|
|
|
Offset & ((1 << 10)-1));
|
|
|
|
}
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2004-02-29 05:18:30 +00:00
|
|
|
void SparcV8RegisterInfo::
|
|
|
|
processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
|
2004-02-25 19:28:19 +00:00
|
|
|
|
|
|
|
void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
2004-02-29 05:18:30 +00:00
|
|
|
MachineBasicBlock &MBB = MF.front();
|
2004-04-02 20:53:37 +00:00
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2004-02-29 05:18:30 +00:00
|
|
|
|
2004-04-02 20:53:37 +00:00
|
|
|
// Get the number of bytes to allocate from the FrameInfo
|
2004-04-13 18:28:37 +00:00
|
|
|
int NumBytes = (int) MFI->getStackSize();
|
2004-04-02 20:53:37 +00:00
|
|
|
|
2004-10-10 19:57:21 +00:00
|
|
|
// Emit the correct save instruction based on the number of bytes in
|
|
|
|
// the frame. Minimum stack frame size according to V8 ABI is:
|
2004-04-02 20:53:37 +00:00
|
|
|
// 16 words for register window spill
|
|
|
|
// 1 word for address of returned aggregate-value
|
|
|
|
// + 6 words for passing parameters on the stack
|
|
|
|
// ----------
|
|
|
|
// 23 words * 4 bytes per word = 92 bytes
|
|
|
|
NumBytes += 92;
|
2004-06-17 22:34:48 +00:00
|
|
|
// Round up to next doubleword boundary -- a double-word boundary
|
|
|
|
// is required by the ABI.
|
|
|
|
NumBytes = (NumBytes + 7) & ~7;
|
Reserve G1 for frame offset stuff and use it to handle large stack frames.
For example, instead of emitting this:
test:
save -40112, %o6, %o6 ;; imm too large
add %i6, -40016, %o0 ;; imm too large
call caller
nop
restore %g0, %g0, %g0
retl
nop
emit this:
test:
sethi 4194264, %g1
or %g1, 848, %g1
save %o6, %g1, %o6
sethi 4194264, %g1
add %g1, %i6, %g1
add %i1, 944, %o0
call caller
nop
restore %g0, %g0, %g0
retl
nop
which doesn't cause the assembler to barf.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24880 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-20 07:56:31 +00:00
|
|
|
NumBytes = -NumBytes;
|
|
|
|
|
|
|
|
if (NumBytes >= -4096) {
|
|
|
|
BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
|
|
|
|
V8::O6).addImm(NumBytes).addReg(V8::O6);
|
|
|
|
} else {
|
|
|
|
MachineBasicBlock::iterator InsertPt = MBB.begin();
|
|
|
|
// Emit this the hard way. This clobbers G1 which we always know is
|
|
|
|
// available here.
|
|
|
|
unsigned OffHi = (unsigned)NumBytes >> 10U;
|
|
|
|
BuildMI(MBB, InsertPt, V8::SETHIi, 1, V8::G1).addImm(OffHi);
|
|
|
|
// Emit G1 = G1 + I6
|
|
|
|
BuildMI(MBB, InsertPt, V8::ORri, 2, V8::G1)
|
|
|
|
.addReg(V8::G1).addImm(NumBytes & ((1 << 10)-1));
|
|
|
|
BuildMI(MBB, InsertPt, V8::SAVErr, 2,
|
|
|
|
V8::O6).addReg(V8::O6).addReg(V8::G1);
|
|
|
|
}
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB) const {
|
2004-02-29 05:18:30 +00:00
|
|
|
MachineBasicBlock::iterator MBBI = prior(MBB.end());
|
2006-01-09 18:28:21 +00:00
|
|
|
assert(MBBI->getOpcode() == V8::RETL &&
|
2004-03-06 05:31:21 +00:00
|
|
|
"Can only put epilog before 'retl' instruction!");
|
|
|
|
BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "SparcV8GenRegisterInfo.inc"
|
|
|
|
|
|
|
|
const TargetRegisterClass*
|
|
|
|
SparcV8RegisterInfo::getRegClassForType(const Type* Ty) const {
|
2004-06-17 18:19:28 +00:00
|
|
|
switch (Ty->getTypeID()) {
|
2005-08-19 18:50:11 +00:00
|
|
|
case Type::FloatTyID: return V8::FPRegsRegisterClass;
|
|
|
|
case Type::DoubleTyID: return V8::DFPRegsRegisterClass;
|
2004-02-25 19:28:19 +00:00
|
|
|
case Type::LongTyID:
|
2004-06-24 08:55:21 +00:00
|
|
|
case Type::ULongTyID: assert(0 && "Long values do not fit in registers!");
|
2004-06-22 20:14:41 +00:00
|
|
|
default: assert(0 && "Invalid type to getClass!");
|
2004-02-25 19:28:19 +00:00
|
|
|
case Type::BoolTyID:
|
|
|
|
case Type::SByteTyID:
|
|
|
|
case Type::UByteTyID:
|
|
|
|
case Type::ShortTyID:
|
|
|
|
case Type::UShortTyID:
|
|
|
|
case Type::IntTyID:
|
|
|
|
case Type::UIntTyID:
|
2005-08-19 18:50:11 +00:00
|
|
|
case Type::PointerTyID: return V8::IntRegsRegisterClass;
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|