LLVM 24.0.0git
X86MachineFunctionInfo.h
Go to the documentation of this file.
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"
22#include <set>
23
24namespace llvm {
25
27
28class X86MachineFunctionInfo;
29
30namespace yaml {
32 static void enumeration(IO &YamlIO, AMXProgModelEnum &Value) {
33 YamlIO.enumCase(Value, "None", AMXProgModelEnum::None);
34 YamlIO.enumCase(Value, "DirectReg", AMXProgModelEnum::DirectReg);
35 YamlIO.enumCase(Value, "ManagedRA", AMXProgModelEnum::ManagedRA);
36 }
37};
38
49
51 static void mapping(IO &YamlIO, X86MachineFunctionInfo &MFI) {
52 YamlIO.mapOptional("amxProgModel", MFI.AMXProgModel);
53 YamlIO.mapOptional("hasVAStartSaveXMMRegs", MFI.HasVAStartSaveXMMRegs);
54 }
55};
56} // end namespace yaml
57
58/// X86MachineFunctionInfo - This class is derived from MachineFunction and
59/// contains private X86 target-specific information for each MachineFunction.
61 virtual void anchor();
62
63 /// ForceFramePointer - True if the function is required to use of frame
64 /// pointer for reasons other than it containing dynamic allocation or
65 /// that FP eliminatation is turned off. For example, Cygwin main function
66 /// contains stack pointer re-alignment code which requires FP.
67 bool ForceFramePointer = false;
68
69 /// RestoreBasePointerOffset - Non-zero if the function has base pointer
70 /// and makes call to llvm.eh.sjlj.setjmp. When non-zero, the value is a
71 /// displacement from the frame pointer to a slot where the base pointer
72 /// is stashed.
73 signed char RestoreBasePointerOffset = 0;
74
75 /// WinEHXMMSlotInfo - Slot information of XMM registers in the stack frame
76 /// in bytes.
77 DenseMap<int, unsigned> WinEHXMMSlotInfo;
78
79 /// CalleeSavedFrameSize - Size of the callee-saved register portion of the
80 /// stack frame in bytes.
81 unsigned CalleeSavedFrameSize = 0;
82
83 /// BytesToPopOnReturn - Number of bytes function pops on return (in addition
84 /// to the space used by the return address).
85 /// Used on windows platform for stdcall & fastcall name decoration
86 unsigned BytesToPopOnReturn = 0;
87
88 /// ReturnAddrIndex - FrameIndex for return slot.
89 int ReturnAddrIndex = 0;
90
91 /// FrameIndex for return slot.
92 int FrameAddrIndex = 0;
93
94 /// TailCallReturnAddrDelta - The number of bytes by which return address
95 /// stack slot is moved as the result of tail call optimization.
96 int TailCallReturnAddrDelta = 0;
97
98 /// SRetReturnReg - Some subtargets require that sret lowering includes
99 /// returning the value of the returned struct in a register. This field
100 /// holds the virtual register into which the sret argument is passed.
101 Register SRetReturnReg;
102
103 /// GlobalBaseReg - keeps track of the virtual register initialized for
104 /// use as the global base register. This is used for PIC in some PIC
105 /// relocation models.
106 Register GlobalBaseReg;
107
108 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
109 int VarArgsFrameIndex = 0;
110 /// RegSaveFrameIndex - X86-64 vararg func register save area.
111 int RegSaveFrameIndex = 0;
112 /// VarArgsGPOffset - X86-64 vararg func int reg offset.
113 unsigned VarArgsGPOffset = 0;
114 /// VarArgsFPOffset - X86-64 vararg func fp reg offset.
115 unsigned VarArgsFPOffset = 0;
116 /// ArgumentStackSize - The number of bytes on stack consumed by the arguments
117 /// being passed on the stack.
118 unsigned ArgumentStackSize = 0;
119 /// NumLocalDynamics - Number of local-dynamic TLS accesses.
120 unsigned NumLocalDynamics = 0;
121 /// HasPushSequences - Keeps track of whether this function uses sequences
122 /// of pushes to pass function parameters.
123 bool HasPushSequences = false;
124
125 /// True if the function contains a VASTART_SAVE_XMM_REGS pseudo.
126 bool HasVAStartSaveXMMRegs = false;
127
128 /// True if the function recovers from an SEH exception, and therefore needs
129 /// to spill and restore the frame pointer.
130 bool HasSEHFramePtrSave = false;
131
132 /// The frame index of a stack object containing the original frame pointer
133 /// used to address arguments in a function using a base pointer.
134 int SEHFramePtrSaveIndex = 0;
135
136 /// The AMX programing model used in the function.
138
139 /// True if this function has a subset of CSRs that is handled explicitly via
140 /// copies.
141 bool IsSplitCSR = false;
142
143 /// True if this function uses the red zone.
144 bool UsesRedZone = false;
145
146 /// True if this function has DYN_ALLOCA instructions.
147 bool HasDynAlloca = false;
148
149 /// True if this function has any preallocated calls.
150 bool HasPreallocatedCall = false;
151
152 /// Whether this function has an extended frame record [Ctx, RBP, Return
153 /// addr]. If so, bit 60 of the in-memory frame pointer will be 1 to enable
154 /// other tools to detect the extended record.
155 bool HasSwiftAsyncContext = false;
156
157 /// Candidate registers for push2/pop2
158 std::set<Register> CandidatesForPush2Pop2;
159
160 /// True if this function has CFI directives that adjust the CFA.
161 /// This is used to determine if we should direct the debugger to use
162 /// the CFA instead of the stack pointer.
163 bool HasCFIAdjustCfa = false;
164
165 MachineInstr *StackPtrSaveMI = nullptr;
166
167 std::optional<int> SwiftAsyncContextFrameIdx;
168
169 // Preallocated fields are only used during isel.
170 // FIXME: Can we find somewhere else to store these?
171 DenseMap<const Value *, size_t> PreallocatedIds;
172 SmallVector<size_t, 0> PreallocatedStackSizes;
173 SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;
174
175 // True if a function clobbers FP/BP according to its calling convention.
176 bool FPClobberedByCall = false;
177 bool BPClobberedByCall = false;
178 bool FPClobberedByInvoke = false;
179 bool BPClobberedByInvoke = false;
180
181private:
182 /// ForwardedMustTailRegParms - A list of virtual and physical registers
183 /// that must be forwarded to every musttail call.
184 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
185
186public:
189
191
195 const override;
196
198
199 bool getForceFramePointer() const { return ForceFramePointer;}
200 void setForceFramePointer(bool forceFP) { ForceFramePointer = forceFP; }
201
202 bool getHasPushSequences() const { return HasPushSequences; }
203 void setHasPushSequences(bool HasPush) { HasPushSequences = HasPush; }
204
205 bool getHasVAStartSaveXMMRegs() const { return HasVAStartSaveXMMRegs; }
206 void setHasVAStartSaveXMMRegs(bool Has) { HasVAStartSaveXMMRegs = Has; }
207
208 bool getRestoreBasePointer() const { return RestoreBasePointerOffset!=0; }
210 void setRestoreBasePointer(unsigned CalleeSavedFrameSize) {
211 RestoreBasePointerOffset = -CalleeSavedFrameSize;
212 }
213 int getRestoreBasePointerOffset() const {return RestoreBasePointerOffset; }
214
215 DenseMap<int, unsigned>& getWinEHXMMSlotInfo() { return WinEHXMMSlotInfo; }
217 return WinEHXMMSlotInfo; }
218
219 unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
220 void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
221
222 unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
223 void setBytesToPopOnReturn (unsigned bytes) { BytesToPopOnReturn = bytes;}
224
225 int getRAIndex() const { return ReturnAddrIndex; }
226 void setRAIndex(int Index) { ReturnAddrIndex = Index; }
227
228 int getFAIndex() const { return FrameAddrIndex; }
229 void setFAIndex(int Index) { FrameAddrIndex = Index; }
230
231 int getTCReturnAddrDelta() const { return TailCallReturnAddrDelta; }
232 void setTCReturnAddrDelta(int delta) {TailCallReturnAddrDelta = delta;}
233
234 Register getSRetReturnReg() const { return SRetReturnReg; }
235 void setSRetReturnReg(Register Reg) { SRetReturnReg = Reg; }
236
237 Register getGlobalBaseReg() const { return GlobalBaseReg; }
238 void setGlobalBaseReg(Register Reg) { GlobalBaseReg = Reg; }
239
240 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
241 void setVarArgsFrameIndex(int Idx) { VarArgsFrameIndex = Idx; }
242
243 int getRegSaveFrameIndex() const { return RegSaveFrameIndex; }
244 void setRegSaveFrameIndex(int Idx) { RegSaveFrameIndex = Idx; }
245
246 unsigned getVarArgsGPOffset() const { return VarArgsGPOffset; }
247 void setVarArgsGPOffset(unsigned Offset) { VarArgsGPOffset = Offset; }
248
249 unsigned getVarArgsFPOffset() const { return VarArgsFPOffset; }
250 void setVarArgsFPOffset(unsigned Offset) { VarArgsFPOffset = Offset; }
251
252 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
253 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
254
255 unsigned getNumLocalDynamicTLSAccesses() const { return NumLocalDynamics; }
256 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamics; }
257
258 bool getHasSEHFramePtrSave() const { return HasSEHFramePtrSave; }
259 void setHasSEHFramePtrSave(bool V) { HasSEHFramePtrSave = V; }
260
261 int getSEHFramePtrSaveIndex() const { return SEHFramePtrSaveIndex; }
262 void setSEHFramePtrSaveIndex(int Index) { SEHFramePtrSaveIndex = Index; }
263
264 AMXProgModelEnum getAMXProgModel() const { return AMXProgModel; }
266 assert((AMXProgModel == AMXProgModelEnum::None || AMXProgModel == Model) &&
267 "mixed model is not supported");
268 AMXProgModel = Model;
269 }
270
272 return ForwardedMustTailRegParms;
273 }
274
275 bool isSplitCSR() const { return IsSplitCSR; }
276 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
277
278 bool getUsesRedZone() const { return UsesRedZone; }
279 void setUsesRedZone(bool V) { UsesRedZone = V; }
280
281 bool hasDynAlloca() const { return HasDynAlloca; }
282 void setHasDynAlloca(bool v) { HasDynAlloca = v; }
283
284 bool hasPreallocatedCall() const { return HasPreallocatedCall; }
285 void setHasPreallocatedCall(bool v) { HasPreallocatedCall = v; }
286
287 bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
288 void setHasSwiftAsyncContext(bool v) { HasSwiftAsyncContext = v; }
289
291 return CandidatesForPush2Pop2.find(Reg) != CandidatesForPush2Pop2.end();
292 }
294 CandidatesForPush2Pop2.insert(Reg);
295 }
297 return CandidatesForPush2Pop2.size();
298 }
299
300 bool hasCFIAdjustCfa() const { return HasCFIAdjustCfa; }
301 void setHasCFIAdjustCfa(bool v) { HasCFIAdjustCfa = v; }
302
303 void setStackPtrSaveMI(MachineInstr *MI) { StackPtrSaveMI = MI; }
304 MachineInstr *getStackPtrSaveMI() const { return StackPtrSaveMI; }
305
306 std::optional<int> getSwiftAsyncContextFrameIdx() const {
307 return SwiftAsyncContextFrameIdx;
308 }
309 void setSwiftAsyncContextFrameIdx(int v) { SwiftAsyncContextFrameIdx = v; }
310
312 auto Insert = PreallocatedIds.insert({CS, PreallocatedIds.size()});
313 if (Insert.second) {
314 PreallocatedStackSizes.push_back(0);
315 PreallocatedArgOffsets.emplace_back();
316 }
317 return Insert.first->second;
318 }
319
320 void setPreallocatedStackSize(size_t Id, size_t StackSize) {
321 PreallocatedStackSizes[Id] = StackSize;
322 }
323
324 size_t getPreallocatedStackSize(const size_t Id) {
325 assert(PreallocatedStackSizes[Id] != 0 && "stack size not set");
326 return PreallocatedStackSizes[Id];
327 }
328
330 PreallocatedArgOffsets[Id].assign(AO.begin(), AO.end());
331 }
332
334 assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
335 return PreallocatedArgOffsets[Id];
336 }
337
338 bool getFPClobberedByCall() const { return FPClobberedByCall; }
339 void setFPClobberedByCall(bool C) { FPClobberedByCall = C; }
340
341 bool getBPClobberedByCall() const { return BPClobberedByCall; }
342 void setBPClobberedByCall(bool C) { BPClobberedByCall = C; }
343
344 bool getFPClobberedByInvoke() const { return FPClobberedByInvoke; }
345 void setFPClobberedByInvoke(bool C) { FPClobberedByInvoke = C; }
346
347 bool getBPClobberedByInvoke() const { return BPClobberedByInvoke; }
348 void setBPClobberedByInvoke(bool C) { BPClobberedByInvoke = C; }
349};
350
351} // End llvm namespace
352
353#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
Register Reg
Basic Register Allocator
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:130
iterator begin() const
Definition ArrayRef.h:129
Representation of each machine instruction.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetSubtargetInfo - Generic base class for all target subtargets.
LLVM Value Representation.
Definition Value.h:75
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
void setBytesToPopOnReturn(unsigned bytes)
const DenseMap< int, unsigned > & getWinEHXMMSlotInfo() const
void setAMXProgModel(AMXProgModelEnum Model)
bool isCandidateForPush2Pop2(Register Reg) const
X86MachineFunctionInfo(const X86MachineFunctionInfo &)=default
ArrayRef< size_t > getPreallocatedArgOffsets(const size_t Id)
void setVarArgsGPOffset(unsigned Offset)
X86MachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI)
void setPreallocatedArgOffsets(size_t Id, ArrayRef< size_t > AO)
void setRestoreBasePointer(unsigned CalleeSavedFrameSize)
SmallVectorImpl< ForwardedRegister > & getForwardedMustTailRegParms()
void setRestoreBasePointer(const MachineFunction *MF)
std::optional< int > getSwiftAsyncContextFrameIdx() const
size_t getPreallocatedStackSize(const size_t Id)
void setPreallocatedStackSize(size_t Id, size_t StackSize)
DenseMap< int, unsigned > & getWinEHXMMSlotInfo()
MachineInstr * getStackPtrSaveMI() const
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
void initializeBaseYamlFields(const yaml::X86MachineFunctionInfo &YamlMFI)
AMXProgModelEnum getAMXProgModel() const
void setVarArgsFPOffset(unsigned Offset)
void setStackPtrSaveMI(MachineInstr *MI)
void setCalleeSavedFrameSize(unsigned bytes)
size_t getPreallocatedIdForCallSite(const Value *CS)
void enumCase(T &Val, StringRef Str, const T ConstVal)
Definition YAMLTraits.h:735
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1685
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
static void mapping(IO &YamlIO, X86MachineFunctionInfo &MFI)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63
static void enumeration(IO &YamlIO, AMXProgModelEnum &Value)
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition YAMLTraits.h:108
~X86MachineFunctionInfo() override=default
void mappingImpl(yaml::IO &YamlIO) override