summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/RegAllocSimple.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-12-17 04:19:40 +0000
committerChris Lattner <sabre@nondot.org>2002-12-17 04:19:40 +0000
commite7d361d15a9fdf02e7c491c9bc6e8615f4464914 (patch)
treed1a9fa8c2b2ae2e4b0c228efea8bfba3cdddc586 /lib/CodeGen/RegAllocSimple.cpp
parent79de6319b1ff6a5609c4ef0d4a0d603b66127a20 (diff)
downloadexternal_llvm-e7d361d15a9fdf02e7c491c9bc6e8615f4464914.zip
external_llvm-e7d361d15a9fdf02e7c491c9bc6e8615f4464914.tar.gz
external_llvm-e7d361d15a9fdf02e7c491c9bc6e8615f4464914.tar.bz2
Use new reginfo interface
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5099 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/RegAllocSimple.cpp')
-rw-r--r--lib/CodeGen/RegAllocSimple.cpp62
1 files changed, 59 insertions, 3 deletions
diff --git a/lib/CodeGen/RegAllocSimple.cpp b/lib/CodeGen/RegAllocSimple.cpp
index 925915e..34d4d57 100644
--- a/lib/CodeGen/RegAllocSimple.cpp
+++ b/lib/CodeGen/RegAllocSimple.cpp
@@ -62,6 +62,13 @@ namespace {
/// in predecessor basic blocks.
void EliminatePHINodes(MachineBasicBlock &MBB);
+ /// EmitPrologue/EmitEpilogue - Use the register info object to add a
+ /// prologue/epilogue to the function and save/restore any callee saved
+ /// registers we are responsible for.
+ ///
+ void EmitPrologue();
+ void EmitEpilogue(MachineBasicBlock &MBB);
+
/// getStackSpaceFor - This returns the offset of the specified virtual
/// register on the stack, allocating space if neccesary.
@@ -307,6 +314,55 @@ void RegAllocSimple::AllocateBasicBlock(MachineBasicBlock &MBB) {
}
}
+
+/// EmitPrologue - Use the register info object to add a prologue to the
+/// function and save any callee saved registers we are responsible for.
+///
+void RegAllocSimple::EmitPrologue() {
+ // Get a list of the callee saved registers, so that we can save them on entry
+ // to the function.
+ //
+ MachineBasicBlock &MBB = MF->front(); // Prolog goes in entry BB
+ MachineBasicBlock::iterator I = MBB.begin();
+
+ const unsigned *CSRegs = RegInfo->getCalleeSaveRegs();
+ for (unsigned i = 0; CSRegs[i]; ++i) {
+ const TargetRegisterClass *RegClass = RegInfo->getRegClass(CSRegs[i]);
+ unsigned Offset = getStackSpaceFor(CSRegs[i], RegClass);
+
+ // Insert the spill to the stack frame...
+ I = RegInfo->storeReg2RegOffset(MBB, I,CSRegs[i],RegInfo->getFramePointer(),
+ -Offset, RegClass->getDataSize());
+ ++NumSpilled;
+ }
+
+ // Add prologue to the function...
+ RegInfo->emitPrologue(*MF, NumBytesAllocated);
+}
+
+
+/// EmitEpilogue - Use the register info object to add a epilogue to the
+/// function and restore any callee saved registers we are responsible for.
+///
+void RegAllocSimple::EmitEpilogue(MachineBasicBlock &MBB) {
+ // Insert instructions before the return.
+ MachineBasicBlock::iterator I = --MBB.end();
+
+ const unsigned *CSRegs = RegInfo->getCalleeSaveRegs();
+ for (unsigned i = 0; CSRegs[i]; ++i) {
+ const TargetRegisterClass *RegClass = RegInfo->getRegClass(CSRegs[i]);
+ unsigned Offset = getStackSpaceFor(CSRegs[i], RegClass);
+
+ I = RegInfo->loadRegOffset2Reg(MBB, I, CSRegs[i],RegInfo->getFramePointer(),
+ -Offset, RegClass->getDataSize());
+ --I; // Insert in reverse order
+ ++NumReloaded;
+ }
+
+ RegInfo->emitEpilogue(MBB, NumBytesAllocated);
+}
+
+
/// runOnMachineFunction - Register allocate the whole function
///
bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) {
@@ -328,8 +384,8 @@ bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) {
// FIXME: This is X86 specific! Move to frame manager
NumBytesAllocated = (NumBytesAllocated + 3) & ~3;
- // Add prologue to the function...
- RegInfo->emitPrologue(Fn, NumBytesAllocated);
+ // Emit a prologue for the function...
+ EmitPrologue();
const MachineInstrInfo &MII = TM.getInstrInfo();
@@ -338,7 +394,7 @@ bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) {
MBB != MBBe; ++MBB) {
// If last instruction is a return instruction, add an epilogue
if (MII.isReturn(MBB->back()->getOpcode()))
- RegInfo->emitEpilogue(*MBB, NumBytesAllocated);
+ EmitEpilogue(*MBB);
}
cleanupAfterFunction();