Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 1 | //===-- MBlazeMachineFunctionInfo.h - Private data ----------------*- C++ -*-=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the MBlaze specific subclass of MachineFunctionInfo. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef MBLAZE_MACHINE_FUNCTION_INFO_H |
| 15 | #define MBLAZE_MACHINE_FUNCTION_INFO_H |
| 16 | |
| 17 | #include "llvm/ADT/SmallVector.h" |
| 18 | #include "llvm/ADT/VectorExtras.h" |
| 19 | #include "llvm/CodeGen/MachineFunction.h" |
| 20 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | /// MBlazeFunctionInfo - This class is derived from MachineFunction private |
| 25 | /// MBlaze target-specific information for each MachineFunction. |
| 26 | class MBlazeFunctionInfo : public MachineFunctionInfo { |
| 27 | |
| 28 | private: |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 29 | /// Holds for each function where on the stack the Frame Pointer must be |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 30 | /// saved. This is used on Prologue and Epilogue to emit FP save/restore |
| 31 | int FPStackOffset; |
| 32 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 33 | /// Holds for each function where on the stack the Return Address must be |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 34 | /// saved. This is used on Prologue and Epilogue to emit RA save/restore |
| 35 | int RAStackOffset; |
| 36 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 37 | /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset |
| 38 | struct MBlazeFIHolder { |
| 39 | |
| 40 | int FI; |
| 41 | int SPOffset; |
| 42 | |
| 43 | MBlazeFIHolder(int FrameIndex, int StackPointerOffset) |
| 44 | : FI(FrameIndex), SPOffset(StackPointerOffset) {} |
| 45 | }; |
| 46 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 47 | /// When PIC is used the GP must be saved on the stack on the function |
| 48 | /// prologue and must be reloaded from this stack location after every |
| 49 | /// call. A reference to its stack location and frame index must be kept |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 50 | /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. |
| 51 | MBlazeFIHolder GPHolder; |
| 52 | |
| 53 | /// On LowerFormalArguments the stack size is unknown, so the Stack |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 54 | /// Pointer Offset calculation of "not in register arguments" must be |
| 55 | /// postponed to emitPrologue. |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 56 | SmallVector<MBlazeFIHolder, 16> FnLoadArgs; |
| 57 | bool HasLoadArgs; |
| 58 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 59 | // When VarArgs, we must write registers back to caller stack, preserving |
| 60 | // on register arguments. Since the stack size is unknown on |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 61 | // LowerFormalArguments, the Stack Pointer Offset calculation must be |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 62 | // postponed to emitPrologue. |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 63 | SmallVector<MBlazeFIHolder, 4> FnStoreVarArgs; |
| 64 | bool HasStoreVarArgs; |
| 65 | |
| 66 | /// SRetReturnReg - Some subtargets require that sret lowering includes |
| 67 | /// returning the value of the returned struct in a register. This field |
| 68 | /// holds the virtual register into which the sret argument is passed. |
| 69 | unsigned SRetReturnReg; |
| 70 | |
| 71 | /// GlobalBaseReg - keeps track of the virtual register initialized for |
| 72 | /// use as the global base register. This is used for PIC in some PIC |
| 73 | /// relocation models. |
| 74 | unsigned GlobalBaseReg; |
| 75 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 76 | // VarArgsFrameIndex - FrameIndex for start of varargs area. |
| 77 | int VarArgsFrameIndex; |
| 78 | |
Wesley Peck | eb13382 | 2010-12-12 20:52:31 +0000 | [diff] [blame] | 79 | /// LiveInFI - keeps track of the frame indexes in a callers stack |
| 80 | /// frame that are live into a function. |
| 81 | SmallVector<int, 16> LiveInFI; |
| 82 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 83 | public: |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 84 | MBlazeFunctionInfo(MachineFunction& MF) |
Wesley Peck | b020808 | 2011-01-03 21:40:26 +0000 | [diff] [blame^] | 85 | : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false), |
| 86 | HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0), |
| 87 | VarArgsFrameIndex(0), LiveInFI() |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +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 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 96 | int getGPStackOffset() const { return GPHolder.SPOffset; } |
| 97 | int getGPFI() const { return GPHolder.FI; } |
| 98 | void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } |
| 99 | void setGPFI(int FI) { GPHolder.FI = FI; } |
| 100 | bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; } |
| 101 | |
| 102 | bool hasLoadArgs() const { return HasLoadArgs; } |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 103 | bool hasStoreVarArgs() const { return HasStoreVarArgs; } |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 104 | |
Wesley Peck | eb13382 | 2010-12-12 20:52:31 +0000 | [diff] [blame] | 105 | void recordLiveIn(int FI) { |
| 106 | LiveInFI.push_back(FI); |
| 107 | } |
| 108 | |
| 109 | bool isLiveIn(int FI) { |
| 110 | for (unsigned i = 0, e = LiveInFI.size(); i < e; ++i) |
| 111 | if (FI == LiveInFI[i]) return true; |
| 112 | |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | const SmallVector<int, 16>& getLiveIn() const { return LiveInFI; } |
| 117 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 118 | void recordLoadArgsFI(int FI, int SPOffset) { |
| 119 | if (!HasLoadArgs) HasLoadArgs=true; |
| 120 | FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset)); |
| 121 | } |
Wesley Peck | b020808 | 2011-01-03 21:40:26 +0000 | [diff] [blame^] | 122 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 123 | void recordStoreVarArgsFI(int FI, int SPOffset) { |
| 124 | if (!HasStoreVarArgs) HasStoreVarArgs=true; |
| 125 | FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset)); |
| 126 | } |
| 127 | |
| 128 | void adjustLoadArgsFI(MachineFrameInfo *MFI) const { |
| 129 | if (!hasLoadArgs()) return; |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 130 | for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) |
| 131 | MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset); |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 132 | } |
Wesley Peck | b020808 | 2011-01-03 21:40:26 +0000 | [diff] [blame^] | 133 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 134 | void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 135 | if (!hasStoreVarArgs()) return; |
| 136 | for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) |
| 137 | MFI->setObjectOffset(FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset); |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | unsigned getSRetReturnReg() const { return SRetReturnReg; } |
| 141 | void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } |
| 142 | |
| 143 | unsigned getGlobalBaseReg() const { return GlobalBaseReg; } |
| 144 | void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; } |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 145 | |
| 146 | int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } |
| 147 | void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | } // end of namespace llvm |
| 151 | |
| 152 | #endif // MBLAZE_MACHINE_FUNCTION_INFO_H |