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 // Use the TOC save slot in the PowerPC linkage area for saving the frame
46 // pointer (if needed.) LLVM does not generate code that uses the TOC (R2
47 // is treated as a caller saved register.)
49 return isPPC64 ? 40 : 20;
51 // SVR4 ABI: First slot in the general register save area.
55 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
57 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI) {
58 if (isDarwinABI || isPPC64)
59 return 6 * (isPPC64 ? 8 : 4);
65 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
67 static unsigned getMinCallArgumentsSize(bool isPPC64, bool isDarwinABI) {
68 // For the Darwin ABI / 64-bit SVR4 ABI:
69 // The prolog code of the callee may store up to 8 GPR argument registers to
70 // the stack, allowing va_start to index over them in memory if its varargs.
71 // Because we cannot tell if this is needed on the caller side, we have to
72 // conservatively assume that it is needed. As such, make sure we have at
73 // least enough stack space for the caller to store the 8 GPRs.
74 if (isDarwinABI || isPPC64)
75 return 8 * (isPPC64 ? 8 : 4);
78 // There is no default stack allocated for the 8 first GPR arguments.
82 /// getMinCallFrameSize - Return the minimum size a call frame can be using
84 static unsigned getMinCallFrameSize(bool isPPC64, bool isDarwinABI) {
85 // The call frame needs to be at least big enough for linkage and 8 args.
86 return getLinkageSize(isPPC64, isDarwinABI) +
87 getMinCallArgumentsSize(isPPC64, isDarwinABI);
90 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
92 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
93 // Early exit if not using the SVR4 ABI.
94 if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) {
99 static const SpillSlot Offsets[] = {
100 // Floating-point register save area offsets.
120 // General register save area offsets.
140 // CR save area offset.
141 // FIXME SVR4: Disable CR save area for now.
158 // VRSAVE save area offset.
161 // Vector register save area
176 static const SpillSlot Offsets64[] = {
177 // Floating-point register save area offsets.
197 // General register save area offsets.
198 // FIXME 64-bit SVR4: Are 32-bit registers actually allocated in 64-bit
238 // CR save area offset.
239 // FIXME SVR4: Disable CR save area for now.
256 // VRSAVE save area offset.
259 // Vector register save area
274 if (TM.getSubtarget<PPCSubtarget>().isPPC64()) {
275 NumEntries = array_lengthof(Offsets64);
279 NumEntries = array_lengthof(Offsets);
286 } // End llvm namespace