Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 1 | //===-- PPCFrameInfo.h - Define TargetFrameInfo for PowerPC -----*- C++ -*-===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 11 | //===----------------------------------------------------------------------===// |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 12 | |
| 13 | #ifndef POWERPC_FRAMEINFO_H |
| 14 | #define POWERPC_FRAMEINFO_H |
| 15 | |
Chris Lattner | 2668959 | 2005-10-14 23:51:18 +0000 | [diff] [blame] | 16 | #include "PPC.h" |
Tilmann Scheller | ffd0200 | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 17 | #include "PPCSubtarget.h" |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetFrameInfo.h" |
| 19 | #include "llvm/Target/TargetMachine.h" |
Tilmann Scheller | ffd0200 | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 24 | class PPCFrameInfo: public TargetFrameInfo { |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 25 | const TargetMachine &TM; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 26 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 27 | public: |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 28 | PPCFrameInfo(const TargetMachine &tm, bool LP64) |
Misha Brukman | 6316181 | 2004-08-17 05:09:39 +0000 | [diff] [blame] | 29 | : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) { |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 32 | /// getReturnSaveOffset - Return the previous frame offset to save the |
| 33 | /// return address. |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 34 | static unsigned getReturnSaveOffset(bool LP64, bool isDarwinABI) { |
| 35 | if (isDarwinABI) |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 36 | return LP64 ? 16 : 8; |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 37 | // SVR4 ABI: |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 38 | return 4; |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 39 | } |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 40 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 41 | /// getFramePointerSaveOffset - Return the previous frame offset to save the |
| 42 | /// frame pointer. |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 43 | static unsigned getFramePointerSaveOffset(bool LP64, bool isDarwinABI) { |
| 44 | // For the Darwin ABI: |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 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.) |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 48 | if (isDarwinABI) |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 49 | return LP64 ? 40 : 20; |
| 50 | |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 51 | // SVR4 ABI: |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 52 | // Save it right before the link register |
Reid Spencer | 6733a16 | 2007-04-04 22:07:24 +0000 | [diff] [blame] | 53 | return -4U; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /// getLinkageSize - Return the size of the PowerPC ABI linkage area. |
| 57 | /// |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 58 | static unsigned getLinkageSize(bool LP64, bool isDarwinABI) { |
| 59 | if (isDarwinABI) |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 60 | return 6 * (LP64 ? 8 : 4); |
| 61 | |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 62 | // SVR4 ABI: |
Nicolas Geoffray | ec58d9f | 2007-04-03 12:35:28 +0000 | [diff] [blame] | 63 | return 8; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI |
| 67 | /// argument area. |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 68 | static unsigned getMinCallArgumentsSize(bool LP64, bool isDarwinABI) { |
| 69 | // For the Darwin ABI: |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 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. |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 75 | if (isDarwinABI) |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 76 | return 8 * (LP64 ? 8 : 4); |
| 77 | |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 78 | // SVR4 ABI: |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 79 | // There is no default stack allocated for the 8 first GPR arguments. |
| 80 | return 0; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /// getMinCallFrameSize - Return the minimum size a call frame can be using |
| 84 | /// the PowerPC ABI. |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 85 | static unsigned getMinCallFrameSize(bool LP64, bool isDarwinABI) { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 86 | // The call frame needs to be at least big enough for linkage and 8 args. |
Tilmann Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 87 | return getLinkageSize(LP64, isDarwinABI) + |
| 88 | getMinCallArgumentsSize(LP64, isDarwinABI); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 89 | } |
Tilmann Scheller | ffd0200 | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 90 | |
| 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 Scheller | 2a9ddfb | 2009-07-03 06:47:08 +0000 | [diff] [blame^] | 95 | if (!TM.getSubtarget<PPCSubtarget>().isSVR4ABI()) { |
Tilmann Scheller | ffd0200 | 2009-07-03 06:45:56 +0000 | [diff] [blame] | 96 | 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 Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | } // End llvm namespace |
| 183 | |
| 184 | #endif |