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
28
29class X86MachineFunctionInfo;
30
31namespace yaml {
33 static void enumeration(IO &YamlIO, AMXProgModelEnum &Value) {
34 YamlIO.enumCase(Value, "None", AMXProgModelEnum::None);
35 YamlIO.enumCase(Value, "DirectReg", AMXProgModelEnum::DirectReg);
36 YamlIO.enumCase(Value, "ManagedRA", AMXProgModelEnum::ManagedRA);
37 }
38};
39
41 static void enumeration(IO &YamlIO, ACEProgModelEnum &Value) {
45 }
46};
47
59
61 static void mapping(IO &YamlIO, X86MachineFunctionInfo &MFI) {
62 YamlIO.mapOptional("amxProgModel", MFI.AMXProgModel);
63 YamlIO.mapOptional("aceProgModel", MFI.ACEProgModel);
64 YamlIO.mapOptional("hasVAStartSaveXMMRegs", MFI.HasVAStartSaveXMMRegs);
65 }
66};
67} // end namespace yaml
68
69/// X86MachineFunctionInfo - This class is derived from MachineFunction and
70/// contains private X86 target-specific information for each MachineFunction.
72 virtual void anchor();
73
74 /// ForceFramePointer - True if the function is required to use of frame
75 /// pointer for reasons other than it containing dynamic allocation or
76 /// that FP eliminatation is turned off. For example, Cygwin main function
77 /// contains stack pointer re-alignment code which requires FP.
78 bool ForceFramePointer = false;
79
80 /// RestoreBasePointerOffset - Non-zero if the function has base pointer
81 /// and makes call to llvm.eh.sjlj.setjmp. When non-zero, the value is a
82 /// displacement from the frame pointer to a slot where the base pointer
83 /// is stashed.
84 signed char RestoreBasePointerOffset = 0;
85
86 /// WinEHXMMSlotInfo - Slot information of XMM registers in the stack frame
87 /// in bytes.
88 DenseMap<int, unsigned> WinEHXMMSlotInfo;
89
90 /// CalleeSavedFrameSize - Size of the callee-saved register portion of the
91 /// stack frame in bytes.
92 unsigned CalleeSavedFrameSize = 0;
93
94 /// BytesToPopOnReturn - Number of bytes function pops on return (in addition
95 /// to the space used by the return address).
96 /// Used on windows platform for stdcall & fastcall name decoration
97 unsigned BytesToPopOnReturn = 0;
98
99 /// ReturnAddrIndex - FrameIndex for return slot.
100 int ReturnAddrIndex = 0;
101
102 /// FrameIndex for return slot.
103 int FrameAddrIndex = 0;
104
105 /// TailCallReturnAddrDelta - The number of bytes by which return address
106 /// stack slot is moved as the result of tail call optimization.
107 int TailCallReturnAddrDelta = 0;
108
109 /// SRetReturnReg - Some subtargets require that sret lowering includes
110 /// returning the value of the returned struct in a register. This field
111 /// holds the virtual register into which the sret argument is passed.
112 Register SRetReturnReg;
113
114 /// GlobalBaseReg - keeps track of the virtual register initialized for
115 /// use as the global base register. This is used for PIC in some PIC
116 /// relocation models.
117 Register GlobalBaseReg;
118
119 /// VarArgsFrameIndex - FrameIndex for start of varargs area.
120 int VarArgsFrameIndex = 0;
121 /// RegSaveFrameIndex - X86-64 vararg func register save area.
122 int RegSaveFrameIndex = 0;
123 /// VarArgsGPOffset - X86-64 vararg func int reg offset.
124 unsigned VarArgsGPOffset = 0;
125 /// VarArgsFPOffset - X86-64 vararg func fp reg offset.
126 unsigned VarArgsFPOffset = 0;
127 /// ArgumentStackSize - The number of bytes on stack consumed by the arguments
128 /// being passed on the stack.
129 unsigned ArgumentStackSize = 0;
130 /// NumLocalDynamics - Number of local-dynamic TLS accesses.
131 unsigned NumLocalDynamics = 0;
132 /// HasPushSequences - Keeps track of whether this function uses sequences
133 /// of pushes to pass function parameters.
134 bool HasPushSequences = false;
135
136 /// True if the function contains a VASTART_SAVE_XMM_REGS pseudo.
137 bool HasVAStartSaveXMMRegs = false;
138
139 /// True if the function recovers from an SEH exception, and therefore needs
140 /// to spill and restore the frame pointer.
141 bool HasSEHFramePtrSave = false;
142
143 /// The frame index of a stack object containing the original frame pointer
144 /// used to address arguments in a function using a base pointer.
145 int SEHFramePtrSaveIndex = 0;
146
147 /// The AMX programing model used in the function.
149
150 /// The ACE programming model used in the function.
152
153 /// True once a function using both ACE programming models has been reported.
154 bool ReportedACEProgModelMix = false;
155
156 /// True if this function has a subset of CSRs that is handled explicitly via
157 /// copies.
158 bool IsSplitCSR = false;
159
160 /// True if this function uses the red zone.
161 bool UsesRedZone = false;
162
163 /// True if this function has DYN_ALLOCA instructions.
164 bool HasDynAlloca = false;
165
166 /// True if this function has any preallocated calls.
167 bool HasPreallocatedCall = false;
168
169 /// Whether this function has an extended frame record [Ctx, RBP, Return
170 /// addr]. If so, bit 60 of the in-memory frame pointer will be 1 to enable
171 /// other tools to detect the extended record.
172 bool HasSwiftAsyncContext = false;
173
174 /// Candidate registers for push2/pop2
175 std::set<Register> CandidatesForPush2Pop2;
176
177 /// True if this function has CFI directives that adjust the CFA.
178 /// This is used to determine if we should direct the debugger to use
179 /// the CFA instead of the stack pointer.
180 bool HasCFIAdjustCfa = false;
181
182 MachineInstr *StackPtrSaveMI = nullptr;
183
184 std::optional<int> SwiftAsyncContextFrameIdx;
185
186 // Preallocated fields are only used during isel.
187 // FIXME: Can we find somewhere else to store these?
188 DenseMap<const Value *, size_t> PreallocatedIds;
189 SmallVector<size_t, 0> PreallocatedStackSizes;
190 SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;
191
192 // True if a function clobbers FP/BP according to its calling convention.
193 bool FPClobberedByCall = false;
194 bool BPClobberedByCall = false;
195 bool FPClobberedByInvoke = false;
196 bool BPClobberedByInvoke = false;
197
198private:
199 /// ForwardedMustTailRegParms - A list of virtual and physical registers
200 /// that must be forwarded to every musttail call.
201 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
202
203public:
206
208
212 const override;
213
215
216 bool getForceFramePointer() const { return ForceFramePointer;}
217 void setForceFramePointer(bool forceFP) { ForceFramePointer = forceFP; }
218
219 bool getHasPushSequences() const { return HasPushSequences; }
220 void setHasPushSequences(bool HasPush) { HasPushSequences = HasPush; }
221
222 bool getHasVAStartSaveXMMRegs() const { return HasVAStartSaveXMMRegs; }
223 void setHasVAStartSaveXMMRegs(bool Has) { HasVAStartSaveXMMRegs = Has; }
224
225 bool getRestoreBasePointer() const { return RestoreBasePointerOffset!=0; }
227 void setRestoreBasePointer(unsigned CalleeSavedFrameSize) {
228 RestoreBasePointerOffset = -CalleeSavedFrameSize;
229 }
230 int getRestoreBasePointerOffset() const {return RestoreBasePointerOffset; }
231
232 DenseMap<int, unsigned>& getWinEHXMMSlotInfo() { return WinEHXMMSlotInfo; }
234 return WinEHXMMSlotInfo; }
235
236 unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
237 void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
238
239 unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
240 void setBytesToPopOnReturn (unsigned bytes) { BytesToPopOnReturn = bytes;}
241
242 int getRAIndex() const { return ReturnAddrIndex; }
243 void setRAIndex(int Index) { ReturnAddrIndex = Index; }
244
245 int getFAIndex() const { return FrameAddrIndex; }
246 void setFAIndex(int Index) { FrameAddrIndex = Index; }
247
248 int getTCReturnAddrDelta() const { return TailCallReturnAddrDelta; }
249 void setTCReturnAddrDelta(int delta) {TailCallReturnAddrDelta = delta;}
250
251 Register getSRetReturnReg() const { return SRetReturnReg; }
252 void setSRetReturnReg(Register Reg) { SRetReturnReg = Reg; }
253
254 Register getGlobalBaseReg() const { return GlobalBaseReg; }
255 void setGlobalBaseReg(Register Reg) { GlobalBaseReg = Reg; }
256
257 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
258 void setVarArgsFrameIndex(int Idx) { VarArgsFrameIndex = Idx; }
259
260 int getRegSaveFrameIndex() const { return RegSaveFrameIndex; }
261 void setRegSaveFrameIndex(int Idx) { RegSaveFrameIndex = Idx; }
262
263 unsigned getVarArgsGPOffset() const { return VarArgsGPOffset; }
264 void setVarArgsGPOffset(unsigned Offset) { VarArgsGPOffset = Offset; }
265
266 unsigned getVarArgsFPOffset() const { return VarArgsFPOffset; }
267 void setVarArgsFPOffset(unsigned Offset) { VarArgsFPOffset = Offset; }
268
269 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
270 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
271
272 unsigned getNumLocalDynamicTLSAccesses() const { return NumLocalDynamics; }
273 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamics; }
274
275 bool getHasSEHFramePtrSave() const { return HasSEHFramePtrSave; }
276 void setHasSEHFramePtrSave(bool V) { HasSEHFramePtrSave = V; }
277
278 int getSEHFramePtrSaveIndex() const { return SEHFramePtrSaveIndex; }
279 void setSEHFramePtrSaveIndex(int Index) { SEHFramePtrSaveIndex = Index; }
280
281 AMXProgModelEnum getAMXProgModel() const { return AMXProgModel; }
283 assert((AMXProgModel == AMXProgModelEnum::None || AMXProgModel == Model) &&
284 "mixed model is not supported");
285 AMXProgModel = Model;
286 }
287
288 ACEProgModelEnum getACEProgModel() const { return ACEProgModel; }
289 /// Record the ACE programming model of \p MF, reporting an error if it
290 /// already uses the other one.
291 void setACEProgModel(const MachineFunction *MF, ACEProgModelEnum Model);
292
294 return ForwardedMustTailRegParms;
295 }
296
297 bool isSplitCSR() const { return IsSplitCSR; }
298 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
299
300 bool getUsesRedZone() const { return UsesRedZone; }
301 void setUsesRedZone(bool V) { UsesRedZone = V; }
302
303 bool hasDynAlloca() const { return HasDynAlloca; }
304 void setHasDynAlloca(bool v) { HasDynAlloca = v; }
305
306 bool hasPreallocatedCall() const { return HasPreallocatedCall; }
307 void setHasPreallocatedCall(bool v) { HasPreallocatedCall = v; }
308
309 bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
310 void setHasSwiftAsyncContext(bool v) { HasSwiftAsyncContext = v; }
311
313 return CandidatesForPush2Pop2.find(Reg) != CandidatesForPush2Pop2.end();
314 }
316 CandidatesForPush2Pop2.insert(Reg);
317 }
319 return CandidatesForPush2Pop2.size();
320 }
321
322 bool hasCFIAdjustCfa() const { return HasCFIAdjustCfa; }
323 void setHasCFIAdjustCfa(bool v) { HasCFIAdjustCfa = v; }
324
325 void setStackPtrSaveMI(MachineInstr *MI) { StackPtrSaveMI = MI; }
326 MachineInstr *getStackPtrSaveMI() const { return StackPtrSaveMI; }
327
328 std::optional<int> getSwiftAsyncContextFrameIdx() const {
329 return SwiftAsyncContextFrameIdx;
330 }
331 void setSwiftAsyncContextFrameIdx(int v) { SwiftAsyncContextFrameIdx = v; }
332
334 auto Insert = PreallocatedIds.insert({CS, PreallocatedIds.size()});
335 if (Insert.second) {
336 PreallocatedStackSizes.push_back(0);
337 PreallocatedArgOffsets.emplace_back();
338 }
339 return Insert.first->second;
340 }
341
342 void setPreallocatedStackSize(size_t Id, size_t StackSize) {
343 PreallocatedStackSizes[Id] = StackSize;
344 }
345
346 size_t getPreallocatedStackSize(const size_t Id) {
347 assert(PreallocatedStackSizes[Id] != 0 && "stack size not set");
348 return PreallocatedStackSizes[Id];
349 }
350
352 PreallocatedArgOffsets[Id].assign(AO.begin(), AO.end());
353 }
354
356 assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
357 return PreallocatedArgOffsets[Id];
358 }
359
360 bool getFPClobberedByCall() const { return FPClobberedByCall; }
361 void setFPClobberedByCall(bool C) { FPClobberedByCall = C; }
362
363 bool getBPClobberedByCall() const { return BPClobberedByCall; }
364 void setBPClobberedByCall(bool C) { BPClobberedByCall = C; }
365
366 bool getFPClobberedByInvoke() const { return FPClobberedByInvoke; }
367 void setFPClobberedByInvoke(bool C) { FPClobberedByInvoke = C; }
368
369 bool getBPClobberedByInvoke() const { return BPClobberedByInvoke; }
370 void setBPClobberedByInvoke(bool C) { BPClobberedByInvoke = C; }
371};
372
373} // End llvm namespace
374
375#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)
void setACEProgModel(const MachineFunction *MF, ACEProgModelEnum Model)
Record the ACE programming model of MF, reporting an error if it already uses the other one.
ACEProgModelEnum getACEProgModel() const
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, ACEProgModelEnum &Value)
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