2012-02-18 12:03:15 +00:00
|
|
|
//===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-08-14 22:16:36 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-08-14 22:16:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
//
|
2005-10-16 05:39:50 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-14 22:16:36 +00:00
|
|
|
|
|
|
|
#ifndef POWERPC_FRAMEINFO_H
|
|
|
|
#define POWERPC_FRAMEINFO_H
|
|
|
|
|
2005-10-14 23:51:18 +00:00
|
|
|
#include "PPC.h"
|
2009-07-03 06:45:56 +00:00
|
|
|
#include "PPCSubtarget.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2004-08-14 22:16:36 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2010-11-15 00:06:54 +00:00
|
|
|
class PPCSubtarget;
|
2004-08-14 22:16:36 +00:00
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
class PPCFrameLowering: public TargetFrameLowering {
|
2010-11-15 00:06:54 +00:00
|
|
|
const PPCSubtarget &Subtarget;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-08-14 22:16:36 +00:00
|
|
|
public:
|
2011-01-10 12:39:04 +00:00
|
|
|
PPCFrameLowering(const PPCSubtarget &sti)
|
2013-01-30 23:43:27 +00:00
|
|
|
: TargetFrameLowering(TargetFrameLowering::StackGrowsDown,
|
|
|
|
(sti.hasQPX() || sti.isBGQ()) ? 32 : 16, 0),
|
2011-01-10 12:39:04 +00:00
|
|
|
Subtarget(sti) {
|
2004-08-14 22:16:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 05:06:04 +00:00
|
|
|
unsigned determineFrameLayout(MachineFunction &MF,
|
|
|
|
bool UpdateMF = true,
|
|
|
|
bool UseEstimate = false) const;
|
2010-11-15 00:06:54 +00:00
|
|
|
|
|
|
|
/// emitProlog/emitEpilog - These methods insert prolog and epilog code into
|
|
|
|
/// the function.
|
|
|
|
void emitPrologue(MachineFunction &MF) const;
|
|
|
|
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
|
|
|
|
|
2010-11-18 21:19:35 +00:00
|
|
|
bool hasFP(const MachineFunction &MF) const;
|
2010-12-18 19:53:14 +00:00
|
|
|
bool needsFP(const MachineFunction &MF) const;
|
2013-03-21 19:03:19 +00:00
|
|
|
void replaceFPWithRealFP(MachineFunction &MF) const;
|
2010-11-18 21:19:35 +00:00
|
|
|
|
2010-11-27 23:05:25 +00:00
|
|
|
void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
|
|
|
|
RegScavenger *RS = NULL) const;
|
2013-03-14 20:33:40 +00:00
|
|
|
void processFunctionBeforeFrameFinalized(MachineFunction &MF,
|
|
|
|
RegScavenger *RS = NULL) const;
|
2013-03-15 05:06:04 +00:00
|
|
|
void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
|
2010-11-27 23:05:25 +00:00
|
|
|
|
2012-09-12 14:47:47 +00:00
|
|
|
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const;
|
|
|
|
|
2013-02-21 20:05:00 +00:00
|
|
|
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
|
|
|
MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I) const;
|
|
|
|
|
2012-09-12 14:47:47 +00:00
|
|
|
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const;
|
|
|
|
|
2010-11-15 00:06:54 +00:00
|
|
|
/// targetHandlesStackFrameRounding - Returns true if the target is
|
|
|
|
/// responsible for rounding up the stack frame (probably at emitPrologue
|
|
|
|
/// time).
|
|
|
|
bool targetHandlesStackFrameRounding() const { return true; }
|
|
|
|
|
2006-12-06 17:42:06 +00:00
|
|
|
/// getReturnSaveOffset - Return the previous frame offset to save the
|
|
|
|
/// return address.
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
|
2009-07-03 06:47:08 +00:00
|
|
|
if (isDarwinABI)
|
2009-08-15 11:54:46 +00:00
|
|
|
return isPPC64 ? 16 : 8;
|
2009-07-03 06:47:08 +00:00
|
|
|
// SVR4 ABI:
|
2009-08-15 11:54:46 +00:00
|
|
|
return isPPC64 ? 16 : 4;
|
2004-08-14 22:16:36 +00:00
|
|
|
}
|
2006-12-06 17:42:06 +00:00
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
/// getFramePointerSaveOffset - Return the previous frame offset to save the
|
|
|
|
/// frame pointer.
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
|
2009-07-03 06:47:08 +00:00
|
|
|
// For the Darwin ABI:
|
2009-11-24 22:59:02 +00:00
|
|
|
// 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.
|
2009-07-03 06:47:08 +00:00
|
|
|
if (isDarwinABI)
|
2009-11-24 22:59:02 +00:00
|
|
|
return isPPC64 ? -8U : -4U;
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2009-08-15 11:54:46 +00:00
|
|
|
// SVR4 ABI: First slot in the general register save area.
|
2009-12-18 13:00:34 +00:00
|
|
|
return isPPC64 ? -8U : -4U;
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2006-11-16 22:43:37 +00:00
|
|
|
/// getLinkageSize - Return the size of the PowerPC ABI linkage area.
|
|
|
|
///
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
|
|
|
|
if (isDarwinABI || isPPC64)
|
|
|
|
return 6 * (isPPC64 ? 8 : 4);
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2009-07-03 06:47:08 +00:00
|
|
|
// SVR4 ABI:
|
2007-04-03 12:35:28 +00:00
|
|
|
return 8;
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
|
|
|
|
/// argument area.
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
|
|
|
|
// For the Darwin ABI / 64-bit SVR4 ABI:
|
2007-02-25 05:34:32 +00:00
|
|
|
// The prolog code of the callee may store up to 8 GPR argument registers to
|
|
|
|
// the stack, allowing va_start to index over them in memory if its varargs.
|
|
|
|
// Because we cannot tell if this is needed on the caller side, we have to
|
|
|
|
// conservatively assume that it is needed. As such, make sure we have at
|
|
|
|
// least enough stack space for the caller to store the 8 GPRs.
|
2009-08-15 11:54:46 +00:00
|
|
|
if (isDarwinABI || isPPC64)
|
|
|
|
return 8 * (isPPC64 ? 8 : 4);
|
2010-11-15 00:06:05 +00:00
|
|
|
|
2009-08-15 11:54:46 +00:00
|
|
|
// 32-bit SVR4 ABI:
|
2007-02-25 05:34:32 +00:00
|
|
|
// There is no default stack allocated for the 8 first GPR arguments.
|
|
|
|
return 0;
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getMinCallFrameSize - Return the minimum size a call frame can be using
|
|
|
|
/// the PowerPC ABI.
|
2009-08-15 11:54:46 +00:00
|
|
|
static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
|
2006-11-16 22:43:37 +00:00
|
|
|
// The call frame needs to be at least big enough for linkage and 8 args.
|
2009-08-15 11:54:46 +00:00
|
|
|
return getLinkageSize(isPPC64, isDarwinABI) +
|
|
|
|
getMinCallArgumentsSize(isPPC64, isDarwinABI);
|
2006-11-16 22:43:37 +00:00
|
|
|
}
|
2009-07-03 06:45:56 +00:00
|
|
|
|
|
|
|
// With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
|
2009-09-27 17:58:47 +00:00
|
|
|
const SpillSlot *
|
2009-07-03 06:45:56 +00:00
|
|
|
getCalleeSavedSpillSlots(unsigned &NumEntries) const {
|
2010-11-15 00:06:54 +00:00
|
|
|
if (Subtarget.isDarwinABI()) {
|
2009-11-24 22:59:02 +00:00
|
|
|
NumEntries = 1;
|
2010-11-15 00:06:54 +00:00
|
|
|
if (Subtarget.isPPC64()) {
|
2009-11-25 00:58:21 +00:00
|
|
|
static const SpillSlot darwin64Offsets = {PPC::X31, -8};
|
|
|
|
return &darwin64Offsets;
|
2009-11-24 22:59:02 +00:00
|
|
|
} else {
|
2009-11-25 00:58:21 +00:00
|
|
|
static const SpillSlot darwinOffsets = {PPC::R31, -4};
|
|
|
|
return &darwinOffsets;
|
2009-11-24 22:59:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:45:56 +00:00
|
|
|
// Early exit if not using the SVR4 ABI.
|
2010-11-15 00:06:54 +00:00
|
|
|
if (!Subtarget.isSVR4ABI()) {
|
2009-07-03 06:45:56 +00:00
|
|
|
NumEntries = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-09-27 17:58:47 +00:00
|
|
|
|
2013-03-14 18:38:31 +00:00
|
|
|
// Note that the offsets here overlap, but this is fixed up in
|
|
|
|
// processFunctionBeforeFrameFinalized.
|
|
|
|
|
2009-09-27 17:58:47 +00:00
|
|
|
static const SpillSlot Offsets[] = {
|
2009-07-03 06:45:56 +00:00
|
|
|
// Floating-point register save area offsets.
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::F31, -8},
|
|
|
|
{PPC::F30, -16},
|
|
|
|
{PPC::F29, -24},
|
|
|
|
{PPC::F28, -32},
|
|
|
|
{PPC::F27, -40},
|
|
|
|
{PPC::F26, -48},
|
|
|
|
{PPC::F25, -56},
|
|
|
|
{PPC::F24, -64},
|
|
|
|
{PPC::F23, -72},
|
|
|
|
{PPC::F22, -80},
|
|
|
|
{PPC::F21, -88},
|
|
|
|
{PPC::F20, -96},
|
|
|
|
{PPC::F19, -104},
|
|
|
|
{PPC::F18, -112},
|
|
|
|
{PPC::F17, -120},
|
|
|
|
{PPC::F16, -128},
|
|
|
|
{PPC::F15, -136},
|
|
|
|
{PPC::F14, -144},
|
|
|
|
|
2009-07-03 06:45:56 +00:00
|
|
|
// General register save area offsets.
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::R31, -4},
|
|
|
|
{PPC::R30, -8},
|
|
|
|
{PPC::R29, -12},
|
|
|
|
{PPC::R28, -16},
|
|
|
|
{PPC::R27, -20},
|
|
|
|
{PPC::R26, -24},
|
|
|
|
{PPC::R25, -28},
|
|
|
|
{PPC::R24, -32},
|
|
|
|
{PPC::R23, -36},
|
|
|
|
{PPC::R22, -40},
|
|
|
|
{PPC::R21, -44},
|
|
|
|
{PPC::R20, -48},
|
|
|
|
{PPC::R19, -52},
|
|
|
|
{PPC::R18, -56},
|
|
|
|
{PPC::R17, -60},
|
|
|
|
{PPC::R16, -64},
|
|
|
|
{PPC::R15, -68},
|
|
|
|
{PPC::R14, -72},
|
2009-07-03 06:45:56 +00:00
|
|
|
|
2012-09-12 14:47:47 +00:00
|
|
|
// CR save area offset. We map each of the nonvolatile CR fields
|
|
|
|
// to the slot for CR2, which is the first of the nonvolatile CR
|
|
|
|
// fields to be assigned, so that we only allocate one save slot.
|
|
|
|
// See PPCRegisterInfo::hasReservedSpillSlot() for more information.
|
|
|
|
{PPC::CR2, -4},
|
2009-07-03 06:45:56 +00:00
|
|
|
|
|
|
|
// VRSAVE save area offset.
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::VRSAVE, -4},
|
|
|
|
|
2009-07-03 06:45:56 +00:00
|
|
|
// Vector register save area
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::V31, -16},
|
|
|
|
{PPC::V30, -32},
|
|
|
|
{PPC::V29, -48},
|
|
|
|
{PPC::V28, -64},
|
|
|
|
{PPC::V27, -80},
|
|
|
|
{PPC::V26, -96},
|
|
|
|
{PPC::V25, -112},
|
|
|
|
{PPC::V24, -128},
|
|
|
|
{PPC::V23, -144},
|
|
|
|
{PPC::V22, -160},
|
|
|
|
{PPC::V21, -176},
|
|
|
|
{PPC::V20, -192}
|
2009-07-03 06:45:56 +00:00
|
|
|
};
|
2009-09-27 17:58:47 +00:00
|
|
|
|
|
|
|
static const SpillSlot Offsets64[] = {
|
2009-08-15 11:54:46 +00:00
|
|
|
// Floating-point register save area offsets.
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::F31, -8},
|
|
|
|
{PPC::F30, -16},
|
|
|
|
{PPC::F29, -24},
|
|
|
|
{PPC::F28, -32},
|
|
|
|
{PPC::F27, -40},
|
|
|
|
{PPC::F26, -48},
|
|
|
|
{PPC::F25, -56},
|
|
|
|
{PPC::F24, -64},
|
|
|
|
{PPC::F23, -72},
|
|
|
|
{PPC::F22, -80},
|
|
|
|
{PPC::F21, -88},
|
|
|
|
{PPC::F20, -96},
|
|
|
|
{PPC::F19, -104},
|
|
|
|
{PPC::F18, -112},
|
|
|
|
{PPC::F17, -120},
|
|
|
|
{PPC::F16, -128},
|
|
|
|
{PPC::F15, -136},
|
|
|
|
{PPC::F14, -144},
|
2009-08-15 11:54:46 +00:00
|
|
|
|
|
|
|
// General register save area offsets.
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::X31, -8},
|
|
|
|
{PPC::X30, -16},
|
|
|
|
{PPC::X29, -24},
|
|
|
|
{PPC::X28, -32},
|
|
|
|
{PPC::X27, -40},
|
|
|
|
{PPC::X26, -48},
|
|
|
|
{PPC::X25, -56},
|
|
|
|
{PPC::X24, -64},
|
|
|
|
{PPC::X23, -72},
|
|
|
|
{PPC::X22, -80},
|
|
|
|
{PPC::X21, -88},
|
|
|
|
{PPC::X20, -96},
|
|
|
|
{PPC::X19, -104},
|
|
|
|
{PPC::X18, -112},
|
|
|
|
{PPC::X17, -120},
|
|
|
|
{PPC::X16, -128},
|
|
|
|
{PPC::X15, -136},
|
|
|
|
{PPC::X14, -144},
|
2009-08-15 11:54:46 +00:00
|
|
|
|
|
|
|
// VRSAVE save area offset.
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::VRSAVE, -4},
|
2009-08-15 11:54:46 +00:00
|
|
|
|
|
|
|
// Vector register save area
|
2009-09-27 17:58:47 +00:00
|
|
|
{PPC::V31, -16},
|
|
|
|
{PPC::V30, -32},
|
|
|
|
{PPC::V29, -48},
|
|
|
|
{PPC::V28, -64},
|
|
|
|
{PPC::V27, -80},
|
|
|
|
{PPC::V26, -96},
|
|
|
|
{PPC::V25, -112},
|
|
|
|
{PPC::V24, -128},
|
|
|
|
{PPC::V23, -144},
|
|
|
|
{PPC::V22, -160},
|
|
|
|
{PPC::V21, -176},
|
|
|
|
{PPC::V20, -192}
|
2009-08-15 11:54:46 +00:00
|
|
|
};
|
2009-09-27 17:58:47 +00:00
|
|
|
|
2010-11-15 00:06:54 +00:00
|
|
|
if (Subtarget.isPPC64()) {
|
2009-08-15 11:54:46 +00:00
|
|
|
NumEntries = array_lengthof(Offsets64);
|
|
|
|
|
|
|
|
return Offsets64;
|
|
|
|
} else {
|
|
|
|
NumEntries = array_lengthof(Offsets);
|
|
|
|
|
|
|
|
return Offsets;
|
|
|
|
}
|
2009-07-03 06:45:56 +00:00
|
|
|
}
|
2004-08-14 22:16:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|