- Fixing naming inconsistency: calleesave -> calleesaved.

- Make use of spillCalleeSavedRegisters() and restoreCalleeSavedRegisters().

llvm-svn: 32822
This commit is contained in:
Evan Cheng 2007-01-02 21:31:15 +00:00
parent 07140c22c7
commit 92484c2aa4
1 changed files with 30 additions and 24 deletions

View File

@ -46,7 +46,8 @@ namespace {
// Allow the target machine to make some adjustments to the function // Allow the target machine to make some adjustments to the function
// e.g. UsedPhysRegs before calculateCalleeSavedRegisters. // e.g. UsedPhysRegs before calculateCalleeSavedRegisters.
Fn.getTarget().getRegisterInfo()->processFunctionBeforeCalleeSaveScan(Fn); Fn.getTarget().getRegisterInfo()
->processFunctionBeforeCalleeSavedScan(Fn);
// Scan the function for modified callee saved registers and insert spill // Scan the function for modified callee saved registers and insert spill
// code for any callee saved registers that are modified. Also calculate // code for any callee saved registers that are modified. Also calculate
@ -80,7 +81,7 @@ namespace {
} }
private: private:
// MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee save // MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
// stack frame indexes. // stack frame indexes.
unsigned MinCSFrameIndex, MaxCSFrameIndex; unsigned MinCSFrameIndex, MaxCSFrameIndex;
@ -109,7 +110,7 @@ void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
const TargetFrameInfo *TFI = Fn.getTarget().getFrameInfo(); const TargetFrameInfo *TFI = Fn.getTarget().getFrameInfo();
// Get the callee saved register list... // Get the callee saved register list...
const unsigned *CSRegs = RegInfo->getCalleeSaveRegs(); const unsigned *CSRegs = RegInfo->getCalleeSavedRegs();
// Get the function call frame set-up and tear-down instruction opcode // Get the function call frame set-up and tear-down instruction opcode
int FrameSetupOpcode = RegInfo->getCallFrameSetupOpcode(); int FrameSetupOpcode = RegInfo->getCallFrameSetupOpcode();
@ -151,7 +152,7 @@ void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
// //
const bool *PhysRegsUsed = Fn.getUsedPhysregs(); const bool *PhysRegsUsed = Fn.getUsedPhysregs();
const TargetRegisterClass* const *CSRegClasses = const TargetRegisterClass* const *CSRegClasses =
RegInfo->getCalleeSaveRegClasses(); RegInfo->getCalleeSavedRegClasses();
std::vector<CalleeSavedInfo> CSI; std::vector<CalleeSavedInfo> CSI;
for (unsigned i = 0; CSRegs[i]; ++i) { for (unsigned i = 0; CSRegs[i]; ++i) {
unsigned Reg = CSRegs[i]; unsigned Reg = CSRegs[i];
@ -174,7 +175,7 @@ void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
unsigned NumFixedSpillSlots; unsigned NumFixedSpillSlots;
const std::pair<unsigned,int> *FixedSpillSlots = const std::pair<unsigned,int> *FixedSpillSlots =
TFI->getCalleeSaveSpillSlots(NumFixedSpillSlots); TFI->getCalleeSavedSpillSlots(NumFixedSpillSlots);
// Now that we know which registers need to be saved and restored, allocate // Now that we know which registers need to be saved and restored, allocate
// stack slots for them. // stack slots for them.
@ -228,10 +229,13 @@ void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) {
// code into the entry block. // code into the entry block.
MachineBasicBlock *MBB = Fn.begin(); MachineBasicBlock *MBB = Fn.begin();
MachineBasicBlock::iterator I = MBB->begin(); MachineBasicBlock::iterator I = MBB->begin();
for (unsigned i = 0, e = CSI.size(); i != e; ++i) { if (!RegInfo->spillCalleeSavedRegisters(*MBB, I, CSI)) {
// Insert the spill to the stack frame. for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
RegInfo->storeRegToStackSlot(*MBB, I, CSI[i].getReg(), CSI[i].getFrameIdx(), // Insert the spill to the stack frame.
CSI[i].getRegClass()); RegInfo->storeRegToStackSlot(*MBB, I, CSI[i].getReg(),
CSI[i].getFrameIdx(),
CSI[i].getRegClass());
}
} }
// Add code to restore the callee-save registers in each exiting block. // Add code to restore the callee-save registers in each exiting block.
@ -255,19 +259,21 @@ void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) {
// Restore all registers immediately before the return and any terminators // Restore all registers immediately before the return and any terminators
// that preceed it. // that preceed it.
for (unsigned i = 0, e = CSI.size(); i != e; ++i) { if (!RegInfo->restoreCalleeSavedRegisters(*MBB, I, CSI)) {
RegInfo->loadRegFromStackSlot(*MBB, I, CSI[i].getReg(), for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
CSI[i].getFrameIdx(), RegInfo->loadRegFromStackSlot(*MBB, I, CSI[i].getReg(),
CSI[i].getRegClass()); CSI[i].getFrameIdx(),
assert(I != MBB->begin() && CSI[i].getRegClass());
"loadRegFromStackSlot didn't insert any code!"); assert(I != MBB->begin() &&
// Insert in reverse order. loadRegFromStackSlot can insert multiple "loadRegFromStackSlot didn't insert any code!");
// instructions. // Insert in reverse order. loadRegFromStackSlot can insert multiple
if (AtStart) // instructions.
I = MBB->begin(); if (AtStart)
else { I = MBB->begin();
I = BeforeI; else {
++I; I = BeforeI;
++I;
}
} }
} }
} }
@ -319,7 +325,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
} }
// First assign frame offsets to stack objects that are used to spill // First assign frame offsets to stack objects that are used to spill
// callee save registers. // callee saved registers.
if (StackGrowsDown) { if (StackGrowsDown) {
for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) { for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
if (i < MinCSFrameIndex || i > MaxCSFrameIndex) if (i < MinCSFrameIndex || i > MaxCSFrameIndex)
@ -356,7 +362,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
} }
// Then assign frame offsets to stack objects that are not used to spill // Then assign frame offsets to stack objects that are not used to spill
// callee save registers. // callee saved registers.
for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) { for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex) if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
continue; continue;