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 | |
Wesley Peck | 3d2148f | 2011-01-05 17:34:20 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/ADT/VectorExtras.h" |
| 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | /// MBlazeFunctionInfo - This class is derived from MachineFunction private |
| 26 | /// MBlaze target-specific information for each MachineFunction. |
| 27 | class MBlazeFunctionInfo : public MachineFunctionInfo { |
| 28 | |
| 29 | private: |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 30 | /// 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] | 31 | /// saved. This is used on Prologue and Epilogue to emit FP save/restore |
| 32 | int FPStackOffset; |
| 33 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 34 | /// 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] | 35 | /// saved. This is used on Prologue and Epilogue to emit RA save/restore |
| 36 | int RAStackOffset; |
| 37 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 38 | /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset |
| 39 | struct MBlazeFIHolder { |
| 40 | |
| 41 | int FI; |
| 42 | int SPOffset; |
| 43 | |
| 44 | MBlazeFIHolder(int FrameIndex, int StackPointerOffset) |
| 45 | : FI(FrameIndex), SPOffset(StackPointerOffset) {} |
| 46 | }; |
| 47 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 48 | /// When PIC is used the GP must be saved on the stack on the function |
| 49 | /// prologue and must be reloaded from this stack location after every |
| 50 | /// 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] | 51 | /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. |
| 52 | MBlazeFIHolder GPHolder; |
| 53 | |
| 54 | /// On LowerFormalArguments the stack size is unknown, so the Stack |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 55 | /// Pointer Offset calculation of "not in register arguments" must be |
| 56 | /// postponed to emitPrologue. |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 57 | SmallVector<MBlazeFIHolder, 16> FnLoadArgs; |
| 58 | bool HasLoadArgs; |
| 59 | |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 60 | // When VarArgs, we must write registers back to caller stack, preserving |
| 61 | // on register arguments. Since the stack size is unknown on |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 62 | // LowerFormalArguments, the Stack Pointer Offset calculation must be |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 63 | // postponed to emitPrologue. |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 64 | SmallVector<MBlazeFIHolder, 4> FnStoreVarArgs; |
| 65 | bool HasStoreVarArgs; |
| 66 | |
Wesley Peck | 3d2148f | 2011-01-05 17:34:20 +0000 | [diff] [blame] | 67 | // When determining the final stack layout some of the frame indexes may |
| 68 | // be replaced by new frame indexes that reside in the caller's stack |
| 69 | // frame. The replacements are recorded in this structure. |
| 70 | DenseMap<int,int> FIReplacements; |
| 71 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 72 | /// SRetReturnReg - Some subtargets require that sret lowering includes |
| 73 | /// returning the value of the returned struct in a register. This field |
| 74 | /// holds the virtual register into which the sret argument is passed. |
| 75 | unsigned SRetReturnReg; |
| 76 | |
| 77 | /// GlobalBaseReg - keeps track of the virtual register initialized for |
| 78 | /// use as the global base register. This is used for PIC in some PIC |
| 79 | /// relocation models. |
| 80 | unsigned GlobalBaseReg; |
| 81 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 82 | // VarArgsFrameIndex - FrameIndex for start of varargs area. |
| 83 | int VarArgsFrameIndex; |
| 84 | |
Wesley Peck | eb13382 | 2010-12-12 20:52:31 +0000 | [diff] [blame] | 85 | /// LiveInFI - keeps track of the frame indexes in a callers stack |
| 86 | /// frame that are live into a function. |
| 87 | SmallVector<int, 16> LiveInFI; |
| 88 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 89 | public: |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 90 | MBlazeFunctionInfo(MachineFunction& MF) |
Wesley Peck | b020808 | 2011-01-03 21:40:26 +0000 | [diff] [blame] | 91 | : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false), |
| 92 | HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0), |
| 93 | VarArgsFrameIndex(0), LiveInFI() |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 94 | {} |
| 95 | |
| 96 | int getFPStackOffset() const { return FPStackOffset; } |
| 97 | void setFPStackOffset(int Off) { FPStackOffset = Off; } |
| 98 | |
| 99 | int getRAStackOffset() const { return RAStackOffset; } |
| 100 | void setRAStackOffset(int Off) { RAStackOffset = Off; } |
| 101 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +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; } |
| 106 | bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; } |
| 107 | |
| 108 | bool hasLoadArgs() const { return HasLoadArgs; } |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 109 | bool hasStoreVarArgs() const { return HasStoreVarArgs; } |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 110 | |
Wesley Peck | eb13382 | 2010-12-12 20:52:31 +0000 | [diff] [blame] | 111 | void recordLiveIn(int FI) { |
| 112 | LiveInFI.push_back(FI); |
| 113 | } |
| 114 | |
| 115 | bool isLiveIn(int FI) { |
| 116 | for (unsigned i = 0, e = LiveInFI.size(); i < e; ++i) |
| 117 | if (FI == LiveInFI[i]) return true; |
| 118 | |
| 119 | return false; |
| 120 | } |
| 121 | |
| 122 | const SmallVector<int, 16>& getLiveIn() const { return LiveInFI; } |
| 123 | |
Wesley Peck | 3d2148f | 2011-01-05 17:34:20 +0000 | [diff] [blame] | 124 | void recordReplacement(int OFI, int NFI) { |
| 125 | FIReplacements.insert(std::make_pair(OFI,NFI)); |
| 126 | } |
| 127 | |
| 128 | bool hasReplacement(int OFI) const { |
| 129 | return FIReplacements.find(OFI) != FIReplacements.end(); |
| 130 | } |
| 131 | |
| 132 | int getReplacement(int OFI) const { |
| 133 | return FIReplacements.lookup(OFI); |
| 134 | } |
| 135 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 136 | void recordLoadArgsFI(int FI, int SPOffset) { |
| 137 | if (!HasLoadArgs) HasLoadArgs=true; |
| 138 | FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset)); |
| 139 | } |
Wesley Peck | b020808 | 2011-01-03 21:40:26 +0000 | [diff] [blame] | 140 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 141 | void recordStoreVarArgsFI(int FI, int SPOffset) { |
| 142 | if (!HasStoreVarArgs) HasStoreVarArgs=true; |
| 143 | FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset)); |
| 144 | } |
| 145 | |
| 146 | void adjustLoadArgsFI(MachineFrameInfo *MFI) const { |
| 147 | if (!hasLoadArgs()) return; |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 148 | for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) |
| 149 | MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset); |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 150 | } |
Wesley Peck | b020808 | 2011-01-03 21:40:26 +0000 | [diff] [blame] | 151 | |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 152 | void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { |
Wesley Peck | 0a67d92 | 2010-11-08 19:40:01 +0000 | [diff] [blame] | 153 | if (!hasStoreVarArgs()) return; |
| 154 | for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) |
| 155 | MFI->setObjectOffset(FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset); |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | unsigned getSRetReturnReg() const { return SRetReturnReg; } |
| 159 | void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } |
| 160 | |
| 161 | unsigned getGlobalBaseReg() const { return GlobalBaseReg; } |
| 162 | void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; } |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 163 | |
| 164 | int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } |
| 165 | void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } |
Wesley Peck | a70f28c | 2010-02-23 19:15:24 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | } // end of namespace llvm |
| 169 | |
| 170 | #endif // MBLAZE_MACHINE_FUNCTION_INFO_H |