1 //=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares AArch64-specific per-machine-function information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
15 #define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/CodeGen/CallingConvLower.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/MC/MCLinkerOptimizationHint.h"
30 /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
31 /// contains private AArch64-specific information for each MachineFunction.
32 class AArch64FunctionInfo final : public MachineFunctionInfo {
33 /// Number of bytes of arguments this function has on the stack. If the callee
34 /// is expected to restore the argument stack this should be a multiple of 16,
35 /// all usable during a tail call.
37 /// The alternative would forbid tail call optimisation in some cases: if we
38 /// want to transfer control from a function with 8-bytes of stack-argument
39 /// space to a function with 16-bytes then misalignment of this value would
40 /// make a stack adjustment necessary, which could not be undone by the
42 unsigned BytesInStackArgArea = 0;
44 /// The number of bytes to restore to deallocate space for incoming
45 /// arguments. Canonically 0 in the C calling convention, but non-zero when
46 /// callee is expected to pop the args.
47 unsigned ArgumentStackToRestore = 0;
49 /// HasStackFrame - True if this function has a stack frame. Set by
50 /// determineCalleeSaves().
51 bool HasStackFrame = false;
53 /// Amount of stack frame size, not including callee-saved registers.
54 unsigned LocalStackSize;
56 /// Amount of stack frame size used for saving callee-saved registers.
57 unsigned CalleeSavedStackSize;
59 /// Number of TLS accesses using the special (combinable)
60 /// _TLS_MODULE_BASE_ symbol.
61 unsigned NumLocalDynamicTLSAccesses = 0;
63 /// FrameIndex for start of varargs area for arguments passed on the
65 int VarArgsStackIndex = 0;
67 /// FrameIndex for start of varargs area for arguments passed in
68 /// general purpose registers.
69 int VarArgsGPRIndex = 0;
71 /// Size of the varargs area for arguments passed in general purpose
73 unsigned VarArgsGPRSize = 0;
75 /// FrameIndex for start of varargs area for arguments passed in
76 /// floating-point registers.
77 int VarArgsFPRIndex = 0;
79 /// Size of the varargs area for arguments passed in floating-point
81 unsigned VarArgsFPRSize = 0;
83 /// True if this function has a subset of CSRs that is handled explicitly via
85 bool IsSplitCSR = false;
87 /// True when the stack gets realigned dynamically because the size of stack
88 /// frame is unknown at compile time. e.g., in case of VLAs.
89 bool StackRealigned = false;
91 /// True when the callee-save stack area has unused gaps that may be used for
92 /// other stack allocations.
93 bool CalleeSaveStackHasFreeSpace = false;
95 /// Has a value when it is known whether or not the function uses a
96 /// redzone, and no value otherwise.
97 /// Initialized during frame lowering, unless the function has the noredzone
98 /// attribute, in which case it is set to false at construction.
99 Optional<bool> HasRedZone;
101 /// ForwardedMustTailRegParms - A list of virtual and physical registers
102 /// that must be forwarded to every musttail call.
103 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
105 AArch64FunctionInfo() = default;
107 explicit AArch64FunctionInfo(MachineFunction &MF) {
110 // If we already know that the function doesn't have a redzone, set
112 if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
116 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
117 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
119 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
120 void setArgumentStackToRestore(unsigned bytes) {
121 ArgumentStackToRestore = bytes;
124 bool hasStackFrame() const { return HasStackFrame; }
125 void setHasStackFrame(bool s) { HasStackFrame = s; }
127 bool isStackRealigned() const { return StackRealigned; }
128 void setStackRealigned(bool s) { StackRealigned = s; }
130 bool hasCalleeSaveStackFreeSpace() const {
131 return CalleeSaveStackHasFreeSpace;
133 void setCalleeSaveStackHasFreeSpace(bool s) {
134 CalleeSaveStackHasFreeSpace = s;
137 bool isSplitCSR() const { return IsSplitCSR; }
138 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
140 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
141 unsigned getLocalStackSize() const { return LocalStackSize; }
143 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
144 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
146 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
147 unsigned getNumLocalDynamicTLSAccesses() const {
148 return NumLocalDynamicTLSAccesses;
151 Optional<bool> hasRedZone() const { return HasRedZone; }
152 void setHasRedZone(bool s) { HasRedZone = s; }
154 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
155 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
157 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
158 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
160 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
161 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
163 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
164 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
166 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
167 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
169 unsigned getJumpTableEntrySize(int Idx) const {
170 auto It = JumpTableEntryInfo.find(Idx);
171 if (It != JumpTableEntryInfo.end())
172 return It->second.first;
175 MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
176 return JumpTableEntryInfo.find(Idx)->second.second;
178 void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
179 JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
182 using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
184 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
186 // Shortcuts for LOH related types.
187 class MILOHDirective {
190 /// Arguments of this directive. Order matters.
191 SmallVector<const MachineInstr *, 3> Args;
194 using LOHArgs = ArrayRef<const MachineInstr *>;
196 MILOHDirective(MCLOHType Kind, LOHArgs Args)
197 : Kind(Kind), Args(Args.begin(), Args.end()) {
198 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
201 MCLOHType getKind() const { return Kind; }
202 LOHArgs getArgs() const { return Args; }
205 using MILOHArgs = MILOHDirective::LOHArgs;
206 using MILOHContainer = SmallVector<MILOHDirective, 32>;
208 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
210 /// Add a LOH directive of this @p Kind and this @p Args.
211 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
212 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
213 LOHRelated.insert(Args.begin(), Args.end());
216 SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
217 return ForwardedMustTailRegParms;
221 // Hold the lists of LOHs.
222 MILOHContainer LOHContainerSet;
223 SetOfInstructions LOHRelated;
225 DenseMap<int, std::pair<unsigned, MCSymbol *>> JumpTableEntryInfo;
228 } // end namespace llvm
230 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H