1 //=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- C++ -*-=//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares AArch64-specific per-machine-function information.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/CodeGen/CallingConvLower.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/MC/MCLinkerOptimizationHint.h"
29 /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
30 /// contains private AArch64-specific information for each MachineFunction.
31 class AArch64FunctionInfo final
: public MachineFunctionInfo
{
32 /// Number of bytes of arguments this function has on the stack. If the callee
33 /// is expected to restore the argument stack this should be a multiple of 16,
34 /// all usable during a tail call.
36 /// The alternative would forbid tail call optimisation in some cases: if we
37 /// want to transfer control from a function with 8-bytes of stack-argument
38 /// space to a function with 16-bytes then misalignment of this value would
39 /// make a stack adjustment necessary, which could not be undone by the
41 unsigned BytesInStackArgArea
= 0;
43 /// The number of bytes to restore to deallocate space for incoming
44 /// arguments. Canonically 0 in the C calling convention, but non-zero when
45 /// callee is expected to pop the args.
46 unsigned ArgumentStackToRestore
= 0;
48 /// HasStackFrame - True if this function has a stack frame. Set by
49 /// determineCalleeSaves().
50 bool HasStackFrame
= false;
52 /// Amount of stack frame size, not including callee-saved registers.
53 unsigned LocalStackSize
;
55 /// Amount of stack frame size used for saving callee-saved registers.
56 unsigned CalleeSavedStackSize
;
58 /// Number of TLS accesses using the special (combinable)
59 /// _TLS_MODULE_BASE_ symbol.
60 unsigned NumLocalDynamicTLSAccesses
= 0;
62 /// FrameIndex for start of varargs area for arguments passed on the
64 int VarArgsStackIndex
= 0;
66 /// FrameIndex for start of varargs area for arguments passed in
67 /// general purpose registers.
68 int VarArgsGPRIndex
= 0;
70 /// Size of the varargs area for arguments passed in general purpose
72 unsigned VarArgsGPRSize
= 0;
74 /// FrameIndex for start of varargs area for arguments passed in
75 /// floating-point registers.
76 int VarArgsFPRIndex
= 0;
78 /// Size of the varargs area for arguments passed in floating-point
80 unsigned VarArgsFPRSize
= 0;
82 /// True if this function has a subset of CSRs that is handled explicitly via
84 bool IsSplitCSR
= false;
86 /// True when the stack gets realigned dynamically because the size of stack
87 /// frame is unknown at compile time. e.g., in case of VLAs.
88 bool StackRealigned
= false;
90 /// True when the callee-save stack area has unused gaps that may be used for
91 /// other stack allocations.
92 bool CalleeSaveStackHasFreeSpace
= false;
94 /// Has a value when it is known whether or not the function uses a
95 /// redzone, and no value otherwise.
96 /// Initialized during frame lowering, unless the function has the noredzone
97 /// attribute, in which case it is set to false at construction.
98 Optional
<bool> HasRedZone
;
100 /// ForwardedMustTailRegParms - A list of virtual and physical registers
101 /// that must be forwarded to every musttail call.
102 SmallVector
<ForwardedRegister
, 1> ForwardedMustTailRegParms
;
104 AArch64FunctionInfo() = default;
106 explicit AArch64FunctionInfo(MachineFunction
&MF
) {
109 // If we already know that the function doesn't have a redzone, set
111 if (MF
.getFunction().hasFnAttribute(Attribute::NoRedZone
))
115 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea
; }
116 void setBytesInStackArgArea(unsigned bytes
) { BytesInStackArgArea
= bytes
; }
118 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore
; }
119 void setArgumentStackToRestore(unsigned bytes
) {
120 ArgumentStackToRestore
= bytes
;
123 bool hasStackFrame() const { return HasStackFrame
; }
124 void setHasStackFrame(bool s
) { HasStackFrame
= s
; }
126 bool isStackRealigned() const { return StackRealigned
; }
127 void setStackRealigned(bool s
) { StackRealigned
= s
; }
129 bool hasCalleeSaveStackFreeSpace() const {
130 return CalleeSaveStackHasFreeSpace
;
132 void setCalleeSaveStackHasFreeSpace(bool s
) {
133 CalleeSaveStackHasFreeSpace
= s
;
136 bool isSplitCSR() const { return IsSplitCSR
; }
137 void setIsSplitCSR(bool s
) { IsSplitCSR
= s
; }
139 void setLocalStackSize(unsigned Size
) { LocalStackSize
= Size
; }
140 unsigned getLocalStackSize() const { return LocalStackSize
; }
142 void setCalleeSavedStackSize(unsigned Size
) { CalleeSavedStackSize
= Size
; }
143 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize
; }
145 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses
; }
146 unsigned getNumLocalDynamicTLSAccesses() const {
147 return NumLocalDynamicTLSAccesses
;
150 Optional
<bool> hasRedZone() const { return HasRedZone
; }
151 void setHasRedZone(bool s
) { HasRedZone
= s
; }
153 int getVarArgsStackIndex() const { return VarArgsStackIndex
; }
154 void setVarArgsStackIndex(int Index
) { VarArgsStackIndex
= Index
; }
156 int getVarArgsGPRIndex() const { return VarArgsGPRIndex
; }
157 void setVarArgsGPRIndex(int Index
) { VarArgsGPRIndex
= Index
; }
159 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize
; }
160 void setVarArgsGPRSize(unsigned Size
) { VarArgsGPRSize
= Size
; }
162 int getVarArgsFPRIndex() const { return VarArgsFPRIndex
; }
163 void setVarArgsFPRIndex(int Index
) { VarArgsFPRIndex
= Index
; }
165 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize
; }
166 void setVarArgsFPRSize(unsigned Size
) { VarArgsFPRSize
= Size
; }
168 unsigned getJumpTableEntrySize(int Idx
) const {
169 auto It
= JumpTableEntryInfo
.find(Idx
);
170 if (It
!= JumpTableEntryInfo
.end())
171 return It
->second
.first
;
174 MCSymbol
*getJumpTableEntryPCRelSymbol(int Idx
) const {
175 return JumpTableEntryInfo
.find(Idx
)->second
.second
;
177 void setJumpTableEntryInfo(int Idx
, unsigned Size
, MCSymbol
*PCRelSym
) {
178 JumpTableEntryInfo
[Idx
] = std::make_pair(Size
, PCRelSym
);
181 using SetOfInstructions
= SmallPtrSet
<const MachineInstr
*, 16>;
183 const SetOfInstructions
&getLOHRelated() const { return LOHRelated
; }
185 // Shortcuts for LOH related types.
186 class MILOHDirective
{
189 /// Arguments of this directive. Order matters.
190 SmallVector
<const MachineInstr
*, 3> Args
;
193 using LOHArgs
= ArrayRef
<const MachineInstr
*>;
195 MILOHDirective(MCLOHType Kind
, LOHArgs Args
)
196 : Kind(Kind
), Args(Args
.begin(), Args
.end()) {
197 assert(isValidMCLOHType(Kind
) && "Invalid LOH directive type!");
200 MCLOHType
getKind() const { return Kind
; }
201 LOHArgs
getArgs() const { return Args
; }
204 using MILOHArgs
= MILOHDirective::LOHArgs
;
205 using MILOHContainer
= SmallVector
<MILOHDirective
, 32>;
207 const MILOHContainer
&getLOHContainer() const { return LOHContainerSet
; }
209 /// Add a LOH directive of this @p Kind and this @p Args.
210 void addLOHDirective(MCLOHType Kind
, MILOHArgs Args
) {
211 LOHContainerSet
.push_back(MILOHDirective(Kind
, Args
));
212 LOHRelated
.insert(Args
.begin(), Args
.end());
215 SmallVectorImpl
<ForwardedRegister
> &getForwardedMustTailRegParms() {
216 return ForwardedMustTailRegParms
;
220 // Hold the lists of LOHs.
221 MILOHContainer LOHContainerSet
;
222 SetOfInstructions LOHRelated
;
224 DenseMap
<int, std::pair
<unsigned, MCSymbol
*>> JumpTableEntryInfo
;
227 } // end namespace llvm
229 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H