2006-02-05 05:50:24 +00:00
|
|
|
//===- SparcRegisterInfo.cpp - SPARC Register Information -------*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file 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
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-02-10 18:45:23 +00:00
|
|
|
// This file contains the SPARC implementation of the TargetRegisterInfo class.
|
2004-02-25 19:28:19 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "Sparc.h"
|
|
|
|
#include "SparcRegisterInfo.h"
|
|
|
|
#include "SparcSubtarget.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"
|
2006-03-23 18:12:57 +00:00
|
|
|
#include "llvm/CodeGen/MachineLocation.h"
|
2006-11-27 23:37:22 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2004-02-25 19:28:19 +00:00
|
|
|
#include "llvm/Type.h"
|
2007-02-19 21:49:54 +00:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2004-09-02 02:37:43 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2004-02-25 19:28:19 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2006-11-13 23:36:35 +00:00
|
|
|
SparcRegisterInfo::SparcRegisterInfo(SparcSubtarget &st,
|
|
|
|
const TargetInstrInfo &tii)
|
2006-02-05 05:50:24 +00:00
|
|
|
: SparcGenRegisterInfo(SP::ADJCALLSTACKDOWN, SP::ADJCALLSTACKUP),
|
2006-11-13 23:36:35 +00:00
|
|
|
Subtarget(st), TII(tii) {
|
2006-02-04 06:58:46 +00:00
|
|
|
}
|
2004-02-25 19:28:19 +00:00
|
|
|
|
2007-07-14 14:06:15 +00:00
|
|
|
const unsigned* SparcRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF)
|
|
|
|
const {
|
2007-01-02 21:33:40 +00:00
|
|
|
static const unsigned CalleeSavedRegs[] = { 0 };
|
|
|
|
return CalleeSavedRegs;
|
2006-05-18 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2007-02-19 21:49:54 +00:00
|
|
|
BitVector SparcRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
|
|
|
|
BitVector Reserved(getNumRegs());
|
|
|
|
Reserved.set(SP::G2);
|
|
|
|
Reserved.set(SP::G3);
|
|
|
|
Reserved.set(SP::G4);
|
|
|
|
Reserved.set(SP::O6);
|
|
|
|
Reserved.set(SP::I6);
|
|
|
|
Reserved.set(SP::I7);
|
|
|
|
Reserved.set(SP::G0);
|
|
|
|
Reserved.set(SP::G5);
|
|
|
|
Reserved.set(SP::G6);
|
|
|
|
Reserved.set(SP::G7);
|
|
|
|
return Reserved;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-18 00:12:58 +00:00
|
|
|
const TargetRegisterClass* const*
|
2007-07-14 14:06:15 +00:00
|
|
|
SparcRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const {
|
2007-01-02 21:33:40 +00:00
|
|
|
static const TargetRegisterClass * const CalleeSavedRegClasses[] = { 0 };
|
|
|
|
return CalleeSavedRegClasses;
|
2006-05-18 00:12:58 +00:00
|
|
|
}
|
|
|
|
|
2007-01-23 00:57:47 +00:00
|
|
|
bool SparcRegisterInfo::hasFP(const MachineFunction &MF) const {
|
|
|
|
return false;
|
|
|
|
}
|
2006-05-18 00:12:58 +00:00
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
void SparcRegisterInfo::
|
2004-02-25 19:28:19 +00:00
|
|
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const {
|
2004-10-10 19:57:21 +00:00
|
|
|
MachineInstr &MI = *I;
|
2009-02-13 02:31:35 +00:00
|
|
|
DebugLoc dl = MI.getDebugLoc();
|
2007-12-30 20:49:49 +00:00
|
|
|
int Size = MI.getOperand(0).getImm();
|
2006-02-05 05:50:24 +00:00
|
|
|
if (MI.getOpcode() == SP::ADJCALLSTACKDOWN)
|
2005-12-19 02:51:12 +00:00
|
|
|
Size = -Size;
|
|
|
|
if (Size)
|
2009-02-13 02:31:35 +00:00
|
|
|
BuildMI(MBB, I, dl, TII.get(SP::ADDri), SP::O6).addReg(SP::O6).addImm(Size);
|
2005-12-19 02:51:12 +00:00
|
|
|
MBB.erase(I);
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2007-02-28 00:21:17 +00:00
|
|
|
void SparcRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
|
2007-05-01 09:13:03 +00:00
|
|
|
int SPAdj, RegScavenger *RS) const {
|
|
|
|
assert(SPAdj == 0 && "Unexpected");
|
|
|
|
|
2004-04-02 20:53:37 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
MachineInstr &MI = *II;
|
2009-02-13 02:31:35 +00:00
|
|
|
DebugLoc dl = MI.getDebugLoc();
|
2008-10-03 15:45:36 +00:00
|
|
|
while (!MI.getOperand(i).isFI()) {
|
2004-04-02 20:53:37 +00:00
|
|
|
++i;
|
|
|
|
assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
|
|
|
|
}
|
|
|
|
|
2007-12-30 23:10:15 +00:00
|
|
|
int FrameIndex = MI.getOperand(i).getIndex();
|
2004-04-02 20:53:37 +00:00
|
|
|
|
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) +
|
2007-12-30 20:49:49 +00:00
|
|
|
MI.getOperand(i+1).getImm();
|
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.
|
2006-09-05 02:31:13 +00:00
|
|
|
MI.getOperand(i).ChangeToRegister(SP::I6, false);
|
2006-05-04 17:52:23 +00:00
|
|
|
MI.getOperand(i+1).ChangeToImmediate(Offset);
|
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
|
|
|
} 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;
|
2009-02-13 02:31:35 +00:00
|
|
|
BuildMI(*MI.getParent(), II, dl, TII.get(SP::SETHIi), SP::G1).addImm(OffHi);
|
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
|
|
|
// Emit G1 = G1 + I6
|
2009-02-13 02:31:35 +00:00
|
|
|
BuildMI(*MI.getParent(), II, dl, TII.get(SP::ADDrr), SP::G1).addReg(SP::G1)
|
2006-11-27 23:37:22 +00:00
|
|
|
.addReg(SP::I6);
|
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
|
|
|
// Insert: G1+%lo(offset) into the user.
|
2006-09-05 02:31:13 +00:00
|
|
|
MI.getOperand(i).ChangeToRegister(SP::G1, false);
|
2006-05-04 17:52:23 +00:00
|
|
|
MI.getOperand(i+1).ChangeToImmediate(Offset & ((1 << 10)-1));
|
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
|
|
|
}
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
void SparcRegisterInfo::
|
2004-02-29 05:18:30 +00:00
|
|
|
processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
|
2004-02-25 19:28:19 +00:00
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
void SparcRegisterInfo::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();
|
2009-02-23 00:42:30 +00:00
|
|
|
MachineBasicBlock::iterator MBBI = MBB.begin();
|
|
|
|
DebugLoc dl = (MBBI != MBB.end() ?
|
|
|
|
MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
|
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;
|
2009-02-23 00:42:30 +00:00
|
|
|
|
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) {
|
2009-02-23 00:42:30 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(SP::SAVEri), SP::O6)
|
|
|
|
.addReg(SP::O6).addImm(NumBytes);
|
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
|
|
|
} else {
|
|
|
|
// Emit this the hard way. This clobbers G1 which we always know is
|
|
|
|
// available here.
|
|
|
|
unsigned OffHi = (unsigned)NumBytes >> 10U;
|
2009-02-23 00:42:30 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(SP::SETHIi), SP::G1).addImm(OffHi);
|
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
|
|
|
// Emit G1 = G1 + I6
|
2009-02-23 00:42:30 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(SP::ORri), SP::G1)
|
2006-02-05 05:50:24 +00:00
|
|
|
.addReg(SP::G1).addImm(NumBytes & ((1 << 10)-1));
|
2009-02-23 00:42:30 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(SP::SAVErr), SP::O6)
|
2006-11-27 23:37:22 +00:00
|
|
|
.addReg(SP::O6).addReg(SP::G1);
|
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
|
|
|
}
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
void SparcRegisterInfo::emitEpilogue(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB) const {
|
2004-02-29 05:18:30 +00:00
|
|
|
MachineBasicBlock::iterator MBBI = prior(MBB.end());
|
2009-02-23 00:42:30 +00:00
|
|
|
DebugLoc dl = MBBI->getDebugLoc();
|
2006-02-05 05:50:24 +00:00
|
|
|
assert(MBBI->getOpcode() == SP::RETL &&
|
2004-03-06 05:31:21 +00:00
|
|
|
"Can only put epilog before 'retl' instruction!");
|
2009-02-13 02:31:35 +00:00
|
|
|
BuildMI(MBB, MBBI, dl, TII.get(SP::RESTORErr), SP::G0).addReg(SP::G0)
|
2006-11-27 23:37:22 +00:00
|
|
|
.addReg(SP::G0);
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2006-04-07 16:34:46 +00:00
|
|
|
unsigned SparcRegisterInfo::getRARegister() const {
|
|
|
|
assert(0 && "What is the return address register");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-28 13:48:33 +00:00
|
|
|
unsigned SparcRegisterInfo::getFrameRegister(MachineFunction &MF) const {
|
2006-04-07 16:34:46 +00:00
|
|
|
assert(0 && "What is the frame register");
|
|
|
|
return SP::G1;
|
2006-03-23 18:12:57 +00:00
|
|
|
}
|
|
|
|
|
2007-02-21 22:54:50 +00:00
|
|
|
unsigned SparcRegisterInfo::getEHExceptionRegister() const {
|
|
|
|
assert(0 && "What is the exception register");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned SparcRegisterInfo::getEHHandlerRegister() const {
|
|
|
|
assert(0 && "What is the exception handler register");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-13 19:13:01 +00:00
|
|
|
int SparcRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
|
2007-11-11 19:50:10 +00:00
|
|
|
assert(0 && "What is the dwarf register number");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "SparcGenRegisterInfo.inc"
|
2004-02-25 19:28:19 +00:00
|
|
|
|