- while (!PhysRegsUsed.empty())
- spillVirtReg(MBB, I, PhysRegsUsed.begin()->second,
- PhysRegsUsed.begin()->first);
-
- assert(Virt2PhysRegMap.empty() && "Virtual registers still in phys regs?");
- assert(PhysRegsUseOrder.empty() && "Physical regs still allocated?");
-}
-
-
-/// EmitPrologue - Use the register info object to add a prologue to the
-/// function and save any callee saved registers we are responsible for.
-///
-void RA::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...
- ++NumSpilled;
- I = RegInfo.storeReg2RegOffset(MBB, I, CSRegs[i], RegInfo.getFramePointer(),
- -Offset, RegClass->getDataSize());
- }
-
- // 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 RA::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);
- ++NumReloaded;
- I = RegInfo.loadRegOffset2Reg(MBB, I, CSRegs[i], RegInfo.getFramePointer(),
- -Offset, RegClass->getDataSize());
- --I; // Insert in reverse order
- }
+ for (unsigned i = 0, e = RegInfo->getNumRegs(); i != e; ++i)
+ if (PhysRegsUsed[i] != -1)
+ if (unsigned VirtReg = PhysRegsUsed[i])
+ spillVirtReg(MBB, MI, VirtReg, i);
+ else
+ removePhysReg(i);
+
+#ifndef NDEBUG
+ bool AllOk = true;
+ for (unsigned i = MRegisterInfo::FirstVirtualRegister,
+ e = MF->getSSARegMap()->getLastVirtReg(); i <= e; ++i)
+ if (unsigned PR = Virt2PhysRegMap[i]) {
+ std::cerr << "Register still mapped: " << i << " -> " << PR << "\n";
+ AllOk = false;
+ }
+ assert(AllOk && "Virtual registers still in phys regs?");
+#endif