mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 00:11:00 +00:00
2b46e8eccc
PHI nodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5001 91177308-0d34-0410-b5e6-96231b3b80d8
176 lines
5.2 KiB
C++
176 lines
5.2 KiB
C++
//===- X86RegisterInfo.cpp - X86 Register Information -----------*- C++ -*-===//
|
|
//
|
|
// This file contains the X86 implementation of the MRegisterInfo class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "X86.h"
|
|
#include "X86RegisterInfo.h"
|
|
#include "X86InstrBuilder.h"
|
|
#include "llvm/Constants.h"
|
|
#include "llvm/Type.h"
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
// X86Regs - Turn the X86RegisterInfo.def file into a bunch of register
|
|
// descriptors
|
|
//
|
|
static const MRegisterDesc X86Regs[] = {
|
|
#define R(ENUM, NAME, FLAGS, TSFLAGS) { NAME, FLAGS, TSFLAGS },
|
|
#include "X86RegisterInfo.def"
|
|
};
|
|
|
|
X86RegisterInfo::X86RegisterInfo()
|
|
: MRegisterInfo(X86Regs, sizeof(X86Regs)/sizeof(X86Regs[0])) {
|
|
}
|
|
|
|
MachineBasicBlock::iterator
|
|
X86RegisterInfo::storeReg2RegOffset(MachineBasicBlock *MBB,
|
|
MachineBasicBlock::iterator MBBI,
|
|
unsigned SrcReg, unsigned DestReg,
|
|
unsigned ImmOffset, unsigned dataSize)
|
|
const
|
|
{
|
|
unsigned opcode;
|
|
switch (dataSize) {
|
|
case 1: opcode = X86::MOVrm8; break;
|
|
case 2: opcode = X86::MOVrm16; break;
|
|
case 4: opcode = X86::MOVrm32; break;
|
|
default: assert(0 && "Invalid data size!");
|
|
}
|
|
|
|
MachineInstr *MI = addRegOffset(BuildMI(opcode, 5),
|
|
DestReg, ImmOffset).addReg(SrcReg);
|
|
return ++(MBB->insert(MBBI, MI));
|
|
}
|
|
|
|
MachineBasicBlock::iterator
|
|
X86RegisterInfo::loadRegOffset2Reg(MachineBasicBlock *MBB,
|
|
MachineBasicBlock::iterator MBBI,
|
|
unsigned DestReg, unsigned SrcReg,
|
|
unsigned ImmOffset, unsigned dataSize)
|
|
const
|
|
{
|
|
unsigned opcode;
|
|
switch (dataSize) {
|
|
case 1: opcode = X86::MOVmr8; break;
|
|
case 2: opcode = X86::MOVmr16; break;
|
|
case 4: opcode = X86::MOVmr32; break;
|
|
default: assert(0 && "Invalid data size!");
|
|
}
|
|
|
|
MachineInstr *MI = addRegOffset(BuildMI(opcode, 5).addReg(DestReg),
|
|
SrcReg, ImmOffset);
|
|
return ++(MBB->insert(MBBI, MI));
|
|
}
|
|
|
|
MachineBasicBlock::iterator
|
|
X86RegisterInfo::moveReg2Reg(MachineBasicBlock *MBB,
|
|
MachineBasicBlock::iterator MBBI,
|
|
unsigned DestReg, unsigned SrcReg,
|
|
unsigned dataSize) const
|
|
{
|
|
unsigned opcode;
|
|
switch (dataSize) {
|
|
case 1: opcode = X86::MOVrr8; break;
|
|
case 2: opcode = X86::MOVrr16; break;
|
|
case 4: opcode = X86::MOVrr32; break;
|
|
default: assert(0 && "Invalid data size!");
|
|
}
|
|
|
|
MachineInstr *MI = BuildMI(opcode, 2).addReg(DestReg).addReg(SrcReg);
|
|
return ++(MBB->insert(MBBI, MI));
|
|
}
|
|
|
|
MachineBasicBlock::iterator
|
|
X86RegisterInfo::moveImm2Reg(MachineBasicBlock *MBB,
|
|
MachineBasicBlock::iterator MBBI,
|
|
unsigned DestReg, unsigned Imm, unsigned dataSize)
|
|
const
|
|
{
|
|
unsigned opcode;
|
|
switch (dataSize) {
|
|
case 1: opcode = X86::MOVir8; break;
|
|
case 2: opcode = X86::MOVir16; break;
|
|
case 4: opcode = X86::MOVir32; break;
|
|
default: assert(0 && "Invalid data size!");
|
|
}
|
|
|
|
MachineInstr *MI = BuildMI(opcode, 2).addReg(DestReg).addReg(Imm);
|
|
return ++(MBB->insert(MBBI, MI));
|
|
}
|
|
|
|
|
|
unsigned X86RegisterInfo::getFramePointer() const {
|
|
return X86::EBP;
|
|
}
|
|
|
|
unsigned X86RegisterInfo::getStackPointer() const {
|
|
return X86::ESP;
|
|
}
|
|
|
|
const unsigned* X86RegisterInfo::getCalleeSaveRegs() const {
|
|
static const unsigned CalleeSaveRegs[] = { X86::ESI, X86::EDI, X86::EBX,
|
|
MRegisterInfo::NoRegister };
|
|
return CalleeSaveRegs;
|
|
}
|
|
|
|
|
|
const unsigned* X86RegisterInfo::getCallerSaveRegs() const {
|
|
static const unsigned CallerSaveRegs[] = { X86::EAX, X86::ECX, X86::EDX,
|
|
MRegisterInfo::NoRegister };
|
|
return CallerSaveRegs;
|
|
}
|
|
|
|
MachineBasicBlock::iterator
|
|
X86RegisterInfo::emitPrologue(MachineBasicBlock *MBB,
|
|
MachineBasicBlock::iterator MBBI,
|
|
unsigned numBytes) const
|
|
{
|
|
MachineInstr *MI;
|
|
|
|
// PUSH ebp
|
|
MI = BuildMI (X86::PUSHr32, 1).addReg(X86::EBP);
|
|
MBBI = ++(MBB->insert(MBBI, MI));
|
|
|
|
// MOV ebp, esp
|
|
MI = BuildMI (X86::MOVrr32, 2).addReg(X86::EBP).addReg(X86::ESP);
|
|
MBBI = ++(MBB->insert(MBBI, MI));
|
|
|
|
// adjust stack pointer
|
|
MI = BuildMI(X86::SUBri32, 2).addReg(X86::ESP).addZImm(numBytes);
|
|
MBBI = ++(MBB->insert(MBBI, MI));
|
|
|
|
// PUSH all callee-save registers
|
|
const unsigned* regs = getCalleeSaveRegs();
|
|
while (*regs) {
|
|
MI = BuildMI(X86::PUSHr32, 1).addReg(*regs);
|
|
MBBI = ++(MBB->insert(MBBI, MI));
|
|
++regs;
|
|
}
|
|
|
|
return MBBI;
|
|
}
|
|
|
|
MachineBasicBlock::iterator
|
|
X86RegisterInfo::emitEpilogue(MachineBasicBlock *MBB,
|
|
MachineBasicBlock::iterator MBBI,
|
|
unsigned numBytes) const
|
|
{
|
|
MachineInstr *MI;
|
|
|
|
// POP all callee-save registers in REVERSE ORDER
|
|
static const unsigned regs[] = { X86::EBX, X86::EDI, X86::ESI,
|
|
MRegisterInfo::NoRegister };
|
|
unsigned idx = 0;
|
|
while (regs[idx]) {
|
|
MI = BuildMI(X86::POPr32, 1).addReg(regs[idx++]);
|
|
MBBI = ++(MBB->insert(MBBI, MI));
|
|
}
|
|
|
|
// insert LEAVE
|
|
MI = BuildMI(X86::LEAVE, 0);
|
|
MBBI = ++(MBB->insert(MBBI, MI));
|
|
|
|
return MBBI;
|
|
}
|