return regclass_end()-regclass_begin();
}
+ //===--------------------------------------------------------------------===//
+ // 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.
+ //
+
//===--------------------------------------------------------------------===//
// 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 void storeRegToStackSlot(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned SrcReg, int FrameIndex,
- const TargetRegisterClass *RC) const = 0;
+ virtual int storeRegToStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned SrcReg, int FrameIndex,
+ const TargetRegisterClass *RC) const = 0;
- virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned DestReg, int FrameIndex,
- const TargetRegisterClass *RC) const = 0;
+ virtual int loadRegFromStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned DestReg, int FrameIndex,
+ const TargetRegisterClass *RC) const = 0;
- virtual void copyRegToReg(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned DestReg, unsigned SrcReg,
- const TargetRegisterClass *RC) const = 0;
+ virtual int copyRegToReg(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned DestReg, unsigned SrcReg,
+ const TargetRegisterClass *RC) const = 0;
/// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the
/// 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 &&
/// 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,
- MachineBasicBlock::iterator &II) const = 0;
+ 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,
- MachineBasicBlock &MBB) const = 0;
+ /// 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;
};
#endif
}
}
-void X86RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned SrcReg, int FrameIdx,
- const TargetRegisterClass *RC) const {
+int X86RegisterInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned SrcReg, int FrameIdx,
+ const TargetRegisterClass *RC) const {
static const unsigned Opcode[] =
{ X86::MOVrm8, X86::MOVrm16, X86::MOVrm32, X86::FSTPr80 };
MachineInstr *MI = addFrameReference(BuildMI(Opcode[getIdx(RC)], 5),
FrameIdx).addReg(SrcReg);
MBBI = MBB.insert(MBBI, MI)+1;
+ return 1;
}
-void X86RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned DestReg, int FrameIdx,
- const TargetRegisterClass *RC) const{
+int X86RegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned DestReg, int FrameIdx,
+ const TargetRegisterClass *RC) const{
static const unsigned Opcode[] =
{ X86::MOVmr8, X86::MOVmr16, X86::MOVmr32, X86::FLDr80 };
MachineInstr *MI = addFrameReference(BuildMI(Opcode[getIdx(RC)], 4, DestReg),
FrameIdx);
MBBI = MBB.insert(MBBI, MI)+1;
+ return 1;
}
-void X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned DestReg, unsigned SrcReg,
- const TargetRegisterClass *RC) const {
+int X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned DestReg, unsigned SrcReg,
+ const TargetRegisterClass *RC) const {
static const unsigned Opcode[] =
{ 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;
}
//===----------------------------------------------------------------------===//
return NoFPElim || MF.getFrameInfo()->hasVarSizedObjects();
}
-void X86RegisterInfo::eliminateCallFramePseudoInstr(MachineFunction &MF,
- MachineBasicBlock &MBB,
+int X86RegisterInfo::eliminateCallFramePseudoInstr(MachineFunction &MF,
+ MachineBasicBlock &MBB,
MachineBasicBlock::iterator &I) const {
MachineInstr *New = 0, *Old = *I;;
if (hasFP(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;
+ delete Old;
+ return -1;
+ }
}
-void X86RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
- MachineBasicBlock::iterator &II) const {
+int X86RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
+ MachineBasicBlock::iterator &II) const {
unsigned i = 0;
MachineInstr &MI = **II;
while (!MI.getOperand(i).isFrameIndex()) {
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.
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)) {
MBB.insert(MBBI, MI);
}
}
+ return MBB.size() - oldSize;
}
-void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
- MachineBasicBlock &MBB) const {
+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;
MBBI = 1+MBB.insert(MBBI, MI);
}
}
+ return MBB.size() - oldSize;
}
#include "X86GenRegisterInfo.inc"
const TargetRegisterClass* getRegClassForType(const Type* Ty) const;
/// Code Generation virtual methods...
- void storeRegToStackSlot(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned SrcReg, int FrameIndex,
- const TargetRegisterClass *RC) const;
-
- void loadRegFromStackSlot(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &MBBI,
- unsigned DestReg, int FrameIndex,
- const TargetRegisterClass *RC) const;
+ int storeRegToStackSlot(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &MBBI,
+ unsigned SrcReg, int FrameIndex,
+ const TargetRegisterClass *RC) const;
+
+ 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,
- MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &I) const;
+ int eliminateCallFramePseudoInstr(MachineFunction &MF,
+ MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator &I) const;
- void eliminateFrameIndex(MachineFunction &MF,
- MachineBasicBlock::iterator &II) const;
+ 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