1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Simplify interfaces used by regalloc to insert code

llvm-svn: 5052
This commit is contained in:
Chris Lattner 2002-12-15 20:06:35 +00:00
parent 351dc9af16
commit 4214ac384a
4 changed files with 47 additions and 65 deletions

View File

@ -13,6 +13,7 @@
#include <assert.h>
class Type;
class MachineFunction;
/// MRegisterDesc - This record contains all of the information known about a
/// particular register.
@ -112,36 +113,32 @@ public:
virtual MachineBasicBlock::iterator
storeReg2RegOffset(MachineBasicBlock *MBB,
storeReg2RegOffset(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned SrcReg, unsigned DestReg,
unsigned ImmOffset, unsigned dataSize) const = 0;
virtual MachineBasicBlock::iterator
loadRegOffset2Reg(MachineBasicBlock *MBB,
loadRegOffset2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg,
unsigned ImmOffset, unsigned dataSize) const = 0;
virtual MachineBasicBlock::iterator
moveReg2Reg(MachineBasicBlock *MBB,
moveReg2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg, unsigned dataSize) const = 0;
virtual MachineBasicBlock::iterator
moveImm2Reg(MachineBasicBlock *MBB,
moveImm2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned Imm, unsigned dataSize) const = 0;
virtual MachineBasicBlock::iterator
emitPrologue(MachineBasicBlock *MBB,
MachineBasicBlock::iterator MBBI,
unsigned numBytes) const = 0;
virtual void
emitPrologue(MachineFunction &MF, unsigned numBytes) const = 0;
virtual MachineBasicBlock::iterator
emitEpilogue(MachineBasicBlock *MBB,
MachineBasicBlock::iterator MBBI,
unsigned numBytes) const = 0;
virtual void
emitEpilogue(MachineBasicBlock &MBB, unsigned numBytes) const = 0;
virtual const unsigned* getCalleeSaveRegs() const = 0;
virtual const unsigned* getCallerSaveRegs() const = 0;

View File

@ -199,7 +199,7 @@ RegAllocSimple::moveUseToReg (MachineBasicBlock &MBB,
PhysReg = getFreeReg(VirtReg);
// Add move instruction(s)
return RegInfo->loadRegOffset2Reg(&MBB, I, PhysReg,
return RegInfo->loadRegOffset2Reg(MBB, I, PhysReg,
RegInfo->getFramePointer(),
-stackOffset, regClass->getDataSize());
}
@ -215,7 +215,7 @@ RegAllocSimple::saveVirtRegToStack (MachineBasicBlock &MBB,
unsigned stackOffset = allocateStackSpaceFor(VirtReg, regClass);
// Add move instruction(s)
return RegInfo->storeReg2RegOffset(&MBB, I, PhysReg,
return RegInfo->storeReg2RegOffset(MBB, I, PhysReg,
RegInfo->getFramePointer(),
-stackOffset, regClass->getDataSize());
}
@ -231,7 +231,7 @@ RegAllocSimple::savePhysRegToStack (MachineBasicBlock &MBB,
unsigned offset = allocateStackSpaceFor(PhysReg, regClass);
// Add move instruction(s)
return RegInfo->storeReg2RegOffset(&MBB, I, PhysReg,
return RegInfo->storeReg2RegOffset(MBB, I, PhysReg,
RegInfo->getFramePointer(),
offset, regClass->getDataSize());
}
@ -293,7 +293,7 @@ void RegAllocSimple::EliminatePHINodes(MachineBasicBlock &MBB) {
// Retrieve the constant value from this op, move it to target
// register of the phi
if (opVal.isImmediate()) {
opI = RegInfo->moveImm2Reg(&opBlock, opI, physReg,
opI = RegInfo->moveImm2Reg(opBlock, opI, physReg,
(unsigned) opVal.getImmedValue(),
dataSize);
saveVirtRegToStack(opBlock, opI, virtualReg, physReg);
@ -384,10 +384,7 @@ bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) {
AllocateBasicBlock(*MBB);
// add prologue we should preserve callee-save registers...
MachineFunction::iterator Fi = Fn.begin();
MachineBasicBlock *MBB = Fi;
MachineBasicBlock::iterator MBBi = MBB->begin();
RegInfo->emitPrologue(MBB, MBBi, NumBytesAllocated);
RegInfo->emitPrologue(Fn, NumBytesAllocated);
const MachineInstrInfo &MII = TM.getInstrInfo();
@ -400,7 +397,7 @@ bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) {
MachineInstr *MI = *--I;
if (MII.isReturn(MI->getOpcode())) {
// this block has a return instruction, add epilogue
RegInfo->emitEpilogue(MBB, I, NumBytesAllocated);
RegInfo->emitEpilogue(*MBB, NumBytesAllocated);
}
}

View File

@ -10,6 +10,7 @@
#include "llvm/Constants.h"
#include "llvm/Type.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineFunction.h"
// X86Regs - Turn the X86RegisterInfo.def file into a bunch of register
// descriptors
@ -35,7 +36,7 @@ unsigned getIdx(unsigned dataSize) {
}
MachineBasicBlock::iterator
X86RegisterInfo::storeReg2RegOffset(MachineBasicBlock *MBB,
X86RegisterInfo::storeReg2RegOffset(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned SrcReg, unsigned DestReg,
unsigned ImmOffset, unsigned dataSize)
@ -44,11 +45,11 @@ X86RegisterInfo::storeReg2RegOffset(MachineBasicBlock *MBB,
static const unsigned Opcode[] = { X86::MOVrm8, X86::MOVrm16, X86::MOVrm32 };
MachineInstr *MI = addRegOffset(BuildMI(Opcode[getIdx(dataSize)], 5),
DestReg, ImmOffset).addReg(SrcReg);
return ++(MBB->insert(MBBI, MI));
return ++MBB.insert(MBBI, MI);
}
MachineBasicBlock::iterator
X86RegisterInfo::loadRegOffset2Reg(MachineBasicBlock *MBB,
X86RegisterInfo::loadRegOffset2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg,
unsigned ImmOffset, unsigned dataSize)
@ -57,11 +58,11 @@ X86RegisterInfo::loadRegOffset2Reg(MachineBasicBlock *MBB,
static const unsigned Opcode[] = { X86::MOVmr8, X86::MOVmr16, X86::MOVmr32 };
MachineInstr *MI = addRegOffset(BuildMI(Opcode[getIdx(dataSize)], 5)
.addReg(DestReg), SrcReg, ImmOffset);
return ++(MBB->insert(MBBI, MI));
return ++MBB.insert(MBBI, MI);
}
MachineBasicBlock::iterator
X86RegisterInfo::moveReg2Reg(MachineBasicBlock *MBB,
X86RegisterInfo::moveReg2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg,
unsigned dataSize) const
@ -69,11 +70,11 @@ X86RegisterInfo::moveReg2Reg(MachineBasicBlock *MBB,
static const unsigned Opcode[] = { X86::MOVrr8, X86::MOVrr16, X86::MOVrr32 };
MachineInstr *MI =
BuildMI(Opcode[getIdx(dataSize)], 2).addReg(DestReg).addReg(SrcReg);
return ++(MBB->insert(MBBI, MI));
return ++MBB.insert(MBBI, MI);
}
MachineBasicBlock::iterator
X86RegisterInfo::moveImm2Reg(MachineBasicBlock *MBB,
X86RegisterInfo::moveImm2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned Imm, unsigned dataSize)
const
@ -81,7 +82,7 @@ X86RegisterInfo::moveImm2Reg(MachineBasicBlock *MBB,
static const unsigned Opcode[] = { X86::MOVir8, X86::MOVir16, X86::MOVir32 };
MachineInstr *MI =
BuildMI(Opcode[getIdx(dataSize)], 2).addReg(DestReg).addReg(Imm);
return ++(MBB->insert(MBBI, MI));
return ++MBB.insert(MBBI, MI);
}
@ -106,55 +107,47 @@ const unsigned* X86RegisterInfo::getCallerSaveRegs() const {
return CallerSaveRegs;
}
MachineBasicBlock::iterator
X86RegisterInfo::emitPrologue(MachineBasicBlock *MBB,
MachineBasicBlock::iterator MBBI,
unsigned numBytes) const
{
MachineInstr *MI;
void X86RegisterInfo::emitPrologue(MachineFunction &MF,
unsigned numBytes) const {
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
MachineBasicBlock::iterator MBBI = MBB.begin();
// PUSH ebp
MI = BuildMI (X86::PUSHr32, 1).addReg(X86::EBP);
MBBI = ++(MBB->insert(MBBI, MI));
MachineInstr *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));
MBBI = ++MBB.insert(MBBI, MI);
// adjust stack pointer
MI = BuildMI(X86::SUBri32, 2).addReg(X86::ESP).addZImm(numBytes);
MBBI = ++(MBB->insert(MBBI, MI));
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));
MBBI = ++MBB.insert(MBBI, MI);
++regs;
}
return MBBI;
}
MachineBasicBlock::iterator
X86RegisterInfo::emitEpilogue(MachineBasicBlock *MBB,
MachineBasicBlock::iterator MBBI,
unsigned numBytes) const
{
MachineInstr *MI;
void X86RegisterInfo::emitEpilogue(MachineBasicBlock &MBB,
unsigned numBytes) const {
MachineBasicBlock::iterator MBBI = --MBB.end();
assert((*MBBI)->getOpcode() == X86::RET &&
"Can only insert epilog into returning blocks");
// 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));
MachineInstr *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;
MBB.insert(MBBI, BuildMI(X86::LEAVE, 0));
}

View File

@ -18,24 +18,24 @@ struct X86RegisterInfo : public MRegisterInfo {
MRegisterInfo::const_iterator regclass_end() const;
MachineBasicBlock::iterator
storeReg2RegOffset(MachineBasicBlock *MBB,
storeReg2RegOffset(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg,
unsigned ImmOffset, unsigned dataSize) const;
MachineBasicBlock::iterator
loadRegOffset2Reg(MachineBasicBlock *MBB,
loadRegOffset2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg,
unsigned ImmOffset, unsigned dataSize) const;
MachineBasicBlock::iterator
moveReg2Reg(MachineBasicBlock *MBB,
moveReg2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned SrcReg, unsigned dataSize) const;
MachineBasicBlock::iterator
moveImm2Reg(MachineBasicBlock *MBB,
moveImm2Reg(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
unsigned DestReg, unsigned Imm, unsigned dataSize) const;
@ -45,13 +45,8 @@ struct X86RegisterInfo : public MRegisterInfo {
const unsigned* getCalleeSaveRegs() const;
const unsigned* getCallerSaveRegs() const;
MachineBasicBlock::iterator emitPrologue(MachineBasicBlock *MBB,
MachineBasicBlock::iterator MBBI,
unsigned numBytes) const;
MachineBasicBlock::iterator emitEpilogue(MachineBasicBlock *MBB,
MachineBasicBlock::iterator MBBI,
unsigned numBytes) const;
void emitPrologue(MachineFunction &MF, unsigned numBytes) const;
void emitEpilogue(MachineBasicBlock &MBB, unsigned numBytes) const;
/// Returns register class appropriate for input SSA register
///