1 //===-- MipsMachineFunctionInfo.h - Private data used for Mips ----*- 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 Mips specific subclass of MachineFunctionInfo. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MIPS_MACHINE_FUNCTION_INFO_H 15 #define MIPS_MACHINE_FUNCTION_INFO_H 16 17 #include "MipsSubtarget.h" 18 #include "llvm/CodeGen/MachineFunction.h" 19 #include "llvm/CodeGen/MachineFrameInfo.h" 20 #include "llvm/Target/TargetFrameLowering.h" 21 #include "llvm/Target/TargetMachine.h" 22 #include <utility> 23 24 namespace llvm { 25 26 /// MipsFunctionInfo - This class is derived from MachineFunction private 27 /// Mips target-specific information for each MachineFunction. 28 class MipsFunctionInfo : public MachineFunctionInfo { 29 virtual void anchor(); 30 31 MachineFunction& MF; 32 /// SRetReturnReg - Some subtargets require that sret lowering includes 33 /// returning the value of the returned struct in a register. This field 34 /// holds the virtual register into which the sret argument is passed. 35 unsigned SRetReturnReg; 36 37 /// GlobalBaseReg - keeps track of the virtual register initialized for 38 /// use as the global base register. This is used for PIC in some PIC 39 /// relocation models. 40 unsigned GlobalBaseReg; 41 42 /// VarArgsFrameIndex - FrameIndex for start of varargs area. 43 int VarArgsFrameIndex; 44 45 // Range of frame object indices. 46 // InArgFIRange: Range of indices of all frame objects created during call to 47 // LowerFormalArguments. 48 // OutArgFIRange: Range of indices of all frame objects created during call to 49 // LowerCall except for the frame object for restoring $gp. 50 std::pair<int, int> InArgFIRange, OutArgFIRange; 51 int GlobalRegFI; 52 mutable int DynAllocFI; // Frame index of dynamically allocated stack area. 53 unsigned MaxCallFrameSize; 54 55 bool EmitNOAT; 56 57 public: 58 MipsFunctionInfo(MachineFunction& MF) 59 : MF(MF), SRetReturnReg(0), GlobalBaseReg(0), 60 VarArgsFrameIndex(0), InArgFIRange(std::make_pair(-1, 0)), 61 OutArgFIRange(std::make_pair(-1, 0)), GlobalRegFI(0), DynAllocFI(0), 62 MaxCallFrameSize(0), EmitNOAT(false) 63 {} 64 65 bool isInArgFI(int FI) const { 66 return FI <= InArgFIRange.first && FI >= InArgFIRange.second; 67 } 68 void setLastInArgFI(int FI) { InArgFIRange.second = FI; } 69 70 bool isOutArgFI(int FI) const { 71 return FI <= OutArgFIRange.first && FI >= OutArgFIRange.second; 72 } 73 void extendOutArgFIRange(int FirstFI, int LastFI) { 74 if (!OutArgFIRange.second) 75 // this must be the first time this function was called. 76 OutArgFIRange.first = FirstFI; 77 OutArgFIRange.second = LastFI; 78 } 79 80 bool isGlobalRegFI(int FI) const { 81 return GlobalRegFI && (FI == GlobalRegFI); 82 } 83 84 int getGlobalRegFI() const { 85 return GlobalRegFI; 86 } 87 88 int initGlobalRegFI() { 89 const TargetMachine &TM = MF.getTarget(); 90 unsigned RegSize = TM.getSubtarget<MipsSubtarget>().isABI_N64() ? 8 : 4; 91 int64_t StackAlignment = TM.getFrameLowering()->getStackAlignment(); 92 uint64_t Offset = RoundUpToAlignment(MaxCallFrameSize, StackAlignment); 93 94 GlobalRegFI = MF.getFrameInfo()->CreateFixedObject(RegSize, Offset, true); 95 return GlobalRegFI; 96 } 97 98 // The first call to this function creates a frame object for dynamically 99 // allocated stack area. 100 int getDynAllocFI() const { 101 if (!DynAllocFI) 102 DynAllocFI = MF.getFrameInfo()->CreateFixedObject(4, 0, true); 103 104 return DynAllocFI; 105 } 106 bool isDynAllocFI(int FI) const { return DynAllocFI && DynAllocFI == FI; } 107 108 unsigned getSRetReturnReg() const { return SRetReturnReg; } 109 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } 110 111 bool globalBaseRegSet() const; 112 unsigned getGlobalBaseReg(); 113 114 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } 115 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } 116 117 unsigned getMaxCallFrameSize() const { return MaxCallFrameSize; } 118 void setMaxCallFrameSize(unsigned S) { MaxCallFrameSize = S; } 119 120 bool getEmitNOAT() const { return EmitNOAT; } 121 void setEmitNOAT() { EmitNOAT = true; } 122 }; 123 124 } // end of namespace llvm 125 126 #endif // MIPS_MACHINE_FUNCTION_INFO_H 127