xref: /freebsd/contrib/llvm-project/llvm/lib/Target/X86/X86MachineFunctionInfo.h (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
1 //===-- X86MachineFunctionInfo.h - X86 machine function info ----*- 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 X86-specific per-machine-function information.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_X86_X86MACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_X86_X86MACHINEFUNCTIONINFO_H
15 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/CodeGen/CallingConvLower.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 
21 namespace llvm {
22 
23 /// X86MachineFunctionInfo - This class is derived from MachineFunction and
24 /// contains private X86 target-specific information for each MachineFunction.
25 class X86MachineFunctionInfo : public MachineFunctionInfo {
26   virtual void anchor();
27 
28   /// ForceFramePointer - True if the function is required to use of frame
29   /// pointer for reasons other than it containing dynamic allocation or
30   /// that FP eliminatation is turned off. For example, Cygwin main function
31   /// contains stack pointer re-alignment code which requires FP.
32   bool ForceFramePointer = false;
33 
34   /// RestoreBasePointerOffset - Non-zero if the function has base pointer
35   /// and makes call to llvm.eh.sjlj.setjmp. When non-zero, the value is a
36   /// displacement from the frame pointer to a slot where the base pointer
37   /// is stashed.
38   signed char RestoreBasePointerOffset = 0;
39 
40   /// WinEHXMMSlotInfo - Slot information of XMM registers in the stack frame
41   /// in bytes.
42   DenseMap<int, unsigned> WinEHXMMSlotInfo;
43 
44   /// CalleeSavedFrameSize - Size of the callee-saved register portion of the
45   /// stack frame in bytes.
46   unsigned CalleeSavedFrameSize = 0;
47 
48   /// BytesToPopOnReturn - Number of bytes function pops on return (in addition
49   /// to the space used by the return address).
50   /// Used on windows platform for stdcall & fastcall name decoration
51   unsigned BytesToPopOnReturn = 0;
52 
53   /// ReturnAddrIndex - FrameIndex for return slot.
54   int ReturnAddrIndex = 0;
55 
56   /// FrameIndex for return slot.
57   int FrameAddrIndex = 0;
58 
59   /// TailCallReturnAddrDelta - The number of bytes by which return address
60   /// stack slot is moved as the result of tail call optimization.
61   int TailCallReturnAddrDelta = 0;
62 
63   /// SRetReturnReg - Some subtargets require that sret lowering includes
64   /// returning the value of the returned struct in a register. This field
65   /// holds the virtual register into which the sret argument is passed.
66   Register SRetReturnReg;
67 
68   /// GlobalBaseReg - keeps track of the virtual register initialized for
69   /// use as the global base register. This is used for PIC in some PIC
70   /// relocation models.
71   Register GlobalBaseReg;
72 
73   /// VarArgsFrameIndex - FrameIndex for start of varargs area.
74   int VarArgsFrameIndex = 0;
75   /// RegSaveFrameIndex - X86-64 vararg func register save area.
76   int RegSaveFrameIndex = 0;
77   /// VarArgsGPOffset - X86-64 vararg func int reg offset.
78   unsigned VarArgsGPOffset = 0;
79   /// VarArgsFPOffset - X86-64 vararg func fp reg offset.
80   unsigned VarArgsFPOffset = 0;
81   /// ArgumentStackSize - The number of bytes on stack consumed by the arguments
82   /// being passed on the stack.
83   unsigned ArgumentStackSize = 0;
84   /// NumLocalDynamics - Number of local-dynamic TLS accesses.
85   unsigned NumLocalDynamics = 0;
86   /// HasPushSequences - Keeps track of whether this function uses sequences
87   /// of pushes to pass function parameters.
88   bool HasPushSequences = false;
89 
90   /// True if the function recovers from an SEH exception, and therefore needs
91   /// to spill and restore the frame pointer.
92   bool HasSEHFramePtrSave = false;
93 
94   /// The frame index of a stack object containing the original frame pointer
95   /// used to address arguments in a function using a base pointer.
96   int SEHFramePtrSaveIndex = 0;
97 
98   /// True if this function has a subset of CSRs that is handled explicitly via
99   /// copies.
100   bool IsSplitCSR = false;
101 
102   /// True if this function uses the red zone.
103   bool UsesRedZone = false;
104 
105   /// True if this function has DYN_ALLOCA instructions.
106   bool HasDynAlloca = false;
107 
108   /// True if this function has any preallocated calls.
109   bool HasPreallocatedCall = false;
110 
111   /// Whether this function has an extended frame record [Ctx, RBP, Return
112   /// addr]. If so, bit 60 of the in-memory frame pointer will be 1 to enable
113   /// other tools to detect the extended record.
114   bool HasSwiftAsyncContext = false;
115 
116   /// True if this function has tile virtual register. This is used to
117   /// determine if we should insert tilerelease in frame lowering.
118   bool HasVirtualTileReg = false;
119 
120   Optional<int> SwiftAsyncContextFrameIdx;
121 
122   ValueMap<const Value *, size_t> PreallocatedIds;
123   SmallVector<size_t, 0> PreallocatedStackSizes;
124   SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;
125 
126 private:
127   /// ForwardedMustTailRegParms - A list of virtual and physical registers
128   /// that must be forwarded to every musttail call.
129   SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
130 
131 public:
132   X86MachineFunctionInfo() = default;
133 
134   explicit X86MachineFunctionInfo(MachineFunction &MF) {}
135 
136   bool getForceFramePointer() const { return ForceFramePointer;}
137   void setForceFramePointer(bool forceFP) { ForceFramePointer = forceFP; }
138 
139   bool getHasPushSequences() const { return HasPushSequences; }
140   void setHasPushSequences(bool HasPush) { HasPushSequences = HasPush; }
141 
142   bool getRestoreBasePointer() const { return RestoreBasePointerOffset!=0; }
143   void setRestoreBasePointer(const MachineFunction *MF);
144   int getRestoreBasePointerOffset() const {return RestoreBasePointerOffset; }
145 
146   DenseMap<int, unsigned>& getWinEHXMMSlotInfo() { return WinEHXMMSlotInfo; }
147   const DenseMap<int, unsigned>& getWinEHXMMSlotInfo() const {
148     return WinEHXMMSlotInfo; }
149 
150   unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
151   void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
152 
153   unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
154   void setBytesToPopOnReturn (unsigned bytes) { BytesToPopOnReturn = bytes;}
155 
156   int getRAIndex() const { return ReturnAddrIndex; }
157   void setRAIndex(int Index) { ReturnAddrIndex = Index; }
158 
159   int getFAIndex() const { return FrameAddrIndex; }
160   void setFAIndex(int Index) { FrameAddrIndex = Index; }
161 
162   int getTCReturnAddrDelta() const { return TailCallReturnAddrDelta; }
163   void setTCReturnAddrDelta(int delta) {TailCallReturnAddrDelta = delta;}
164 
165   Register getSRetReturnReg() const { return SRetReturnReg; }
166   void setSRetReturnReg(Register Reg) { SRetReturnReg = Reg; }
167 
168   Register getGlobalBaseReg() const { return GlobalBaseReg; }
169   void setGlobalBaseReg(Register Reg) { GlobalBaseReg = Reg; }
170 
171   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
172   void setVarArgsFrameIndex(int Idx) { VarArgsFrameIndex = Idx; }
173 
174   int getRegSaveFrameIndex() const { return RegSaveFrameIndex; }
175   void setRegSaveFrameIndex(int Idx) { RegSaveFrameIndex = Idx; }
176 
177   unsigned getVarArgsGPOffset() const { return VarArgsGPOffset; }
178   void setVarArgsGPOffset(unsigned Offset) { VarArgsGPOffset = Offset; }
179 
180   unsigned getVarArgsFPOffset() const { return VarArgsFPOffset; }
181   void setVarArgsFPOffset(unsigned Offset) { VarArgsFPOffset = Offset; }
182 
183   unsigned getArgumentStackSize() const { return ArgumentStackSize; }
184   void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
185 
186   unsigned getNumLocalDynamicTLSAccesses() const { return NumLocalDynamics; }
187   void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamics; }
188 
189   bool getHasSEHFramePtrSave() const { return HasSEHFramePtrSave; }
190   void setHasSEHFramePtrSave(bool V) { HasSEHFramePtrSave = V; }
191 
192   int getSEHFramePtrSaveIndex() const { return SEHFramePtrSaveIndex; }
193   void setSEHFramePtrSaveIndex(int Index) { SEHFramePtrSaveIndex = Index; }
194 
195   SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
196     return ForwardedMustTailRegParms;
197   }
198 
199   bool isSplitCSR() const { return IsSplitCSR; }
200   void setIsSplitCSR(bool s) { IsSplitCSR = s; }
201 
202   bool getUsesRedZone() const { return UsesRedZone; }
203   void setUsesRedZone(bool V) { UsesRedZone = V; }
204 
205   bool hasDynAlloca() const { return HasDynAlloca; }
206   void setHasDynAlloca(bool v) { HasDynAlloca = v; }
207 
208   bool hasPreallocatedCall() const { return HasPreallocatedCall; }
209   void setHasPreallocatedCall(bool v) { HasPreallocatedCall = v; }
210 
211   bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
212   void setHasSwiftAsyncContext(bool v) { HasSwiftAsyncContext = v; }
213 
214   bool hasVirtualTileReg() const { return HasVirtualTileReg; }
215   void setHasVirtualTileReg(bool v) { HasVirtualTileReg = v; }
216 
217   Optional<int> getSwiftAsyncContextFrameIdx() const {
218     return SwiftAsyncContextFrameIdx;
219   }
220   void setSwiftAsyncContextFrameIdx(int v) { SwiftAsyncContextFrameIdx = v; }
221 
222   size_t getPreallocatedIdForCallSite(const Value *CS) {
223     auto Insert = PreallocatedIds.insert({CS, PreallocatedIds.size()});
224     if (Insert.second) {
225       PreallocatedStackSizes.push_back(0);
226       PreallocatedArgOffsets.emplace_back();
227     }
228     return Insert.first->second;
229   }
230 
231   void setPreallocatedStackSize(size_t Id, size_t StackSize) {
232     PreallocatedStackSizes[Id] = StackSize;
233   }
234 
235   size_t getPreallocatedStackSize(const size_t Id) {
236     assert(PreallocatedStackSizes[Id] != 0 && "stack size not set");
237     return PreallocatedStackSizes[Id];
238   }
239 
240   void setPreallocatedArgOffsets(size_t Id, ArrayRef<size_t> AO) {
241     PreallocatedArgOffsets[Id].assign(AO.begin(), AO.end());
242   }
243 
244   ArrayRef<size_t> getPreallocatedArgOffsets(const size_t Id) {
245     assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
246     return PreallocatedArgOffsets[Id];
247   }
248 };
249 
250 } // End llvm namespace
251 
252 #endif
253