xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric //=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- C++ -*-=//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares AArch64-specific per-machine-function information.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
170b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h"
180b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
190b57cec5SDimitry Andric #include "llvm/CodeGen/CallingConvLower.h"
205ffd83dbSDimitry Andric #include "llvm/CodeGen/MIRYamlMapping.h"
2181ad6265SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
220b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
238bcb0991SDimitry Andric #include "llvm/IR/Function.h"
240b57cec5SDimitry Andric #include "llvm/MC/MCLinkerOptimizationHint.h"
250b57cec5SDimitry Andric #include <cassert>
26*bdd1243dSDimitry Andric #include <optional>
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric namespace llvm {
290b57cec5SDimitry Andric 
305ffd83dbSDimitry Andric namespace yaml {
315ffd83dbSDimitry Andric struct AArch64FunctionInfo;
325ffd83dbSDimitry Andric } // end namespace yaml
335ffd83dbSDimitry Andric 
34*bdd1243dSDimitry Andric class AArch64Subtarget;
350b57cec5SDimitry Andric class MachineInstr;
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
380b57cec5SDimitry Andric /// contains private AArch64-specific information for each MachineFunction.
390b57cec5SDimitry Andric class AArch64FunctionInfo final : public MachineFunctionInfo {
400b57cec5SDimitry Andric   /// Number of bytes of arguments this function has on the stack. If the callee
410b57cec5SDimitry Andric   /// is expected to restore the argument stack this should be a multiple of 16,
420b57cec5SDimitry Andric   /// all usable during a tail call.
430b57cec5SDimitry Andric   ///
440b57cec5SDimitry Andric   /// The alternative would forbid tail call optimisation in some cases: if we
450b57cec5SDimitry Andric   /// want to transfer control from a function with 8-bytes of stack-argument
460b57cec5SDimitry Andric   /// space to a function with 16-bytes then misalignment of this value would
470b57cec5SDimitry Andric   /// make a stack adjustment necessary, which could not be undone by the
480b57cec5SDimitry Andric   /// callee.
490b57cec5SDimitry Andric   unsigned BytesInStackArgArea = 0;
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric   /// The number of bytes to restore to deallocate space for incoming
520b57cec5SDimitry Andric   /// arguments. Canonically 0 in the C calling convention, but non-zero when
530b57cec5SDimitry Andric   /// callee is expected to pop the args.
540b57cec5SDimitry Andric   unsigned ArgumentStackToRestore = 0;
550b57cec5SDimitry Andric 
56fe6060f1SDimitry Andric   /// Space just below incoming stack pointer reserved for arguments being
57fe6060f1SDimitry Andric   /// passed on the stack during a tail call. This will be the difference
58fe6060f1SDimitry Andric   /// between the largest tail call argument space needed in this function and
59fe6060f1SDimitry Andric   /// what's already available by reusing space of incoming arguments.
60fe6060f1SDimitry Andric   unsigned TailCallReservedStack = 0;
61fe6060f1SDimitry Andric 
620b57cec5SDimitry Andric   /// HasStackFrame - True if this function has a stack frame. Set by
630b57cec5SDimitry Andric   /// determineCalleeSaves().
640b57cec5SDimitry Andric   bool HasStackFrame = false;
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   /// Amount of stack frame size, not including callee-saved registers.
67480093f4SDimitry Andric   uint64_t LocalStackSize = 0;
68480093f4SDimitry Andric 
69480093f4SDimitry Andric   /// The start and end frame indices for the SVE callee saves.
70480093f4SDimitry Andric   int MinSVECSFrameIndex = 0;
71480093f4SDimitry Andric   int MaxSVECSFrameIndex = 0;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   /// Amount of stack frame size used for saving callee-saved registers.
74480093f4SDimitry Andric   unsigned CalleeSavedStackSize = 0;
75480093f4SDimitry Andric   unsigned SVECalleeSavedStackSize = 0;
76480093f4SDimitry Andric   bool HasCalleeSavedStackSize = false;
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   /// Number of TLS accesses using the special (combinable)
790b57cec5SDimitry Andric   /// _TLS_MODULE_BASE_ symbol.
800b57cec5SDimitry Andric   unsigned NumLocalDynamicTLSAccesses = 0;
810b57cec5SDimitry Andric 
820b57cec5SDimitry Andric   /// FrameIndex for start of varargs area for arguments passed on the
830b57cec5SDimitry Andric   /// stack.
840b57cec5SDimitry Andric   int VarArgsStackIndex = 0;
850b57cec5SDimitry Andric 
86*bdd1243dSDimitry Andric   /// Offset of start of varargs area for arguments passed on the stack.
87*bdd1243dSDimitry Andric   unsigned VarArgsStackOffset = 0;
88*bdd1243dSDimitry Andric 
890b57cec5SDimitry Andric   /// FrameIndex for start of varargs area for arguments passed in
900b57cec5SDimitry Andric   /// general purpose registers.
910b57cec5SDimitry Andric   int VarArgsGPRIndex = 0;
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   /// Size of the varargs area for arguments passed in general purpose
940b57cec5SDimitry Andric   /// registers.
950b57cec5SDimitry Andric   unsigned VarArgsGPRSize = 0;
960b57cec5SDimitry Andric 
970b57cec5SDimitry Andric   /// FrameIndex for start of varargs area for arguments passed in
980b57cec5SDimitry Andric   /// floating-point registers.
990b57cec5SDimitry Andric   int VarArgsFPRIndex = 0;
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   /// Size of the varargs area for arguments passed in floating-point
1020b57cec5SDimitry Andric   /// registers.
1030b57cec5SDimitry Andric   unsigned VarArgsFPRSize = 0;
1040b57cec5SDimitry Andric 
1050b57cec5SDimitry Andric   /// True if this function has a subset of CSRs that is handled explicitly via
1060b57cec5SDimitry Andric   /// copies.
1070b57cec5SDimitry Andric   bool IsSplitCSR = false;
1080b57cec5SDimitry Andric 
1090b57cec5SDimitry Andric   /// True when the stack gets realigned dynamically because the size of stack
1100b57cec5SDimitry Andric   /// frame is unknown at compile time. e.g., in case of VLAs.
1110b57cec5SDimitry Andric   bool StackRealigned = false;
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric   /// True when the callee-save stack area has unused gaps that may be used for
1140b57cec5SDimitry Andric   /// other stack allocations.
1150b57cec5SDimitry Andric   bool CalleeSaveStackHasFreeSpace = false;
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric   /// SRetReturnReg - sret lowering includes returning the value of the
1180b57cec5SDimitry Andric   /// returned struct in a register. This field holds the virtual register into
1190b57cec5SDimitry Andric   /// which the sret argument is passed.
12081ad6265SDimitry Andric   Register SRetReturnReg;
12181ad6265SDimitry Andric 
1228bcb0991SDimitry Andric   /// SVE stack size (for predicates and data vectors) are maintained here
1238bcb0991SDimitry Andric   /// rather than in FrameInfo, as the placement and Stack IDs are target
1248bcb0991SDimitry Andric   /// specific.
1258bcb0991SDimitry Andric   uint64_t StackSizeSVE = 0;
1268bcb0991SDimitry Andric 
1278bcb0991SDimitry Andric   /// HasCalculatedStackSizeSVE indicates whether StackSizeSVE is valid.
1288bcb0991SDimitry Andric   bool HasCalculatedStackSizeSVE = false;
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric   /// Has a value when it is known whether or not the function uses a
1310b57cec5SDimitry Andric   /// redzone, and no value otherwise.
1320b57cec5SDimitry Andric   /// Initialized during frame lowering, unless the function has the noredzone
1330b57cec5SDimitry Andric   /// attribute, in which case it is set to false at construction.
134*bdd1243dSDimitry Andric   std::optional<bool> HasRedZone;
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   /// ForwardedMustTailRegParms - A list of virtual and physical registers
1370b57cec5SDimitry Andric   /// that must be forwarded to every musttail call.
1380b57cec5SDimitry Andric   SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
1390b57cec5SDimitry Andric 
140e8d8bef9SDimitry Andric   /// FrameIndex for the tagged base pointer.
141*bdd1243dSDimitry Andric   std::optional<int> TaggedBasePointerIndex;
142e8d8bef9SDimitry Andric 
143e8d8bef9SDimitry Andric   /// Offset from SP-at-entry to the tagged base pointer.
144e8d8bef9SDimitry Andric   /// Tagged base pointer is set up to point to the first (lowest address)
145e8d8bef9SDimitry Andric   /// tagged stack slot.
146e8d8bef9SDimitry Andric   unsigned TaggedBasePointerOffset;
1470b57cec5SDimitry Andric 
1485ffd83dbSDimitry Andric   /// OutliningStyle denotes, if a function was outined, how it was outlined,
1495ffd83dbSDimitry Andric   /// e.g. Tail Call, Thunk, or Function if none apply.
150*bdd1243dSDimitry Andric   std::optional<std::string> OutliningStyle;
1515ffd83dbSDimitry Andric 
152e8d8bef9SDimitry Andric   // Offset from SP-after-callee-saved-spills (i.e. SP-at-entry minus
153e8d8bef9SDimitry Andric   // CalleeSavedStackSize) to the address of the frame record.
154e8d8bef9SDimitry Andric   int CalleeSaveBaseToFrameRecordOffset = 0;
155e8d8bef9SDimitry Andric 
156e8d8bef9SDimitry Andric   /// SignReturnAddress is true if PAC-RET is enabled for the function with
157e8d8bef9SDimitry Andric   /// defaults being sign non-leaf functions only, with the B key.
158e8d8bef9SDimitry Andric   bool SignReturnAddress = false;
159e8d8bef9SDimitry Andric 
160e8d8bef9SDimitry Andric   /// SignReturnAddressAll modifies the default PAC-RET mode to signing leaf
161e8d8bef9SDimitry Andric   /// functions as well.
162e8d8bef9SDimitry Andric   bool SignReturnAddressAll = false;
163e8d8bef9SDimitry Andric 
164e8d8bef9SDimitry Andric   /// SignWithBKey modifies the default PAC-RET mode to signing with the B key.
165e8d8bef9SDimitry Andric   bool SignWithBKey = false;
166e8d8bef9SDimitry Andric 
167e8d8bef9SDimitry Andric   /// BranchTargetEnforcement enables placing BTI instructions at potential
168e8d8bef9SDimitry Andric   /// indirect branch destinations.
169e8d8bef9SDimitry Andric   bool BranchTargetEnforcement = false;
170e8d8bef9SDimitry Andric 
171fe6060f1SDimitry Andric   /// Whether this function has an extended frame record [Ctx, FP, LR]. If so,
172fe6060f1SDimitry Andric   /// bit 60 of the in-memory FP will be 1 to enable other tools to detect the
173fe6060f1SDimitry Andric   /// extended record.
174fe6060f1SDimitry Andric   bool HasSwiftAsyncContext = false;
175fe6060f1SDimitry Andric 
176fe6060f1SDimitry Andric   /// The stack slot where the Swift asynchronous context is stored.
177fe6060f1SDimitry Andric   int SwiftAsyncContextFrameIdx = std::numeric_limits<int>::max();
178fe6060f1SDimitry Andric 
17981ad6265SDimitry Andric   bool IsMTETagged = false;
18081ad6265SDimitry Andric 
18181ad6265SDimitry Andric   /// The function has Scalable Vector or Scalable Predicate register argument
18281ad6265SDimitry Andric   /// or return type
18381ad6265SDimitry Andric   bool IsSVECC = false;
18481ad6265SDimitry Andric 
185*bdd1243dSDimitry Andric   /// The frame-index for the TPIDR2 object used for lazy saves.
186*bdd1243dSDimitry Andric   Register LazySaveTPIDR2Obj = 0;
187*bdd1243dSDimitry Andric 
188*bdd1243dSDimitry Andric 
18981ad6265SDimitry Andric   /// True if the function need unwind information.
190*bdd1243dSDimitry Andric   mutable std::optional<bool> NeedsDwarfUnwindInfo;
19181ad6265SDimitry Andric 
19281ad6265SDimitry Andric   /// True if the function need asynchronous unwind information.
193*bdd1243dSDimitry Andric   mutable std::optional<bool> NeedsAsyncDwarfUnwindInfo;
19481ad6265SDimitry Andric 
1950b57cec5SDimitry Andric public:
196*bdd1243dSDimitry Andric   AArch64FunctionInfo(const Function &F, const AArch64Subtarget *STI);
1970b57cec5SDimitry Andric 
19881ad6265SDimitry Andric   MachineFunctionInfo *
19981ad6265SDimitry Andric   clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
20081ad6265SDimitry Andric         const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
20181ad6265SDimitry Andric       const override;
20281ad6265SDimitry Andric 
20381ad6265SDimitry Andric   bool isSVECC() const { return IsSVECC; };
20481ad6265SDimitry Andric   void setIsSVECC(bool s) { IsSVECC = s; };
20581ad6265SDimitry Andric 
206*bdd1243dSDimitry Andric   unsigned getLazySaveTPIDR2Obj() const { return LazySaveTPIDR2Obj; }
207*bdd1243dSDimitry Andric   void setLazySaveTPIDR2Obj(unsigned Reg) { LazySaveTPIDR2Obj = Reg; }
208*bdd1243dSDimitry Andric 
2095ffd83dbSDimitry Andric   void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI);
2100b57cec5SDimitry Andric 
2110b57cec5SDimitry Andric   unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
2120b57cec5SDimitry Andric   void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
2130b57cec5SDimitry Andric 
2140b57cec5SDimitry Andric   unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
2150b57cec5SDimitry Andric   void setArgumentStackToRestore(unsigned bytes) {
2160b57cec5SDimitry Andric     ArgumentStackToRestore = bytes;
2170b57cec5SDimitry Andric   }
2180b57cec5SDimitry Andric 
219fe6060f1SDimitry Andric   unsigned getTailCallReservedStack() const { return TailCallReservedStack; }
220fe6060f1SDimitry Andric   void setTailCallReservedStack(unsigned bytes) {
221fe6060f1SDimitry Andric     TailCallReservedStack = bytes;
222fe6060f1SDimitry Andric   }
223fe6060f1SDimitry Andric 
2248bcb0991SDimitry Andric   bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; }
2258bcb0991SDimitry Andric 
2268bcb0991SDimitry Andric   void setStackSizeSVE(uint64_t S) {
2278bcb0991SDimitry Andric     HasCalculatedStackSizeSVE = true;
2288bcb0991SDimitry Andric     StackSizeSVE = S;
2298bcb0991SDimitry Andric   }
2308bcb0991SDimitry Andric 
2318bcb0991SDimitry Andric   uint64_t getStackSizeSVE() const { return StackSizeSVE; }
2328bcb0991SDimitry Andric 
2330b57cec5SDimitry Andric   bool hasStackFrame() const { return HasStackFrame; }
2340b57cec5SDimitry Andric   void setHasStackFrame(bool s) { HasStackFrame = s; }
2350b57cec5SDimitry Andric 
2360b57cec5SDimitry Andric   bool isStackRealigned() const { return StackRealigned; }
2370b57cec5SDimitry Andric   void setStackRealigned(bool s) { StackRealigned = s; }
2380b57cec5SDimitry Andric 
2390b57cec5SDimitry Andric   bool hasCalleeSaveStackFreeSpace() const {
2400b57cec5SDimitry Andric     return CalleeSaveStackHasFreeSpace;
2410b57cec5SDimitry Andric   }
2420b57cec5SDimitry Andric   void setCalleeSaveStackHasFreeSpace(bool s) {
2430b57cec5SDimitry Andric     CalleeSaveStackHasFreeSpace = s;
2440b57cec5SDimitry Andric   }
2450b57cec5SDimitry Andric   bool isSplitCSR() const { return IsSplitCSR; }
2460b57cec5SDimitry Andric   void setIsSplitCSR(bool s) { IsSplitCSR = s; }
2470b57cec5SDimitry Andric 
248480093f4SDimitry Andric   void setLocalStackSize(uint64_t Size) { LocalStackSize = Size; }
249480093f4SDimitry Andric   uint64_t getLocalStackSize() const { return LocalStackSize; }
2500b57cec5SDimitry Andric 
2515ffd83dbSDimitry Andric   void setOutliningStyle(std::string Style) { OutliningStyle = Style; }
252*bdd1243dSDimitry Andric   std::optional<std::string> getOutliningStyle() const {
253*bdd1243dSDimitry Andric     return OutliningStyle;
254*bdd1243dSDimitry Andric   }
2555ffd83dbSDimitry Andric 
256480093f4SDimitry Andric   void setCalleeSavedStackSize(unsigned Size) {
257480093f4SDimitry Andric     CalleeSavedStackSize = Size;
258480093f4SDimitry Andric     HasCalleeSavedStackSize = true;
259480093f4SDimitry Andric   }
260480093f4SDimitry Andric 
261480093f4SDimitry Andric   // When CalleeSavedStackSize has not been set (for example when
262480093f4SDimitry Andric   // some MachineIR pass is run in isolation), then recalculate
263480093f4SDimitry Andric   // the CalleeSavedStackSize directly from the CalleeSavedInfo.
264480093f4SDimitry Andric   // Note: This information can only be recalculated after PEI
265480093f4SDimitry Andric   // has assigned offsets to the callee save objects.
266480093f4SDimitry Andric   unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const {
267480093f4SDimitry Andric     bool ValidateCalleeSavedStackSize = false;
268480093f4SDimitry Andric 
269480093f4SDimitry Andric #ifndef NDEBUG
270480093f4SDimitry Andric     // Make sure the calculated size derived from the CalleeSavedInfo
271480093f4SDimitry Andric     // equals the cached size that was calculated elsewhere (e.g. in
272480093f4SDimitry Andric     // determineCalleeSaves).
273480093f4SDimitry Andric     ValidateCalleeSavedStackSize = HasCalleeSavedStackSize;
274480093f4SDimitry Andric #endif
275480093f4SDimitry Andric 
276480093f4SDimitry Andric     if (!HasCalleeSavedStackSize || ValidateCalleeSavedStackSize) {
277480093f4SDimitry Andric       assert(MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated");
278480093f4SDimitry Andric       if (MFI.getCalleeSavedInfo().empty())
279480093f4SDimitry Andric         return 0;
280480093f4SDimitry Andric 
281480093f4SDimitry Andric       int64_t MinOffset = std::numeric_limits<int64_t>::max();
282480093f4SDimitry Andric       int64_t MaxOffset = std::numeric_limits<int64_t>::min();
283480093f4SDimitry Andric       for (const auto &Info : MFI.getCalleeSavedInfo()) {
284480093f4SDimitry Andric         int FrameIdx = Info.getFrameIdx();
285480093f4SDimitry Andric         if (MFI.getStackID(FrameIdx) != TargetStackID::Default)
286480093f4SDimitry Andric           continue;
287480093f4SDimitry Andric         int64_t Offset = MFI.getObjectOffset(FrameIdx);
288480093f4SDimitry Andric         int64_t ObjSize = MFI.getObjectSize(FrameIdx);
289480093f4SDimitry Andric         MinOffset = std::min<int64_t>(Offset, MinOffset);
290480093f4SDimitry Andric         MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset);
291480093f4SDimitry Andric       }
292480093f4SDimitry Andric 
293fe6060f1SDimitry Andric       if (SwiftAsyncContextFrameIdx != std::numeric_limits<int>::max()) {
294fe6060f1SDimitry Andric         int64_t Offset = MFI.getObjectOffset(getSwiftAsyncContextFrameIdx());
295fe6060f1SDimitry Andric         int64_t ObjSize = MFI.getObjectSize(getSwiftAsyncContextFrameIdx());
296fe6060f1SDimitry Andric         MinOffset = std::min<int64_t>(Offset, MinOffset);
297fe6060f1SDimitry Andric         MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset);
298fe6060f1SDimitry Andric       }
299fe6060f1SDimitry Andric 
300480093f4SDimitry Andric       unsigned Size = alignTo(MaxOffset - MinOffset, 16);
301480093f4SDimitry Andric       assert((!HasCalleeSavedStackSize || getCalleeSavedStackSize() == Size) &&
302480093f4SDimitry Andric              "Invalid size calculated for callee saves");
303480093f4SDimitry Andric       return Size;
304480093f4SDimitry Andric     }
305480093f4SDimitry Andric 
306480093f4SDimitry Andric     return getCalleeSavedStackSize();
307480093f4SDimitry Andric   }
308480093f4SDimitry Andric 
309480093f4SDimitry Andric   unsigned getCalleeSavedStackSize() const {
310480093f4SDimitry Andric     assert(HasCalleeSavedStackSize &&
311480093f4SDimitry Andric            "CalleeSavedStackSize has not been calculated");
312480093f4SDimitry Andric     return CalleeSavedStackSize;
313480093f4SDimitry Andric   }
314480093f4SDimitry Andric 
315480093f4SDimitry Andric   // Saves the CalleeSavedStackSize for SVE vectors in 'scalable bytes'
316480093f4SDimitry Andric   void setSVECalleeSavedStackSize(unsigned Size) {
317480093f4SDimitry Andric     SVECalleeSavedStackSize = Size;
318480093f4SDimitry Andric   }
319480093f4SDimitry Andric   unsigned getSVECalleeSavedStackSize() const {
320480093f4SDimitry Andric     return SVECalleeSavedStackSize;
321480093f4SDimitry Andric   }
322480093f4SDimitry Andric 
323480093f4SDimitry Andric   void setMinMaxSVECSFrameIndex(int Min, int Max) {
324480093f4SDimitry Andric     MinSVECSFrameIndex = Min;
325480093f4SDimitry Andric     MaxSVECSFrameIndex = Max;
326480093f4SDimitry Andric   }
327480093f4SDimitry Andric 
328480093f4SDimitry Andric   int getMinSVECSFrameIndex() const { return MinSVECSFrameIndex; }
329480093f4SDimitry Andric   int getMaxSVECSFrameIndex() const { return MaxSVECSFrameIndex; }
3300b57cec5SDimitry Andric 
3310b57cec5SDimitry Andric   void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
3320b57cec5SDimitry Andric   unsigned getNumLocalDynamicTLSAccesses() const {
3330b57cec5SDimitry Andric     return NumLocalDynamicTLSAccesses;
3340b57cec5SDimitry Andric   }
3350b57cec5SDimitry Andric 
336*bdd1243dSDimitry Andric   std::optional<bool> hasRedZone() const { return HasRedZone; }
3370b57cec5SDimitry Andric   void setHasRedZone(bool s) { HasRedZone = s; }
3380b57cec5SDimitry Andric 
3390b57cec5SDimitry Andric   int getVarArgsStackIndex() const { return VarArgsStackIndex; }
3400b57cec5SDimitry Andric   void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
3410b57cec5SDimitry Andric 
342*bdd1243dSDimitry Andric   unsigned getVarArgsStackOffset() const { return VarArgsStackOffset; }
343*bdd1243dSDimitry Andric   void setVarArgsStackOffset(unsigned Offset) { VarArgsStackOffset = Offset; }
344*bdd1243dSDimitry Andric 
3450b57cec5SDimitry Andric   int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
3460b57cec5SDimitry Andric   void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric   unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
3490b57cec5SDimitry Andric   void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
3500b57cec5SDimitry Andric 
3510b57cec5SDimitry Andric   int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
3520b57cec5SDimitry Andric   void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
3530b57cec5SDimitry Andric 
3540b57cec5SDimitry Andric   unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
3550b57cec5SDimitry Andric   void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric   unsigned getSRetReturnReg() const { return SRetReturnReg; }
3580b57cec5SDimitry Andric   void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
3590b57cec5SDimitry Andric 
3600b57cec5SDimitry Andric   unsigned getJumpTableEntrySize(int Idx) const {
361e8d8bef9SDimitry Andric     return JumpTableEntryInfo[Idx].first;
3620b57cec5SDimitry Andric   }
3630b57cec5SDimitry Andric   MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
364e8d8bef9SDimitry Andric     return JumpTableEntryInfo[Idx].second;
3650b57cec5SDimitry Andric   }
3660b57cec5SDimitry Andric   void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
367e8d8bef9SDimitry Andric     if ((unsigned)Idx >= JumpTableEntryInfo.size())
368e8d8bef9SDimitry Andric       JumpTableEntryInfo.resize(Idx+1);
3690b57cec5SDimitry Andric     JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
3700b57cec5SDimitry Andric   }
3710b57cec5SDimitry Andric 
3720b57cec5SDimitry Andric   using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
3730b57cec5SDimitry Andric 
3740b57cec5SDimitry Andric   const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
3750b57cec5SDimitry Andric 
3760b57cec5SDimitry Andric   // Shortcuts for LOH related types.
3770b57cec5SDimitry Andric   class MILOHDirective {
3780b57cec5SDimitry Andric     MCLOHType Kind;
3790b57cec5SDimitry Andric 
3800b57cec5SDimitry Andric     /// Arguments of this directive. Order matters.
3810b57cec5SDimitry Andric     SmallVector<const MachineInstr *, 3> Args;
3820b57cec5SDimitry Andric 
3830b57cec5SDimitry Andric   public:
3840b57cec5SDimitry Andric     using LOHArgs = ArrayRef<const MachineInstr *>;
3850b57cec5SDimitry Andric 
3860b57cec5SDimitry Andric     MILOHDirective(MCLOHType Kind, LOHArgs Args)
3870b57cec5SDimitry Andric         : Kind(Kind), Args(Args.begin(), Args.end()) {
3880b57cec5SDimitry Andric       assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
3890b57cec5SDimitry Andric     }
3900b57cec5SDimitry Andric 
3910b57cec5SDimitry Andric     MCLOHType getKind() const { return Kind; }
3920b57cec5SDimitry Andric     LOHArgs getArgs() const { return Args; }
3930b57cec5SDimitry Andric   };
3940b57cec5SDimitry Andric 
3950b57cec5SDimitry Andric   using MILOHArgs = MILOHDirective::LOHArgs;
3960b57cec5SDimitry Andric   using MILOHContainer = SmallVector<MILOHDirective, 32>;
3970b57cec5SDimitry Andric 
3980b57cec5SDimitry Andric   const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
3990b57cec5SDimitry Andric 
4000b57cec5SDimitry Andric   /// Add a LOH directive of this @p Kind and this @p Args.
4010b57cec5SDimitry Andric   void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
4020b57cec5SDimitry Andric     LOHContainerSet.push_back(MILOHDirective(Kind, Args));
4030b57cec5SDimitry Andric     LOHRelated.insert(Args.begin(), Args.end());
4040b57cec5SDimitry Andric   }
4050b57cec5SDimitry Andric 
4060b57cec5SDimitry Andric   SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
4070b57cec5SDimitry Andric     return ForwardedMustTailRegParms;
4080b57cec5SDimitry Andric   }
4090b57cec5SDimitry Andric 
410*bdd1243dSDimitry Andric   std::optional<int> getTaggedBasePointerIndex() const {
411e8d8bef9SDimitry Andric     return TaggedBasePointerIndex;
412e8d8bef9SDimitry Andric   }
413e8d8bef9SDimitry Andric   void setTaggedBasePointerIndex(int Index) { TaggedBasePointerIndex = Index; }
414e8d8bef9SDimitry Andric 
4150b57cec5SDimitry Andric   unsigned getTaggedBasePointerOffset() const {
4160b57cec5SDimitry Andric     return TaggedBasePointerOffset;
4170b57cec5SDimitry Andric   }
4180b57cec5SDimitry Andric   void setTaggedBasePointerOffset(unsigned Offset) {
4190b57cec5SDimitry Andric     TaggedBasePointerOffset = Offset;
4200b57cec5SDimitry Andric   }
4210b57cec5SDimitry Andric 
422e8d8bef9SDimitry Andric   int getCalleeSaveBaseToFrameRecordOffset() const {
423e8d8bef9SDimitry Andric     return CalleeSaveBaseToFrameRecordOffset;
424e8d8bef9SDimitry Andric   }
425e8d8bef9SDimitry Andric   void setCalleeSaveBaseToFrameRecordOffset(int Offset) {
426e8d8bef9SDimitry Andric     CalleeSaveBaseToFrameRecordOffset = Offset;
427e8d8bef9SDimitry Andric   }
428e8d8bef9SDimitry Andric 
429*bdd1243dSDimitry Andric   bool shouldSignReturnAddress(const MachineFunction &MF) const;
430e8d8bef9SDimitry Andric   bool shouldSignReturnAddress(bool SpillsLR) const;
431e8d8bef9SDimitry Andric 
432e8d8bef9SDimitry Andric   bool shouldSignWithBKey() const { return SignWithBKey; }
43381ad6265SDimitry Andric   bool isMTETagged() const { return IsMTETagged; }
434e8d8bef9SDimitry Andric 
435e8d8bef9SDimitry Andric   bool branchTargetEnforcement() const { return BranchTargetEnforcement; }
436e8d8bef9SDimitry Andric 
437fe6060f1SDimitry Andric   void setHasSwiftAsyncContext(bool HasContext) {
438fe6060f1SDimitry Andric     HasSwiftAsyncContext = HasContext;
439fe6060f1SDimitry Andric   }
440fe6060f1SDimitry Andric   bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; }
441fe6060f1SDimitry Andric 
442fe6060f1SDimitry Andric   void setSwiftAsyncContextFrameIdx(int FI) {
443fe6060f1SDimitry Andric     SwiftAsyncContextFrameIdx = FI;
444fe6060f1SDimitry Andric   }
445fe6060f1SDimitry Andric   int getSwiftAsyncContextFrameIdx() const { return SwiftAsyncContextFrameIdx; }
446fe6060f1SDimitry Andric 
447*bdd1243dSDimitry Andric   bool needsDwarfUnwindInfo(const MachineFunction &MF) const;
448*bdd1243dSDimitry Andric   bool needsAsyncDwarfUnwindInfo(const MachineFunction &MF) const;
44981ad6265SDimitry Andric 
4500b57cec5SDimitry Andric private:
4510b57cec5SDimitry Andric   // Hold the lists of LOHs.
4520b57cec5SDimitry Andric   MILOHContainer LOHContainerSet;
4530b57cec5SDimitry Andric   SetOfInstructions LOHRelated;
4540b57cec5SDimitry Andric 
455e8d8bef9SDimitry Andric   SmallVector<std::pair<unsigned, MCSymbol *>, 2> JumpTableEntryInfo;
4560b57cec5SDimitry Andric };
4570b57cec5SDimitry Andric 
4585ffd83dbSDimitry Andric namespace yaml {
4595ffd83dbSDimitry Andric struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo {
460*bdd1243dSDimitry Andric   std::optional<bool> HasRedZone;
4615ffd83dbSDimitry Andric 
4625ffd83dbSDimitry Andric   AArch64FunctionInfo() = default;
4635ffd83dbSDimitry Andric   AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI);
4645ffd83dbSDimitry Andric 
4655ffd83dbSDimitry Andric   void mappingImpl(yaml::IO &YamlIO) override;
4665ffd83dbSDimitry Andric   ~AArch64FunctionInfo() = default;
4675ffd83dbSDimitry Andric };
4685ffd83dbSDimitry Andric 
4695ffd83dbSDimitry Andric template <> struct MappingTraits<AArch64FunctionInfo> {
4705ffd83dbSDimitry Andric   static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) {
4715ffd83dbSDimitry Andric     YamlIO.mapOptional("hasRedZone", MFI.HasRedZone);
4725ffd83dbSDimitry Andric   }
4735ffd83dbSDimitry Andric };
4745ffd83dbSDimitry Andric 
4755ffd83dbSDimitry Andric } // end namespace yaml
4765ffd83dbSDimitry Andric 
4770b57cec5SDimitry Andric } // end namespace llvm
4780b57cec5SDimitry Andric 
4790b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
480