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 /// targetHandlesStackFrameRounding - Returns true if the target is
49 /// responsible for rounding up the stack frame (probably at emitPrologue
51 bool targetHandlesStackFrameRounding() const { return true; }
53 /// getReturnSaveOffset - Return the previous frame offset to save the
55 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
57 return isPPC64 ? 16 : 8;
59 return isPPC64 ? 16 : 4;
62 /// getFramePointerSaveOffset - Return the previous frame offset to save the
64 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
65 // For the Darwin ABI:
66 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
67 // for saving the frame pointer (if needed.) While the published ABI has
68 // not used this slot since at least MacOSX 10.2, there is older code
69 // around that does use it, and that needs to continue to work.
71 return isPPC64 ? -8U : -4U;
73 // SVR4 ABI: First slot in the general register save area.
74 return isPPC64 ? -8U : -4U;
77 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
79 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
80 if (isDarwinABI || isPPC64)
81 return 6 * (isPPC64 ? 8 : 4);
87 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
89 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
90 // For the Darwin ABI / 64-bit SVR4 ABI:
91 // The prolog code of the callee may store up to 8 GPR argument registers to
92 // the stack, allowing va_start to index over them in memory if its varargs.
93 // Because we cannot tell if this is needed on the caller side, we have to
94 // conservatively assume that it is needed. As such, make sure we have at
95 // least enough stack space for the caller to store the 8 GPRs.
96 if (isDarwinABI || isPPC64)
97 return 8 * (isPPC64 ? 8 : 4);
100 // There is no default stack allocated for the 8 first GPR arguments.
104 /// getMinCallFrameSize - Return the minimum size a call frame can be using
106 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
107 // The call frame needs to be at least big enough for linkage and 8 args.
108 return getLinkageSize(isPPC64, isDarwinABI) +
109 getMinCallArgumentsSize(isPPC64, isDarwinABI);
112 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
114 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
115 if (Subtarget.isDarwinABI()) {
117 if (Subtarget.isPPC64()) {
118 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
119 return &darwin64Offsets;
121 static const SpillSlot darwinOffsets = {PPC::R31, -4};
122 return &darwinOffsets;
126 // Early exit if not using the SVR4 ABI.
127 if (!Subtarget.isSVR4ABI()) {
132 static const SpillSlot Offsets[] = {
133 // Floating-point register save area offsets.
153 // General register save area offsets.
173 // CR save area offset.
174 // FIXME SVR4: Disable CR save area for now.
191 // VRSAVE save area offset.
194 // Vector register save area
209 static const SpillSlot Offsets64[] = {
210 // Floating-point register save area offsets.
230 // General register save area offsets.
231 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
271 // CR save area offset.
272 // FIXME SVR4: Disable CR save area for now.
289 // VRSAVE save area offset.
292 // Vector register save area
307 if (Subtarget.isPPC64()) {
308 NumEntries = array_lengthof(Offsets64);
312 NumEntries = array_lengthof(Offsets);
319 } // End llvm namespace