PPCFrameLowering's FramePointerOffset can be computed at initialization

time. Do so.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228998 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2015-02-13 00:39:38 +00:00
parent 82eeeb5b94
commit 2b4e1b9abf
3 changed files with 25 additions and 28 deletions

View File

@ -47,11 +47,25 @@ static unsigned computeTOCSaveOffset(const PPCSubtarget &STI) {
return STI.isELFv2ABI() ? 24 : 40; return STI.isELFv2ABI() ? 24 : 40;
} }
static unsigned computeFramePointerSaveOffset(const PPCSubtarget &STI) {
// For the Darwin ABI:
// We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
// for saving the frame pointer (if needed.) While the published ABI has
// not used this slot since at least MacOSX 10.2, there is older code
// around that does use it, and that needs to continue to work.
if (STI.isDarwinABI())
return STI.isPPC64() ? -8U : -4U;
// SVR4 ABI: First slot in the general register save area.
return STI.isPPC64() ? -8U : -4U;
}
PPCFrameLowering::PPCFrameLowering(const PPCSubtarget &STI) PPCFrameLowering::PPCFrameLowering(const PPCSubtarget &STI)
: TargetFrameLowering(TargetFrameLowering::StackGrowsDown, : TargetFrameLowering(TargetFrameLowering::StackGrowsDown,
(STI.hasQPX() || STI.isBGQ()) ? 32 : 16, 0), (STI.hasQPX() || STI.isBGQ()) ? 32 : 16, 0),
Subtarget(STI), ReturnSaveOffset(computeReturnSaveOffset(Subtarget)), Subtarget(STI), ReturnSaveOffset(computeReturnSaveOffset(Subtarget)),
TOCSaveOffset(computeTOCSaveOffset(Subtarget)) {} TOCSaveOffset(computeTOCSaveOffset(Subtarget)),
FramePointerSaveOffset(computeFramePointerSaveOffset(Subtarget)) {}
// With the SVR4 ABI, callee-saved registers have fixed offsets on the stack. // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
const PPCFrameLowering::SpillSlot *PPCFrameLowering::getCalleeSavedSpillSlots( const PPCFrameLowering::SpillSlot *PPCFrameLowering::getCalleeSavedSpillSlots(
@ -620,8 +634,7 @@ void PPCFrameLowering::emitPrologue(MachineFunction &MF) const {
assert(FPIndex && "No Frame Pointer Save Slot!"); assert(FPIndex && "No Frame Pointer Save Slot!");
FPOffset = FFI->getObjectOffset(FPIndex); FPOffset = FFI->getObjectOffset(FPIndex);
} else { } else {
FPOffset = FPOffset = getFramePointerSaveOffset();
PPCFrameLowering::getFramePointerSaveOffset(isPPC64, isDarwinABI);
} }
} }
@ -958,8 +971,7 @@ void PPCFrameLowering::emitEpilogue(MachineFunction &MF,
assert(FPIndex && "No Frame Pointer Save Slot!"); assert(FPIndex && "No Frame Pointer Save Slot!");
FPOffset = FFI->getObjectOffset(FPIndex); FPOffset = FFI->getObjectOffset(FPIndex);
} else { } else {
FPOffset = FPOffset = getFramePointerSaveOffset();
PPCFrameLowering::getFramePointerSaveOffset(isPPC64, isDarwinABI);
} }
} }
@ -1159,7 +1171,7 @@ PPCFrameLowering::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
// If the frame pointer save index hasn't been defined yet. // If the frame pointer save index hasn't been defined yet.
if (!FPSI && needsFP(MF)) { if (!FPSI && needsFP(MF)) {
// Find out what the fix offset of the frame pointer save area. // Find out what the fix offset of the frame pointer save area.
int FPOffset = getFramePointerSaveOffset(isPPC64, isDarwinABI); int FPOffset = getFramePointerSaveOffset();
// Allocate the frame index for frame pointer save area. // Allocate the frame index for frame pointer save area.
FPSI = MFI->CreateFixedObject(isPPC64? 8 : 4, FPOffset, true); FPSI = MFI->CreateFixedObject(isPPC64? 8 : 4, FPOffset, true);
// Save the result. // Save the result.

View File

@ -25,6 +25,7 @@ class PPCFrameLowering: public TargetFrameLowering {
const PPCSubtarget &Subtarget; const PPCSubtarget &Subtarget;
const unsigned ReturnSaveOffset; const unsigned ReturnSaveOffset;
const unsigned TOCSaveOffset; const unsigned TOCSaveOffset;
const unsigned FramePointerSaveOffset;
public: public:
PPCFrameLowering(const PPCSubtarget &STI); PPCFrameLowering(const PPCSubtarget &STI);
@ -77,18 +78,7 @@ public:
/// getFramePointerSaveOffset - Return the previous frame offset to save the /// getFramePointerSaveOffset - Return the previous frame offset to save the
/// frame pointer. /// frame pointer.
static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) { unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; }
// For the Darwin ABI:
// We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
// for saving the frame pointer (if needed.) While the published ABI has
// not used this slot since at least MacOSX 10.2, there is older code
// around that does use it, and that needs to continue to work.
if (isDarwinABI)
return isPPC64 ? -8U : -4U;
// SVR4 ABI: First slot in the general register save area.
return isPPC64 ? -8U : -4U;
}
/// getBasePointerSaveOffset - Return the previous frame offset to save the /// getBasePointerSaveOffset - Return the previous frame offset to save the
/// base pointer. /// base pointer.

View File

@ -3472,10 +3472,9 @@ static SDValue EmitTailCallStoreFPAndRetAddr(SelectionDAG &DAG,
if (SPDiff) { if (SPDiff) {
// Calculate the new stack slot for the return address. // Calculate the new stack slot for the return address.
int SlotSize = isPPC64 ? 8 : 4; int SlotSize = isPPC64 ? 8 : 4;
int NewRetAddrLoc = SPDiff + const PPCFrameLowering *FL =
MF.getSubtarget<PPCSubtarget>() MF.getSubtarget<PPCSubtarget>().getFrameLowering();
.getFrameLowering() int NewRetAddrLoc = SPDiff + FL->getReturnSaveOffset();
->getReturnSaveOffset();
int NewRetAddr = MF.getFrameInfo()->CreateFixedObject(SlotSize, int NewRetAddr = MF.getFrameInfo()->CreateFixedObject(SlotSize,
NewRetAddrLoc, true); NewRetAddrLoc, true);
EVT VT = isPPC64 ? MVT::i64 : MVT::i32; EVT VT = isPPC64 ? MVT::i64 : MVT::i32;
@ -3487,8 +3486,7 @@ static SDValue EmitTailCallStoreFPAndRetAddr(SelectionDAG &DAG,
// When using the 32/64-bit SVR4 ABI there is no need to move the FP stack // When using the 32/64-bit SVR4 ABI there is no need to move the FP stack
// slot as the FP is never overwritten. // slot as the FP is never overwritten.
if (isDarwinABI) { if (isDarwinABI) {
int NewFPLoc = int NewFPLoc = SPDiff + FL->getFramePointerSaveOffset();
SPDiff + PPCFrameLowering::getFramePointerSaveOffset(isPPC64, isDarwinABI);
int NewFPIdx = MF.getFrameInfo()->CreateFixedObject(SlotSize, NewFPLoc, int NewFPIdx = MF.getFrameInfo()->CreateFixedObject(SlotSize, NewFPLoc,
true); true);
SDValue NewFramePtrIdx = DAG.getFrameIndex(NewFPIdx, VT); SDValue NewFramePtrIdx = DAG.getFrameIndex(NewFPIdx, VT);
@ -5332,7 +5330,6 @@ SDValue
PPCTargetLowering::getFramePointerFrameIndex(SelectionDAG & DAG) const { PPCTargetLowering::getFramePointerFrameIndex(SelectionDAG & DAG) const {
MachineFunction &MF = DAG.getMachineFunction(); MachineFunction &MF = DAG.getMachineFunction();
bool isPPC64 = Subtarget.isPPC64(); bool isPPC64 = Subtarget.isPPC64();
bool isDarwinABI = Subtarget.isDarwinABI();
EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
// Get current frame pointer save index. The users of this index will be // Get current frame pointer save index. The users of this index will be
@ -5343,9 +5340,7 @@ PPCTargetLowering::getFramePointerFrameIndex(SelectionDAG & DAG) const {
// If the frame pointer save index hasn't been defined yet. // If the frame pointer save index hasn't been defined yet.
if (!FPSI) { if (!FPSI) {
// Find out what the fix offset of the frame pointer save area. // Find out what the fix offset of the frame pointer save area.
int FPOffset = PPCFrameLowering::getFramePointerSaveOffset(isPPC64, int FPOffset = Subtarget.getFrameLowering()->getFramePointerSaveOffset();
isDarwinABI);
// Allocate the frame index for frame pointer save area. // Allocate the frame index for frame pointer save area.
FPSI = MF.getFrameInfo()->CreateFixedObject(isPPC64? 8 : 4, FPOffset, true); FPSI = MF.getFrameInfo()->CreateFixedObject(isPPC64? 8 : 4, FPOffset, true);
// Save the result. // Save the result.