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/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;
101 AArch64FunctionInfo() = default;
103 explicit AArch64FunctionInfo(MachineFunction &MF) {
106 // If we already know that the function doesn't have a redzone, set
108 if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
112 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
113 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
115 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
116 void setArgumentStackToRestore(unsigned bytes) {
117 ArgumentStackToRestore = bytes;
120 bool hasStackFrame() const { return HasStackFrame; }
121 void setHasStackFrame(bool s) { HasStackFrame = s; }
123 bool isStackRealigned() const { return StackRealigned; }
124 void setStackRealigned(bool s) { StackRealigned = s; }
126 bool hasCalleeSaveStackFreeSpace() const {
127 return CalleeSaveStackHasFreeSpace;
129 void setCalleeSaveStackHasFreeSpace(bool s) {
130 CalleeSaveStackHasFreeSpace = s;
133 bool isSplitCSR() const { return IsSplitCSR; }
134 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
136 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
137 unsigned getLocalStackSize() const { return LocalStackSize; }
139 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
140 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
142 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
143 unsigned getNumLocalDynamicTLSAccesses() const {
144 return NumLocalDynamicTLSAccesses;
147 Optional<bool> hasRedZone() const { return HasRedZone; }
148 void setHasRedZone(bool s) { HasRedZone = s; }
150 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
151 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
153 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
154 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
156 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
157 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
159 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
160 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
162 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
163 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
165 using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
167 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
169 // Shortcuts for LOH related types.
170 class MILOHDirective {
173 /// Arguments of this directive. Order matters.
174 SmallVector<const MachineInstr *, 3> Args;
177 using LOHArgs = ArrayRef<const MachineInstr *>;
179 MILOHDirective(MCLOHType Kind, LOHArgs Args)
180 : Kind(Kind), Args(Args.begin(), Args.end()) {
181 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
184 MCLOHType getKind() const { return Kind; }
185 LOHArgs getArgs() const { return Args; }
188 using MILOHArgs = MILOHDirective::LOHArgs;
189 using MILOHContainer = SmallVector<MILOHDirective, 32>;
191 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
193 /// Add a LOH directive of this @p Kind and this @p Args.
194 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
195 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
196 LOHRelated.insert(Args.begin(), Args.end());
200 // Hold the lists of LOHs.
201 MILOHContainer LOHContainerSet;
202 SetOfInstructions LOHRelated;
205 } // end namespace llvm
207 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H