From b020808f0d29433e84d6ab4c57a7ec54eed41860 Mon Sep 17 00:00:00 2001 From: Wesley Peck Date: Mon, 3 Jan 2011 21:40:26 +0000 Subject: [PATCH] Fix more stack layout issues in the MBlaze backend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122778 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/MBlaze/MBlazeFrameInfo.cpp | 46 +++++++++++++++++------ lib/Target/MBlaze/MBlazeMachineFunction.h | 14 +++---- lib/Target/MBlaze/MBlazeRegisterInfo.cpp | 5 --- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/lib/Target/MBlaze/MBlazeFrameInfo.cpp b/lib/Target/MBlaze/MBlazeFrameInfo.cpp index 8bd2c1b14ed..1e4f337fe5a 100644 --- a/lib/Target/MBlaze/MBlazeFrameInfo.cpp +++ b/lib/Target/MBlaze/MBlazeFrameInfo.cpp @@ -40,6 +40,35 @@ namespace llvm { cl::Hidden); } +static void replaceFrameIndexes(MachineFunction &MF, + SmallVector, 16> &FR) { + MachineFrameInfo *MFI = MF.getFrameInfo(); + const SmallVector, 16>::iterator FRB = FR.begin(); + const SmallVector, 16>::iterator FRE = FR.end(); + + SmallVector, 16>::iterator FRI = FRB; + for (; FRI != FRE; ++FRI) { + MFI->RemoveStackObject(FRI->first); + int NFI = MFI->CreateFixedObject(4, FRI->second, true); + + for (MachineFunction::iterator MB=MF.begin(), ME=MF.end(); MB!=ME; ++MB) { + MachineBasicBlock::iterator MBB = MB->begin(); + const MachineBasicBlock::iterator MBE = MB->end(); + + for (; MBB != MBE; ++MBB) { + MachineInstr::mop_iterator MIB = MBB->operands_begin(); + const MachineInstr::mop_iterator MIE = MBB->operands_end(); + + for (MachineInstr::mop_iterator MII = MIB; MII != MIE; ++MII) { + if (!MII->isFI() || MII->getIndex() != FRI->first) continue; + DEBUG(dbgs() << "FOUND FI#" << MII->getIndex() << "\n"); + MII->setIndex(NFI); + } + } + } + } +} + //===----------------------------------------------------------------------===// // // Stack Frame Processing methods @@ -64,6 +93,7 @@ static void analyzeFrameIndexes(MachineFunction &MF) { MachineRegisterInfo::livein_iterator LIE = MRI.livein_end(); const SmallVector &LiveInFI = MBlazeFI->getLiveIn(); SmallVector EraseInstr; + SmallVector, 16> FrameRelocate; MachineBasicBlock *MBB = MF.getBlockNumbered(0); MachineBasicBlock::iterator MIB = MBB->begin(); @@ -87,7 +117,6 @@ static void analyzeFrameIndexes(MachineFunction &MF) { // // Additionally, if the SWI operation kills the def of REG then we don't // need the LWI operation so we can erase it as well. -#if 1 for (unsigned i = 0, e = LiveInFI.size(); i < e; ++i) { for (MachineBasicBlock::iterator I=MIB; I != MIE; ++I) { if (I->getOpcode() != MBlaze::LWI || I->getNumOperands() != 3 || @@ -117,7 +146,7 @@ static void analyzeFrameIndexes(MachineFunction &MF) { EraseInstr.push_back(SI); DEBUG(dbgs() << "SWI for FI#" << FI << " removed\n"); - MBlazeFI->recordLoadArgsFI(FI, StackOffset); + FrameRelocate.push_back(std::make_pair(FI,StackOffset)); DEBUG(dbgs() << "FI#" << FI << " relocated to " << StackOffset << "\n"); StackOffset -= 4; @@ -126,7 +155,6 @@ static void analyzeFrameIndexes(MachineFunction &MF) { } } } -#endif // In this loop we are searching for frame indexes that corrospond to // incoming arguments that are in registers. We look for instruction @@ -139,7 +167,6 @@ static void analyzeFrameIndexes(MachineFunction &MF) { // caller has allocated stack space for it already. Instead of allocating // stack space on our frame, we record the correct location in the callers // frame. -#if 1 for (MachineRegisterInfo::livein_iterator LI = LII; LI != LIE; ++LI) { for (MachineBasicBlock::iterator I=MIB; I != MIE; ++I) { if (I->definesRegister(LI->first)) @@ -165,21 +192,21 @@ static void analyzeFrameIndexes(MachineFunction &MF) { } StackAdjust += 4; - MBlazeFI->recordLoadArgsFI(FI, FILoc); + FrameRelocate.push_back(std::make_pair(FI,FILoc)); DEBUG(dbgs() << "FI#" << FI << " relocated to " << FILoc << "\n"); break; } } } -#endif // Go ahead and erase all of the instructions that we determined were // no longer needed. for (int i = 0, e = EraseInstr.size(); i < e; ++i) MBB->erase(EraseInstr[i]); - DEBUG(dbgs() << "Final stack adjustment: " << StackAdjust << "\n"); - MBlazeFI->setStackAdjust(StackAdjust); + // Replace all of the frame indexes that we have relocated with new + // fixed object frame indexes. + replaceFrameIndexes(MF, FrameRelocate); } static void interruptFrameLayout(MachineFunction &MF) { @@ -282,9 +309,6 @@ static void determineFrameLayout(MachineFunction &MF) { unsigned FrameSize = MFI->getStackSize(); DEBUG(dbgs() << "Original Frame Size: " << FrameSize << "\n" ); - FrameSize -= MBlazeFI->getStackAdjust(); - DEBUG(dbgs() << "Adjusted Frame Size: " << FrameSize << "\n" ); - // Get the alignments provided by the target, and the maximum alignment // (if any) of the fixed frame objects. // unsigned MaxAlign = MFI->getMaxAlignment(); diff --git a/lib/Target/MBlaze/MBlazeMachineFunction.h b/lib/Target/MBlaze/MBlazeMachineFunction.h index d1468db45be..8340d921ba4 100644 --- a/lib/Target/MBlaze/MBlazeMachineFunction.h +++ b/lib/Target/MBlaze/MBlazeMachineFunction.h @@ -34,9 +34,6 @@ private: /// saved. This is used on Prologue and Epilogue to emit RA save/restore int RAStackOffset; - /// Holds the stack adjustment necessary for each function. - int StackAdjust; - /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset struct MBlazeFIHolder { @@ -85,9 +82,9 @@ private: public: MBlazeFunctionInfo(MachineFunction& MF) - : FPStackOffset(0), RAStackOffset(0), StackAdjust(0), GPHolder(-1,-1), - HasLoadArgs(false), HasStoreVarArgs(false), SRetReturnReg(0), - GlobalBaseReg(0), VarArgsFrameIndex(0), LiveInFI() + : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false), + HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0), + VarArgsFrameIndex(0), LiveInFI() {} int getFPStackOffset() const { return FPStackOffset; } @@ -96,9 +93,6 @@ public: int getRAStackOffset() const { return RAStackOffset; } void setRAStackOffset(int Off) { RAStackOffset = Off; } - int getStackAdjust() const { return StackAdjust; } - void setStackAdjust(int Adj) { StackAdjust = Adj; } - int getGPStackOffset() const { return GPHolder.SPOffset; } int getGPFI() const { return GPHolder.FI; } void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } @@ -125,6 +119,7 @@ public: if (!HasLoadArgs) HasLoadArgs=true; FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset)); } + void recordStoreVarArgsFI(int FI, int SPOffset) { if (!HasStoreVarArgs) HasStoreVarArgs=true; FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset)); @@ -135,6 +130,7 @@ public: for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset); } + void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { if (!hasStoreVarArgs()) return; for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) diff --git a/lib/Target/MBlaze/MBlazeRegisterInfo.cpp b/lib/Target/MBlaze/MBlazeRegisterInfo.cpp index a14f7f38fba..7c323b2f7d1 100644 --- a/lib/Target/MBlaze/MBlazeRegisterInfo.cpp +++ b/lib/Target/MBlaze/MBlazeRegisterInfo.cpp @@ -296,11 +296,6 @@ eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, // and adjust SPOffsets considering the final stack size. int Offset = (spOffset < 0) ? (stackSize - spOffset) : spOffset; Offset += MI.getOperand(oi).getImm(); - if (!MFI->isFixedObjectIndex(FrameIndex) && - !MFI->isSpillSlotObjectIndex(FrameIndex) && - !MBlazeFI->isLiveIn(FrameIndex) && - spOffset >= 0) - Offset -= MBlazeFI->getStackAdjust(); DEBUG(dbgs() << "Offset : " << Offset << "\n" << "<--------->\n");