aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2003-11-04 22:57:09 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2003-11-04 22:57:09 +0000
commite668dab5b339df01920b8bff890a70455b7dd27a (patch)
tree06b1ea7b9742d92dde98a521457df178f311b59f
parent55766e139a2eae8d44e703c1933d1084c1d5a586 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9704 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Target/MRegisterInfo.h68
-rw-r--r--lib/Target/X86/X86RegisterInfo.cpp59
-rw-r--r--lib/Target/X86/X86RegisterInfo.h36
3 files changed, 99 insertions, 64 deletions
diff --git a/include/llvm/Target/MRegisterInfo.h b/include/llvm/Target/MRegisterInfo.h
index 3af32a278b..c4bcceefe5 100644
--- a/include/llvm/Target/MRegisterInfo.h
+++ b/include/llvm/Target/MRegisterInfo.h
@@ -185,24 +185,40 @@ public:
}
//===--------------------------------------------------------------------===//
+ // 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
@@ -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,25 +251,30 @@ 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,
- 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
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index e6b6319b80..fd8a615e31 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -44,36 +44,39 @@ static unsigned getIdx(const TargetRegisterClass *RC) {
}
}
-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;
}
//===----------------------------------------------------------------------===//
@@ -88,8 +91,8 @@ static bool hasFP(MachineFunction &MF) {
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)) {
@@ -113,15 +116,19 @@ 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;
+ 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()) {
@@ -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,
- 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;
@@ -238,6 +250,7 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
MBBI = 1+MBB.insert(MBBI, MI);
}
}
+ return MBB.size() - oldSize;
}
#include "X86GenRegisterInfo.inc"
diff --git a/lib/Target/X86/X86RegisterInfo.h b/lib/Target/X86/X86RegisterInfo.h
index 02fe14b7d4..0db8e18bee 100644
--- a/lib/Target/X86/X86RegisterInfo.h
+++ b/lib/Target/X86/X86RegisterInfo.h
@@ -25,31 +25,31 @@ struct X86RegisterInfo : public X86GenRegisterInfo {
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