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" 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> 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric namespace llvm { 280b57cec5SDimitry Andric 295ffd83dbSDimitry Andric namespace yaml { 305ffd83dbSDimitry Andric struct AArch64FunctionInfo; 315ffd83dbSDimitry Andric } // end namespace yaml 325ffd83dbSDimitry Andric 330b57cec5SDimitry Andric class MachineInstr; 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and 360b57cec5SDimitry Andric /// contains private AArch64-specific information for each MachineFunction. 370b57cec5SDimitry Andric class AArch64FunctionInfo final : public MachineFunctionInfo { 38e8d8bef9SDimitry Andric /// Backreference to the machine function. 39e8d8bef9SDimitry Andric MachineFunction &MF; 40e8d8bef9SDimitry Andric 410b57cec5SDimitry Andric /// Number of bytes of arguments this function has on the stack. If the callee 420b57cec5SDimitry Andric /// is expected to restore the argument stack this should be a multiple of 16, 430b57cec5SDimitry Andric /// all usable during a tail call. 440b57cec5SDimitry Andric /// 450b57cec5SDimitry Andric /// The alternative would forbid tail call optimisation in some cases: if we 460b57cec5SDimitry Andric /// want to transfer control from a function with 8-bytes of stack-argument 470b57cec5SDimitry Andric /// space to a function with 16-bytes then misalignment of this value would 480b57cec5SDimitry Andric /// make a stack adjustment necessary, which could not be undone by the 490b57cec5SDimitry Andric /// callee. 500b57cec5SDimitry Andric unsigned BytesInStackArgArea = 0; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric /// The number of bytes to restore to deallocate space for incoming 530b57cec5SDimitry Andric /// arguments. Canonically 0 in the C calling convention, but non-zero when 540b57cec5SDimitry Andric /// callee is expected to pop the args. 550b57cec5SDimitry Andric unsigned ArgumentStackToRestore = 0; 560b57cec5SDimitry Andric 57*fe6060f1SDimitry Andric /// Space just below incoming stack pointer reserved for arguments being 58*fe6060f1SDimitry Andric /// passed on the stack during a tail call. This will be the difference 59*fe6060f1SDimitry Andric /// between the largest tail call argument space needed in this function and 60*fe6060f1SDimitry Andric /// what's already available by reusing space of incoming arguments. 61*fe6060f1SDimitry Andric unsigned TailCallReservedStack = 0; 62*fe6060f1SDimitry Andric 630b57cec5SDimitry Andric /// HasStackFrame - True if this function has a stack frame. Set by 640b57cec5SDimitry Andric /// determineCalleeSaves(). 650b57cec5SDimitry Andric bool HasStackFrame = false; 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric /// Amount of stack frame size, not including callee-saved registers. 68480093f4SDimitry Andric uint64_t LocalStackSize = 0; 69480093f4SDimitry Andric 70480093f4SDimitry Andric /// The start and end frame indices for the SVE callee saves. 71480093f4SDimitry Andric int MinSVECSFrameIndex = 0; 72480093f4SDimitry Andric int MaxSVECSFrameIndex = 0; 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric /// Amount of stack frame size used for saving callee-saved registers. 75480093f4SDimitry Andric unsigned CalleeSavedStackSize = 0; 76480093f4SDimitry Andric unsigned SVECalleeSavedStackSize = 0; 77480093f4SDimitry Andric bool HasCalleeSavedStackSize = false; 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric /// Number of TLS accesses using the special (combinable) 800b57cec5SDimitry Andric /// _TLS_MODULE_BASE_ symbol. 810b57cec5SDimitry Andric unsigned NumLocalDynamicTLSAccesses = 0; 820b57cec5SDimitry Andric 830b57cec5SDimitry Andric /// FrameIndex for start of varargs area for arguments passed on the 840b57cec5SDimitry Andric /// stack. 850b57cec5SDimitry Andric int VarArgsStackIndex = 0; 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric /// FrameIndex for start of varargs area for arguments passed in 880b57cec5SDimitry Andric /// general purpose registers. 890b57cec5SDimitry Andric int VarArgsGPRIndex = 0; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric /// Size of the varargs area for arguments passed in general purpose 920b57cec5SDimitry Andric /// registers. 930b57cec5SDimitry Andric unsigned VarArgsGPRSize = 0; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric /// FrameIndex for start of varargs area for arguments passed in 960b57cec5SDimitry Andric /// floating-point registers. 970b57cec5SDimitry Andric int VarArgsFPRIndex = 0; 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric /// Size of the varargs area for arguments passed in floating-point 1000b57cec5SDimitry Andric /// registers. 1010b57cec5SDimitry Andric unsigned VarArgsFPRSize = 0; 1020b57cec5SDimitry Andric 1030b57cec5SDimitry Andric /// True if this function has a subset of CSRs that is handled explicitly via 1040b57cec5SDimitry Andric /// copies. 1050b57cec5SDimitry Andric bool IsSplitCSR = false; 1060b57cec5SDimitry Andric 1070b57cec5SDimitry Andric /// True when the stack gets realigned dynamically because the size of stack 1080b57cec5SDimitry Andric /// frame is unknown at compile time. e.g., in case of VLAs. 1090b57cec5SDimitry Andric bool StackRealigned = false; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric /// True when the callee-save stack area has unused gaps that may be used for 1120b57cec5SDimitry Andric /// other stack allocations. 1130b57cec5SDimitry Andric bool CalleeSaveStackHasFreeSpace = false; 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric /// SRetReturnReg - sret lowering includes returning the value of the 1160b57cec5SDimitry Andric /// returned struct in a register. This field holds the virtual register into 1170b57cec5SDimitry Andric /// which the sret argument is passed. 1180b57cec5SDimitry Andric unsigned SRetReturnReg = 0; 1198bcb0991SDimitry Andric /// SVE stack size (for predicates and data vectors) are maintained here 1208bcb0991SDimitry Andric /// rather than in FrameInfo, as the placement and Stack IDs are target 1218bcb0991SDimitry Andric /// specific. 1228bcb0991SDimitry Andric uint64_t StackSizeSVE = 0; 1238bcb0991SDimitry Andric 1248bcb0991SDimitry Andric /// HasCalculatedStackSizeSVE indicates whether StackSizeSVE is valid. 1258bcb0991SDimitry Andric bool HasCalculatedStackSizeSVE = false; 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andric /// Has a value when it is known whether or not the function uses a 1280b57cec5SDimitry Andric /// redzone, and no value otherwise. 1290b57cec5SDimitry Andric /// Initialized during frame lowering, unless the function has the noredzone 1300b57cec5SDimitry Andric /// attribute, in which case it is set to false at construction. 1310b57cec5SDimitry Andric Optional<bool> HasRedZone; 1320b57cec5SDimitry Andric 1330b57cec5SDimitry Andric /// ForwardedMustTailRegParms - A list of virtual and physical registers 1340b57cec5SDimitry Andric /// that must be forwarded to every musttail call. 1350b57cec5SDimitry Andric SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms; 1360b57cec5SDimitry Andric 137e8d8bef9SDimitry Andric /// FrameIndex for the tagged base pointer. 138e8d8bef9SDimitry Andric Optional<int> TaggedBasePointerIndex; 139e8d8bef9SDimitry Andric 140e8d8bef9SDimitry Andric /// Offset from SP-at-entry to the tagged base pointer. 141e8d8bef9SDimitry Andric /// Tagged base pointer is set up to point to the first (lowest address) 142e8d8bef9SDimitry Andric /// tagged stack slot. 143e8d8bef9SDimitry Andric unsigned TaggedBasePointerOffset; 1440b57cec5SDimitry Andric 1455ffd83dbSDimitry Andric /// OutliningStyle denotes, if a function was outined, how it was outlined, 1465ffd83dbSDimitry Andric /// e.g. Tail Call, Thunk, or Function if none apply. 1475ffd83dbSDimitry Andric Optional<std::string> OutliningStyle; 1485ffd83dbSDimitry Andric 149e8d8bef9SDimitry Andric // Offset from SP-after-callee-saved-spills (i.e. SP-at-entry minus 150e8d8bef9SDimitry Andric // CalleeSavedStackSize) to the address of the frame record. 151e8d8bef9SDimitry Andric int CalleeSaveBaseToFrameRecordOffset = 0; 152e8d8bef9SDimitry Andric 153e8d8bef9SDimitry Andric /// SignReturnAddress is true if PAC-RET is enabled for the function with 154e8d8bef9SDimitry Andric /// defaults being sign non-leaf functions only, with the B key. 155e8d8bef9SDimitry Andric bool SignReturnAddress = false; 156e8d8bef9SDimitry Andric 157e8d8bef9SDimitry Andric /// SignReturnAddressAll modifies the default PAC-RET mode to signing leaf 158e8d8bef9SDimitry Andric /// functions as well. 159e8d8bef9SDimitry Andric bool SignReturnAddressAll = false; 160e8d8bef9SDimitry Andric 161e8d8bef9SDimitry Andric /// SignWithBKey modifies the default PAC-RET mode to signing with the B key. 162e8d8bef9SDimitry Andric bool SignWithBKey = false; 163e8d8bef9SDimitry Andric 164e8d8bef9SDimitry Andric /// BranchTargetEnforcement enables placing BTI instructions at potential 165e8d8bef9SDimitry Andric /// indirect branch destinations. 166e8d8bef9SDimitry Andric bool BranchTargetEnforcement = false; 167e8d8bef9SDimitry Andric 168*fe6060f1SDimitry Andric /// Whether this function has an extended frame record [Ctx, FP, LR]. If so, 169*fe6060f1SDimitry Andric /// bit 60 of the in-memory FP will be 1 to enable other tools to detect the 170*fe6060f1SDimitry Andric /// extended record. 171*fe6060f1SDimitry Andric bool HasSwiftAsyncContext = false; 172*fe6060f1SDimitry Andric 173*fe6060f1SDimitry Andric /// The stack slot where the Swift asynchronous context is stored. 174*fe6060f1SDimitry Andric int SwiftAsyncContextFrameIdx = std::numeric_limits<int>::max(); 175*fe6060f1SDimitry Andric 1760b57cec5SDimitry Andric public: 177e8d8bef9SDimitry Andric explicit AArch64FunctionInfo(MachineFunction &MF); 1780b57cec5SDimitry Andric 1795ffd83dbSDimitry Andric void initializeBaseYamlFields(const yaml::AArch64FunctionInfo &YamlMFI); 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; } 1820b57cec5SDimitry Andric void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; } 1830b57cec5SDimitry Andric 1840b57cec5SDimitry Andric unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; } 1850b57cec5SDimitry Andric void setArgumentStackToRestore(unsigned bytes) { 1860b57cec5SDimitry Andric ArgumentStackToRestore = bytes; 1870b57cec5SDimitry Andric } 1880b57cec5SDimitry Andric 189*fe6060f1SDimitry Andric unsigned getTailCallReservedStack() const { return TailCallReservedStack; } 190*fe6060f1SDimitry Andric void setTailCallReservedStack(unsigned bytes) { 191*fe6060f1SDimitry Andric TailCallReservedStack = bytes; 192*fe6060f1SDimitry Andric } 193*fe6060f1SDimitry Andric 1948bcb0991SDimitry Andric bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE; } 1958bcb0991SDimitry Andric 1968bcb0991SDimitry Andric void setStackSizeSVE(uint64_t S) { 1978bcb0991SDimitry Andric HasCalculatedStackSizeSVE = true; 1988bcb0991SDimitry Andric StackSizeSVE = S; 1998bcb0991SDimitry Andric } 2008bcb0991SDimitry Andric 2018bcb0991SDimitry Andric uint64_t getStackSizeSVE() const { return StackSizeSVE; } 2028bcb0991SDimitry Andric 2030b57cec5SDimitry Andric bool hasStackFrame() const { return HasStackFrame; } 2040b57cec5SDimitry Andric void setHasStackFrame(bool s) { HasStackFrame = s; } 2050b57cec5SDimitry Andric 2060b57cec5SDimitry Andric bool isStackRealigned() const { return StackRealigned; } 2070b57cec5SDimitry Andric void setStackRealigned(bool s) { StackRealigned = s; } 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric bool hasCalleeSaveStackFreeSpace() const { 2100b57cec5SDimitry Andric return CalleeSaveStackHasFreeSpace; 2110b57cec5SDimitry Andric } 2120b57cec5SDimitry Andric void setCalleeSaveStackHasFreeSpace(bool s) { 2130b57cec5SDimitry Andric CalleeSaveStackHasFreeSpace = s; 2140b57cec5SDimitry Andric } 2150b57cec5SDimitry Andric bool isSplitCSR() const { return IsSplitCSR; } 2160b57cec5SDimitry Andric void setIsSplitCSR(bool s) { IsSplitCSR = s; } 2170b57cec5SDimitry Andric 218480093f4SDimitry Andric void setLocalStackSize(uint64_t Size) { LocalStackSize = Size; } 219480093f4SDimitry Andric uint64_t getLocalStackSize() const { return LocalStackSize; } 2200b57cec5SDimitry Andric 2215ffd83dbSDimitry Andric void setOutliningStyle(std::string Style) { OutliningStyle = Style; } 2225ffd83dbSDimitry Andric Optional<std::string> getOutliningStyle() const { return OutliningStyle; } 2235ffd83dbSDimitry Andric 224480093f4SDimitry Andric void setCalleeSavedStackSize(unsigned Size) { 225480093f4SDimitry Andric CalleeSavedStackSize = Size; 226480093f4SDimitry Andric HasCalleeSavedStackSize = true; 227480093f4SDimitry Andric } 228480093f4SDimitry Andric 229480093f4SDimitry Andric // When CalleeSavedStackSize has not been set (for example when 230480093f4SDimitry Andric // some MachineIR pass is run in isolation), then recalculate 231480093f4SDimitry Andric // the CalleeSavedStackSize directly from the CalleeSavedInfo. 232480093f4SDimitry Andric // Note: This information can only be recalculated after PEI 233480093f4SDimitry Andric // has assigned offsets to the callee save objects. 234480093f4SDimitry Andric unsigned getCalleeSavedStackSize(const MachineFrameInfo &MFI) const { 235480093f4SDimitry Andric bool ValidateCalleeSavedStackSize = false; 236480093f4SDimitry Andric 237480093f4SDimitry Andric #ifndef NDEBUG 238480093f4SDimitry Andric // Make sure the calculated size derived from the CalleeSavedInfo 239480093f4SDimitry Andric // equals the cached size that was calculated elsewhere (e.g. in 240480093f4SDimitry Andric // determineCalleeSaves). 241480093f4SDimitry Andric ValidateCalleeSavedStackSize = HasCalleeSavedStackSize; 242480093f4SDimitry Andric #endif 243480093f4SDimitry Andric 244480093f4SDimitry Andric if (!HasCalleeSavedStackSize || ValidateCalleeSavedStackSize) { 245480093f4SDimitry Andric assert(MFI.isCalleeSavedInfoValid() && "CalleeSavedInfo not calculated"); 246480093f4SDimitry Andric if (MFI.getCalleeSavedInfo().empty()) 247480093f4SDimitry Andric return 0; 248480093f4SDimitry Andric 249480093f4SDimitry Andric int64_t MinOffset = std::numeric_limits<int64_t>::max(); 250480093f4SDimitry Andric int64_t MaxOffset = std::numeric_limits<int64_t>::min(); 251480093f4SDimitry Andric for (const auto &Info : MFI.getCalleeSavedInfo()) { 252480093f4SDimitry Andric int FrameIdx = Info.getFrameIdx(); 253480093f4SDimitry Andric if (MFI.getStackID(FrameIdx) != TargetStackID::Default) 254480093f4SDimitry Andric continue; 255480093f4SDimitry Andric int64_t Offset = MFI.getObjectOffset(FrameIdx); 256480093f4SDimitry Andric int64_t ObjSize = MFI.getObjectSize(FrameIdx); 257480093f4SDimitry Andric MinOffset = std::min<int64_t>(Offset, MinOffset); 258480093f4SDimitry Andric MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset); 259480093f4SDimitry Andric } 260480093f4SDimitry Andric 261*fe6060f1SDimitry Andric if (SwiftAsyncContextFrameIdx != std::numeric_limits<int>::max()) { 262*fe6060f1SDimitry Andric int64_t Offset = MFI.getObjectOffset(getSwiftAsyncContextFrameIdx()); 263*fe6060f1SDimitry Andric int64_t ObjSize = MFI.getObjectSize(getSwiftAsyncContextFrameIdx()); 264*fe6060f1SDimitry Andric MinOffset = std::min<int64_t>(Offset, MinOffset); 265*fe6060f1SDimitry Andric MaxOffset = std::max<int64_t>(Offset + ObjSize, MaxOffset); 266*fe6060f1SDimitry Andric } 267*fe6060f1SDimitry Andric 268480093f4SDimitry Andric unsigned Size = alignTo(MaxOffset - MinOffset, 16); 269480093f4SDimitry Andric assert((!HasCalleeSavedStackSize || getCalleeSavedStackSize() == Size) && 270480093f4SDimitry Andric "Invalid size calculated for callee saves"); 271480093f4SDimitry Andric return Size; 272480093f4SDimitry Andric } 273480093f4SDimitry Andric 274480093f4SDimitry Andric return getCalleeSavedStackSize(); 275480093f4SDimitry Andric } 276480093f4SDimitry Andric 277480093f4SDimitry Andric unsigned getCalleeSavedStackSize() const { 278480093f4SDimitry Andric assert(HasCalleeSavedStackSize && 279480093f4SDimitry Andric "CalleeSavedStackSize has not been calculated"); 280480093f4SDimitry Andric return CalleeSavedStackSize; 281480093f4SDimitry Andric } 282480093f4SDimitry Andric 283480093f4SDimitry Andric // Saves the CalleeSavedStackSize for SVE vectors in 'scalable bytes' 284480093f4SDimitry Andric void setSVECalleeSavedStackSize(unsigned Size) { 285480093f4SDimitry Andric SVECalleeSavedStackSize = Size; 286480093f4SDimitry Andric } 287480093f4SDimitry Andric unsigned getSVECalleeSavedStackSize() const { 288480093f4SDimitry Andric return SVECalleeSavedStackSize; 289480093f4SDimitry Andric } 290480093f4SDimitry Andric 291480093f4SDimitry Andric void setMinMaxSVECSFrameIndex(int Min, int Max) { 292480093f4SDimitry Andric MinSVECSFrameIndex = Min; 293480093f4SDimitry Andric MaxSVECSFrameIndex = Max; 294480093f4SDimitry Andric } 295480093f4SDimitry Andric 296480093f4SDimitry Andric int getMinSVECSFrameIndex() const { return MinSVECSFrameIndex; } 297480093f4SDimitry Andric int getMaxSVECSFrameIndex() const { return MaxSVECSFrameIndex; } 2980b57cec5SDimitry Andric 2990b57cec5SDimitry Andric void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; } 3000b57cec5SDimitry Andric unsigned getNumLocalDynamicTLSAccesses() const { 3010b57cec5SDimitry Andric return NumLocalDynamicTLSAccesses; 3020b57cec5SDimitry Andric } 3030b57cec5SDimitry Andric 3040b57cec5SDimitry Andric Optional<bool> hasRedZone() const { return HasRedZone; } 3050b57cec5SDimitry Andric void setHasRedZone(bool s) { HasRedZone = s; } 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andric int getVarArgsStackIndex() const { return VarArgsStackIndex; } 3080b57cec5SDimitry Andric void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; } 3090b57cec5SDimitry Andric 3100b57cec5SDimitry Andric int getVarArgsGPRIndex() const { return VarArgsGPRIndex; } 3110b57cec5SDimitry Andric void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; } 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andric unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; } 3140b57cec5SDimitry Andric void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; } 3150b57cec5SDimitry Andric 3160b57cec5SDimitry Andric int getVarArgsFPRIndex() const { return VarArgsFPRIndex; } 3170b57cec5SDimitry Andric void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; } 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; } 3200b57cec5SDimitry Andric void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; } 3210b57cec5SDimitry Andric 3220b57cec5SDimitry Andric unsigned getSRetReturnReg() const { return SRetReturnReg; } 3230b57cec5SDimitry Andric void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; } 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andric unsigned getJumpTableEntrySize(int Idx) const { 326e8d8bef9SDimitry Andric return JumpTableEntryInfo[Idx].first; 3270b57cec5SDimitry Andric } 3280b57cec5SDimitry Andric MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const { 329e8d8bef9SDimitry Andric return JumpTableEntryInfo[Idx].second; 3300b57cec5SDimitry Andric } 3310b57cec5SDimitry Andric void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) { 332e8d8bef9SDimitry Andric if ((unsigned)Idx >= JumpTableEntryInfo.size()) 333e8d8bef9SDimitry Andric JumpTableEntryInfo.resize(Idx+1); 3340b57cec5SDimitry Andric JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym); 3350b57cec5SDimitry Andric } 3360b57cec5SDimitry Andric 3370b57cec5SDimitry Andric using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>; 3380b57cec5SDimitry Andric 3390b57cec5SDimitry Andric const SetOfInstructions &getLOHRelated() const { return LOHRelated; } 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric // Shortcuts for LOH related types. 3420b57cec5SDimitry Andric class MILOHDirective { 3430b57cec5SDimitry Andric MCLOHType Kind; 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric /// Arguments of this directive. Order matters. 3460b57cec5SDimitry Andric SmallVector<const MachineInstr *, 3> Args; 3470b57cec5SDimitry Andric 3480b57cec5SDimitry Andric public: 3490b57cec5SDimitry Andric using LOHArgs = ArrayRef<const MachineInstr *>; 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andric MILOHDirective(MCLOHType Kind, LOHArgs Args) 3520b57cec5SDimitry Andric : Kind(Kind), Args(Args.begin(), Args.end()) { 3530b57cec5SDimitry Andric assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!"); 3540b57cec5SDimitry Andric } 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andric MCLOHType getKind() const { return Kind; } 3570b57cec5SDimitry Andric LOHArgs getArgs() const { return Args; } 3580b57cec5SDimitry Andric }; 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric using MILOHArgs = MILOHDirective::LOHArgs; 3610b57cec5SDimitry Andric using MILOHContainer = SmallVector<MILOHDirective, 32>; 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric const MILOHContainer &getLOHContainer() const { return LOHContainerSet; } 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric /// Add a LOH directive of this @p Kind and this @p Args. 3660b57cec5SDimitry Andric void addLOHDirective(MCLOHType Kind, MILOHArgs Args) { 3670b57cec5SDimitry Andric LOHContainerSet.push_back(MILOHDirective(Kind, Args)); 3680b57cec5SDimitry Andric LOHRelated.insert(Args.begin(), Args.end()); 3690b57cec5SDimitry Andric } 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() { 3720b57cec5SDimitry Andric return ForwardedMustTailRegParms; 3730b57cec5SDimitry Andric } 3740b57cec5SDimitry Andric 375e8d8bef9SDimitry Andric Optional<int> getTaggedBasePointerIndex() const { 376e8d8bef9SDimitry Andric return TaggedBasePointerIndex; 377e8d8bef9SDimitry Andric } 378e8d8bef9SDimitry Andric void setTaggedBasePointerIndex(int Index) { TaggedBasePointerIndex = Index; } 379e8d8bef9SDimitry Andric 3800b57cec5SDimitry Andric unsigned getTaggedBasePointerOffset() const { 3810b57cec5SDimitry Andric return TaggedBasePointerOffset; 3820b57cec5SDimitry Andric } 3830b57cec5SDimitry Andric void setTaggedBasePointerOffset(unsigned Offset) { 3840b57cec5SDimitry Andric TaggedBasePointerOffset = Offset; 3850b57cec5SDimitry Andric } 3860b57cec5SDimitry Andric 387e8d8bef9SDimitry Andric int getCalleeSaveBaseToFrameRecordOffset() const { 388e8d8bef9SDimitry Andric return CalleeSaveBaseToFrameRecordOffset; 389e8d8bef9SDimitry Andric } 390e8d8bef9SDimitry Andric void setCalleeSaveBaseToFrameRecordOffset(int Offset) { 391e8d8bef9SDimitry Andric CalleeSaveBaseToFrameRecordOffset = Offset; 392e8d8bef9SDimitry Andric } 393e8d8bef9SDimitry Andric 394e8d8bef9SDimitry Andric bool shouldSignReturnAddress() const; 395e8d8bef9SDimitry Andric bool shouldSignReturnAddress(bool SpillsLR) const; 396e8d8bef9SDimitry Andric 397e8d8bef9SDimitry Andric bool shouldSignWithBKey() const { return SignWithBKey; } 398e8d8bef9SDimitry Andric 399e8d8bef9SDimitry Andric bool branchTargetEnforcement() const { return BranchTargetEnforcement; } 400e8d8bef9SDimitry Andric 401*fe6060f1SDimitry Andric void setHasSwiftAsyncContext(bool HasContext) { 402*fe6060f1SDimitry Andric HasSwiftAsyncContext = HasContext; 403*fe6060f1SDimitry Andric } 404*fe6060f1SDimitry Andric bool hasSwiftAsyncContext() const { return HasSwiftAsyncContext; } 405*fe6060f1SDimitry Andric 406*fe6060f1SDimitry Andric void setSwiftAsyncContextFrameIdx(int FI) { 407*fe6060f1SDimitry Andric SwiftAsyncContextFrameIdx = FI; 408*fe6060f1SDimitry Andric } 409*fe6060f1SDimitry Andric int getSwiftAsyncContextFrameIdx() const { return SwiftAsyncContextFrameIdx; } 410*fe6060f1SDimitry Andric 4110b57cec5SDimitry Andric private: 4120b57cec5SDimitry Andric // Hold the lists of LOHs. 4130b57cec5SDimitry Andric MILOHContainer LOHContainerSet; 4140b57cec5SDimitry Andric SetOfInstructions LOHRelated; 4150b57cec5SDimitry Andric 416e8d8bef9SDimitry Andric SmallVector<std::pair<unsigned, MCSymbol *>, 2> JumpTableEntryInfo; 4170b57cec5SDimitry Andric }; 4180b57cec5SDimitry Andric 4195ffd83dbSDimitry Andric namespace yaml { 4205ffd83dbSDimitry Andric struct AArch64FunctionInfo final : public yaml::MachineFunctionInfo { 4215ffd83dbSDimitry Andric Optional<bool> HasRedZone; 4225ffd83dbSDimitry Andric 4235ffd83dbSDimitry Andric AArch64FunctionInfo() = default; 4245ffd83dbSDimitry Andric AArch64FunctionInfo(const llvm::AArch64FunctionInfo &MFI); 4255ffd83dbSDimitry Andric 4265ffd83dbSDimitry Andric void mappingImpl(yaml::IO &YamlIO) override; 4275ffd83dbSDimitry Andric ~AArch64FunctionInfo() = default; 4285ffd83dbSDimitry Andric }; 4295ffd83dbSDimitry Andric 4305ffd83dbSDimitry Andric template <> struct MappingTraits<AArch64FunctionInfo> { 4315ffd83dbSDimitry Andric static void mapping(IO &YamlIO, AArch64FunctionInfo &MFI) { 4325ffd83dbSDimitry Andric YamlIO.mapOptional("hasRedZone", MFI.HasRedZone); 4335ffd83dbSDimitry Andric } 4345ffd83dbSDimitry Andric }; 4355ffd83dbSDimitry Andric 4365ffd83dbSDimitry Andric } // end namespace yaml 4375ffd83dbSDimitry Andric 4380b57cec5SDimitry Andric } // end namespace llvm 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H 441