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/IR/Function.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 /// SRetReturnReg - sret lowering includes returning the value of the
96 /// returned struct in a register. This field holds the virtual register into
97 /// which the sret argument is passed.
98 unsigned SRetReturnReg
= 0;
99 /// SVE stack size (for predicates and data vectors) are maintained here
100 /// rather than in FrameInfo, as the placement and Stack IDs are target
102 uint64_t StackSizeSVE
= 0;
104 /// HasCalculatedStackSizeSVE indicates whether StackSizeSVE is valid.
105 bool HasCalculatedStackSizeSVE
= false;
107 /// Has a value when it is known whether or not the function uses a
108 /// redzone, and no value otherwise.
109 /// Initialized during frame lowering, unless the function has the noredzone
110 /// attribute, in which case it is set to false at construction.
111 Optional
<bool> HasRedZone
;
113 /// ForwardedMustTailRegParms - A list of virtual and physical registers
114 /// that must be forwarded to every musttail call.
115 SmallVector
<ForwardedRegister
, 1> ForwardedMustTailRegParms
;
117 // Offset from SP-at-entry to the tagged base pointer.
118 // Tagged base pointer is set up to point to the first (lowest address) tagged
120 unsigned TaggedBasePointerOffset
;
123 AArch64FunctionInfo() = default;
125 explicit AArch64FunctionInfo(MachineFunction
&MF
) {
128 // If we already know that the function doesn't have a redzone, set
130 if (MF
.getFunction().hasFnAttribute(Attribute::NoRedZone
))
134 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea
; }
135 void setBytesInStackArgArea(unsigned bytes
) { BytesInStackArgArea
= bytes
; }
137 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore
; }
138 void setArgumentStackToRestore(unsigned bytes
) {
139 ArgumentStackToRestore
= bytes
;
142 bool hasCalculatedStackSizeSVE() const { return HasCalculatedStackSizeSVE
; }
144 void setStackSizeSVE(uint64_t S
) {
145 HasCalculatedStackSizeSVE
= true;
149 uint64_t getStackSizeSVE() const { return StackSizeSVE
; }
151 bool hasStackFrame() const { return HasStackFrame
; }
152 void setHasStackFrame(bool s
) { HasStackFrame
= s
; }
154 bool isStackRealigned() const { return StackRealigned
; }
155 void setStackRealigned(bool s
) { StackRealigned
= s
; }
157 bool hasCalleeSaveStackFreeSpace() const {
158 return CalleeSaveStackHasFreeSpace
;
160 void setCalleeSaveStackHasFreeSpace(bool s
) {
161 CalleeSaveStackHasFreeSpace
= s
;
164 bool isSplitCSR() const { return IsSplitCSR
; }
165 void setIsSplitCSR(bool s
) { IsSplitCSR
= s
; }
167 void setLocalStackSize(unsigned Size
) { LocalStackSize
= Size
; }
168 unsigned getLocalStackSize() const { return LocalStackSize
; }
170 void setCalleeSavedStackSize(unsigned Size
) { CalleeSavedStackSize
= Size
; }
171 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize
; }
173 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses
; }
174 unsigned getNumLocalDynamicTLSAccesses() const {
175 return NumLocalDynamicTLSAccesses
;
178 Optional
<bool> hasRedZone() const { return HasRedZone
; }
179 void setHasRedZone(bool s
) { HasRedZone
= s
; }
181 int getVarArgsStackIndex() const { return VarArgsStackIndex
; }
182 void setVarArgsStackIndex(int Index
) { VarArgsStackIndex
= Index
; }
184 int getVarArgsGPRIndex() const { return VarArgsGPRIndex
; }
185 void setVarArgsGPRIndex(int Index
) { VarArgsGPRIndex
= Index
; }
187 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize
; }
188 void setVarArgsGPRSize(unsigned Size
) { VarArgsGPRSize
= Size
; }
190 int getVarArgsFPRIndex() const { return VarArgsFPRIndex
; }
191 void setVarArgsFPRIndex(int Index
) { VarArgsFPRIndex
= Index
; }
193 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize
; }
194 void setVarArgsFPRSize(unsigned Size
) { VarArgsFPRSize
= Size
; }
196 unsigned getSRetReturnReg() const { return SRetReturnReg
; }
197 void setSRetReturnReg(unsigned Reg
) { SRetReturnReg
= Reg
; }
199 unsigned getJumpTableEntrySize(int Idx
) const {
200 auto It
= JumpTableEntryInfo
.find(Idx
);
201 if (It
!= JumpTableEntryInfo
.end())
202 return It
->second
.first
;
205 MCSymbol
*getJumpTableEntryPCRelSymbol(int Idx
) const {
206 return JumpTableEntryInfo
.find(Idx
)->second
.second
;
208 void setJumpTableEntryInfo(int Idx
, unsigned Size
, MCSymbol
*PCRelSym
) {
209 JumpTableEntryInfo
[Idx
] = std::make_pair(Size
, PCRelSym
);
212 using SetOfInstructions
= SmallPtrSet
<const MachineInstr
*, 16>;
214 const SetOfInstructions
&getLOHRelated() const { return LOHRelated
; }
216 // Shortcuts for LOH related types.
217 class MILOHDirective
{
220 /// Arguments of this directive. Order matters.
221 SmallVector
<const MachineInstr
*, 3> Args
;
224 using LOHArgs
= ArrayRef
<const MachineInstr
*>;
226 MILOHDirective(MCLOHType Kind
, LOHArgs Args
)
227 : Kind(Kind
), Args(Args
.begin(), Args
.end()) {
228 assert(isValidMCLOHType(Kind
) && "Invalid LOH directive type!");
231 MCLOHType
getKind() const { return Kind
; }
232 LOHArgs
getArgs() const { return Args
; }
235 using MILOHArgs
= MILOHDirective::LOHArgs
;
236 using MILOHContainer
= SmallVector
<MILOHDirective
, 32>;
238 const MILOHContainer
&getLOHContainer() const { return LOHContainerSet
; }
240 /// Add a LOH directive of this @p Kind and this @p Args.
241 void addLOHDirective(MCLOHType Kind
, MILOHArgs Args
) {
242 LOHContainerSet
.push_back(MILOHDirective(Kind
, Args
));
243 LOHRelated
.insert(Args
.begin(), Args
.end());
246 SmallVectorImpl
<ForwardedRegister
> &getForwardedMustTailRegParms() {
247 return ForwardedMustTailRegParms
;
250 unsigned getTaggedBasePointerOffset() const {
251 return TaggedBasePointerOffset
;
253 void setTaggedBasePointerOffset(unsigned Offset
) {
254 TaggedBasePointerOffset
= Offset
;
258 // Hold the lists of LOHs.
259 MILOHContainer LOHContainerSet
;
260 SetOfInstructions LOHRelated
;
262 DenseMap
<int, std::pair
<unsigned, MCSymbol
*>> JumpTableEntryInfo
;
265 } // end namespace llvm
267 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H