diff options
author | Wesley Peck <peckw@wesleypeck.com> | 2010-12-09 03:42:04 +0000 |
---|---|---|
committer | Wesley Peck <peckw@wesleypeck.com> | 2010-12-09 03:42:04 +0000 |
commit | 8397be042766f1913ceaa2b3e6782de0322bbe6a (patch) | |
tree | c9a36c534fb1fc85287eedf1e15bb4452c401334 /lib/Target/MBlaze/MBlazeRegisterInfo.cpp | |
parent | 6b0fa635d5bfd80940e667cec1662e611f5d270f (diff) |
Reworking the stack layout generated by the MBlaze backend.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121355 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/MBlaze/MBlazeRegisterInfo.cpp')
-rw-r--r-- | lib/Target/MBlaze/MBlazeRegisterInfo.cpp | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/lib/Target/MBlaze/MBlazeRegisterInfo.cpp b/lib/Target/MBlaze/MBlazeRegisterInfo.cpp index f8f77f1487..58aa151cd5 100644 --- a/lib/Target/MBlaze/MBlazeRegisterInfo.cpp +++ b/lib/Target/MBlaze/MBlazeRegisterInfo.cpp @@ -164,11 +164,40 @@ getReservedRegs(const MachineFunction &MF) const { return Reserved; } -// This function eliminate ADJCALLSTACKDOWN, -// ADJCALLSTACKUP pseudo instructions +// This function eliminate ADJCALLSTACKDOWN/ADJCALLSTACKUP pseudo instructions void MBlazeRegisterInfo:: eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const { + const TargetFrameInfo *TFI = MF.getTarget().getFrameInfo(); + + if (!TFI->hasReservedCallFrame(MF)) { + // If we have a frame pointer, turn the adjcallstackup instruction into a + // 'addi r1, r1, -<amt>' and the adjcallstackdown instruction into + // 'addi r1, r1, <amt>' + MachineInstr *Old = I; + int Amount = Old->getOperand(0).getImm() + 4; + if (Amount != 0) { + // We need to keep the stack aligned properly. To do this, we round the + // amount of space needed for the outgoing arguments up to the next + // alignment boundary. + unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment(); + Amount = (Amount+Align-1)/Align*Align; + + MachineInstr *New; + if (Old->getOpcode() == MBlaze::ADJCALLSTACKDOWN) { + New = BuildMI(MF, Old->getDebugLoc(), TII.get(MBlaze::ADDI), MBlaze::R1) + .addReg(MBlaze::R1).addImm(-Amount); + } else { + assert(Old->getOpcode() == MBlaze::ADJCALLSTACKUP); + New = BuildMI(MF, Old->getDebugLoc(), TII.get(MBlaze::ADDI), MBlaze::R1) + .addReg(MBlaze::R1).addImm(Amount); + } + + // Replace the pseudo instruction with a new instruction... + MBB.insert(I, New); + } + } + // Simply discard ADJCALLSTACKDOWN, ADJCALLSTACKUP instructions. MBB.erase(I); } @@ -204,12 +233,11 @@ eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, // as explained on LowerFormalArguments, detect negative offsets // and adjust SPOffsets considering the final stack size. - int Offset = (spOffset < 0) ? (stackSize - spOffset) : (spOffset + 4); - Offset += MI.getOperand(oi).getImm(); - - DEBUG(errs() << "Offset : " << Offset << "\n" << "<--------->\n"); + spOffset = (spOffset < 0) ? (stackSize - spOffset) : spOffset; + spOffset += MI.getOperand(oi).getImm(); + DEBUG(errs() << "Offset : " << spOffset << "\n" << "<--------->\n"); - MI.getOperand(oi).ChangeToImmediate(Offset); + MI.getOperand(oi).ChangeToImmediate(spOffset); MI.getOperand(i).ChangeToRegister(getFrameRegister(MF), false); } |