mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-28 22:43:29 +00:00
Change all machine basic block modifier functions in MRegisterInfo to
return the number of instructions added to/removed from the basic block passed as their first argument. Note: This is only needed because we use a std::vector instead of an ilist to keep MachineBasicBlock instructions. Inserting an instruction to a MachineBasicBlock invalidates all iterators to the basic block. The return value can be used to update an index to the machine basic block instruction vector and circumvent the iterator elimination problem but this is really not needed if we move to a better representation. llvm-svn: 9704
This commit is contained in:
parent
8dadbe31dc
commit
c6a7c83333
@ -185,21 +185,37 @@ public:
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Interfaces used by the register allocator and stack frame manipulation
|
||||
// passes to move data around between registers, immediates and memory.
|
||||
// All basic block modifier functions below return the number of
|
||||
// instructions added to/removed from the basic block passed as their
|
||||
// first argument.
|
||||
//
|
||||
// FIXME: This is only needed because we use a std::vector instead
|
||||
// of an ilist to keep MachineBasicBlock instructions. Inserting an
|
||||
// instruction to a MachineBasicBlock invalidates all iterators to
|
||||
// the basic block. The return value can be used to update an index
|
||||
// to the machine basic block instruction vector and circumvent the
|
||||
// iterator elimination problem but this is really not needed if we
|
||||
// move to a better representation.
|
||||
//
|
||||
|
||||
virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Interfaces used by the register allocator and stack frame manipulation
|
||||
// passes to move data around between registers, immediates and memory.
|
||||
// The return value is the number of instructions added/deleted to/from the
|
||||
// basic block.
|
||||
//
|
||||
|
||||
virtual int storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned SrcReg, int FrameIndex,
|
||||
const TargetRegisterClass *RC) const = 0;
|
||||
|
||||
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
virtual int loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned DestReg, int FrameIndex,
|
||||
const TargetRegisterClass *RC) const = 0;
|
||||
|
||||
virtual void copyRegToReg(MachineBasicBlock &MBB,
|
||||
virtual int copyRegToReg(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned DestReg, unsigned SrcReg,
|
||||
const TargetRegisterClass *RC) const = 0;
|
||||
@ -220,9 +236,10 @@ public:
|
||||
/// instructions (but only if the Target is using them). It is responsible
|
||||
/// for eliminating these instructions, replacing them with concrete
|
||||
/// instructions. This method need only be implemented if using call frame
|
||||
/// setup/destroy pseudo instructions.
|
||||
/// setup/destroy pseudo instructions. The return value is the number of
|
||||
/// instructions added/deleted to/from the basic block.
|
||||
///
|
||||
virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
virtual int eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &I) const {
|
||||
assert(getCallFrameSetupOpcode()== -1 && getCallFrameDestroyOpcode()== -1 &&
|
||||
@ -234,24 +251,29 @@ public:
|
||||
/// processFunctionBeforeFrameFinalized - This method is called immediately
|
||||
/// before the specified functions frame layout (MF.getFrameInfo()) is
|
||||
/// finalized. Once the frame is finalized, MO_FrameIndex operands are
|
||||
/// replaced with direct constants. This method is optional.
|
||||
/// replaced with direct constants. This method is optional. The return value
|
||||
/// is the number of instructions added/deleted to/from the basic block
|
||||
///
|
||||
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
|
||||
virtual int processFunctionBeforeFrameFinalized(MachineFunction &MF) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// eliminateFrameIndex - This method must be overriden to eliminate abstract
|
||||
/// frame indices from instructions which may use them. The instruction
|
||||
/// referenced by the iterator contains an MO_FrameIndex operand which must be
|
||||
/// eliminated by this method. This method may modify or replace the
|
||||
/// specified instruction, as long as it keeps the iterator pointing the the
|
||||
/// finished product.
|
||||
/// finished product. The return value is the number of instructions
|
||||
/// added/deleted to/from the basic block
|
||||
///
|
||||
virtual void eliminateFrameIndex(MachineFunction &MF,
|
||||
virtual int eliminateFrameIndex(MachineFunction &MF,
|
||||
MachineBasicBlock::iterator &II) const = 0;
|
||||
|
||||
/// emitProlog/emitEpilog - These methods insert prolog and epilog code into
|
||||
/// the function.
|
||||
virtual void emitPrologue(MachineFunction &MF) const = 0;
|
||||
virtual void emitEpilogue(MachineFunction &MF,
|
||||
/// the function. The return value is the number of instructions
|
||||
/// added/deleted to/from the basic block (entry for prologue,
|
||||
virtual int emitPrologue(MachineFunction &MF) const = 0;
|
||||
virtual int emitEpilogue(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB) const = 0;
|
||||
};
|
||||
|
||||
|
@ -44,7 +44,7 @@ static unsigned getIdx(const TargetRegisterClass *RC) {
|
||||
}
|
||||
}
|
||||
|
||||
void X86RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
int X86RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned SrcReg, int FrameIdx,
|
||||
const TargetRegisterClass *RC) const {
|
||||
@ -53,9 +53,10 @@ void X86RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
MachineInstr *MI = addFrameReference(BuildMI(Opcode[getIdx(RC)], 5),
|
||||
FrameIdx).addReg(SrcReg);
|
||||
MBBI = MBB.insert(MBBI, MI)+1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void X86RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
int X86RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned DestReg, int FrameIdx,
|
||||
const TargetRegisterClass *RC) const{
|
||||
@ -64,9 +65,10 @@ void X86RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
MachineInstr *MI = addFrameReference(BuildMI(Opcode[getIdx(RC)], 4, DestReg),
|
||||
FrameIdx);
|
||||
MBBI = MBB.insert(MBBI, MI)+1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
||||
int X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned DestReg, unsigned SrcReg,
|
||||
const TargetRegisterClass *RC) const {
|
||||
@ -74,6 +76,7 @@ void X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
|
||||
{ X86::MOVrr8, X86::MOVrr16, X86::MOVrr32, X86::FpMOV };
|
||||
MachineInstr *MI = BuildMI(Opcode[getIdx(RC)],1,DestReg).addReg(SrcReg);
|
||||
MBBI = MBB.insert(MBBI, MI)+1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@ -88,7 +91,7 @@ static bool hasFP(MachineFunction &MF) {
|
||||
return NoFPElim || MF.getFrameInfo()->hasVarSizedObjects();
|
||||
}
|
||||
|
||||
void X86RegisterInfo::eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
int X86RegisterInfo::eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &I) const {
|
||||
MachineInstr *New = 0, *Old = *I;;
|
||||
@ -113,14 +116,18 @@ void X86RegisterInfo::eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
}
|
||||
}
|
||||
|
||||
if (New)
|
||||
if (New) {
|
||||
*I = New; // Replace the pseudo instruction with a new instruction...
|
||||
else
|
||||
delete Old;
|
||||
return 0;
|
||||
} else {
|
||||
I = MBB.erase(I);// Just delete the pseudo instruction...
|
||||
delete Old;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void X86RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
||||
int X86RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
||||
MachineBasicBlock::iterator &II) const {
|
||||
unsigned i = 0;
|
||||
MachineInstr &MI = **II;
|
||||
@ -143,9 +150,10 @@ void X86RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
|
||||
Offset += MF.getFrameInfo()->getStackSize();
|
||||
|
||||
MI.SetMachineOperandConst(i+3, MachineOperand::MO_SignExtendedImmed, Offset);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void X86RegisterInfo::processFunctionBeforeFrameFinalized(MachineFunction &MF)
|
||||
int X86RegisterInfo::processFunctionBeforeFrameFinalized(MachineFunction &MF)
|
||||
const {
|
||||
if (hasFP(MF)) {
|
||||
// Create a frame entry for the EBP register that must be saved.
|
||||
@ -153,14 +161,16 @@ void X86RegisterInfo::processFunctionBeforeFrameFinalized(MachineFunction &MF)
|
||||
assert(FrameIdx == MF.getFrameInfo()->getObjectIndexEnd()-1 &&
|
||||
"Slot for EBP register must be last in order to be found!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||
int X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||
MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
|
||||
MachineBasicBlock::iterator MBBI = MBB.begin();
|
||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||
MachineInstr *MI;
|
||||
|
||||
unsigned oldSize = MBB.size();
|
||||
// Get the number of bytes to allocate from the FrameInfo
|
||||
unsigned NumBytes = MFI->getStackSize();
|
||||
if (hasFP(MF)) {
|
||||
@ -207,10 +217,12 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
||||
MBB.insert(MBBI, MI);
|
||||
}
|
||||
}
|
||||
return MBB.size() - oldSize;
|
||||
}
|
||||
|
||||
void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||
int X86RegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB) const {
|
||||
unsigned oldSize = MBB.size();
|
||||
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||
MachineBasicBlock::iterator MBBI = MBB.end()-1;
|
||||
MachineInstr *MI;
|
||||
@ -238,6 +250,7 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
|
||||
MBBI = 1+MBB.insert(MBBI, MI);
|
||||
}
|
||||
}
|
||||
return MBB.size() - oldSize;
|
||||
}
|
||||
|
||||
#include "X86GenRegisterInfo.inc"
|
||||
|
@ -25,31 +25,31 @@ struct X86RegisterInfo : public X86GenRegisterInfo {
|
||||
const TargetRegisterClass* getRegClassForType(const Type* Ty) const;
|
||||
|
||||
/// Code Generation virtual methods...
|
||||
void storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
int storeRegToStackSlot(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned SrcReg, int FrameIndex,
|
||||
const TargetRegisterClass *RC) const;
|
||||
|
||||
void loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
int loadRegFromStackSlot(MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &MBBI,
|
||||
unsigned DestReg, int FrameIndex,
|
||||
const TargetRegisterClass *RC) const;
|
||||
|
||||
void copyRegToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
|
||||
int copyRegToReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
|
||||
unsigned DestReg, unsigned SrcReg,
|
||||
const TargetRegisterClass *RC) const;
|
||||
|
||||
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
int eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB,
|
||||
MachineBasicBlock::iterator &I) const;
|
||||
|
||||
void eliminateFrameIndex(MachineFunction &MF,
|
||||
int eliminateFrameIndex(MachineFunction &MF,
|
||||
MachineBasicBlock::iterator &II) const;
|
||||
|
||||
void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
|
||||
int processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
|
||||
|
||||
void emitPrologue(MachineFunction &MF) const;
|
||||
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
|
||||
int emitPrologue(MachineFunction &MF) const;
|
||||
int emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user