Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 1 | //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=// |
| 2 | // |
| 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. |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the Mips specific subclass of MachineFunctionInfo. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef MIPS_MACHINE_FUNCTION_INFO_H |
| 15 | #define MIPS_MACHINE_FUNCTION_INFO_H |
| 16 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/VectorExtras.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
| 23 | /// MipsFunctionInfo - This class is derived from MachineFunction private |
| 24 | /// Mips target-specific information for each MachineFunction. |
| 25 | class MipsFunctionInfo : public MachineFunctionInfo { |
| 26 | |
| 27 | private: |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 28 | /// Holds for each function where on the stack the Frame Pointer must be |
| 29 | /// saved. |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 30 | int FPStackOffset; |
| 31 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 32 | /// Holds for each function where on the stack the Return Address must be |
| 33 | /// saved. |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 34 | int RAStackOffset; |
| 35 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 36 | /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset |
| 37 | struct MipsFIHolder { |
| 38 | |
| 39 | int FI; |
| 40 | int SPOffset; |
| 41 | |
| 42 | MipsFIHolder(int FrameIndex, int StackPointerOffset) |
| 43 | : FI(FrameIndex), SPOffset(StackPointerOffset) {} |
| 44 | }; |
| 45 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 46 | /// When PIC is used the GP must be saved on the stack on the function |
| 47 | /// prologue and must be reloaded from this stack location after every |
| 48 | /// call. A reference to its stack location and frame index must be kept |
| 49 | /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 50 | MipsFIHolder GPHolder; |
| 51 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 52 | // On LowerFORMAL_ARGUMENTS the stack size is unknown, so the Stack |
| 53 | // Pointer Offset calculation of "not in register arguments" must be |
| 54 | // postponed to emitPrologue. |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 55 | SmallVector<MipsFIHolder, 16> FnLoadArgs; |
| 56 | bool HasLoadArgs; |
| 57 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 58 | // When VarArgs, we must write registers back to caller stack, preserving |
| 59 | // on register arguments. Since the stack size is unknown on |
| 60 | // LowerFORMAL_ARGUMENTS, the Stack Pointer Offset calculation must be |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 61 | // postponed to emitPrologue. |
| 62 | SmallVector<MipsFIHolder, 4> FnStoreVarArgs; |
| 63 | bool HasStoreVarArgs; |
| 64 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 65 | /// SRetReturnReg - Some subtargets require that sret lowering includes |
| 66 | /// returning the value of the returned struct in a register. This field |
| 67 | /// holds the virtual register into which the sret argument is passed. |
| 68 | unsigned SRetReturnReg; |
| 69 | |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 70 | public: |
| 71 | MipsFunctionInfo(MachineFunction& MF) |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 72 | : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false), |
| 73 | HasStoreVarArgs(false), SRetReturnReg(0) |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 74 | {} |
| 75 | |
| 76 | int getFPStackOffset() const { return FPStackOffset; } |
| 77 | void setFPStackOffset(int Off) { FPStackOffset = Off; } |
| 78 | |
| 79 | int getRAStackOffset() const { return RAStackOffset; } |
| 80 | void setRAStackOffset(int Off) { RAStackOffset = Off; } |
| 81 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 82 | int getGPStackOffset() const { return GPHolder.SPOffset; } |
| 83 | int getGPFI() const { return GPHolder.FI; } |
| 84 | void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } |
| 85 | void setGPFI(int FI) { GPHolder.FI = FI; } |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 86 | |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 87 | int getTopSavedRegOffset() const { |
| 88 | return (RAStackOffset > FPStackOffset) ? |
| 89 | (RAStackOffset) : (FPStackOffset); |
| 90 | } |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 91 | |
| 92 | bool hasLoadArgs() const { return HasLoadArgs; } |
| 93 | bool hasStoreVarArgs() const { return HasStoreVarArgs; } |
| 94 | |
| 95 | void recordLoadArgsFI(int FI, int SPOffset) { |
| 96 | if (!HasLoadArgs) HasLoadArgs=true; |
| 97 | FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset)); |
| 98 | } |
| 99 | void recordStoreVarArgsFI(int FI, int SPOffset) { |
| 100 | if (!HasStoreVarArgs) HasStoreVarArgs=true; |
| 101 | FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset)); |
| 102 | } |
| 103 | |
| 104 | void adjustLoadArgsFI(MachineFrameInfo *MFI) const { |
| 105 | if (!hasLoadArgs()) return; |
| 106 | for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) |
| 107 | MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset ); |
| 108 | } |
| 109 | void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { |
| 110 | if (!hasStoreVarArgs()) return; |
| 111 | for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) |
| 112 | MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset ); |
| 113 | } |
| 114 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 115 | unsigned getSRetReturnReg() const { return SRetReturnReg; } |
| 116 | void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | } // end of namespace llvm |
| 120 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 121 | #endif // MIPS_MACHINE_FUNCTION_INFO_H |