LLVM API Documentation
00001 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- C++ -*-=// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the Mips specific subclass of MachineFunctionInfo. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef MIPS_MACHINE_FUNCTION_INFO_H 00015 #define MIPS_MACHINE_FUNCTION_INFO_H 00016 00017 #include "llvm/ADT/SmallVector.h" 00018 #include "llvm/ADT/VectorExtras.h" 00019 #include "llvm/CodeGen/MachineFunction.h" 00020 #include "llvm/CodeGen/MachineFrameInfo.h" 00021 00022 namespace llvm { 00023 00024 /// MipsFunctionInfo - This class is derived from MachineFunction private 00025 /// Mips target-specific information for each MachineFunction. 00026 class MipsFunctionInfo : public MachineFunctionInfo { 00027 00028 private: 00029 /// Holds for each function where on the stack the Frame Pointer must be 00030 /// saved. This is used on Prologue and Epilogue to emit FP save/restore 00031 int FPStackOffset; 00032 00033 /// Holds for each function where on the stack the Return Address must be 00034 /// saved. This is used on Prologue and Epilogue to emit RA save/restore 00035 int RAStackOffset; 00036 00037 /// At each function entry, two special bitmask directives must be emitted 00038 /// to help debugging, for CPU and FPU callee saved registers. Both need 00039 /// the negative offset from the final stack size and its higher registers 00040 /// location on the stack. 00041 int CPUTopSavedRegOff; 00042 int FPUTopSavedRegOff; 00043 00044 /// MipsFIHolder - Holds a FrameIndex and it's Stack Pointer Offset 00045 struct MipsFIHolder { 00046 00047 int FI; 00048 int SPOffset; 00049 00050 MipsFIHolder(int FrameIndex, int StackPointerOffset) 00051 : FI(FrameIndex), SPOffset(StackPointerOffset) {} 00052 }; 00053 00054 /// When PIC is used the GP must be saved on the stack on the function 00055 /// prologue and must be reloaded from this stack location after every 00056 /// call. A reference to its stack location and frame index must be kept 00057 /// to be used on emitPrologue and processFunctionBeforeFrameFinalized. 00058 MipsFIHolder GPHolder; 00059 00060 /// On LowerFormalArguments the stack size is unknown, so the Stack 00061 /// Pointer Offset calculation of "not in register arguments" must be 00062 /// postponed to emitPrologue. 00063 SmallVector<MipsFIHolder, 16> FnLoadArgs; 00064 bool HasLoadArgs; 00065 00066 // When VarArgs, we must write registers back to caller stack, preserving 00067 // on register arguments. Since the stack size is unknown on 00068 // LowerFormalArguments, the Stack Pointer Offset calculation must be 00069 // postponed to emitPrologue. 00070 SmallVector<MipsFIHolder, 4> FnStoreVarArgs; 00071 bool HasStoreVarArgs; 00072 00073 /// SRetReturnReg - Some subtargets require that sret lowering includes 00074 /// returning the value of the returned struct in a register. This field 00075 /// holds the virtual register into which the sret argument is passed. 00076 unsigned SRetReturnReg; 00077 00078 /// GlobalBaseReg - keeps track of the virtual register initialized for 00079 /// use as the global base register. This is used for PIC in some PIC 00080 /// relocation models. 00081 unsigned GlobalBaseReg; 00082 00083 public: 00084 MipsFunctionInfo(MachineFunction& MF) 00085 : FPStackOffset(0), RAStackOffset(0), CPUTopSavedRegOff(0), 00086 FPUTopSavedRegOff(0), GPHolder(-1,-1), HasLoadArgs(false), 00087 HasStoreVarArgs(false), SRetReturnReg(0), GlobalBaseReg(0) 00088 {} 00089 00090 int getFPStackOffset() const { return FPStackOffset; } 00091 void setFPStackOffset(int Off) { FPStackOffset = Off; } 00092 00093 int getRAStackOffset() const { return RAStackOffset; } 00094 void setRAStackOffset(int Off) { RAStackOffset = Off; } 00095 00096 int getCPUTopSavedRegOff() const { return CPUTopSavedRegOff; } 00097 void setCPUTopSavedRegOff(int Off) { CPUTopSavedRegOff = Off; } 00098 00099 int getFPUTopSavedRegOff() const { return FPUTopSavedRegOff; } 00100 void setFPUTopSavedRegOff(int Off) { FPUTopSavedRegOff = Off; } 00101 00102 int getGPStackOffset() const { return GPHolder.SPOffset; } 00103 int getGPFI() const { return GPHolder.FI; } 00104 void setGPStackOffset(int Off) { GPHolder.SPOffset = Off; } 00105 void setGPFI(int FI) { GPHolder.FI = FI; } 00106 00107 bool hasLoadArgs() const { return HasLoadArgs; } 00108 bool hasStoreVarArgs() const { return HasStoreVarArgs; } 00109 00110 void recordLoadArgsFI(int FI, int SPOffset) { 00111 if (!HasLoadArgs) HasLoadArgs=true; 00112 FnLoadArgs.push_back(MipsFIHolder(FI, SPOffset)); 00113 } 00114 void recordStoreVarArgsFI(int FI, int SPOffset) { 00115 if (!HasStoreVarArgs) HasStoreVarArgs=true; 00116 FnStoreVarArgs.push_back(MipsFIHolder(FI, SPOffset)); 00117 } 00118 00119 void adjustLoadArgsFI(MachineFrameInfo *MFI) const { 00120 if (!hasLoadArgs()) return; 00121 for (unsigned i = 0, e = FnLoadArgs.size(); i != e; ++i) 00122 MFI->setObjectOffset( FnLoadArgs[i].FI, FnLoadArgs[i].SPOffset ); 00123 } 00124 void adjustStoreVarArgsFI(MachineFrameInfo *MFI) const { 00125 if (!hasStoreVarArgs()) return; 00126 for (unsigned i = 0, e = FnStoreVarArgs.size(); i != e; ++i) 00127 MFI->setObjectOffset( FnStoreVarArgs[i].FI, FnStoreVarArgs[i].SPOffset ); 00128 } 00129 00130 unsigned getSRetReturnReg() const { return SRetReturnReg; } 00131 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } 00132 00133 unsigned getGlobalBaseReg() const { return GlobalBaseReg; } 00134 void setGlobalBaseReg(unsigned Reg) { GlobalBaseReg = Reg; } 00135 }; 00136 00137 } // end of namespace llvm 00138 00139 #endif // MIPS_MACHINE_FUNCTION_INFO_H