Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 1 | //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=// |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 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 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file declares the Mips specific subclass of MachineFunctionInfo. |
| 11 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 13 | |
| 14 | #ifndef MIPS_MACHINE_FUNCTION_INFO_H |
| 15 | #define MIPS_MACHINE_FUNCTION_INFO_H |
| 16 | |
Akira Hatanaka | da0a357 | 2011-05-20 01:17:58 +0000 | [diff] [blame^] | 17 | #include <utility> |
Dan Gohman | d68a076 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/VectorExtras.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunction.h" |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | /// MipsFunctionInfo - This class is derived from MachineFunction private |
| 26 | /// Mips target-specific information for each MachineFunction. |
| 27 | class MipsFunctionInfo : public MachineFunctionInfo { |
| 28 | |
| 29 | private: |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 30 | /// 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] | 31 | /// 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] | 32 | int FPStackOffset; |
| 33 | |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 34 | /// 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] | 35 | /// 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] | 36 | int RAStackOffset; |
| 37 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 38 | /// At each function entry, two special bitmask directives must be emitted |
| 39 | /// to help debugging, for CPU and FPU callee saved registers. Both need |
| 40 | /// the negative offset from the final stack size and its higher registers |
| 41 | /// location on the stack. |
| 42 | int CPUTopSavedRegOff; |
| 43 | int FPUTopSavedRegOff; |
| 44 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 45 | /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset |
| 46 | struct MipsFIHolder { |
| 47 | |
| 48 | int FI; |
| 49 | int SPOffset; |
| 50 | |
| 51 | MipsFIHolder(int FrameIndex, int StackPointerOffset) |
| 52 | : FI(FrameIndex), SPOffset(StackPointerOffset) {} |
| 53 | }; |
| 54 | |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 55 | /// When PIC is used the GP must be saved on the stack on the function |
| 56 | /// prologue and must be reloaded from this stack location after every |
| 57 | /// call. A reference to its stack location and frame index must be kept |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 58 | /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 59 | MipsFIHolder GPHolder; |
| 60 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 61 | /// On LowerFormalArguments the stack size is unknown, so the Stack |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 62 | /// Pointer Offset calculation of "not in register arguments" must be |
| 63 | /// postponed to emitPrologue. |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 64 | SmallVector<MipsFIHolder, 16> FnLoadArgs; |
| 65 | bool HasLoadArgs; |
| 66 | |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 67 | // When VarArgs, we must write registers back to caller stack, preserving |
| 68 | // on register arguments. Since the stack size is unknown on |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 69 | // LowerFormalArguments, the Stack Pointer Offset calculation must be |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 70 | // postponed to emitPrologue. |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 71 | SmallVector<MipsFIHolder, 4> FnStoreVarArgs; |
| 72 | bool HasStoreVarArgs; |
| 73 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 74 | /// SRetReturnReg - Some subtargets require that sret lowering includes |
| 75 | /// returning the value of the returned struct in a register. This field |
| 76 | /// holds the virtual register into which the sret argument is passed. |
| 77 | unsigned SRetReturnReg; |
| 78 | |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 79 | /// GlobalBaseReg - keeps track of the virtual register initialized for |
| 80 | /// use as the global base register. This is used for PIC in some PIC |
| 81 | /// relocation models. |
| 82 | unsigned GlobalBaseReg; |
| 83 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 84 | /// VarArgsFrameIndex - FrameIndex for start of varargs area. |
| 85 | int VarArgsFrameIndex; |
| 86 | |
Akira Hatanaka | da0a357 | 2011-05-20 01:17:58 +0000 | [diff] [blame^] | 87 | // Range of frame object indices. |
| 88 | // InArgFIRange: Range of indices of all frame objects created during call to |
| 89 | // LowerFormalArguments. |
| 90 | // OutArgFIRange: Range of indices of all frame objects created during call to |
| 91 | // LowerCall except for the frame object for restoring $gp. |
| 92 | std::pair<int, int> InArgFIRange, OutArgFIRange; |
| 93 | int GPFI; // Index of the frame object for restoring $gp |
| 94 | bool HasCall; // True if function has a function call. |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 95 | public: |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 96 | MipsFunctionInfo(MachineFunction& MF) |
| 97 | : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0), |
| 98 | FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false), |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 99 | HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0), |
Akira Hatanaka | da0a357 | 2011-05-20 01:17:58 +0000 | [diff] [blame^] | 100 | VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)), |
| 101 | OutArgFIRange(std::make_pair(-1, 0)), GPFI(0), HasCall(false) |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 102 | {} |
| 103 | |
| 104 | int getFPStackOffset() const { return FPStackOffset; } |
| 105 | void setFPStackOffset(int Off) { FPStackOffset = Off; } |
| 106 | |
| 107 | int getRAStackOffset() const { return RAStackOffset; } |
| 108 | void setRAStackOffset(int Off) { RAStackOffset = Off; } |
| 109 | |
Bruno Cardoso Lopes | bbe5136 | 2008-08-06 06:14:43 +0000 | [diff] [blame] | 110 | int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; } |
| 111 | void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; } |
| 112 | |
| 113 | int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; } |
| 114 | void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; } |
| 115 | |
Akira Hatanaka | da0a357 | 2011-05-20 01:17:58 +0000 | [diff] [blame^] | 116 | bool isInArgFI(int FI) const { |
| 117 | return FI <= InArgFIRange.first && FI >= InArgFIRange.second; |
| 118 | } |
| 119 | void setLastInArgFI(int FI) { InArgFIRange.second = FI; } |
| 120 | |
| 121 | bool isOutArgFI(int FI) const { |
| 122 | return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second; |
| 123 | } |
| 124 | void extendOutArgFIRange(int FirstFI, int LastFI) { |
| 125 | if (!OutArgFIRange.second) |
| 126 | // this must be the first time this function was called. |
| 127 | OutArgFIRange.first = FirstFI; |
| 128 | OutArgFIRange.second = LastFI; |
| 129 | } |
| 130 | |
Bruno Cardoso Lopes | c7db561 | 2007-11-05 03:02:32 +0000 | [diff] [blame] | 131 | int getGPStackOffset() const { return GPHolder.SPOffset; } |
| 132 | int getGPFI() const { return GPHolder.FI; } |
| 133 | void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } |
| 134 | void setGPFI(int FI) { GPHolder.FI = FI; } |
Bruno Cardoso Lopes | b8e0ebf | 2009-11-09 14:27:49 +0000 | [diff] [blame] | 135 | bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; } |
Akira Hatanaka | da0a357 | 2011-05-20 01:17:58 +0000 | [diff] [blame^] | 136 | bool isGPFI(int FI) const { return GPFI && GPFI == FI; } |
Bruno Cardoso Lopes | 0a60400 | 2007-10-09 03:01:19 +0000 | [diff] [blame] | 137 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 138 | bool hasLoadArgs() const { return HasLoadArgs; } |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 139 | bool hasStoreVarArgs() const { return HasStoreVarArgs; } |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 140 | |
| 141 | void recordLoadArgsFI(int FI, int SPOffset) { |
| 142 | if (!HasLoadArgs) HasLoadArgs=true; |
| 143 | FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset)); |
| 144 | } |
| 145 | void recordStoreVarArgsFI(int FI, int SPOffset) { |
| 146 | if (!HasStoreVarArgs) HasStoreVarArgs=true; |
| 147 | FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset)); |
| 148 | } |
| 149 | |
| 150 | void adjustLoadArgsFI(MachineFrameInfo *MFI) const { |
| 151 | if (!hasLoadArgs()) return; |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 152 | for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 153 | MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset ); |
| 154 | } |
| 155 | void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { |
Che-Liang Chiou | acf1d48 | 2010-09-28 10:06:53 +0000 | [diff] [blame] | 156 | if (!hasStoreVarArgs()) return; |
| 157 | for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 158 | MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset ); |
| 159 | } |
| 160 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 161 | unsigned getSRetReturnReg() const { return SRetReturnReg; } |
| 162 | void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 163 | |
| 164 | unsigned getGlobalBaseReg() const { return GlobalBaseReg; } |
| 165 | void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; } |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 166 | |
| 167 | int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } |
| 168 | void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } |
Akira Hatanaka | da0a357 | 2011-05-20 01:17:58 +0000 | [diff] [blame^] | 169 | |
| 170 | bool hasCall() const { return HasCall; }; |
| 171 | void setHasCall() { HasCall = true; } |
Bruno Cardoso Lopes | 4215a59 | 2007-07-11 22:44:21 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | } // end of namespace llvm |
| 175 | |
Bruno Cardoso Lopes | 2d4575e | 2007-08-28 05:04:41 +0000 | [diff] [blame] | 176 | #endif // MIPS_MACHINE_FUNCTION_INFO_H |