Simplify interfaces used by regalloc to insert code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5052 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Target/MRegisterInfo.h b/include/llvm/Target/MRegisterInfo.h
index 2fa4a5a..107adc3 100644
--- a/include/llvm/Target/MRegisterInfo.h
+++ b/include/llvm/Target/MRegisterInfo.h
@@ -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 @@
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;
diff --git a/lib/CodeGen/RegAllocSimple.cpp b/lib/CodeGen/RegAllocSimple.cpp
index c7348d5..49a205a 100644
--- a/lib/CodeGen/RegAllocSimple.cpp
+++ b/lib/CodeGen/RegAllocSimple.cpp
@@ -199,7 +199,7 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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);
}
}
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index 4e5afce..e2c0efd 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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));
}
diff --git a/lib/Target/X86/X86RegisterInfo.h b/lib/Target/X86/X86RegisterInfo.h
index 5b0c30c..be45f30 100644
--- a/lib/Target/X86/X86RegisterInfo.h
+++ b/lib/Target/X86/X86RegisterInfo.h
@@ -18,24 +18,24 @@
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 @@
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
///