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/DenseMap.h" 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: 30 /// Holds for each function where on the stack the Frame Pointer must be 31 /// saved. This is used on Prologue and Epilogue to emit FP save/restore 32 int FPStackOffset; 33 34 /// Holds for each function where on the stack the Return Address must be 35 /// saved. This is used on Prologue and Epilogue to emit RA save/restore 36 int RAStackOffset; 37 38 /// MBlazeFIHolder - Holds a FrameIndex and it's Stack Pointer Offset 39 struct MBlazeFIHolder { 40 41 int FI; 42 int SPOffset; 43 MBlazeFIHolderMBlazeFIHolder44 MBlazeFIHolder(int FrameIndex, int StackPointerOffset) 45 : FI(FrameIndex), SPOffset(StackPointerOffset) {} 46 }; 47 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 51 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. 52 MBlazeFIHolder GPHolder; 53 54 /// On LowerFormalArguments the stack size is unknown, so the Stack 55 /// Pointer Offset calculation of "not in register arguments" must be 56 /// postponed to emitPrologue. 57 SmallVector<MBlazeFIHolder, 16> FnLoadArgs; 58 bool HasLoadArgs; 59 60 // When VarArgs, we must write registers back to caller stack, preserving 61 // on register arguments. Since the stack size is unknown on 62 // LowerFormalArguments, the Stack Pointer Offset calculation must be 63 // postponed to emitPrologue. 64 SmallVector<MBlazeFIHolder, 4> FnStoreVarArgs; 65 bool HasStoreVarArgs; 66 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 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 82 // VarArgsFrameIndex - FrameIndex for start of varargs area. 83 int VarArgsFrameIndex; 84 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 89 public: MBlazeFunctionInfo(MachineFunction & MF)90 MBlazeFunctionInfo(MachineFunction& MF) 91 : FPStackOffset(0), RAStackOffset(0), GPHolder(-1,-1), HasLoadArgs(false), 92 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0), 93 VarArgsFrameIndex(0), LiveInFI() 94 {} 95 getFPStackOffset()96 int getFPStackOffset() const { return FPStackOffset; } setFPStackOffset(int Off)97 void setFPStackOffset(int Off) { FPStackOffset = Off; } 98 getRAStackOffset()99 int getRAStackOffset() const { return RAStackOffset; } setRAStackOffset(int Off)100 void setRAStackOffset(int Off) { RAStackOffset = Off; } 101 getGPStackOffset()102 int getGPStackOffset() const { return GPHolder.SPOffset; } getGPFI()103 int getGPFI() const { return GPHolder.FI; } setGPStackOffset(int Off)104 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } setGPFI(int FI)105 void setGPFI(int FI) { GPHolder.FI = FI; } needGPSaveRestore()106 bool needGPSaveRestore() const { return GPHolder.SPOffset != -1; } 107 hasLoadArgs()108 bool hasLoadArgs() const { return HasLoadArgs; } hasStoreVarArgs()109 bool hasStoreVarArgs() const { return HasStoreVarArgs; } 110 recordLiveIn(int FI)111 void recordLiveIn(int FI) { 112 LiveInFI.push_back(FI); 113 } 114 isLiveIn(int FI)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 getLiveIn()122 const SmallVector<int, 16>& getLiveIn() const { return LiveInFI; } 123 recordReplacement(int OFI,int NFI)124 void recordReplacement(int OFI, int NFI) { 125 FIReplacements.insert(std::make_pair(OFI,NFI)); 126 } 127 hasReplacement(int OFI)128 bool hasReplacement(int OFI) const { 129 return FIReplacements.find(OFI) != FIReplacements.end(); 130 } 131 getReplacement(int OFI)132 int getReplacement(int OFI) const { 133 return FIReplacements.lookup(OFI); 134 } 135 recordLoadArgsFI(int FI,int SPOffset)136 void recordLoadArgsFI(int FI, int SPOffset) { 137 if (!HasLoadArgs) HasLoadArgs=true; 138 FnLoadArgs.push_back(MBlazeFIHolder(FI, SPOffset)); 139 } 140 recordStoreVarArgsFI(int FI,int SPOffset)141 void recordStoreVarArgsFI(int FI, int SPOffset) { 142 if (!HasStoreVarArgs) HasStoreVarArgs=true; 143 FnStoreVarArgs.push_back(MBlazeFIHolder(FI, SPOffset)); 144 } 145 adjustLoadArgsFI(MachineFrameInfo * MFI)146 void adjustLoadArgsFI(MachineFrameInfo *MFI) const { 147 if (!hasLoadArgs()) return; 148 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) 149 MFI->setObjectOffset(FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset); 150 } 151 adjustStoreVarArgsFI(MachineFrameInfo * MFI)152 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { 153 if (!hasStoreVarArgs()) return; 154 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) 155 MFI->setObjectOffset(FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset); 156 } 157 getSRetReturnReg()158 unsigned getSRetReturnReg() const { return SRetReturnReg; } setSRetReturnReg(unsigned Reg)159 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } 160 getGlobalBaseReg()161 unsigned getGlobalBaseReg() const { return GlobalBaseReg; } setGlobalBaseReg(unsigned Reg)162 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; } 163 getVarArgsFrameIndex()164 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } setVarArgsFrameIndex(int Index)165 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } 166 }; 167 168 } // end of namespace llvm 169 170 #endif // MBLAZE_MACHINE_FUNCTION_INFO_H 171