LLVM 18.0.0git
AArch64MachineFunctionInfo.h
Go to the documentation of this file.
1//=- AArch64MachineFunctionInfo.h - AArch64 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 AArch64-specific per-machine-function information.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
15
16#include "llvm/ADT/ArrayRef.h"
23#include "llvm/IR/Function.h"
25#include <cassert>
26#include <optional>
27
28namespace llvm {
29
30namespace yaml {
31struct AArch64FunctionInfo;
32} // end namespace yaml
33
34class AArch64Subtarget;
35class MachineInstr;
36
37/// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
38/// contains private AArch64-specific information for each MachineFunction.
40 /// Number of bytes of arguments this function has on the stack. If the callee
41 /// is expected to restore the argument stack this should be a multiple of 16,
42 /// all usable during a tail call.
43 ///
44 /// The alternative would forbid tail call optimisation in some cases: if we
45 /// want to transfer control from a function with 8-bytes of stack-argument
46 /// space to a function with 16-bytes then misalignment of this value would
47 /// make a stack adjustment necessary, which could not be undone by the
48 /// callee.
49 unsigned BytesInStackArgArea = 0;
50
51 /// The number of bytes to restore to deallocate space for incoming
52 /// arguments. Canonically 0 in the C calling convention, but non-zero when
53 /// callee is expected to pop the args.
54 unsigned ArgumentStackToRestore = 0;
55
56 /// Space just below incoming stack pointer reserved for arguments being
57 /// passed on the stack during a tail call. This will be the difference
58 /// between the largest tail call argument space needed in this function and
59 /// what's already available by reusing space of incoming arguments.
60 unsigned TailCallReservedStack = 0;
61
62 /// HasStackFrame - True if this function has a stack frame. Set by
63 /// determineCalleeSaves().
64 bool HasStackFrame = false;
65
66 /// Amount of stack frame size, not including callee-saved registers.
67 uint64_t LocalStackSize = 0;
68
69 /// The start and end frame indices for the SVE callee saves.
70 int MinSVECSFrameIndex = 0;
71 int MaxSVECSFrameIndex = 0;
72
73 /// Amount of stack frame size used for saving callee-saved registers.
74 unsigned CalleeSavedStackSize = 0;
75 unsigned SVECalleeSavedStackSize = 0;
76 bool HasCalleeSavedStackSize = false;
77
78 /// Number of TLS accesses using the special (combinable)
79 /// _TLS_MODULE_BASE_ symbol.
80 unsigned NumLocalDynamicTLSAccesses = 0;
81
82 /// FrameIndex for start of varargs area for arguments passed on the
83 /// stack.
84 int VarArgsStackIndex = 0;
85
86 /// Offset of start of varargs area for arguments passed on the stack.
87 unsigned VarArgsStackOffset = 0;
88
89 /// FrameIndex for start of varargs area for arguments passed in
90 /// general purpose registers.
91 int VarArgsGPRIndex = 0;
92
93 /// Size of the varargs area for arguments passed in general purpose
94 /// registers.
95 unsigned VarArgsGPRSize = 0;
96
97 /// FrameIndex for start of varargs area for arguments passed in
98 /// floating-point registers.
99 int VarArgsFPRIndex = 0;
100
101 /// Size of the varargs area for arguments passed in floating-point
102 /// registers.
103 unsigned VarArgsFPRSize = 0;
104
105 /// True if this function has a subset of CSRs that is handled explicitly via
106 /// copies.
107 bool IsSplitCSR = false;
108
109 /// True when the stack gets realigned dynamically because the size of stack
110 /// frame is unknown at compile time. e.g., in case of VLAs.
111 bool StackRealigned = false;
112
113 /// True when the callee-save stack area has unused gaps that may be used for
114 /// other stack allocations.
115 bool CalleeSaveStackHasFreeSpace = false;
116
117 /// SRetReturnReg - sret lowering includes returning the value of the
118 /// returned struct in a register. This field holds the virtual register into
119 /// which the sret argument is passed.
120 Register SRetReturnReg;
121
122 /// SVE stack size (for predicates and data vectors) are maintained here
123 /// rather than in FrameInfo, as the placement and Stack IDs are target
124 /// specific.
125 uint64_t StackSizeSVE = 0;
126
127 /// HasCalculatedStackSizeSVE indicates whether StackSizeSVE is valid.
128 bool HasCalculatedStackSizeSVE = false;
129
130 /// Has a value when it is known whether or not the function uses a
131 /// redzone, and no value otherwise.
132 /// Initialized during frame lowering, unless the function has the noredzone
133 /// attribute, in which case it is set to false at construction.
134 std::optional<bool> HasRedZone;
135
136 /// ForwardedMustTailRegParms - A list of virtual and physical registers
137 /// that must be forwarded to every musttail call.
138 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
139
140 /// FrameIndex for the tagged base pointer.
141 std::optional<int> TaggedBasePointerIndex;
142
143 /// Offset from SP-at-entry to the tagged base pointer.
144 /// Tagged base pointer is set up to point to the first (lowest address)
145 /// tagged stack slot.
146 unsigned TaggedBasePointerOffset;
147
148 /// OutliningStyle denotes, if a function was outined, how it was outlined,
149 /// e.g. Tail Call, Thunk, or Function if none apply.
150 std::optional<std::string> OutliningStyle;
151
152 // Offset from SP-after-callee-saved-spills (i.e. SP-at-entry minus
153 // CalleeSavedStackSize) to the address of the frame record.
154 int CalleeSaveBaseToFrameRecordOffset = 0;
155
156 /// SignReturnAddress is true if PAC-RET is enabled for the function with
157 /// defaults being sign non-leaf functions only, with the B key.
158 bool SignReturnAddress = false;
159
160 /// SignReturnAddressAll modifies the default PAC-RET mode to signing leaf
161 /// functions as well.
162 bool SignReturnAddressAll = false;
163
164 /// SignWithBKey modifies the default PAC-RET mode to signing with the B key.
165 bool SignWithBKey = false;
166
167 /// BranchTargetEnforcement enables placing BTI instructions at potential
168 /// indirect branch destinations.
169 bool BranchTargetEnforcement = false;
170
171 /// Whether this function has an extended frame record [Ctx, FP, LR]. If so,
172 /// bit 60 of the in-memory FP will be 1 to enable other tools to detect the
173 /// extended record.
174 bool HasSwiftAsyncContext = false;
175
176 /// The stack slot where the Swift asynchronous context is stored.
177 int SwiftAsyncContextFrameIdx = std::numeric_limits<int>::max();
178
179 bool IsMTETagged = false;
180
181 /// The function has Scalable Vector or Scalable Predicate register argument
182 /// or return type
183 bool IsSVECC = false;
184
185 /// The frame-index for the TPIDR2 object used for lazy saves.
186 Register LazySaveTPIDR2Obj = 0;
187
188 /// Whether this function changes streaming mode within the function.
189 bool HasStreamingModeChanges = false;
190
191 /// True if the function need unwind information.
192 mutable std::optional<bool> NeedsDwarfUnwindInfo;
193
194 /// True if the function need asynchronous unwind information.
195 mutable std::optional<bool> NeedsAsyncDwarfUnwindInfo;
196
197public:
199
203 const override;
204
205 bool isSVECC() const { return IsSVECC; };
206 void setIsSVECC(bool s) { IsSVECC = s; };
207
208 unsigned getLazySaveTPIDR2Obj() const { return LazySaveTPIDR2Obj; }
209 void setLazySaveTPIDR2Obj(unsigned Reg) { LazySaveTPIDR2Obj = Reg; }
210
212
213 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
214 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
215
216 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
217 void setArgumentStackToRestore(unsigned bytes) {
218 ArgumentStackToRestore = bytes;
219 }
220
221 unsigned getTailCallReservedStack() const { return TailCallReservedStack; }
222 void setTailCallReservedStack(unsigned bytes) {
223 TailCallReservedStack = bytes;
224 }
225
226 bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; }
227
229 HasCalculatedStackSizeSVE = true;
230 StackSizeSVE = S;
231 }
232
233 uint64_t getStackSizeSVE() const { return StackSizeSVE; }
234
235 bool hasStackFrame() const { return HasStackFrame; }
236 void setHasStackFrame(bool s) { HasStackFrame = s; }
237
238 bool isStackRealigned() const { return StackRealigned; }
239 void setStackRealigned(bool s) { StackRealigned = s; }
240
242 return CalleeSaveStackHasFreeSpace;
243 }
245 CalleeSaveStackHasFreeSpace = s;
246 }
247 bool isSplitCSR() const { return IsSplitCSR; }
248 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
249
250 void setLocalStackSize(uint64_t Size) { LocalStackSize = Size; }
251 uint64_t getLocalStackSize() const { return LocalStackSize; }
252
253 void setOutliningStyle(std::string Style) { OutliningStyle = Style; }
254 std::optional<std::string> getOutliningStyle() const {
255 return OutliningStyle;
256 }
257
259 CalleeSavedStackSize = Size;
260 HasCalleeSavedStackSize = true;
261 }
262
263 // When CalleeSavedStackSize has not been set (for example when
264 // some MachineIR pass is run in isolation), then recalculate
265 // the CalleeSavedStackSize directly from the CalleeSavedInfo.
266 // Note: This information can only be recalculated after PEI
267 // has assigned offsets to the callee save objects.
268 unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const {
269 bool ValidateCalleeSavedStackSize = false;
270
271#ifndef NDEBUG
272 // Make sure the calculated size derived from the CalleeSavedInfo
273 // equals the cached size that was calculated elsewhere (e.g. in
274 // determineCalleeSaves).
275 ValidateCalleeSavedStackSize = HasCalleeSavedStackSize;
276#endif
277
278 if (!HasCalleeSavedStackSize || ValidateCalleeSavedStackSize) {
279 assert(MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated");
280 if (MFI.getCalleeSavedInfo().empty())
281 return 0;
282
283 int64_t MinOffset = std::numeric_limits<int64_t>::max();
284 int64_t MaxOffset = std::numeric_limits<int64_t>::min();
285 for (const auto &Info : MFI.getCalleeSavedInfo()) {
286 int FrameIdx = Info.getFrameIdx();
287 if (MFI.getStackID(FrameIdx) != TargetStackID::Default)
288 continue;
289 int64_t Offset = MFI.getObjectOffset(FrameIdx);
290 int64_t ObjSize = MFI.getObjectSize(FrameIdx);
291 MinOffset = std::min<int64_t>(Offset, MinOffset);
292 MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset);
293 }
294
295 if (SwiftAsyncContextFrameIdx != std::numeric_limits<int>::max()) {
297 int64_t ObjSize = MFI.getObjectSize(getSwiftAsyncContextFrameIdx());
298 MinOffset = std::min<int64_t>(Offset, MinOffset);
299 MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset);
300 }
301
302 unsigned Size = alignTo(MaxOffset - MinOffset, 16);
303 assert((!HasCalleeSavedStackSize || getCalleeSavedStackSize() == Size) &&
304 "Invalid size calculated for callee saves");
305 return Size;
306 }
307
309 }
310
311 unsigned getCalleeSavedStackSize() const {
312 assert(HasCalleeSavedStackSize &&
313 "CalleeSavedStackSize has not been calculated");
314 return CalleeSavedStackSize;
315 }
316
317 // Saves the CalleeSavedStackSize for SVE vectors in 'scalable bytes'
319 SVECalleeSavedStackSize = Size;
320 }
321 unsigned getSVECalleeSavedStackSize() const {
322 return SVECalleeSavedStackSize;
323 }
324
325 void setMinMaxSVECSFrameIndex(int Min, int Max) {
326 MinSVECSFrameIndex = Min;
327 MaxSVECSFrameIndex = Max;
328 }
329
330 int getMinSVECSFrameIndex() const { return MinSVECSFrameIndex; }
331 int getMaxSVECSFrameIndex() const { return MaxSVECSFrameIndex; }
332
333 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
335 return NumLocalDynamicTLSAccesses;
336 }
337
338 std::optional<bool> hasRedZone() const { return HasRedZone; }
339 void setHasRedZone(bool s) { HasRedZone = s; }
340
341 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
342 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
343
344 unsigned getVarArgsStackOffset() const { return VarArgsStackOffset; }
345 void setVarArgsStackOffset(unsigned Offset) { VarArgsStackOffset = Offset; }
346
347 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
348 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
349
350 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
351 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
352
353 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
354 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
355
356 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
357 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
358
359 unsigned getSRetReturnReg() const { return SRetReturnReg; }
360 void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
361
362 unsigned getJumpTableEntrySize(int Idx) const {
363 return JumpTableEntryInfo[Idx].first;
364 }
366 return JumpTableEntryInfo[Idx].second;
367 }
368 void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
369 if ((unsigned)Idx >= JumpTableEntryInfo.size())
370 JumpTableEntryInfo.resize(Idx+1);
371 JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
372 }
373
375
376 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
377
378 // Shortcuts for LOH related types.
380 MCLOHType Kind;
381
382 /// Arguments of this directive. Order matters.
384
385 public:
387
389 : Kind(Kind), Args(Args.begin(), Args.end()) {
390 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
391 }
392
393 MCLOHType getKind() const { return Kind; }
394 LOHArgs getArgs() const { return Args; }
395 };
396
399
400 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
401
402 /// Add a LOH directive of this @p Kind and this @p Args.
404 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
405 LOHRelated.insert(Args.begin(), Args.end());
406 }
407
409 return ForwardedMustTailRegParms;
410 }
411
412 std::optional<int> getTaggedBasePointerIndex() const {
413 return TaggedBasePointerIndex;
414 }
415 void setTaggedBasePointerIndex(int Index) { TaggedBasePointerIndex = Index; }
416
417 unsigned getTaggedBasePointerOffset() const {
418 return TaggedBasePointerOffset;
419 }
421 TaggedBasePointerOffset = Offset;
422 }
423
425 return CalleeSaveBaseToFrameRecordOffset;
426 }
428 CalleeSaveBaseToFrameRecordOffset = Offset;
429 }
430
431 bool shouldSignReturnAddress(const MachineFunction &MF) const;
432 bool shouldSignReturnAddress(bool SpillsLR) const;
433
434 bool shouldSignWithBKey() const { return SignWithBKey; }
435 bool isMTETagged() const { return IsMTETagged; }
436
437 bool branchTargetEnforcement() const { return BranchTargetEnforcement; }
438
439 void setHasSwiftAsyncContext(bool HasContext) {
440 HasSwiftAsyncContext = HasContext;
441 }
442 bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
443
445 SwiftAsyncContextFrameIdx = FI;
446 }
447 int getSwiftAsyncContextFrameIdx() const { return SwiftAsyncContextFrameIdx; }
448
449 bool needsDwarfUnwindInfo(const MachineFunction &MF) const;
450 bool needsAsyncDwarfUnwindInfo(const MachineFunction &MF) const;
451
452 bool hasStreamingModeChanges() const { return HasStreamingModeChanges; }
453 void setHasStreamingModeChanges(bool HasChanges) {
454 HasStreamingModeChanges = HasChanges;
455 }
456
457private:
458 // Hold the lists of LOHs.
459 MILOHContainer LOHContainerSet;
460 SetOfInstructions LOHRelated;
461
462 SmallVector<std::pair<unsigned, MCSymbol *>, 2> JumpTableEntryInfo;
463};
464
465namespace yaml {
467 std::optional<bool> HasRedZone;
468
471
472 void mappingImpl(yaml::IO &YamlIO) override;
474};
475
477 static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) {
478 YamlIO.mapOptional("hasRedZone", MFI.HasRedZone);
479 }
480};
481
482} // end namespace yaml
483
484} // end namespace llvm
485
486#endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
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
uint64_t Size
IO & YamlIO
Definition: ELFYAML.cpp:1271
#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 SmallPtrSet class.
This file defines the SmallVector class.
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
void addLOHDirective(MCLOHType Kind, MILOHArgs Args)
Add a LOH directive of this Kind and this Args.
unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const
void setCalleeSaveBaseToFrameRecordOffset(int Offset)
void setVarArgsStackOffset(unsigned Offset)
void setTailCallReservedStack(unsigned bytes)
SmallVector< MILOHDirective, 32 > MILOHContainer
SmallVectorImpl< ForwardedRegister > & getForwardedMustTailRegParms()
bool shouldSignReturnAddress(const MachineFunction &MF) const
const SetOfInstructions & getLOHRelated() const
void setBytesInStackArgArea(unsigned bytes)
void setCalleeSavedStackSize(unsigned Size)
void setHasSwiftAsyncContext(bool HasContext)
std::optional< int > getTaggedBasePointerIndex() const
unsigned getJumpTableEntrySize(int Idx) const
bool needsDwarfUnwindInfo(const MachineFunction &MF) const
void setOutliningStyle(std::string Style)
MCSymbol * getJumpTableEntryPCRelSymbol(int Idx) const
SmallPtrSet< const MachineInstr *, 16 > SetOfInstructions
void setTaggedBasePointerOffset(unsigned Offset)
std::optional< bool > hasRedZone() const
void setSVECalleeSavedStackSize(unsigned Size)
std::optional< std::string > getOutliningStyle() const
void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI)
const MILOHContainer & getLOHContainer() const
void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym)
bool needsAsyncDwarfUnwindInfo(const MachineFunction &MF) 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 setArgumentStackToRestore(unsigned bytes)
void setMinMaxSVECSFrameIndex(int Min, int Max)
void setHasStreamingModeChanges(bool HasChanges)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:366
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
static bool isValidMCLOHType(unsigned Kind)
MCLOHType
Linker Optimization Hint Type.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
void mappingImpl(yaml::IO &YamlIO) override
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI)