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"
26 /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
27 /// contains private AArch64-specific information for each MachineFunction.
28 class AArch64FunctionInfo final : public MachineFunctionInfo {
29 /// Number of bytes of arguments this function has on the stack. If the callee
30 /// is expected to restore the argument stack this should be a multiple of 16,
31 /// all usable during a tail call.
33 /// The alternative would forbid tail call optimisation in some cases: if we
34 /// want to transfer control from a function with 8-bytes of stack-argument
35 /// space to a function with 16-bytes then misalignment of this value would
36 /// make a stack adjustment necessary, which could not be undone by the
38 unsigned BytesInStackArgArea = 0;
40 /// The number of bytes to restore to deallocate space for incoming
41 /// arguments. Canonically 0 in the C calling convention, but non-zero when
42 /// callee is expected to pop the args.
43 unsigned ArgumentStackToRestore = 0;
45 /// HasStackFrame - True if this function has a stack frame. Set by
46 /// determineCalleeSaves().
47 bool HasStackFrame = false;
49 /// \brief Amount of stack frame size, not including callee-saved registers.
50 unsigned LocalStackSize;
52 /// \brief Amount of stack frame size used for saving callee-saved registers.
53 unsigned CalleeSavedStackSize;
55 /// \brief Number of TLS accesses using the special (combinable)
56 /// _TLS_MODULE_BASE_ symbol.
57 unsigned NumLocalDynamicTLSAccesses = 0;
59 /// \brief FrameIndex for start of varargs area for arguments passed on the
61 int VarArgsStackIndex = 0;
63 /// \brief FrameIndex for start of varargs area for arguments passed in
64 /// general purpose registers.
65 int VarArgsGPRIndex = 0;
67 /// \brief Size of the varargs area for arguments passed in general purpose
69 unsigned VarArgsGPRSize = 0;
71 /// \brief FrameIndex for start of varargs area for arguments passed in
72 /// floating-point registers.
73 int VarArgsFPRIndex = 0;
75 /// \brief Size of the varargs area for arguments passed in floating-point
77 unsigned VarArgsFPRSize = 0;
79 /// True if this function has a subset of CSRs that is handled explicitly via
81 bool IsSplitCSR = false;
83 /// True when the stack gets realigned dynamically because the size of stack
84 /// frame is unknown at compile time. e.g., in case of VLAs.
85 bool StackRealigned = false;
87 /// True when the callee-save stack area has unused gaps that may be used for
88 /// other stack allocations.
89 bool CalleeSaveStackHasFreeSpace = false;
92 AArch64FunctionInfo() = default;
94 explicit AArch64FunctionInfo(MachineFunction &MF) {
98 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
99 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
101 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
102 void setArgumentStackToRestore(unsigned bytes) {
103 ArgumentStackToRestore = bytes;
106 bool hasStackFrame() const { return HasStackFrame; }
107 void setHasStackFrame(bool s) { HasStackFrame = s; }
109 bool isStackRealigned() const { return StackRealigned; }
110 void setStackRealigned(bool s) { StackRealigned = s; }
112 bool hasCalleeSaveStackFreeSpace() const {
113 return CalleeSaveStackHasFreeSpace;
115 void setCalleeSaveStackHasFreeSpace(bool s) {
116 CalleeSaveStackHasFreeSpace = s;
119 bool isSplitCSR() const { return IsSplitCSR; }
120 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
122 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
123 unsigned getLocalStackSize() const { return LocalStackSize; }
125 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
126 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
128 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
129 unsigned getNumLocalDynamicTLSAccesses() const {
130 return NumLocalDynamicTLSAccesses;
133 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
134 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
136 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
137 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
139 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
140 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
142 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
143 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
145 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
146 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
148 typedef SmallPtrSet<const MachineInstr *, 16> SetOfInstructions;
150 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
152 // Shortcuts for LOH related types.
153 class MILOHDirective {
156 /// Arguments of this directive. Order matters.
157 SmallVector<const MachineInstr *, 3> Args;
160 typedef ArrayRef<const MachineInstr *> LOHArgs;
162 MILOHDirective(MCLOHType Kind, LOHArgs Args)
163 : Kind(Kind), Args(Args.begin(), Args.end()) {
164 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
167 MCLOHType getKind() const { return Kind; }
168 LOHArgs getArgs() const { return Args; }
171 typedef MILOHDirective::LOHArgs MILOHArgs;
172 typedef SmallVector<MILOHDirective, 32> MILOHContainer;
174 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
176 /// Add a LOH directive of this @p Kind and this @p Args.
177 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
178 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
179 LOHRelated.insert(Args.begin(), Args.end());
183 // Hold the lists of LOHs.
184 MILOHContainer LOHContainerSet;
185 SetOfInstructions LOHRelated;
188 } // end namespace llvm
190 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H