1 //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #ifndef POWERPC_FRAMEINFO_H
14 #define POWERPC_FRAMEINFO_H
17 #include "PPCSubtarget.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Target/TargetFrameLowering.h"
20 #include "llvm/Target/TargetMachine.h"
25 class PPCFrameLowering: public TargetFrameLowering {
26 const PPCSubtarget &Subtarget;
29 PPCFrameLowering(const PPCSubtarget &sti)
30 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown,
31 (sti.hasQPX() || sti.isBGQ()) ? 32 : 16, 0),
35 void determineFrameLayout(MachineFunction &MF) const;
37 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
39 void emitPrologue(MachineFunction &MF) const;
40 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
42 bool hasFP(const MachineFunction &MF) const;
43 bool needsFP(const MachineFunction &MF) const;
45 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
46 RegScavenger *RS = NULL) const;
47 void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
49 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
50 MachineBasicBlock::iterator MI,
51 const std::vector<CalleeSavedInfo> &CSI,
52 const TargetRegisterInfo *TRI) const;
54 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
55 MachineBasicBlock::iterator MI,
56 const std::vector<CalleeSavedInfo> &CSI,
57 const TargetRegisterInfo *TRI) const;
59 /// targetHandlesStackFrameRounding - Returns true if the target is
60 /// responsible for rounding up the stack frame (probably at emitPrologue
62 bool targetHandlesStackFrameRounding() const { return true; }
64 /// getReturnSaveOffset - Return the previous frame offset to save the
66 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
68 return isPPC64 ? 16 : 8;
70 return isPPC64 ? 16 : 4;
73 /// getFramePointerSaveOffset - Return the previous frame offset to save the
75 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
76 // For the Darwin ABI:
77 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
78 // for saving the frame pointer (if needed.) While the published ABI has
79 // not used this slot since at least MacOSX 10.2, there is older code
80 // around that does use it, and that needs to continue to work.
82 return isPPC64 ? -8U : -4U;
84 // SVR4 ABI: First slot in the general register save area.
85 return isPPC64 ? -8U : -4U;
88 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
90 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
91 if (isDarwinABI || isPPC64)
92 return 6 * (isPPC64 ? 8 : 4);
98 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
100 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
101 // For the Darwin ABI / 64-bit SVR4 ABI:
102 // The prolog code of the callee may store up to 8 GPR argument registers to
103 // the stack, allowing va_start to index over them in memory if its varargs.
104 // Because we cannot tell if this is needed on the caller side, we have to
105 // conservatively assume that it is needed. As such, make sure we have at
106 // least enough stack space for the caller to store the 8 GPRs.
107 if (isDarwinABI || isPPC64)
108 return 8 * (isPPC64 ? 8 : 4);
111 // There is no default stack allocated for the 8 first GPR arguments.
115 /// getMinCallFrameSize - Return the minimum size a call frame can be using
117 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
118 // The call frame needs to be at least big enough for linkage and 8 args.
119 return getLinkageSize(isPPC64, isDarwinABI) +
120 getMinCallArgumentsSize(isPPC64, isDarwinABI);
123 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
125 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
126 if (Subtarget.isDarwinABI()) {
128 if (Subtarget.isPPC64()) {
129 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
130 return &darwin64Offsets;
132 static const SpillSlot darwinOffsets = {PPC::R31, -4};
133 return &darwinOffsets;
137 // Early exit if not using the SVR4 ABI.
138 if (!Subtarget.isSVR4ABI()) {
143 static const SpillSlot Offsets[] = {
144 // Floating-point register save area offsets.
164 // General register save area offsets.
184 // CR save area offset. We map each of the nonvolatile CR fields
185 // to the slot for CR2, which is the first of the nonvolatile CR
186 // fields to be assigned, so that we only allocate one save slot.
187 // See PPCRegisterInfo::hasReservedSpillSlot() for more information.
190 // VRSAVE save area offset.
193 // Vector register save area
208 static const SpillSlot Offsets64[] = {
209 // Floating-point register save area offsets.
229 // General register save area offsets.
249 // VRSAVE save area offset.
252 // Vector register save area
267 if (Subtarget.isPPC64()) {
268 NumEntries = array_lengthof(Offsets64);
272 NumEntries = array_lengthof(Offsets);
279 } // End llvm namespace