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 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source 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" |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetFrameInfo.h" |
| 18 | #include "llvm/Target/TargetMachine.h" |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 22 | class PPCFrameInfo: public TargetFrameInfo { |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 23 | const TargetMachine &TM; |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 24 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 25 | public: |
Nate Begeman | 21e463b | 2005-10-16 05:39:50 +0000 | [diff] [blame] | 26 | PPCFrameInfo(const TargetMachine &tm, bool LP64) |
Misha Brukman | 6316181 | 2004-08-17 05:09:39 +0000 | [diff] [blame] | 27 | : TargetFrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), TM(tm) { |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 30 | /// getReturnSaveOffset - Return the previous frame offset to save the |
| 31 | /// return address. |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 32 | static unsigned getReturnSaveOffset(bool LP64, bool isMacho) { |
| 33 | if (isMacho) |
| 34 | return LP64 ? 16 : 8; |
| 35 | // For ELF ABI: |
| 36 | return LP64 ? 8 : 4; |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 37 | } |
Jim Laskey | 51fe9d9 | 2006-12-06 17:42:06 +0000 | [diff] [blame] | 38 | |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 39 | /// getFramePointerSaveOffset - Return the previous frame offset to save the |
| 40 | /// frame pointer. |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 41 | static unsigned getFramePointerSaveOffset(bool LP64, bool isMacho) { |
| 42 | // For MachO ABI: |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 43 | // 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 Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 46 | if (isMacho) |
| 47 | return LP64 ? 40 : 20; |
| 48 | |
| 49 | // For ELF ABI: |
| 50 | // Save it right before the link register |
| 51 | return LP64 ? -8 : -4; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /// getLinkageSize - Return the size of the PowerPC ABI linkage area. |
| 55 | /// |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 56 | static unsigned getLinkageSize(bool LP64, bool isMacho) { |
| 57 | if (isMacho) |
| 58 | return 6 * (LP64 ? 8 : 4); |
| 59 | |
| 60 | // For ELF ABI: |
| 61 | return LP64 ? 16 : 8; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /// getMinCallArgumentsSize - Return the size of the minium PowerPC ABI |
| 65 | /// argument area. |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 66 | 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 | |
| 76 | // For Linux ABI: |
| 77 | // There is no default stack allocated for the 8 first GPR arguments. |
| 78 | return 0; |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /// getMinCallFrameSize - Return the minimum size a call frame can be using |
| 82 | /// the PowerPC ABI. |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 83 | static unsigned getMinCallFrameSize(bool LP64, bool isMacho) { |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 84 | // The call frame needs to be at least big enough for linkage and 8 args. |
Chris Lattner | 9f0bc65 | 2007-02-25 05:34:32 +0000 | [diff] [blame] | 85 | return getLinkageSize(LP64, isMacho) + |
| 86 | getMinCallArgumentsSize(LP64, isMacho); |
Jim Laskey | 2f616bf | 2006-11-16 22:43:37 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Nate Begeman | ca068e8 | 2004-08-14 22:16:36 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // End llvm namespace |
| 92 | |
| 93 | #endif |