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/Target/TargetFrameLowering.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/ADT/STLExtras.h"
25 class PPCFrameLowering: public TargetFrameLowering {
26 const PPCSubtarget &Subtarget;
29 PPCFrameLowering(const PPCSubtarget &sti)
30 : TargetFrameLowering(TargetFrameLowering::StackGrowsDown, 16, 0),
34 void determineFrameLayout(MachineFunction &MF) const;
36 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
38 void emitPrologue(MachineFunction &MF) const;
39 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
41 bool hasFP(const MachineFunction &MF) const;
42 bool needsFP(const MachineFunction &MF) const;
44 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
45 RegScavenger *RS = NULL) const;
46 void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
48 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
49 MachineBasicBlock::iterator MI,
50 const std::vector<CalleeSavedInfo> &CSI,
51 const TargetRegisterInfo *TRI) const;
53 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
54 MachineBasicBlock::iterator MI,
55 const std::vector<CalleeSavedInfo> &CSI,
56 const TargetRegisterInfo *TRI) const;
58 /// targetHandlesStackFrameRounding - Returns true if the target is
59 /// responsible for rounding up the stack frame (probably at emitPrologue
61 bool targetHandlesStackFrameRounding() const { return true; }
63 /// getReturnSaveOffset - Return the previous frame offset to save the
65 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
67 return isPPC64 ? 16 : 8;
69 return isPPC64 ? 16 : 4;
72 /// getFramePointerSaveOffset - Return the previous frame offset to save the
74 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
75 // For the Darwin ABI:
76 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
77 // for saving the frame pointer (if needed.) While the published ABI has
78 // not used this slot since at least MacOSX 10.2, there is older code
79 // around that does use it, and that needs to continue to work.
81 return isPPC64 ? -8U : -4U;
83 // SVR4 ABI: First slot in the general register save area.
84 return isPPC64 ? -8U : -4U;
87 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
89 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
90 if (isDarwinABI || isPPC64)
91 return 6 * (isPPC64 ? 8 : 4);
97 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
99 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
100 // For the Darwin ABI / 64-bit SVR4 ABI:
101 // The prolog code of the callee may store up to 8 GPR argument registers to
102 // the stack, allowing va_start to index over them in memory if its varargs.
103 // Because we cannot tell if this is needed on the caller side, we have to
104 // conservatively assume that it is needed. As such, make sure we have at
105 // least enough stack space for the caller to store the 8 GPRs.
106 if (isDarwinABI || isPPC64)
107 return 8 * (isPPC64 ? 8 : 4);
110 // There is no default stack allocated for the 8 first GPR arguments.
114 /// getMinCallFrameSize - Return the minimum size a call frame can be using
116 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
117 // The call frame needs to be at least big enough for linkage and 8 args.
118 return getLinkageSize(isPPC64, isDarwinABI) +
119 getMinCallArgumentsSize(isPPC64, isDarwinABI);
122 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
124 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
125 if (Subtarget.isDarwinABI()) {
127 if (Subtarget.isPPC64()) {
128 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
129 return &darwin64Offsets;
131 static const SpillSlot darwinOffsets = {PPC::R31, -4};
132 return &darwinOffsets;
136 // Early exit if not using the SVR4 ABI.
137 if (!Subtarget.isSVR4ABI()) {
142 static const SpillSlot Offsets[] = {
143 // Floating-point register save area offsets.
163 // General register save area offsets.
183 // CR save area offset. We map each of the nonvolatile CR fields
184 // to the slot for CR2, which is the first of the nonvolatile CR
185 // fields to be assigned, so that we only allocate one save slot.
186 // See PPCRegisterInfo::hasReservedSpillSlot() for more information.
189 // VRSAVE save area offset.
192 // Vector register save area
207 static const SpillSlot Offsets64[] = {
208 // Floating-point register save area offsets.
228 // General register save area offsets.
248 // VRSAVE save area offset.
251 // Vector register save area
266 if (Subtarget.isPPC64()) {
267 NumEntries = array_lengthof(Offsets64);
271 NumEntries = array_lengthof(Offsets);
278 } // End llvm namespace