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/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/MC/MCLinkerOptimizationHint.h"
28 /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
29 /// contains private AArch64-specific information for each MachineFunction.
30 class AArch64FunctionInfo final : public MachineFunctionInfo {
31 /// Number of bytes of arguments this function has on the stack. If the callee
32 /// is expected to restore the argument stack this should be a multiple of 16,
33 /// all usable during a tail call.
35 /// The alternative would forbid tail call optimisation in some cases: if we
36 /// want to transfer control from a function with 8-bytes of stack-argument
37 /// space to a function with 16-bytes then misalignment of this value would
38 /// make a stack adjustment necessary, which could not be undone by the
40 unsigned BytesInStackArgArea = 0;
42 /// The number of bytes to restore to deallocate space for incoming
43 /// arguments. Canonically 0 in the C calling convention, but non-zero when
44 /// callee is expected to pop the args.
45 unsigned ArgumentStackToRestore = 0;
47 /// HasStackFrame - True if this function has a stack frame. Set by
48 /// determineCalleeSaves().
49 bool HasStackFrame = false;
51 /// \brief Amount of stack frame size, not including callee-saved registers.
52 unsigned LocalStackSize;
54 /// \brief Amount of stack frame size used for saving callee-saved registers.
55 unsigned CalleeSavedStackSize;
57 /// \brief Number of TLS accesses using the special (combinable)
58 /// _TLS_MODULE_BASE_ symbol.
59 unsigned NumLocalDynamicTLSAccesses = 0;
61 /// \brief FrameIndex for start of varargs area for arguments passed on the
63 int VarArgsStackIndex = 0;
65 /// \brief FrameIndex for start of varargs area for arguments passed in
66 /// general purpose registers.
67 int VarArgsGPRIndex = 0;
69 /// \brief Size of the varargs area for arguments passed in general purpose
71 unsigned VarArgsGPRSize = 0;
73 /// \brief FrameIndex for start of varargs area for arguments passed in
74 /// floating-point registers.
75 int VarArgsFPRIndex = 0;
77 /// \brief Size of the varargs area for arguments passed in floating-point
79 unsigned VarArgsFPRSize = 0;
81 /// True if this function has a subset of CSRs that is handled explicitly via
83 bool IsSplitCSR = false;
85 /// True when the stack gets realigned dynamically because the size of stack
86 /// frame is unknown at compile time. e.g., in case of VLAs.
87 bool StackRealigned = false;
89 /// True when the callee-save stack area has unused gaps that may be used for
90 /// other stack allocations.
91 bool CalleeSaveStackHasFreeSpace = false;
94 AArch64FunctionInfo() = default;
96 explicit AArch64FunctionInfo(MachineFunction &MF) {
100 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
101 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
103 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
104 void setArgumentStackToRestore(unsigned bytes) {
105 ArgumentStackToRestore = bytes;
108 bool hasStackFrame() const { return HasStackFrame; }
109 void setHasStackFrame(bool s) { HasStackFrame = s; }
111 bool isStackRealigned() const { return StackRealigned; }
112 void setStackRealigned(bool s) { StackRealigned = s; }
114 bool hasCalleeSaveStackFreeSpace() const {
115 return CalleeSaveStackHasFreeSpace;
117 void setCalleeSaveStackHasFreeSpace(bool s) {
118 CalleeSaveStackHasFreeSpace = s;
121 bool isSplitCSR() const { return IsSplitCSR; }
122 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
124 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
125 unsigned getLocalStackSize() const { return LocalStackSize; }
127 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
128 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
130 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
131 unsigned getNumLocalDynamicTLSAccesses() const {
132 return NumLocalDynamicTLSAccesses;
135 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
136 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
138 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
139 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
141 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
142 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
144 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
145 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
147 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
148 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
150 using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
152 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
154 // Shortcuts for LOH related types.
155 class MILOHDirective {
158 /// Arguments of this directive. Order matters.
159 SmallVector<const MachineInstr *, 3> Args;
162 using LOHArgs = ArrayRef<const MachineInstr *>;
164 MILOHDirective(MCLOHType Kind, LOHArgs Args)
165 : Kind(Kind), Args(Args.begin(), Args.end()) {
166 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
169 MCLOHType getKind() const { return Kind; }
170 LOHArgs getArgs() const { return Args; }
173 using MILOHArgs = MILOHDirective::LOHArgs;
174 using MILOHContainer = SmallVector<MILOHDirective, 32>;
176 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
178 /// Add a LOH directive of this @p Kind and this @p Args.
179 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
180 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
181 LOHRelated.insert(Args.begin(), Args.end());
185 // Hold the lists of LOHs.
186 MILOHContainer LOHContainerSet;
187 SetOfInstructions LOHRelated;
190 } // end namespace llvm
192 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H