blob: 1b5893da0ce2db51d2ab7c0353cd30358c1e5b0e [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Nate Begemanca068e82004-08-14 22:16:36 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Nate Begemanca068e82004-08-14 22:16:36 +00008//===----------------------------------------------------------------------===//
9//
10//
Nate Begeman21e463b2005-10-16 05:39:50 +000011//===----------------------------------------------------------------------===//
Nate Begemanca068e82004-08-14 22:16:36 +000012
13#ifndef POWERPC_FRAMEINFO_H
14#define POWERPC_FRAMEINFO_H
15
Chris Lattner26689592005-10-14 23:51:18 +000016#include "PPC.h"
Nate Begemanca068e82004-08-14 22:16:36 +000017#include "llvm/Target/TargetFrameInfo.h"
18#include "llvm/Target/TargetMachine.h"
Nate Begemanca068e82004-08-14 22:16:36 +000019
20namespace llvm {
21
Nate Begeman21e463b2005-10-16 05:39:50 +000022class PPCFrameInfo: public TargetFrameInfo {
Nate Begemanca068e82004-08-14 22:16:36 +000023 const TargetMachine &TM;
Misha Brukmanb5f662f2005-04-21 23:30:14 +000024
Nate Begemanca068e82004-08-14 22:16:36 +000025public:
Nate Begeman21e463b2005-10-16 05:39:50 +000026 PPCFrameInfo(const TargetMachine &tm, bool LP64)
Misha Brukman63161812004-08-17 05:09:39 +000027 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
Nate Begemanca068e82004-08-14 22:16:36 +000028 }
29
Jim Laskey51fe9d92006-12-06 17:42:06 +000030 /// getReturnSaveOffset - Return the previous frame offset to save the
31 /// return address.
Chris Lattner9f0bc652007-02-25 05:34:32 +000032 static unsigned getReturnSaveOffset(bool LP64, bool isMacho) {
33 if (isMacho)
34 return LP64 ? 16 : 8;
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000035 // For ELF 32 ABI:
36 return 4;
Nate Begemanca068e82004-08-14 22:16:36 +000037 }
Jim Laskey51fe9d92006-12-06 17:42:06 +000038
Jim Laskey2f616bf2006-11-16 22:43:37 +000039 /// getFramePointerSaveOffset - Return the previous frame offset to save the
40 /// frame pointer.
Chris Lattner9f0bc652007-02-25 05:34:32 +000041 static unsigned getFramePointerSaveOffset(bool LP64, bool isMacho) {
42 // For MachO ABI:
Jim Laskey2f616bf2006-11-16 22:43:37 +000043 // Use the TOC save slot in the PowerPC linkage area for saving the frame
44 // pointer (if needed.) LLVM does not generate code that uses the TOC (R2
45 // is treated as a caller saved register.)
Chris Lattner9f0bc652007-02-25 05:34:32 +000046 if (isMacho)
47 return LP64 ? 40 : 20;
48
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000049 // For ELF 32 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000050 // Save it right before the link register
Reid Spencer6733a162007-04-04 22:07:24 +000051 return -4U;
Jim Laskey2f616bf2006-11-16 22:43:37 +000052 }
53
54 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
55 ///
Chris Lattner9f0bc652007-02-25 05:34:32 +000056 static unsigned getLinkageSize(bool LP64, bool isMacho) {
57 if (isMacho)
58 return 6 * (LP64 ? 8 : 4);
59
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000060 // For ELF 32 ABI:
61 return 8;
Jim Laskey2f616bf2006-11-16 22:43:37 +000062 }
63
64 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
65 /// argument area.
Chris Lattner9f0bc652007-02-25 05:34:32 +000066 static unsigned getMinCallArgumentsSize(bool LP64, bool isMacho) {
67 // For Macho ABI:
68 // The prolog code of the callee may store up to 8 GPR argument registers to
69 // the stack, allowing va_start to index over them in memory if its varargs.
70 // Because we cannot tell if this is needed on the caller side, we have to
71 // conservatively assume that it is needed. As such, make sure we have at
72 // least enough stack space for the caller to store the 8 GPRs.
73 if (isMacho)
74 return 8 * (LP64 ? 8 : 4);
75
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000076 // For ELF 32 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000077 // There is no default stack allocated for the 8 first GPR arguments.
78 return 0;
Jim Laskey2f616bf2006-11-16 22:43:37 +000079 }
80
81 /// getMinCallFrameSize - Return the minimum size a call frame can be using
82 /// the PowerPC ABI.
Chris Lattner9f0bc652007-02-25 05:34:32 +000083 static unsigned getMinCallFrameSize(bool LP64, bool isMacho) {
Jim Laskey2f616bf2006-11-16 22:43:37 +000084 // The call frame needs to be at least big enough for linkage and 8 args.
Chris Lattner9f0bc652007-02-25 05:34:32 +000085 return getLinkageSize(LP64, isMacho) +
86 getMinCallArgumentsSize(LP64, isMacho);
Jim Laskey2f616bf2006-11-16 22:43:37 +000087 }
88
Nate Begemanca068e82004-08-14 22:16:36 +000089};
90
91} // End llvm namespace
92
93#endif