mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
Add support for many of the MRegisterInfo callbacks.
Eliminating call-frame pseudo instrs and frame indices are still stubs. Flesh out the emitPrologue method based on better ABI knowledge. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12632 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include "SparcV8RegisterInfo.h"
|
#include "SparcV8RegisterInfo.h"
|
||||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -29,8 +30,12 @@ int SparcV8RegisterInfo::storeRegToStackSlot(
|
|||||||
unsigned SrcReg, int FrameIdx,
|
unsigned SrcReg, int FrameIdx,
|
||||||
const TargetRegisterClass *RC) const
|
const TargetRegisterClass *RC) const
|
||||||
{
|
{
|
||||||
abort();
|
assert (RC == SparcV8::IntRegsRegisterClass
|
||||||
return -1;
|
&& "Can only store 32-bit values to stack slots");
|
||||||
|
MachineInstr *I =
|
||||||
|
BuildMI (V8::STrm, 2).addFrameIndex (FrameIdx).addReg (SrcReg);
|
||||||
|
MBB.insert(MBBI, I);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SparcV8RegisterInfo::loadRegFromStackSlot(
|
int SparcV8RegisterInfo::loadRegFromStackSlot(
|
||||||
@@ -39,27 +44,50 @@ int SparcV8RegisterInfo::loadRegFromStackSlot(
|
|||||||
unsigned DestReg, int FrameIdx,
|
unsigned DestReg, int FrameIdx,
|
||||||
const TargetRegisterClass *RC) const
|
const TargetRegisterClass *RC) const
|
||||||
{
|
{
|
||||||
abort();
|
assert (RC == SparcV8::IntRegsRegisterClass
|
||||||
return -1;
|
&& "Can only load 32-bit registers from stack slots");
|
||||||
|
MachineInstr *I =
|
||||||
|
BuildMI (V8::LDmr, 2).addReg (DestReg).addFrameIndex (FrameIdx);
|
||||||
|
MBB.insert(MBBI, I);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator MBBI,
|
MachineBasicBlock::iterator MBBI,
|
||||||
unsigned DestReg, unsigned SrcReg,
|
unsigned DestReg, unsigned SrcReg,
|
||||||
const TargetRegisterClass *RC) const {
|
const TargetRegisterClass *RC) const {
|
||||||
abort();
|
assert (RC == SparcV8::IntRegsRegisterClass
|
||||||
|
&& "Can only copy 32-bit registers");
|
||||||
|
MBB.insert (MBBI,
|
||||||
|
BuildMI (V8::ORrr, 3, DestReg).addReg (V8::G0).addReg (SrcReg));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparcV8RegisterInfo::
|
void SparcV8RegisterInfo::
|
||||||
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator I) const {
|
MachineBasicBlock::iterator I) const {
|
||||||
|
std::cerr
|
||||||
|
<< "Sorry, I don't know how to eliminate call frame pseudo instrs yet, in\n"
|
||||||
|
<< __FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << "\n";
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
||||||
MachineBasicBlock::iterator II) const {
|
MachineBasicBlock::iterator II) const {
|
||||||
|
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();
|
||||||
|
|
||||||
|
std::cerr
|
||||||
|
<< "Sorry, I don't know how to eliminate frame indices yet\n"
|
||||||
|
<< "Frame index was " << FrameIndex << ", in\n"
|
||||||
|
<< __FUNCTION__ << "() at " << __FILE__ << ":" << __LINE__ << "\n";
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,10 +96,22 @@ processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
|
|||||||
|
|
||||||
void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||||
MachineBasicBlock &MBB = MF.front();
|
MachineBasicBlock &MBB = MF.front();
|
||||||
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
|
|
||||||
// Eventually this should emit the correct save instruction based on the
|
// Get the number of bytes to allocate from the FrameInfo
|
||||||
// number of bytes in the frame. For now we just hardcode it.
|
int NumBytes = (int) MFI->getStackSize();
|
||||||
BuildMI(MBB, MBB.begin(), V8::SAVEri, 2, V8::SP).addImm(-112).addReg(V8::SP);
|
|
||||||
|
// Emit the correct save instruction based on the number of bytes in the frame.
|
||||||
|
// Minimum stack frame size according to V8 ABI is:
|
||||||
|
// 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;
|
||||||
|
NumBytes = (NumBytes + 3) & ~3; // Round up to next word boundary
|
||||||
|
BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
|
||||||
|
V8::SP).addImm(-NumBytes).addReg(V8::SP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||||
@@ -82,7 +122,6 @@ void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
|||||||
BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
|
BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "SparcV8GenRegisterInfo.inc"
|
#include "SparcV8GenRegisterInfo.inc"
|
||||||
|
|
||||||
const TargetRegisterClass*
|
const TargetRegisterClass*
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#include "SparcV8RegisterInfo.h"
|
#include "SparcV8RegisterInfo.h"
|
||||||
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||||
#include "llvm/CodeGen/MachineFunction.h"
|
#include "llvm/CodeGen/MachineFunction.h"
|
||||||
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
||||||
#include "llvm/Type.h"
|
#include "llvm/Type.h"
|
||||||
#include "Support/STLExtras.h"
|
#include "Support/STLExtras.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@@ -29,8 +30,12 @@ int SparcV8RegisterInfo::storeRegToStackSlot(
|
|||||||
unsigned SrcReg, int FrameIdx,
|
unsigned SrcReg, int FrameIdx,
|
||||||
const TargetRegisterClass *RC) const
|
const TargetRegisterClass *RC) const
|
||||||
{
|
{
|
||||||
abort();
|
assert (RC == SparcV8::IntRegsRegisterClass
|
||||||
return -1;
|
&& "Can only store 32-bit values to stack slots");
|
||||||
|
MachineInstr *I =
|
||||||
|
BuildMI (V8::STrm, 2).addFrameIndex (FrameIdx).addReg (SrcReg);
|
||||||
|
MBB.insert(MBBI, I);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SparcV8RegisterInfo::loadRegFromStackSlot(
|
int SparcV8RegisterInfo::loadRegFromStackSlot(
|
||||||
@@ -39,27 +44,50 @@ int SparcV8RegisterInfo::loadRegFromStackSlot(
|
|||||||
unsigned DestReg, int FrameIdx,
|
unsigned DestReg, int FrameIdx,
|
||||||
const TargetRegisterClass *RC) const
|
const TargetRegisterClass *RC) const
|
||||||
{
|
{
|
||||||
abort();
|
assert (RC == SparcV8::IntRegsRegisterClass
|
||||||
return -1;
|
&& "Can only load 32-bit registers from stack slots");
|
||||||
|
MachineInstr *I =
|
||||||
|
BuildMI (V8::LDmr, 2).addReg (DestReg).addFrameIndex (FrameIdx);
|
||||||
|
MBB.insert(MBBI, I);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
int SparcV8RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator MBBI,
|
MachineBasicBlock::iterator MBBI,
|
||||||
unsigned DestReg, unsigned SrcReg,
|
unsigned DestReg, unsigned SrcReg,
|
||||||
const TargetRegisterClass *RC) const {
|
const TargetRegisterClass *RC) const {
|
||||||
abort();
|
assert (RC == SparcV8::IntRegsRegisterClass
|
||||||
|
&& "Can only copy 32-bit registers");
|
||||||
|
MBB.insert (MBBI,
|
||||||
|
BuildMI (V8::ORrr, 3, DestReg).addReg (V8::G0).addReg (SrcReg));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparcV8RegisterInfo::
|
void SparcV8RegisterInfo::
|
||||||
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator I) const {
|
MachineBasicBlock::iterator I) const {
|
||||||
|
std::cerr
|
||||||
|
<< "Sorry, I don't know how to eliminate call frame pseudo instrs yet, in\n"
|
||||||
|
<< __FUNCTION__ << " at " << __FILE__ << ":" << __LINE__ << "\n";
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
||||||
MachineBasicBlock::iterator II) const {
|
MachineBasicBlock::iterator II) const {
|
||||||
|
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();
|
||||||
|
|
||||||
|
std::cerr
|
||||||
|
<< "Sorry, I don't know how to eliminate frame indices yet\n"
|
||||||
|
<< "Frame index was " << FrameIndex << ", in\n"
|
||||||
|
<< __FUNCTION__ << "() at " << __FILE__ << ":" << __LINE__ << "\n";
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,10 +96,22 @@ processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
|
|||||||
|
|
||||||
void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||||
MachineBasicBlock &MBB = MF.front();
|
MachineBasicBlock &MBB = MF.front();
|
||||||
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
|
|
||||||
// Eventually this should emit the correct save instruction based on the
|
// Get the number of bytes to allocate from the FrameInfo
|
||||||
// number of bytes in the frame. For now we just hardcode it.
|
int NumBytes = (int) MFI->getStackSize();
|
||||||
BuildMI(MBB, MBB.begin(), V8::SAVEri, 2, V8::SP).addImm(-112).addReg(V8::SP);
|
|
||||||
|
// Emit the correct save instruction based on the number of bytes in the frame.
|
||||||
|
// Minimum stack frame size according to V8 ABI is:
|
||||||
|
// 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;
|
||||||
|
NumBytes = (NumBytes + 3) & ~3; // Round up to next word boundary
|
||||||
|
BuildMI(MBB, MBB.begin(), V8::SAVEri, 2,
|
||||||
|
V8::SP).addImm(-NumBytes).addReg(V8::SP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||||
@@ -82,7 +122,6 @@ void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
|
|||||||
BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
|
BuildMI(MBB, MBBI, V8::RESTORErr, 2, V8::G0).addReg(V8::G0).addReg(V8::G0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "SparcV8GenRegisterInfo.inc"
|
#include "SparcV8GenRegisterInfo.inc"
|
||||||
|
|
||||||
const TargetRegisterClass*
|
const TargetRegisterClass*
|
||||||
|
Reference in New Issue
Block a user