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 | |
Dan Gohman | d68a076 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/VectorExtras.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFunction.h" |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | /// MipsFunctionInfo - This class is derived from MachineFunction private |
| 25 | /// Mips target-specific information for each MachineFunction. |
| 26 | class MipsFunctionInfo : public MachineFunctionInfo { |
| 27 | |
| 28 | private: |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 29 | /// Holds for each function where on the stack the Frame Pointer must be |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 30 | /// saved. This is used on Prologue and Epilogue to emit FP save/restore |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 31 | int FPStackOffset; |
| 32 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 33 | /// Holds for each function where on the stack the Return Address must be |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 34 | /// saved. This is used on Prologue and Epilogue to emit RA save/restore |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 35 | int RAStackOffset; |
| 36 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 37 | /// At each function entry, two special bitmask directives must be emitted |
| 38 | /// to help debugging, for CPU and FPU callee saved registers. Both need |
| 39 | /// the negative offset from the final stack size and its higher registers |
| 40 | /// location on the stack. |
| 41 | int CPUTopSavedRegOff; |
| 42 | int FPUTopSavedRegOff; |
| 43 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 44 | /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset |
| 45 | struct MipsFIHolder { |
| 46 | |
| 47 | int FI; |
| 48 | int SPOffset; |
| 49 | |
| 50 | MipsFIHolder(int FrameIndex, int StackPointerOffset) |
| 51 | : FI(FrameIndex), SPOffset(StackPointerOffset) {} |
| 52 | }; |
| 53 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 54 | /// When PIC is used the GP must be saved on the stack on the function |
| 55 | /// prologue and must be reloaded from this stack location after every |
| 56 | /// call. A reference to its stack location and frame index must be kept |
| 57 | /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 58 | MipsFIHolder GPHolder; |
| 59 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 60 | /// On LowerFormalArguments the stack size is unknown, so the Stack |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 61 | /// Pointer Offset calculation of "not in register arguments" must be |
| 62 | /// postponed to emitPrologue. |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 63 | SmallVector<MipsFIHolder, 16> FnLoadArgs; |
| 64 | bool HasLoadArgs; |
| 65 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 66 | // When VarArgs, we must write registers back to caller stack, preserving |
| 67 | // on register arguments. Since the stack size is unknown on |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 68 | // LowerFormalArguments, the Stack Pointer Offset calculation must be |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 69 | // postponed to emitPrologue. |
| 70 | SmallVector<MipsFIHolder, 4> FnStoreVarArgs; |
| 71 | bool HasStoreVarArgs; |
| 72 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 73 | /// SRetReturnReg - Some subtargets require that sret lowering includes |
| 74 | /// returning the value of the returned struct in a register. This field |
| 75 | /// holds the virtual register into which the sret argument is passed. |
| 76 | unsigned SRetReturnReg; |
| 77 | |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 78 | /// GlobalBaseReg - keeps track of the virtual register initialized for |
| 79 | /// use as the global base register. This is used for PIC in some PIC |
| 80 | /// relocation models. |
| 81 | unsigned GlobalBaseReg; |
| 82 | |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 83 | public: |
| 84 | MipsFunctionInfo(MachineFunction& MF) |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 85 | : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0), |
| 86 | FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false), |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 87 | HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0) |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 88 | {} |
| 89 | |
| 90 | int getFPStackOffset() const { return FPStackOffset; } |
| 91 | void setFPStackOffset(int Off) { FPStackOffset = Off; } |
| 92 | |
| 93 | int getRAStackOffset() const { return RAStackOffset; } |
| 94 | void setRAStackOffset(int Off) { RAStackOffset = Off; } |
| 95 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 96 | int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; } |
| 97 | void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; } |
| 98 | |
| 99 | int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; } |
| 100 | void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; } |
| 101 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 102 | int getGPStackOffset() const { return GPHolder.SPOffset; } |
| 103 | int getGPFI() const { return GPHolder.FI; } |
| 104 | void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } |
| 105 | void setGPFI(int FI) { GPHolder.FI = FI; } |
Bruno Cardoso Lopes | b8e0ebf | 2009-11-09 14:27:49 +0000 | [diff] [blame] | 106 | bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; } |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 107 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 108 | bool hasLoadArgs() const { return HasLoadArgs; } |
| 109 | bool hasStoreVarArgs() const { return HasStoreVarArgs; } |
| 110 | |
| 111 | void recordLoadArgsFI(int FI, int SPOffset) { |
| 112 | if (!HasLoadArgs) HasLoadArgs=true; |
| 113 | FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset)); |
| 114 | } |
| 115 | void recordStoreVarArgsFI(int FI, int SPOffset) { |
| 116 | if (!HasStoreVarArgs) HasStoreVarArgs=true; |
| 117 | FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset)); |
| 118 | } |
| 119 | |
| 120 | void adjustLoadArgsFI(MachineFrameInfo *MFI) const { |
| 121 | if (!hasLoadArgs()) return; |
| 122 | for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) |
| 123 | MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset ); |
| 124 | } |
| 125 | void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { |
| 126 | if (!hasStoreVarArgs()) return; |
| 127 | for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) |
| 128 | MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset ); |
| 129 | } |
| 130 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 131 | unsigned getSRetReturnReg() const { return SRetReturnReg; } |
| 132 | void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 133 | |
| 134 | unsigned getGlobalBaseReg() const { return GlobalBaseReg; } |
| 135 | void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; } |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // end of namespace llvm |
| 139 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 140 | #endif // MIPS_MACHINE_FUNCTION_INFO_H |