Do not use frame register to reference fixed stack objects if the function is frameless.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79067 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2009-08-15 02:05:35 +00:00
parent d7be663d4f
commit 010b1b9e7b
2 changed files with 14 additions and 13 deletions

View File

@ -440,7 +440,7 @@ bool ARMBaseRegisterInfo::hasFP(const MachineFunction &MF) const {
MFI->isFrameAddressTaken()); MFI->isFrameAddressTaken());
} }
bool ARMBaseRegisterInfo::hasStackFrame(const MachineFunction &MF) const { bool ARMBaseRegisterInfo::cannotEliminateFrame(const MachineFunction &MF) const {
const MachineFrameInfo *MFI = MF.getFrameInfo(); const MachineFrameInfo *MFI = MF.getFrameInfo();
if (NoFramePointerElim && MFI->hasCalls()) if (NoFramePointerElim && MFI->hasCalls())
return true; return true;
@ -596,7 +596,7 @@ ARMBaseRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
} }
bool ExtraCSSpill = false; bool ExtraCSSpill = false;
if (!CanEliminateFrame || hasStackFrame(MF)) { if (!CanEliminateFrame || cannotEliminateFrame(MF)) {
AFI->setHasStackFrame(true); AFI->setHasStackFrame(true);
// If LR is not spilled, but at least one of R4, R5, R6, and R7 is spilled. // If LR is not spilled, but at least one of R4, R5, R6, and R7 is spilled.
@ -1022,6 +1022,7 @@ ARMBaseRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
MachineInstr &MI = *II; MachineInstr &MI = *II;
MachineBasicBlock &MBB = *MI.getParent(); MachineBasicBlock &MBB = *MI.getParent();
MachineFunction &MF = *MBB.getParent(); MachineFunction &MF = *MBB.getParent();
const MachineFrameInfo *MFI = MF.getFrameInfo();
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
assert(!AFI->isThumb1OnlyFunction() && assert(!AFI->isThumb1OnlyFunction() &&
"This eliminateFrameIndex does not suppor Thumb1!"); "This eliminateFrameIndex does not suppor Thumb1!");
@ -1033,8 +1034,7 @@ ARMBaseRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
unsigned FrameReg = ARM::SP; unsigned FrameReg = ARM::SP;
int FrameIndex = MI.getOperand(i).getIndex(); int FrameIndex = MI.getOperand(i).getIndex();
int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) + int Offset = MFI->getObjectOffset(FrameIndex) + MFI->getStackSize() + SPAdj;
MF.getFrameInfo()->getStackSize() + SPAdj;
if (AFI->isGPRCalleeSavedArea1Frame(FrameIndex)) if (AFI->isGPRCalleeSavedArea1Frame(FrameIndex))
Offset -= AFI->getGPRCalleeSavedArea1Offset(); Offset -= AFI->getGPRCalleeSavedArea1Offset();
@ -1042,10 +1042,10 @@ ARMBaseRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
Offset -= AFI->getGPRCalleeSavedArea2Offset(); Offset -= AFI->getGPRCalleeSavedArea2Offset();
else if (AFI->isDPRCalleeSavedAreaFrame(FrameIndex)) else if (AFI->isDPRCalleeSavedAreaFrame(FrameIndex))
Offset -= AFI->getDPRCalleeSavedAreaOffset(); Offset -= AFI->getDPRCalleeSavedAreaOffset();
else if (hasFP(MF)) { else if (hasFP(MF) && AFI->hasStackFrame()) {
assert(SPAdj == 0 && "Unexpected"); assert(SPAdj == 0 && "Unexpected stack offset!");
// There is alloca()'s in this function, must reference off the frame // Use frame pointer to reference fixed objects unless this is a
// pointer instead. // frameless function,
FrameReg = getFrameRegister(MF); FrameReg = getFrameRegister(MF);
Offset -= AFI->getFramePtrSpillOffset(); Offset -= AFI->getFramePtrSpillOffset();
} }
@ -1288,14 +1288,15 @@ emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const {
// Darwin ABI requires FP to point to the stack slot that contains the // Darwin ABI requires FP to point to the stack slot that contains the
// previous FP. // previous FP.
if ((STI.isTargetDarwin() && NumBytes) || hasFP(MF)) { bool HasFP = hasFP(MF);
if ((STI.isTargetDarwin() && NumBytes) || HasFP) {
NumBytes = AFI->getFramePtrSpillOffset() - NumBytes; NumBytes = AFI->getFramePtrSpillOffset() - NumBytes;
// Reset SP based on frame pointer only if the stack frame extends beyond // Reset SP based on frame pointer only if the stack frame extends beyond
// frame pointer stack slot or target is ELF and the function has FP. // frame pointer stack slot or target is ELF and the function has FP.
if (AFI->getGPRCalleeSavedArea2Size() || if (HasFP ||
AFI->getGPRCalleeSavedArea2Size() ||
AFI->getDPRCalleeSavedAreaSize() || AFI->getDPRCalleeSavedAreaSize() ||
AFI->getDPRCalleeSavedAreaOffset()|| AFI->getDPRCalleeSavedAreaOffset()) {
hasFP(MF)) {
if (NumBytes) { if (NumBytes) {
if (isARM) if (isARM)
emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes, emitARMRegPlusImmediate(MBB, MBBI, dl, ARM::SP, FramePtr, -NumBytes,

View File

@ -89,7 +89,7 @@ public:
bool hasFP(const MachineFunction &MF) const; bool hasFP(const MachineFunction &MF) const;
bool hasStackFrame(const MachineFunction &MF) const; bool cannotEliminateFrame(const MachineFunction &MF) const;
void processFunctionBeforeCalleeSavedScan(MachineFunction &MF, void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
RegScavenger *RS = NULL) const; RegScavenger *RS = NULL) const;