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;
43 void getInitialFrameState(std::vector<MachineMove> &Moves) const;
45 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
46 RegScavenger *RS = NULL) const;
47 void processFunctionBeforeFrameFinalized(MachineFunction &MF) const;
49 /// targetHandlesStackFrameRounding - Returns true if the target is
50 /// responsible for rounding up the stack frame (probably at emitPrologue
52 bool targetHandlesStackFrameRounding() const { return true; }
54 /// getReturnSaveOffset - Return the previous frame offset to save the
56 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) {
58 return isPPC64 ? 16 : 8;
60 return isPPC64 ? 16 : 4;
63 /// getFramePointerSaveOffset - Return the previous frame offset to save the
65 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) {
66 // For the Darwin ABI:
67 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
68 // for saving the frame pointer (if needed.) While the published ABI has
69 // not used this slot since at least MacOSX 10.2, there is older code
70 // around that does use it, and that needs to continue to work.
72 return isPPC64 ? -8U : -4U;
74 // SVR4 ABI: First slot in the general register save area.
75 return isPPC64 ? -8U : -4U;
78 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
80 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
81 if (isDarwinABI || isPPC64)
82 return 6 * (isPPC64 ? 8 : 4);
88 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
90 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
91 // For the Darwin ABI / 64-bit SVR4 ABI:
92 // The prolog code of the callee may store up to 8 GPR argument registers to
93 // the stack, allowing va_start to index over them in memory if its varargs.
94 // Because we cannot tell if this is needed on the caller side, we have to
95 // conservatively assume that it is needed. As such, make sure we have at
96 // least enough stack space for the caller to store the 8 GPRs.
97 if (isDarwinABI || isPPC64)
98 return 8 * (isPPC64 ? 8 : 4);
101 // There is no default stack allocated for the 8 first GPR arguments.
105 /// getMinCallFrameSize - Return the minimum size a call frame can be using
107 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
108 // The call frame needs to be at least big enough for linkage and 8 args.
109 return getLinkageSize(isPPC64, isDarwinABI) +
110 getMinCallArgumentsSize(isPPC64, isDarwinABI);
113 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
115 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
116 if (Subtarget.isDarwinABI()) {
118 if (Subtarget.isPPC64()) {
119 static const SpillSlot darwin64Offsets = {PPC::X31, -8};
120 return &darwin64Offsets;
122 static const SpillSlot darwinOffsets = {PPC::R31, -4};
123 return &darwinOffsets;
127 // Early exit if not using the SVR4 ABI.
128 if (!Subtarget.isSVR4ABI()) {
133 static const SpillSlot Offsets[] = {
134 // Floating-point register save area offsets.
154 // General register save area offsets.
174 // CR save area offset.
175 // FIXME SVR4: Disable CR save area for now.
192 // VRSAVE save area offset.
195 // Vector register save area
210 static const SpillSlot Offsets64[] = {
211 // Floating-point register save area offsets.
231 // General register save area offsets.
232 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
272 // CR save area offset.
273 // FIXME SVR4: Disable CR save area for now.
290 // VRSAVE save area offset.
293 // Vector register save area
308 if (Subtarget.isPPC64()) {
309 NumEntries = array_lengthof(Offsets64);
313 NumEntries = array_lengthof(Offsets);
320 } // End llvm namespace