1 //===- MipsMachineFunctionInfo.h - Private data used for Mips ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares the Mips specific subclass of MachineFunctionInfo.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_MIPS_MIPSMACHINEFUNCTION_H
14 #define LLVM_LIB_TARGET_MIPS_MIPSMACHINEFUNCTION_H
15 
16 #include "Mips16HardFloatInfo.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineMemOperand.h"
19 #include <map>
20 
21 namespace llvm {
22 
23 /// MipsFunctionInfo - This class is derived from MachineFunction private
24 /// Mips target-specific information for each MachineFunction.
25 class MipsFunctionInfo : public MachineFunctionInfo {
26 public:
27   MipsFunctionInfo(MachineFunction &MF) : MF(MF) {}
28 
29   ~MipsFunctionInfo() override;
30 
31   unsigned getSRetReturnReg() const { return SRetReturnReg; }
32   void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
33 
34   bool globalBaseRegSet() const;
35   Register getGlobalBaseReg();
36   Register getGlobalBaseRegForGlobalISel();
37 
38   // Insert instructions to initialize the global base register in the
39   // first MBB of the function.
40   void initGlobalBaseReg();
41 
42   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
43   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
44 
45   bool hasByvalArg() const { return HasByvalArg; }
46   void setFormalArgInfo(unsigned Size, bool HasByval) {
47     IncomingArgSize = Size;
48     HasByvalArg = HasByval;
49   }
50 
51   unsigned getIncomingArgSize() const { return IncomingArgSize; }
52 
53   bool callsEhReturn() const { return CallsEhReturn; }
54   void setCallsEhReturn() { CallsEhReturn = true; }
55 
56   void createEhDataRegsFI();
57   int getEhDataRegFI(unsigned Reg) const { return EhDataRegFI[Reg]; }
58   bool isEhDataRegFI(int FI) const;
59 
60   /// Create a MachinePointerInfo that has an ExternalSymbolPseudoSourceValue
61   /// object representing a GOT entry for an external function.
62   MachinePointerInfo callPtrInfo(const char *ES);
63 
64   // Functions with the "interrupt" attribute require special prologues,
65   // epilogues and additional spill slots.
66   bool isISR() const { return IsISR; }
67   void setISR() { IsISR = true; }
68   void createISRRegFI();
69   int getISRRegFI(unsigned Reg) const { return ISRDataRegFI[Reg]; }
70   bool isISRRegFI(int FI) const;
71 
72   /// Create a MachinePointerInfo that has a GlobalValuePseudoSourceValue object
73   /// representing a GOT entry for a global function.
74   MachinePointerInfo callPtrInfo(const GlobalValue *GV);
75 
76   void setSaveS2() { SaveS2 = true; }
77   bool hasSaveS2() const { return SaveS2; }
78 
79   int getMoveF64ViaSpillFI(const TargetRegisterClass *RC);
80 
81   std::map<const char *, const Mips16HardFloatInfo::FuncSignature *>
82   StubsNeeded;
83 
84 private:
85   virtual void anchor();
86 
87   MachineFunction& MF;
88 
89   /// SRetReturnReg - Some subtargets require that sret lowering includes
90   /// returning the value of the returned struct in a register. This field
91   /// holds the virtual register into which the sret argument is passed.
92   unsigned SRetReturnReg = 0;
93 
94   /// GlobalBaseReg - keeps track of the virtual register initialized for
95   /// use as the global base register. This is used for PIC in some PIC
96   /// relocation models.
97   unsigned GlobalBaseReg = 0;
98 
99   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
100   int VarArgsFrameIndex = 0;
101 
102   /// True if function has a byval argument.
103   bool HasByvalArg;
104 
105   /// Size of incoming argument area.
106   unsigned IncomingArgSize;
107 
108   /// CallsEhReturn - Whether the function calls llvm.eh.return.
109   bool CallsEhReturn = false;
110 
111   /// Frame objects for spilling eh data registers.
112   int EhDataRegFI[4];
113 
114   /// ISR - Whether the function is an Interrupt Service Routine.
115   bool IsISR = false;
116 
117   /// Frame objects for spilling C0_STATUS, C0_EPC
118   int ISRDataRegFI[2];
119 
120   // saveS2
121   bool SaveS2 = false;
122 
123   /// FrameIndex for expanding BuildPairF64 nodes to spill and reload when the
124   /// O32 FPXX ABI is enabled. -1 is used to denote invalid index.
125   int MoveF64ViaSpillFI = -1;
126 };
127 
128 } // end namespace llvm
129 
130 #endif // LLVM_LIB_TARGET_MIPS_MIPSMACHINEFUNCTION_H
131