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/Optional.h" 180b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h" 190b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h" 200b57cec5SDimitry Andric #include "llvm/CodeGen/CallingConvLower.h" 215ffd83dbSDimitry Andric #include "llvm/CodeGen/MIRYamlMapping.h" 22*81ad6265SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h" 230b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 248bcb0991SDimitry Andric #include "llvm/IR/Function.h" 250b57cec5SDimitry Andric #include "llvm/MC/MCLinkerOptimizationHint.h" 260b57cec5SDimitry Andric #include <cassert> 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric namespace llvm { 290b57cec5SDimitry Andric 305ffd83dbSDimitry Andric namespace yaml { 315ffd83dbSDimitry Andric struct AArch64FunctionInfo; 325ffd83dbSDimitry Andric } // end namespace yaml 335ffd83dbSDimitry Andric 340b57cec5SDimitry Andric class MachineInstr; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and 370b57cec5SDimitry Andric /// contains private AArch64-specific information for each MachineFunction. 380b57cec5SDimitry Andric class AArch64FunctionInfo final : public MachineFunctionInfo { 39e8d8bef9SDimitry Andric /// Backreference to the machine function. 40*81ad6265SDimitry Andric MachineFunction *MF; 41e8d8bef9SDimitry Andric 420b57cec5SDimitry Andric /// Number of bytes of arguments this function has on the stack. If the callee 430b57cec5SDimitry Andric /// is expected to restore the argument stack this should be a multiple of 16, 440b57cec5SDimitry Andric /// all usable during a tail call. 450b57cec5SDimitry Andric /// 460b57cec5SDimitry Andric /// The alternative would forbid tail call optimisation in some cases: if we 470b57cec5SDimitry Andric /// want to transfer control from a function with 8-bytes of stack-argument 480b57cec5SDimitry Andric /// space to a function with 16-bytes then misalignment of this value would 490b57cec5SDimitry Andric /// make a stack adjustment necessary, which could not be undone by the 500b57cec5SDimitry Andric /// callee. 510b57cec5SDimitry Andric unsigned BytesInStackArgArea = 0; 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric /// The number of bytes to restore to deallocate space for incoming 540b57cec5SDimitry Andric /// arguments. Canonically 0 in the C calling convention, but non-zero when 550b57cec5SDimitry Andric /// callee is expected to pop the args. 560b57cec5SDimitry Andric unsigned ArgumentStackToRestore = 0; 570b57cec5SDimitry Andric 58fe6060f1SDimitry Andric /// Space just below incoming stack pointer reserved for arguments being 59fe6060f1SDimitry Andric /// passed on the stack during a tail call. This will be the difference 60fe6060f1SDimitry Andric /// between the largest tail call argument space needed in this function and 61fe6060f1SDimitry Andric /// what's already available by reusing space of incoming arguments. 62fe6060f1SDimitry Andric unsigned TailCallReservedStack = 0; 63fe6060f1SDimitry Andric 640b57cec5SDimitry Andric /// HasStackFrame - True if this function has a stack frame. Set by 650b57cec5SDimitry Andric /// determineCalleeSaves(). 660b57cec5SDimitry Andric bool HasStackFrame = false; 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric /// Amount of stack frame size, not including callee-saved registers. 69480093f4SDimitry Andric uint64_t LocalStackSize = 0; 70480093f4SDimitry Andric 71480093f4SDimitry Andric /// The start and end frame indices for the SVE callee saves. 72480093f4SDimitry Andric int MinSVECSFrameIndex = 0; 73480093f4SDimitry Andric int MaxSVECSFrameIndex = 0; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric /// Amount of stack frame size used for saving callee-saved registers. 76480093f4SDimitry Andric unsigned CalleeSavedStackSize = 0; 77480093f4SDimitry Andric unsigned SVECalleeSavedStackSize = 0; 78480093f4SDimitry Andric bool HasCalleeSavedStackSize = false; 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric /// Number of TLS accesses using the special (combinable) 810b57cec5SDimitry Andric /// _TLS_MODULE_BASE_ symbol. 820b57cec5SDimitry Andric unsigned NumLocalDynamicTLSAccesses = 0; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric /// FrameIndex for start of varargs area for arguments passed on the 850b57cec5SDimitry Andric /// stack. 860b57cec5SDimitry Andric int VarArgsStackIndex = 0; 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric /// FrameIndex for start of varargs area for arguments passed in 890b57cec5SDimitry Andric /// general purpose registers. 900b57cec5SDimitry Andric int VarArgsGPRIndex = 0; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric /// Size of the varargs area for arguments passed in general purpose 930b57cec5SDimitry Andric /// registers. 940b57cec5SDimitry Andric unsigned VarArgsGPRSize = 0; 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric /// FrameIndex for start of varargs area for arguments passed in 970b57cec5SDimitry Andric /// floating-point registers. 980b57cec5SDimitry Andric int VarArgsFPRIndex = 0; 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric /// Size of the varargs area for arguments passed in floating-point 1010b57cec5SDimitry Andric /// registers. 1020b57cec5SDimitry Andric unsigned VarArgsFPRSize = 0; 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric /// True if this function has a subset of CSRs that is handled explicitly via 1050b57cec5SDimitry Andric /// copies. 1060b57cec5SDimitry Andric bool IsSplitCSR = false; 1070b57cec5SDimitry Andric 1080b57cec5SDimitry Andric /// True when the stack gets realigned dynamically because the size of stack 1090b57cec5SDimitry Andric /// frame is unknown at compile time. e.g., in case of VLAs. 1100b57cec5SDimitry Andric bool StackRealigned = false; 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric /// True when the callee-save stack area has unused gaps that may be used for 1130b57cec5SDimitry Andric /// other stack allocations. 1140b57cec5SDimitry Andric bool CalleeSaveStackHasFreeSpace = false; 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric /// SRetReturnReg - sret lowering includes returning the value of the 1170b57cec5SDimitry Andric /// returned struct in a register. This field holds the virtual register into 1180b57cec5SDimitry Andric /// which the sret argument is passed. 119*81ad6265SDimitry Andric Register SRetReturnReg; 120*81ad6265SDimitry Andric 1218bcb0991SDimitry Andric /// SVE stack size (for predicates and data vectors) are maintained here 1228bcb0991SDimitry Andric /// rather than in FrameInfo, as the placement and Stack IDs are target 1238bcb0991SDimitry Andric /// specific. 1248bcb0991SDimitry Andric uint64_t StackSizeSVE = 0; 1258bcb0991SDimitry Andric 1268bcb0991SDimitry Andric /// HasCalculatedStackSizeSVE indicates whether StackSizeSVE is valid. 1278bcb0991SDimitry Andric bool HasCalculatedStackSizeSVE = false; 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric /// Has a value when it is known whether or not the function uses a 1300b57cec5SDimitry Andric /// redzone, and no value otherwise. 1310b57cec5SDimitry Andric /// Initialized during frame lowering, unless the function has the noredzone 1320b57cec5SDimitry Andric /// attribute, in which case it is set to false at construction. 1330b57cec5SDimitry Andric Optional<bool> HasRedZone; 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andric /// ForwardedMustTailRegParms - A list of virtual and physical registers 1360b57cec5SDimitry Andric /// that must be forwarded to every musttail call. 1370b57cec5SDimitry Andric SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms; 1380b57cec5SDimitry Andric 139e8d8bef9SDimitry Andric /// FrameIndex for the tagged base pointer. 140e8d8bef9SDimitry Andric Optional<int> TaggedBasePointerIndex; 141e8d8bef9SDimitry Andric 142e8d8bef9SDimitry Andric /// Offset from SP-at-entry to the tagged base pointer. 143e8d8bef9SDimitry Andric /// Tagged base pointer is set up to point to the first (lowest address) 144e8d8bef9SDimitry Andric /// tagged stack slot. 145e8d8bef9SDimitry Andric unsigned TaggedBasePointerOffset; 1460b57cec5SDimitry Andric 1475ffd83dbSDimitry Andric /// OutliningStyle denotes, if a function was outined, how it was outlined, 1485ffd83dbSDimitry Andric /// e.g. Tail Call, Thunk, or Function if none apply. 1495ffd83dbSDimitry Andric Optional<std::string> OutliningStyle; 1505ffd83dbSDimitry Andric 151e8d8bef9SDimitry Andric // Offset from SP-after-callee-saved-spills (i.e. SP-at-entry minus 152e8d8bef9SDimitry Andric // CalleeSavedStackSize) to the address of the frame record. 153e8d8bef9SDimitry Andric int CalleeSaveBaseToFrameRecordOffset = 0; 154e8d8bef9SDimitry Andric 155e8d8bef9SDimitry Andric /// SignReturnAddress is true if PAC-RET is enabled for the function with 156e8d8bef9SDimitry Andric /// defaults being sign non-leaf functions only, with the B key. 157e8d8bef9SDimitry Andric bool SignReturnAddress = false; 158e8d8bef9SDimitry Andric 159e8d8bef9SDimitry Andric /// SignReturnAddressAll modifies the default PAC-RET mode to signing leaf 160e8d8bef9SDimitry Andric /// functions as well. 161e8d8bef9SDimitry Andric bool SignReturnAddressAll = false; 162e8d8bef9SDimitry Andric 163e8d8bef9SDimitry Andric /// SignWithBKey modifies the default PAC-RET mode to signing with the B key. 164e8d8bef9SDimitry Andric bool SignWithBKey = false; 165e8d8bef9SDimitry Andric 166e8d8bef9SDimitry Andric /// BranchTargetEnforcement enables placing BTI instructions at potential 167e8d8bef9SDimitry Andric /// indirect branch destinations. 168e8d8bef9SDimitry Andric bool BranchTargetEnforcement = false; 169e8d8bef9SDimitry Andric 170fe6060f1SDimitry Andric /// Whether this function has an extended frame record [Ctx, FP, LR]. If so, 171fe6060f1SDimitry Andric /// bit 60 of the in-memory FP will be 1 to enable other tools to detect the 172fe6060f1SDimitry Andric /// extended record. 173fe6060f1SDimitry Andric bool HasSwiftAsyncContext = false; 174fe6060f1SDimitry Andric 175fe6060f1SDimitry Andric /// The stack slot where the Swift asynchronous context is stored. 176fe6060f1SDimitry Andric int SwiftAsyncContextFrameIdx = std::numeric_limits<int>::max(); 177fe6060f1SDimitry Andric 178*81ad6265SDimitry Andric bool IsMTETagged = false; 179*81ad6265SDimitry Andric 180*81ad6265SDimitry Andric /// The function has Scalable Vector or Scalable Predicate register argument 181*81ad6265SDimitry Andric /// or return type 182*81ad6265SDimitry Andric bool IsSVECC = false; 183*81ad6265SDimitry Andric 184*81ad6265SDimitry Andric /// True if the function need unwind information. 185*81ad6265SDimitry Andric mutable Optional<bool> NeedsDwarfUnwindInfo; 186*81ad6265SDimitry Andric 187*81ad6265SDimitry Andric /// True if the function need asynchronous unwind information. 188*81ad6265SDimitry Andric mutable Optional<bool> NeedsAsyncDwarfUnwindInfo; 189*81ad6265SDimitry Andric 1900b57cec5SDimitry Andric public: 191e8d8bef9SDimitry Andric explicit AArch64FunctionInfo(MachineFunction &MF); 1920b57cec5SDimitry Andric 193*81ad6265SDimitry Andric MachineFunctionInfo * 194*81ad6265SDimitry Andric clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, 195*81ad6265SDimitry Andric const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) 196*81ad6265SDimitry Andric const override; 197*81ad6265SDimitry Andric 198*81ad6265SDimitry Andric bool isSVECC() const { return IsSVECC; }; 199*81ad6265SDimitry Andric void setIsSVECC(bool s) { IsSVECC = s; }; 200*81ad6265SDimitry Andric 2015ffd83dbSDimitry Andric void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; } 2040b57cec5SDimitry Andric void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; } 2050b57cec5SDimitry Andric 2060b57cec5SDimitry Andric unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; } 2070b57cec5SDimitry Andric void setArgumentStackToRestore(unsigned bytes) { 2080b57cec5SDimitry Andric ArgumentStackToRestore = bytes; 2090b57cec5SDimitry Andric } 2100b57cec5SDimitry Andric 211fe6060f1SDimitry Andric unsigned getTailCallReservedStack() const { return TailCallReservedStack; } 212fe6060f1SDimitry Andric void setTailCallReservedStack(unsigned bytes) { 213fe6060f1SDimitry Andric TailCallReservedStack = bytes; 214fe6060f1SDimitry Andric } 215fe6060f1SDimitry Andric 2168bcb0991SDimitry Andric bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; } 2178bcb0991SDimitry Andric 2188bcb0991SDimitry Andric void setStackSizeSVE(uint64_t S) { 2198bcb0991SDimitry Andric HasCalculatedStackSizeSVE = true; 2208bcb0991SDimitry Andric StackSizeSVE = S; 2218bcb0991SDimitry Andric } 2228bcb0991SDimitry Andric 2238bcb0991SDimitry Andric uint64_t getStackSizeSVE() const { return StackSizeSVE; } 2248bcb0991SDimitry Andric 2250b57cec5SDimitry Andric bool hasStackFrame() const { return HasStackFrame; } 2260b57cec5SDimitry Andric void setHasStackFrame(bool s) { HasStackFrame = s; } 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric bool isStackRealigned() const { return StackRealigned; } 2290b57cec5SDimitry Andric void setStackRealigned(bool s) { StackRealigned = s; } 2300b57cec5SDimitry Andric 2310b57cec5SDimitry Andric bool hasCalleeSaveStackFreeSpace() const { 2320b57cec5SDimitry Andric return CalleeSaveStackHasFreeSpace; 2330b57cec5SDimitry Andric } 2340b57cec5SDimitry Andric void setCalleeSaveStackHasFreeSpace(bool s) { 2350b57cec5SDimitry Andric CalleeSaveStackHasFreeSpace = s; 2360b57cec5SDimitry Andric } 2370b57cec5SDimitry Andric bool isSplitCSR() const { return IsSplitCSR; } 2380b57cec5SDimitry Andric void setIsSplitCSR(bool s) { IsSplitCSR = s; } 2390b57cec5SDimitry Andric 240480093f4SDimitry Andric void setLocalStackSize(uint64_t Size) { LocalStackSize = Size; } 241480093f4SDimitry Andric uint64_t getLocalStackSize() const { return LocalStackSize; } 2420b57cec5SDimitry Andric 2435ffd83dbSDimitry Andric void setOutliningStyle(std::string Style) { OutliningStyle = Style; } 2445ffd83dbSDimitry Andric Optional<std::string> getOutliningStyle() const { return OutliningStyle; } 2455ffd83dbSDimitry Andric 246480093f4SDimitry Andric void setCalleeSavedStackSize(unsigned Size) { 247480093f4SDimitry Andric CalleeSavedStackSize = Size; 248480093f4SDimitry Andric HasCalleeSavedStackSize = true; 249480093f4SDimitry Andric } 250480093f4SDimitry Andric 251480093f4SDimitry Andric // When CalleeSavedStackSize has not been set (for example when 252480093f4SDimitry Andric // some MachineIR pass is run in isolation), then recalculate 253480093f4SDimitry Andric // the CalleeSavedStackSize directly from the CalleeSavedInfo. 254480093f4SDimitry Andric // Note: This information can only be recalculated after PEI 255480093f4SDimitry Andric // has assigned offsets to the callee save objects. 256480093f4SDimitry Andric unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const { 257480093f4SDimitry Andric bool ValidateCalleeSavedStackSize = false; 258480093f4SDimitry Andric 259480093f4SDimitry Andric #ifndef NDEBUG 260480093f4SDimitry Andric // Make sure the calculated size derived from the CalleeSavedInfo 261480093f4SDimitry Andric // equals the cached size that was calculated elsewhere (e.g. in 262480093f4SDimitry Andric // determineCalleeSaves). 263480093f4SDimitry Andric ValidateCalleeSavedStackSize = HasCalleeSavedStackSize; 264480093f4SDimitry Andric #endif 265480093f4SDimitry Andric 266480093f4SDimitry Andric if (!HasCalleeSavedStackSize || ValidateCalleeSavedStackSize) { 267480093f4SDimitry Andric assert(MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated"); 268480093f4SDimitry Andric if (MFI.getCalleeSavedInfo().empty()) 269480093f4SDimitry Andric return 0; 270480093f4SDimitry Andric 271480093f4SDimitry Andric int64_t MinOffset = std::numeric_limits<int64_t>::max(); 272480093f4SDimitry Andric int64_t MaxOffset = std::numeric_limits<int64_t>::min(); 273480093f4SDimitry Andric for (const auto &Info : MFI.getCalleeSavedInfo()) { 274480093f4SDimitry Andric int FrameIdx = Info.getFrameIdx(); 275480093f4SDimitry Andric if (MFI.getStackID(FrameIdx) != TargetStackID::Default) 276480093f4SDimitry Andric continue; 277480093f4SDimitry Andric int64_t Offset = MFI.getObjectOffset(FrameIdx); 278480093f4SDimitry Andric int64_t ObjSize = MFI.getObjectSize(FrameIdx); 279480093f4SDimitry Andric MinOffset = std::min<int64_t>(Offset, MinOffset); 280480093f4SDimitry Andric MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset); 281480093f4SDimitry Andric } 282480093f4SDimitry Andric 283fe6060f1SDimitry Andric if (SwiftAsyncContextFrameIdx != std::numeric_limits<int>::max()) { 284fe6060f1SDimitry Andric int64_t Offset = MFI.getObjectOffset(getSwiftAsyncContextFrameIdx()); 285fe6060f1SDimitry Andric int64_t ObjSize = MFI.getObjectSize(getSwiftAsyncContextFrameIdx()); 286fe6060f1SDimitry Andric MinOffset = std::min<int64_t>(Offset, MinOffset); 287fe6060f1SDimitry Andric MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset); 288fe6060f1SDimitry Andric } 289fe6060f1SDimitry Andric 290480093f4SDimitry Andric unsigned Size = alignTo(MaxOffset - MinOffset, 16); 291480093f4SDimitry Andric assert((!HasCalleeSavedStackSize || getCalleeSavedStackSize() == Size) && 292480093f4SDimitry Andric "Invalid size calculated for callee saves"); 293480093f4SDimitry Andric return Size; 294480093f4SDimitry Andric } 295480093f4SDimitry Andric 296480093f4SDimitry Andric return getCalleeSavedStackSize(); 297480093f4SDimitry Andric } 298480093f4SDimitry Andric 299480093f4SDimitry Andric unsigned getCalleeSavedStackSize() const { 300480093f4SDimitry Andric assert(HasCalleeSavedStackSize && 301480093f4SDimitry Andric "CalleeSavedStackSize has not been calculated"); 302480093f4SDimitry Andric return CalleeSavedStackSize; 303480093f4SDimitry Andric } 304480093f4SDimitry Andric 305480093f4SDimitry Andric // Saves the CalleeSavedStackSize for SVE vectors in 'scalable bytes' 306480093f4SDimitry Andric void setSVECalleeSavedStackSize(unsigned Size) { 307480093f4SDimitry Andric SVECalleeSavedStackSize = Size; 308480093f4SDimitry Andric } 309480093f4SDimitry Andric unsigned getSVECalleeSavedStackSize() const { 310480093f4SDimitry Andric return SVECalleeSavedStackSize; 311480093f4SDimitry Andric } 312480093f4SDimitry Andric 313480093f4SDimitry Andric void setMinMaxSVECSFrameIndex(int Min, int Max) { 314480093f4SDimitry Andric MinSVECSFrameIndex = Min; 315480093f4SDimitry Andric MaxSVECSFrameIndex = Max; 316480093f4SDimitry Andric } 317480093f4SDimitry Andric 318480093f4SDimitry Andric int getMinSVECSFrameIndex() const { return MinSVECSFrameIndex; } 319480093f4SDimitry Andric int getMaxSVECSFrameIndex() const { return MaxSVECSFrameIndex; } 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andric void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; } 3220b57cec5SDimitry Andric unsigned getNumLocalDynamicTLSAccesses() const { 3230b57cec5SDimitry Andric return NumLocalDynamicTLSAccesses; 3240b57cec5SDimitry Andric } 3250b57cec5SDimitry Andric 3260b57cec5SDimitry Andric Optional<bool> hasRedZone() const { return HasRedZone; } 3270b57cec5SDimitry Andric void setHasRedZone(bool s) { HasRedZone = s; } 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andric int getVarArgsStackIndex() const { return VarArgsStackIndex; } 3300b57cec5SDimitry Andric void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; } 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andric int getVarArgsGPRIndex() const { return VarArgsGPRIndex; } 3330b57cec5SDimitry Andric void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; } 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; } 3360b57cec5SDimitry Andric void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; } 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric int getVarArgsFPRIndex() const { return VarArgsFPRIndex; } 3390b57cec5SDimitry Andric void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; } 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; } 3420b57cec5SDimitry Andric void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; } 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andric unsigned getSRetReturnReg() const { return SRetReturnReg; } 3450b57cec5SDimitry Andric void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andric unsigned getJumpTableEntrySize(int Idx) const { 348e8d8bef9SDimitry Andric return JumpTableEntryInfo[Idx].first; 3490b57cec5SDimitry Andric } 3500b57cec5SDimitry Andric MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const { 351e8d8bef9SDimitry Andric return JumpTableEntryInfo[Idx].second; 3520b57cec5SDimitry Andric } 3530b57cec5SDimitry Andric void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) { 354e8d8bef9SDimitry Andric if ((unsigned)Idx >= JumpTableEntryInfo.size()) 355e8d8bef9SDimitry Andric JumpTableEntryInfo.resize(Idx+1); 3560b57cec5SDimitry Andric JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym); 3570b57cec5SDimitry Andric } 3580b57cec5SDimitry Andric 3590b57cec5SDimitry Andric using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>; 3600b57cec5SDimitry Andric 3610b57cec5SDimitry Andric const SetOfInstructions &getLOHRelated() const { return LOHRelated; } 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric // Shortcuts for LOH related types. 3640b57cec5SDimitry Andric class MILOHDirective { 3650b57cec5SDimitry Andric MCLOHType Kind; 3660b57cec5SDimitry Andric 3670b57cec5SDimitry Andric /// Arguments of this directive. Order matters. 3680b57cec5SDimitry Andric SmallVector<const MachineInstr *, 3> Args; 3690b57cec5SDimitry Andric 3700b57cec5SDimitry Andric public: 3710b57cec5SDimitry Andric using LOHArgs = ArrayRef<const MachineInstr *>; 3720b57cec5SDimitry Andric 3730b57cec5SDimitry Andric MILOHDirective(MCLOHType Kind, LOHArgs Args) 3740b57cec5SDimitry Andric : Kind(Kind), Args(Args.begin(), Args.end()) { 3750b57cec5SDimitry Andric assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); 3760b57cec5SDimitry Andric } 3770b57cec5SDimitry Andric 3780b57cec5SDimitry Andric MCLOHType getKind() const { return Kind; } 3790b57cec5SDimitry Andric LOHArgs getArgs() const { return Args; } 3800b57cec5SDimitry Andric }; 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andric using MILOHArgs = MILOHDirective::LOHArgs; 3830b57cec5SDimitry Andric using MILOHContainer = SmallVector<MILOHDirective, 32>; 3840b57cec5SDimitry Andric 3850b57cec5SDimitry Andric const MILOHContainer &getLOHContainer() const { return LOHContainerSet; } 3860b57cec5SDimitry Andric 3870b57cec5SDimitry Andric /// Add a LOH directive of this @p Kind and this @p Args. 3880b57cec5SDimitry Andric void addLOHDirective(MCLOHType Kind, MILOHArgs Args) { 3890b57cec5SDimitry Andric LOHContainerSet.push_back(MILOHDirective(Kind, Args)); 3900b57cec5SDimitry Andric LOHRelated.insert(Args.begin(), Args.end()); 3910b57cec5SDimitry Andric } 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() { 3940b57cec5SDimitry Andric return ForwardedMustTailRegParms; 3950b57cec5SDimitry Andric } 3960b57cec5SDimitry Andric 397e8d8bef9SDimitry Andric Optional<int> getTaggedBasePointerIndex() const { 398e8d8bef9SDimitry Andric return TaggedBasePointerIndex; 399e8d8bef9SDimitry Andric } 400e8d8bef9SDimitry Andric void setTaggedBasePointerIndex(int Index) { TaggedBasePointerIndex = Index; } 401e8d8bef9SDimitry Andric 4020b57cec5SDimitry Andric unsigned getTaggedBasePointerOffset() const { 4030b57cec5SDimitry Andric return TaggedBasePointerOffset; 4040b57cec5SDimitry Andric } 4050b57cec5SDimitry Andric void setTaggedBasePointerOffset(unsigned Offset) { 4060b57cec5SDimitry Andric TaggedBasePointerOffset = Offset; 4070b57cec5SDimitry Andric } 4080b57cec5SDimitry Andric 409e8d8bef9SDimitry Andric int getCalleeSaveBaseToFrameRecordOffset() const { 410e8d8bef9SDimitry Andric return CalleeSaveBaseToFrameRecordOffset; 411e8d8bef9SDimitry Andric } 412e8d8bef9SDimitry Andric void setCalleeSaveBaseToFrameRecordOffset(int Offset) { 413e8d8bef9SDimitry Andric CalleeSaveBaseToFrameRecordOffset = Offset; 414e8d8bef9SDimitry Andric } 415e8d8bef9SDimitry Andric 416e8d8bef9SDimitry Andric bool shouldSignReturnAddress() const; 417e8d8bef9SDimitry Andric bool shouldSignReturnAddress(bool SpillsLR) const; 418e8d8bef9SDimitry Andric 419e8d8bef9SDimitry Andric bool shouldSignWithBKey() const { return SignWithBKey; } 420*81ad6265SDimitry Andric bool isMTETagged() const { return IsMTETagged; } 421e8d8bef9SDimitry Andric 422e8d8bef9SDimitry Andric bool branchTargetEnforcement() const { return BranchTargetEnforcement; } 423e8d8bef9SDimitry Andric 424fe6060f1SDimitry Andric void setHasSwiftAsyncContext(bool HasContext) { 425fe6060f1SDimitry Andric HasSwiftAsyncContext = HasContext; 426fe6060f1SDimitry Andric } 427fe6060f1SDimitry Andric bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; } 428fe6060f1SDimitry Andric 429fe6060f1SDimitry Andric void setSwiftAsyncContextFrameIdx(int FI) { 430fe6060f1SDimitry Andric SwiftAsyncContextFrameIdx = FI; 431fe6060f1SDimitry Andric } 432fe6060f1SDimitry Andric int getSwiftAsyncContextFrameIdx() const { return SwiftAsyncContextFrameIdx; } 433fe6060f1SDimitry Andric 434*81ad6265SDimitry Andric bool needsDwarfUnwindInfo() const; 435*81ad6265SDimitry Andric bool needsAsyncDwarfUnwindInfo() const; 436*81ad6265SDimitry Andric 4370b57cec5SDimitry Andric private: 4380b57cec5SDimitry Andric // Hold the lists of LOHs. 4390b57cec5SDimitry Andric MILOHContainer LOHContainerSet; 4400b57cec5SDimitry Andric SetOfInstructions LOHRelated; 4410b57cec5SDimitry Andric 442e8d8bef9SDimitry Andric SmallVector<std::pair<unsigned, MCSymbol *>, 2> JumpTableEntryInfo; 4430b57cec5SDimitry Andric }; 4440b57cec5SDimitry Andric 4455ffd83dbSDimitry Andric namespace yaml { 4465ffd83dbSDimitry Andric struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo { 4475ffd83dbSDimitry Andric Optional<bool> HasRedZone; 4485ffd83dbSDimitry Andric 4495ffd83dbSDimitry Andric AArch64FunctionInfo() = default; 4505ffd83dbSDimitry Andric AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI); 4515ffd83dbSDimitry Andric 4525ffd83dbSDimitry Andric void mappingImpl(yaml::IO &YamlIO) override; 4535ffd83dbSDimitry Andric ~AArch64FunctionInfo() = default; 4545ffd83dbSDimitry Andric }; 4555ffd83dbSDimitry Andric 4565ffd83dbSDimitry Andric template <> struct MappingTraits<AArch64FunctionInfo> { 4575ffd83dbSDimitry Andric static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) { 4585ffd83dbSDimitry Andric YamlIO.mapOptional("hasRedZone", MFI.HasRedZone); 4595ffd83dbSDimitry Andric } 4605ffd83dbSDimitry Andric }; 4615ffd83dbSDimitry Andric 4625ffd83dbSDimitry Andric } // end namespace yaml 4635ffd83dbSDimitry Andric 4640b57cec5SDimitry Andric } // end namespace llvm 4650b57cec5SDimitry Andric 4660b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H 467