1 //===-- PPCFrameInfo.h - Define TargetFrameInfo 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/TargetFrameInfo.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/ADT/STLExtras.h"
24 class PPCFrameInfo
: public TargetFrameInfo
{
25 const TargetMachine
&TM
;
28 PPCFrameInfo(const TargetMachine
&tm
, bool LP64
)
29 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown
, 16, 0), TM(tm
) {
32 /// getReturnSaveOffset - Return the previous frame offset to save the
34 static unsigned getReturnSaveOffset(bool isPPC64
, bool isDarwinABI
) {
36 return isPPC64
? 16 : 8;
38 return isPPC64
? 16 : 4;
41 /// getFramePointerSaveOffset - Return the previous frame offset to save the
43 static unsigned getFramePointerSaveOffset(bool isPPC64
, bool isDarwinABI
) {
44 // For the Darwin ABI:
45 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area
46 // for saving the frame pointer (if needed.) While the published ABI has
47 // not used this slot since at least MacOSX 10.2, there is older code
48 // around that does use it, and that needs to continue to work.
50 return isPPC64
? -8U : -4U;
52 // SVR4 ABI: First slot in the general register save area.
53 return isPPC64
? -8U : -4U;
56 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
58 static unsigned getLinkageSize(bool isPPC64
, bool isDarwinABI
) {
59 if (isDarwinABI
|| isPPC64
)
60 return 6 * (isPPC64
? 8 : 4);
66 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
68 static unsigned getMinCallArgumentsSize(bool isPPC64
, bool isDarwinABI
) {
69 // For the Darwin ABI / 64-bit SVR4 ABI:
70 // The prolog code of the callee may store up to 8 GPR argument registers to
71 // the stack, allowing va_start to index over them in memory if its varargs.
72 // Because we cannot tell if this is needed on the caller side, we have to
73 // conservatively assume that it is needed. As such, make sure we have at
74 // least enough stack space for the caller to store the 8 GPRs.
75 if (isDarwinABI
|| isPPC64
)
76 return 8 * (isPPC64
? 8 : 4);
79 // There is no default stack allocated for the 8 first GPR arguments.
83 /// getMinCallFrameSize - Return the minimum size a call frame can be using
85 static unsigned getMinCallFrameSize(bool isPPC64
, bool isDarwinABI
) {
86 // The call frame needs to be at least big enough for linkage and 8 args.
87 return getLinkageSize(isPPC64
, isDarwinABI
) +
88 getMinCallArgumentsSize(isPPC64
, isDarwinABI
);
91 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
93 getCalleeSavedSpillSlots(unsigned &NumEntries
) const {
94 if (TM
.getSubtarget
<PPCSubtarget
>().isDarwinABI()) {
96 if (TM
.getSubtarget
<PPCSubtarget
>().isPPC64()) {
97 static const SpillSlot darwin64Offsets
= {PPC::X31
, -8};
98 return &darwin64Offsets
;
100 static const SpillSlot darwinOffsets
= {PPC::R31
, -4};
101 return &darwinOffsets
;
105 // Early exit if not using the SVR4 ABI.
106 if (!TM
.getSubtarget
<PPCSubtarget
>().isSVR4ABI()) {
111 static const SpillSlot Offsets
[] = {
112 // Floating-point register save area offsets.
132 // General register save area offsets.
152 // CR save area offset.
153 // FIXME SVR4: Disable CR save area for now.
170 // VRSAVE save area offset.
173 // Vector register save area
188 static const SpillSlot Offsets64
[] = {
189 // Floating-point register save area offsets.
209 // General register save area offsets.
210 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
250 // CR save area offset.
251 // FIXME SVR4: Disable CR save area for now.
268 // VRSAVE save area offset.
271 // Vector register save area
286 if (TM
.getSubtarget
<PPCSubtarget
>().isPPC64()) {
287 NumEntries
= array_lengthof(Offsets64
);
291 NumEntries
= array_lengthof(Offsets
);
298 } // End llvm namespace