blob: 5ab511ee88a54e4605184e5d37dd997cc89aa219 [file] [log] [blame]
Nick Lewyckyc3890d22015-07-29 22:32:47 +00001//=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- C++ -*-=//
Tim Northover3b0846e2014-05-24 12:50:23 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Tim Northover3b0846e2014-05-24 12:50:23 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file declares AArch64-specific per-machine-function information.
10//
11//===----------------------------------------------------------------------===//
12
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000013#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
Tim Northover3b0846e2014-05-24 12:50:23 +000015
Eugene Zelenko049b0172017-01-06 00:30:53 +000016#include "llvm/ADT/ArrayRef.h"
Jessica Paquette642f6c62018-04-03 21:56:10 +000017#include "llvm/ADT/Optional.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000018#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/SmallVector.h"
Mandeep Singh Grang71e0cc22018-10-30 20:46:10 +000020#include "llvm/CodeGen/CallingConvLower.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000021#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/MC/MCLinkerOptimizationHint.h"
Eugene Zelenko049b0172017-01-06 00:30:53 +000023#include <cassert>
Tim Northover3b0846e2014-05-24 12:50:23 +000024
25namespace llvm {
26
Eugene Zelenko96d933d2017-07-25 23:51:02 +000027class MachineInstr;
28
Tim Northover3b0846e2014-05-24 12:50:23 +000029/// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
30/// contains private AArch64-specific information for each MachineFunction.
Ahmed Bougacha5e402ee2016-07-27 14:31:46 +000031class AArch64FunctionInfo final : public MachineFunctionInfo {
Tim Northover3b0846e2014-05-24 12:50:23 +000032 /// 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.
35 ///
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
40 /// callee.
Eugene Zelenko049b0172017-01-06 00:30:53 +000041 unsigned BytesInStackArgArea = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000042
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.
Eugene Zelenko049b0172017-01-06 00:30:53 +000046 unsigned ArgumentStackToRestore = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000047
48 /// HasStackFrame - True if this function has a stack frame. Set by
JF Bastienc8f48c12015-07-14 23:06:07 +000049 /// determineCalleeSaves().
Eugene Zelenko049b0172017-01-06 00:30:53 +000050 bool HasStackFrame = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000051
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000052 /// Amount of stack frame size, not including callee-saved registers.
Tim Northover3b0846e2014-05-24 12:50:23 +000053 unsigned LocalStackSize;
54
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000055 /// Amount of stack frame size used for saving callee-saved registers.
Geoff Berry04bf91a2016-02-01 16:29:19 +000056 unsigned CalleeSavedStackSize;
57
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000058 /// Number of TLS accesses using the special (combinable)
Tim Northover3b0846e2014-05-24 12:50:23 +000059 /// _TLS_MODULE_BASE_ symbol.
Eugene Zelenko049b0172017-01-06 00:30:53 +000060 unsigned NumLocalDynamicTLSAccesses = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000061
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000062 /// FrameIndex for start of varargs area for arguments passed on the
Tim Northover3b0846e2014-05-24 12:50:23 +000063 /// stack.
Eugene Zelenko049b0172017-01-06 00:30:53 +000064 int VarArgsStackIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000065
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000066 /// FrameIndex for start of varargs area for arguments passed in
Tim Northover3b0846e2014-05-24 12:50:23 +000067 /// general purpose registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000068 int VarArgsGPRIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000069
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000070 /// Size of the varargs area for arguments passed in general purpose
Tim Northover3b0846e2014-05-24 12:50:23 +000071 /// registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000072 unsigned VarArgsGPRSize = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000073
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000074 /// FrameIndex for start of varargs area for arguments passed in
Tim Northover3b0846e2014-05-24 12:50:23 +000075 /// floating-point registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000076 int VarArgsFPRIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000077
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000078 /// Size of the varargs area for arguments passed in floating-point
Tim Northover3b0846e2014-05-24 12:50:23 +000079 /// registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000080 unsigned VarArgsFPRSize = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000081
Manman Rencbe4f942015-12-16 21:04:19 +000082 /// True if this function has a subset of CSRs that is handled explicitly via
83 /// copies.
Eugene Zelenko049b0172017-01-06 00:30:53 +000084 bool IsSplitCSR = false;
Manman Rencbe4f942015-12-16 21:04:19 +000085
Chad Rosier6d986552016-03-14 18:17:41 +000086 /// 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.
Eugene Zelenko049b0172017-01-06 00:30:53 +000088 bool StackRealigned = false;
Chad Rosier6d986552016-03-14 18:17:41 +000089
Geoff Berry66f6b652016-06-02 16:22:07 +000090 /// True when the callee-save stack area has unused gaps that may be used for
91 /// other stack allocations.
Eugene Zelenko049b0172017-01-06 00:30:53 +000092 bool CalleeSaveStackHasFreeSpace = false;
Geoff Berry66f6b652016-06-02 16:22:07 +000093
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000094 /// Has a value when it is known whether or not the function uses a
Jessica Paquette642f6c62018-04-03 21:56:10 +000095 /// 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;
99
Mandeep Singh Grang71e0cc22018-10-30 20:46:10 +0000100 /// ForwardedMustTailRegParms - A list of virtual and physical registers
101 /// that must be forwarded to every musttail call.
102 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
Tim Northover3b0846e2014-05-24 12:50:23 +0000103public:
Eugene Zelenko049b0172017-01-06 00:30:53 +0000104 AArch64FunctionInfo() = default;
Tim Northover3b0846e2014-05-24 12:50:23 +0000105
Eugene Zelenko049b0172017-01-06 00:30:53 +0000106 explicit AArch64FunctionInfo(MachineFunction &MF) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000107 (void)MF;
Jessica Paquette642f6c62018-04-03 21:56:10 +0000108
109 // If we already know that the function doesn't have a redzone, set
110 // HasRedZone here.
111 if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
112 HasRedZone = false;
Tim Northover3b0846e2014-05-24 12:50:23 +0000113 }
114
115 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
116 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
117
118 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
119 void setArgumentStackToRestore(unsigned bytes) {
120 ArgumentStackToRestore = bytes;
121 }
122
123 bool hasStackFrame() const { return HasStackFrame; }
124 void setHasStackFrame(bool s) { HasStackFrame = s; }
125
Chad Rosier6d986552016-03-14 18:17:41 +0000126 bool isStackRealigned() const { return StackRealigned; }
127 void setStackRealigned(bool s) { StackRealigned = s; }
128
Geoff Berry66f6b652016-06-02 16:22:07 +0000129 bool hasCalleeSaveStackFreeSpace() const {
130 return CalleeSaveStackHasFreeSpace;
131 }
132 void setCalleeSaveStackHasFreeSpace(bool s) {
133 CalleeSaveStackHasFreeSpace = s;
134 }
135
Manman Rencbe4f942015-12-16 21:04:19 +0000136 bool isSplitCSR() const { return IsSplitCSR; }
137 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
138
Tim Northover3b0846e2014-05-24 12:50:23 +0000139 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
140 unsigned getLocalStackSize() const { return LocalStackSize; }
141
Geoff Berry04bf91a2016-02-01 16:29:19 +0000142 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
143 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
144
Tim Northover3b0846e2014-05-24 12:50:23 +0000145 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
146 unsigned getNumLocalDynamicTLSAccesses() const {
147 return NumLocalDynamicTLSAccesses;
148 }
149
Jessica Paquette642f6c62018-04-03 21:56:10 +0000150 Optional<bool> hasRedZone() const { return HasRedZone; }
151 void setHasRedZone(bool s) { HasRedZone = s; }
Fangrui Songf78650a2018-07-30 19:41:25 +0000152
Tim Northover3b0846e2014-05-24 12:50:23 +0000153 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
154 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
155
156 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
157 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
158
159 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
160 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
161
162 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
163 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
164
165 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
166 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
167
Tim Northover1c353412018-10-24 20:19:09 +0000168 unsigned getJumpTableEntrySize(int Idx) const {
169 auto It = JumpTableEntryInfo.find(Idx);
170 if (It != JumpTableEntryInfo.end())
171 return It->second.first;
172 return 4;
173 }
174 MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
175 return JumpTableEntryInfo.find(Idx)->second.second;
176 }
177 void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
178 JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
179 }
180
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000181 using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
Tim Northover3b0846e2014-05-24 12:50:23 +0000182
183 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
184
185 // Shortcuts for LOH related types.
186 class MILOHDirective {
187 MCLOHType Kind;
188
189 /// Arguments of this directive. Order matters.
190 SmallVector<const MachineInstr *, 3> Args;
191
192 public:
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000193 using LOHArgs = ArrayRef<const MachineInstr *>;
Tim Northover3b0846e2014-05-24 12:50:23 +0000194
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000195 MILOHDirective(MCLOHType Kind, LOHArgs Args)
Tim Northover3b0846e2014-05-24 12:50:23 +0000196 : Kind(Kind), Args(Args.begin(), Args.end()) {
197 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
198 }
199
200 MCLOHType getKind() const { return Kind; }
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000201 LOHArgs getArgs() const { return Args; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000202 };
203
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000204 using MILOHArgs = MILOHDirective::LOHArgs;
205 using MILOHContainer = SmallVector<MILOHDirective, 32>;
Tim Northover3b0846e2014-05-24 12:50:23 +0000206
207 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
208
209 /// Add a LOH directive of this @p Kind and this @p Args.
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000210 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000211 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
212 LOHRelated.insert(Args.begin(), Args.end());
213 }
214
Mandeep Singh Grang71e0cc22018-10-30 20:46:10 +0000215 SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
216 return ForwardedMustTailRegParms;
217 }
218
Tim Northover3b0846e2014-05-24 12:50:23 +0000219private:
220 // Hold the lists of LOHs.
221 MILOHContainer LOHContainerSet;
222 SetOfInstructions LOHRelated;
Tim Northover1c353412018-10-24 20:19:09 +0000223
224 DenseMap<int, std::pair<unsigned, MCSymbol *>> JumpTableEntryInfo;
Tim Northover3b0846e2014-05-24 12:50:23 +0000225};
Tim Northover3b0846e2014-05-24 12:50:23 +0000226
Eugene Zelenko049b0172017-01-06 00:30:53 +0000227} // end namespace llvm
228
229#endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H