blob: a2b81ab3e9fbc445395f2b23a4ae3e9ecb72e6fa [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"
Tilmann Schellerffd02002009-07-03 06:45:56 +000017#include "PPCSubtarget.h"
Nate Begemanca068e82004-08-14 22:16:36 +000018#include "llvm/Target/TargetFrameInfo.h"
19#include "llvm/Target/TargetMachine.h"
Tilmann Schellerffd02002009-07-03 06:45:56 +000020#include "llvm/ADT/STLExtras.h"
Nate Begemanca068e82004-08-14 22:16:36 +000021
22namespace llvm {
23
Nate Begeman21e463b2005-10-16 05:39:50 +000024class PPCFrameInfo: public TargetFrameInfo {
Nate Begemanca068e82004-08-14 22:16:36 +000025 const TargetMachine &TM;
Misha Brukmanb5f662f2005-04-21 23:30:14 +000026
Nate Begemanca068e82004-08-14 22:16:36 +000027public:
Nate Begeman21e463b2005-10-16 05:39:50 +000028 PPCFrameInfo(const TargetMachine &tm, bool LP64)
Misha Brukman63161812004-08-17 05:09:39 +000029 : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) {
Nate Begemanca068e82004-08-14 22:16:36 +000030 }
31
Jim Laskey51fe9d92006-12-06 17:42:06 +000032 /// getReturnSaveOffset - Return the previous frame offset to save the
33 /// return address.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000034 static unsigned getReturnSaveOffset(bool LP64, bool isDarwinABI) {
35 if (isDarwinABI)
Chris Lattner9f0bc652007-02-25 05:34:32 +000036 return LP64 ? 16 : 8;
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000037 // SVR4 ABI:
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000038 return 4;
Nate Begemanca068e82004-08-14 22:16:36 +000039 }
Jim Laskey51fe9d92006-12-06 17:42:06 +000040
Jim Laskey2f616bf2006-11-16 22:43:37 +000041 /// getFramePointerSaveOffset - Return the previous frame offset to save the
42 /// frame pointer.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000043 static unsigned getFramePointerSaveOffset(bool LP64, bool isDarwinABI) {
44 // For the Darwin ABI:
Jim Laskey2f616bf2006-11-16 22:43:37 +000045 // 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.)
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000048 if (isDarwinABI)
Chris Lattner9f0bc652007-02-25 05:34:32 +000049 return LP64 ? 40 : 20;
50
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000051 // SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000052 // Save it right before the link register
Reid Spencer6733a162007-04-04 22:07:24 +000053 return -4U;
Jim Laskey2f616bf2006-11-16 22:43:37 +000054 }
55
56 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
57 ///
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000058 static unsigned getLinkageSize(bool LP64, bool isDarwinABI) {
59 if (isDarwinABI)
Chris Lattner9f0bc652007-02-25 05:34:32 +000060 return 6 * (LP64 ? 8 : 4);
61
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000062 // SVR4 ABI:
Nicolas Geoffrayec58d9f2007-04-03 12:35:28 +000063 return 8;
Jim Laskey2f616bf2006-11-16 22:43:37 +000064 }
65
66 /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI
67 /// argument area.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000068 static unsigned getMinCallArgumentsSize(bool LP64, bool isDarwinABI) {
69 // For the Darwin ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000070 // 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.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000075 if (isDarwinABI)
Chris Lattner9f0bc652007-02-25 05:34:32 +000076 return 8 * (LP64 ? 8 : 4);
77
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000078 // SVR4 ABI:
Chris Lattner9f0bc652007-02-25 05:34:32 +000079 // There is no default stack allocated for the 8 first GPR arguments.
80 return 0;
Jim Laskey2f616bf2006-11-16 22:43:37 +000081 }
82
83 /// getMinCallFrameSize - Return the minimum size a call frame can be using
84 /// the PowerPC ABI.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000085 static unsigned getMinCallFrameSize(bool LP64, bool isDarwinABI) {
Jim Laskey2f616bf2006-11-16 22:43:37 +000086 // The call frame needs to be at least big enough for linkage and 8 args.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000087 return getLinkageSize(LP64, isDarwinABI) +
88 getMinCallArgumentsSize(LP64, isDarwinABI);
Jim Laskey2f616bf2006-11-16 22:43:37 +000089 }
Tilmann Schellerffd02002009-07-03 06:45:56 +000090
91 // With the SVR4 ABI, callee-saved registers have fixed offsets on the stack.
92 const std::pair<unsigned, int> *
93 getCalleeSavedSpillSlots(unsigned &NumEntries) const {
94 // Early exit if not using the SVR4 ABI.
Tilmann Scheller2a9ddfb2009-07-03 06:47:08 +000095 if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) {
Tilmann Schellerffd02002009-07-03 06:45:56 +000096 NumEntries = 0;
97 return 0;
98 }
99
100 static const std::pair<unsigned, int> Offsets[] = {
101 // Floating-point register save area offsets.
102 std::pair<unsigned, int>(PPC::F31, -8),
103 std::pair<unsigned, int>(PPC::F30, -16),
104 std::pair<unsigned, int>(PPC::F29, -24),
105 std::pair<unsigned, int>(PPC::F28, -32),
106 std::pair<unsigned, int>(PPC::F27, -40),
107 std::pair<unsigned, int>(PPC::F26, -48),
108 std::pair<unsigned, int>(PPC::F25, -56),
109 std::pair<unsigned, int>(PPC::F24, -64),
110 std::pair<unsigned, int>(PPC::F23, -72),
111 std::pair<unsigned, int>(PPC::F22, -80),
112 std::pair<unsigned, int>(PPC::F21, -88),
113 std::pair<unsigned, int>(PPC::F20, -96),
114 std::pair<unsigned, int>(PPC::F19, -104),
115 std::pair<unsigned, int>(PPC::F18, -112),
116 std::pair<unsigned, int>(PPC::F17, -120),
117 std::pair<unsigned, int>(PPC::F16, -128),
118 std::pair<unsigned, int>(PPC::F15, -136),
119 std::pair<unsigned, int>(PPC::F14, -144),
120
121 // General register save area offsets.
122 std::pair<unsigned, int>(PPC::R31, -4),
123 std::pair<unsigned, int>(PPC::R30, -8),
124 std::pair<unsigned, int>(PPC::R29, -12),
125 std::pair<unsigned, int>(PPC::R28, -16),
126 std::pair<unsigned, int>(PPC::R27, -20),
127 std::pair<unsigned, int>(PPC::R26, -24),
128 std::pair<unsigned, int>(PPC::R25, -28),
129 std::pair<unsigned, int>(PPC::R24, -32),
130 std::pair<unsigned, int>(PPC::R23, -36),
131 std::pair<unsigned, int>(PPC::R22, -40),
132 std::pair<unsigned, int>(PPC::R21, -44),
133 std::pair<unsigned, int>(PPC::R20, -48),
134 std::pair<unsigned, int>(PPC::R19, -52),
135 std::pair<unsigned, int>(PPC::R18, -56),
136 std::pair<unsigned, int>(PPC::R17, -60),
137 std::pair<unsigned, int>(PPC::R16, -64),
138 std::pair<unsigned, int>(PPC::R15, -68),
139 std::pair<unsigned, int>(PPC::R14, -72),
140
141 // CR save area offset.
142 std::pair<unsigned, int>(PPC::CR2, -4),
143 std::pair<unsigned, int>(PPC::CR3, -4),
144 std::pair<unsigned, int>(PPC::CR4, -4),
145 std::pair<unsigned, int>(PPC::CR2LT, -4),
146 std::pair<unsigned, int>(PPC::CR2GT, -4),
147 std::pair<unsigned, int>(PPC::CR2EQ, -4),
148 std::pair<unsigned, int>(PPC::CR2UN, -4),
149 std::pair<unsigned, int>(PPC::CR3LT, -4),
150 std::pair<unsigned, int>(PPC::CR3GT, -4),
151 std::pair<unsigned, int>(PPC::CR3EQ, -4),
152 std::pair<unsigned, int>(PPC::CR3UN, -4),
153 std::pair<unsigned, int>(PPC::CR4LT, -4),
154 std::pair<unsigned, int>(PPC::CR4GT, -4),
155 std::pair<unsigned, int>(PPC::CR4EQ, -4),
156 std::pair<unsigned, int>(PPC::CR4UN, -4),
157
158 // VRSAVE save area offset.
159 std::pair<unsigned, int>(PPC::VRSAVE, -4),
160
161 // Vector register save area
162 std::pair<unsigned, int>(PPC::V31, -16),
163 std::pair<unsigned, int>(PPC::V30, -32),
164 std::pair<unsigned, int>(PPC::V29, -48),
165 std::pair<unsigned, int>(PPC::V28, -64),
166 std::pair<unsigned, int>(PPC::V27, -80),
167 std::pair<unsigned, int>(PPC::V26, -96),
168 std::pair<unsigned, int>(PPC::V25, -112),
169 std::pair<unsigned, int>(PPC::V24, -128),
170 std::pair<unsigned, int>(PPC::V23, -144),
171 std::pair<unsigned, int>(PPC::V22, -160),
172 std::pair<unsigned, int>(PPC::V21, -176),
173 std::pair<unsigned, int>(PPC::V20, -192)
174 };
175
176 NumEntries = array_lengthof(Offsets);
177
178 return Offsets;
179 }
Nate Begemanca068e82004-08-14 22:16:36 +0000180};
181
182} // End llvm namespace
183
184#endif