LLVM 17.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"
20
21namespace llvm {
22
23/// X86MachineFunctionInfo - This class is derived from MachineFunction and
24/// contains private X86 target-specific information for each MachineFunction.
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 MachineInstr *StackPtrSaveMI = nullptr;
121
122 std::optional<int> SwiftAsyncContextFrameIdx;
123
124 // Preallocated fields are only used during isel.
125 // FIXME: Can we find somewhere else to store these?
126 DenseMap<const Value *, size_t> PreallocatedIds;
127 SmallVector<size_t, 0> PreallocatedStackSizes;
128 SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;
129
130private:
131 /// ForwardedMustTailRegParms - A list of virtual and physical registers
132 /// that must be forwarded to every musttail call.
133 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
134
135public:
138
140
144 const override;
145
146 bool getForceFramePointer() const { return ForceFramePointer;}
147 void setForceFramePointer(bool forceFP) { ForceFramePointer = forceFP; }
148
149 bool getHasPushSequences() const { return HasPushSequences; }
150 void setHasPushSequences(bool HasPush) { HasPushSequences = HasPush; }
151
152 bool getRestoreBasePointer() const { return RestoreBasePointerOffset!=0; }
154 void setRestoreBasePointer(unsigned CalleeSavedFrameSize) {
155 RestoreBasePointerOffset = -CalleeSavedFrameSize;
156 }
157 int getRestoreBasePointerOffset() const {return RestoreBasePointerOffset; }
158
159 DenseMap<int, unsigned>& getWinEHXMMSlotInfo() { return WinEHXMMSlotInfo; }
161 return WinEHXMMSlotInfo; }
162
163 unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
164 void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
165
166 unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
167 void setBytesToPopOnReturn (unsigned bytes) { BytesToPopOnReturn = bytes;}
168
169 int getRAIndex() const { return ReturnAddrIndex; }
170 void setRAIndex(int Index) { ReturnAddrIndex = Index; }
171
172 int getFAIndex() const { return FrameAddrIndex; }
173 void setFAIndex(int Index) { FrameAddrIndex = Index; }
174
175 int getTCReturnAddrDelta() const { return TailCallReturnAddrDelta; }
176 void setTCReturnAddrDelta(int delta) {TailCallReturnAddrDelta = delta;}
177
178 Register getSRetReturnReg() const { return SRetReturnReg; }
179 void setSRetReturnReg(Register Reg) { SRetReturnReg = Reg; }
180
181 Register getGlobalBaseReg() const { return GlobalBaseReg; }
182 void setGlobalBaseReg(Register Reg) { GlobalBaseReg = Reg; }
183
184 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
185 void setVarArgsFrameIndex(int Idx) { VarArgsFrameIndex = Idx; }
186
187 int getRegSaveFrameIndex() const { return RegSaveFrameIndex; }
188 void setRegSaveFrameIndex(int Idx) { RegSaveFrameIndex = Idx; }
189
190 unsigned getVarArgsGPOffset() const { return VarArgsGPOffset; }
191 void setVarArgsGPOffset(unsigned Offset) { VarArgsGPOffset = Offset; }
192
193 unsigned getVarArgsFPOffset() const { return VarArgsFPOffset; }
194 void setVarArgsFPOffset(unsigned Offset) { VarArgsFPOffset = Offset; }
195
196 unsigned getArgumentStackSize() const { return ArgumentStackSize; }
197 void setArgumentStackSize(unsigned size) { ArgumentStackSize = size; }
198
199 unsigned getNumLocalDynamicTLSAccesses() const { return NumLocalDynamics; }
200 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamics; }
201
202 bool getHasSEHFramePtrSave() const { return HasSEHFramePtrSave; }
203 void setHasSEHFramePtrSave(bool V) { HasSEHFramePtrSave = V; }
204
205 int getSEHFramePtrSaveIndex() const { return SEHFramePtrSaveIndex; }
206 void setSEHFramePtrSaveIndex(int Index) { SEHFramePtrSaveIndex = Index; }
207
209 return ForwardedMustTailRegParms;
210 }
211
212 bool isSplitCSR() const { return IsSplitCSR; }
213 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
214
215 bool getUsesRedZone() const { return UsesRedZone; }
216 void setUsesRedZone(bool V) { UsesRedZone = V; }
217
218 bool hasDynAlloca() const { return HasDynAlloca; }
219 void setHasDynAlloca(bool v) { HasDynAlloca = v; }
220
221 bool hasPreallocatedCall() const { return HasPreallocatedCall; }
222 void setHasPreallocatedCall(bool v) { HasPreallocatedCall = v; }
223
224 bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
225 void setHasSwiftAsyncContext(bool v) { HasSwiftAsyncContext = v; }
226
227 bool hasVirtualTileReg() const { return HasVirtualTileReg; }
228 void setHasVirtualTileReg(bool v) { HasVirtualTileReg = v; }
229
230 void setStackPtrSaveMI(MachineInstr *MI) { StackPtrSaveMI = MI; }
231 MachineInstr *getStackPtrSaveMI() const { return StackPtrSaveMI; }
232
233 std::optional<int> getSwiftAsyncContextFrameIdx() const {
234 return SwiftAsyncContextFrameIdx;
235 }
236 void setSwiftAsyncContextFrameIdx(int v) { SwiftAsyncContextFrameIdx = v; }
237
239 auto Insert = PreallocatedIds.insert({CS, PreallocatedIds.size()});
240 if (Insert.second) {
241 PreallocatedStackSizes.push_back(0);
242 PreallocatedArgOffsets.emplace_back();
243 }
244 return Insert.first->second;
245 }
246
247 void setPreallocatedStackSize(size_t Id, size_t StackSize) {
248 PreallocatedStackSizes[Id] = StackSize;
249 }
250
251 size_t getPreallocatedStackSize(const size_t Id) {
252 assert(PreallocatedStackSizes[Id] != 0 && "stack size not set");
253 return PreallocatedStackSizes[Id];
254 }
255
257 PreallocatedArgOffsets[Id].assign(AO.begin(), AO.end());
258 }
259
261 assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
262 return PreallocatedArgOffsets[Id];
263 }
264};
265
266} // End llvm namespace
267
268#endif
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
unsigned Reg
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
iterator end() const
Definition: ArrayRef.h:152
iterator begin() const
Definition: ArrayRef.h:151
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
unsigned size() const
Definition: DenseMap.h:99
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Representation of each machine instruction.
Definition: MachineInstr.h:68
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
void assign(size_type NumElts, ValueParamT Elt)
Definition: SmallVector.h:708
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:941
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
TargetSubtargetInfo - Generic base class for all target subtargets.
LLVM Value Representation.
Definition: Value.h:74
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
void setBytesToPopOnReturn(unsigned bytes)
const DenseMap< int, unsigned > & getWinEHXMMSlotInfo() const
X86MachineFunctionInfo(const X86MachineFunctionInfo &)=default
ArrayRef< size_t > getPreallocatedArgOffsets(const size_t Id)
void setVarArgsGPOffset(unsigned Offset)
void setArgumentStackSize(unsigned size)
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)
unsigned getNumLocalDynamicTLSAccesses() const
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 setVarArgsFPOffset(unsigned Offset)
void setStackPtrSaveMI(MachineInstr *MI)
void setCalleeSavedFrameSize(unsigned bytes)
size_t getPreallocatedIdForCallSite(const Value *CS)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
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:1777
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...