blob: 5183e7d3c0d0974f4d680e48e06eeb4128191082 [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//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares AArch64-specific per-machine-function information.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
15#define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
Tim Northover3b0846e2014-05-24 12:50:23 +000016
Eugene Zelenko049b0172017-01-06 00:30:53 +000017#include "llvm/ADT/ArrayRef.h"
Jessica Paquette642f6c62018-04-03 21:56:10 +000018#include "llvm/ADT/Optional.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000019#include "llvm/ADT/SmallPtrSet.h"
20#include "llvm/ADT/SmallVector.h"
Mandeep Singh Grang71e0cc22018-10-30 20:46:10 +000021#include "llvm/CodeGen/CallingConvLower.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000022#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/MC/MCLinkerOptimizationHint.h"
Eugene Zelenko049b0172017-01-06 00:30:53 +000024#include <cassert>
Tim Northover3b0846e2014-05-24 12:50:23 +000025
26namespace llvm {
27
Eugene Zelenko96d933d2017-07-25 23:51:02 +000028class MachineInstr;
29
Tim Northover3b0846e2014-05-24 12:50:23 +000030/// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
31/// contains private AArch64-specific information for each MachineFunction.
Ahmed Bougacha5e402ee2016-07-27 14:31:46 +000032class AArch64FunctionInfo final : public MachineFunctionInfo {
Tim Northover3b0846e2014-05-24 12:50:23 +000033 /// 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.
36 ///
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
41 /// callee.
Eugene Zelenko049b0172017-01-06 00:30:53 +000042 unsigned BytesInStackArgArea = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000043
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.
Eugene Zelenko049b0172017-01-06 00:30:53 +000047 unsigned ArgumentStackToRestore = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000048
49 /// HasStackFrame - True if this function has a stack frame. Set by
JF Bastienc8f48c12015-07-14 23:06:07 +000050 /// determineCalleeSaves().
Eugene Zelenko049b0172017-01-06 00:30:53 +000051 bool HasStackFrame = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000052
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000053 /// Amount of stack frame size, not including callee-saved registers.
Tim Northover3b0846e2014-05-24 12:50:23 +000054 unsigned LocalStackSize;
55
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000056 /// Amount of stack frame size used for saving callee-saved registers.
Geoff Berry04bf91a2016-02-01 16:29:19 +000057 unsigned CalleeSavedStackSize;
58
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000059 /// Number of TLS accesses using the special (combinable)
Tim Northover3b0846e2014-05-24 12:50:23 +000060 /// _TLS_MODULE_BASE_ symbol.
Eugene Zelenko049b0172017-01-06 00:30:53 +000061 unsigned NumLocalDynamicTLSAccesses = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000062
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000063 /// FrameIndex for start of varargs area for arguments passed on the
Tim Northover3b0846e2014-05-24 12:50:23 +000064 /// stack.
Eugene Zelenko049b0172017-01-06 00:30:53 +000065 int VarArgsStackIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000066
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000067 /// FrameIndex for start of varargs area for arguments passed in
Tim Northover3b0846e2014-05-24 12:50:23 +000068 /// general purpose registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000069 int VarArgsGPRIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000070
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000071 /// Size of the varargs area for arguments passed in general purpose
Tim Northover3b0846e2014-05-24 12:50:23 +000072 /// registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000073 unsigned VarArgsGPRSize = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000074
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000075 /// FrameIndex for start of varargs area for arguments passed in
Tim Northover3b0846e2014-05-24 12:50:23 +000076 /// floating-point registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000077 int VarArgsFPRIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000078
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000079 /// Size of the varargs area for arguments passed in floating-point
Tim Northover3b0846e2014-05-24 12:50:23 +000080 /// registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000081 unsigned VarArgsFPRSize = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000082
Manman Rencbe4f942015-12-16 21:04:19 +000083 /// True if this function has a subset of CSRs that is handled explicitly via
84 /// copies.
Eugene Zelenko049b0172017-01-06 00:30:53 +000085 bool IsSplitCSR = false;
Manman Rencbe4f942015-12-16 21:04:19 +000086
Chad Rosier6d986552016-03-14 18:17:41 +000087 /// 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.
Eugene Zelenko049b0172017-01-06 00:30:53 +000089 bool StackRealigned = false;
Chad Rosier6d986552016-03-14 18:17:41 +000090
Geoff Berry66f6b652016-06-02 16:22:07 +000091 /// True when the callee-save stack area has unused gaps that may be used for
92 /// other stack allocations.
Eugene Zelenko049b0172017-01-06 00:30:53 +000093 bool CalleeSaveStackHasFreeSpace = false;
Geoff Berry66f6b652016-06-02 16:22:07 +000094
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000095 /// Has a value when it is known whether or not the function uses a
Jessica Paquette642f6c62018-04-03 21:56:10 +000096 /// redzone, and no value otherwise.
97 /// Initialized during frame lowering, unless the function has the noredzone
98 /// attribute, in which case it is set to false at construction.
99 Optional<bool> HasRedZone;
100
Mandeep Singh Grang71e0cc22018-10-30 20:46:10 +0000101 /// ForwardedMustTailRegParms - A list of virtual and physical registers
102 /// that must be forwarded to every musttail call.
103 SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
Tim Northover3b0846e2014-05-24 12:50:23 +0000104public:
Eugene Zelenko049b0172017-01-06 00:30:53 +0000105 AArch64FunctionInfo() = default;
Tim Northover3b0846e2014-05-24 12:50:23 +0000106
Eugene Zelenko049b0172017-01-06 00:30:53 +0000107 explicit AArch64FunctionInfo(MachineFunction &MF) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000108 (void)MF;
Jessica Paquette642f6c62018-04-03 21:56:10 +0000109
110 // If we already know that the function doesn't have a redzone, set
111 // HasRedZone here.
112 if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
113 HasRedZone = false;
Tim Northover3b0846e2014-05-24 12:50:23 +0000114 }
115
116 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
117 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
118
119 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
120 void setArgumentStackToRestore(unsigned bytes) {
121 ArgumentStackToRestore = bytes;
122 }
123
124 bool hasStackFrame() const { return HasStackFrame; }
125 void setHasStackFrame(bool s) { HasStackFrame = s; }
126
Chad Rosier6d986552016-03-14 18:17:41 +0000127 bool isStackRealigned() const { return StackRealigned; }
128 void setStackRealigned(bool s) { StackRealigned = s; }
129
Geoff Berry66f6b652016-06-02 16:22:07 +0000130 bool hasCalleeSaveStackFreeSpace() const {
131 return CalleeSaveStackHasFreeSpace;
132 }
133 void setCalleeSaveStackHasFreeSpace(bool s) {
134 CalleeSaveStackHasFreeSpace = s;
135 }
136
Manman Rencbe4f942015-12-16 21:04:19 +0000137 bool isSplitCSR() const { return IsSplitCSR; }
138 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
139
Tim Northover3b0846e2014-05-24 12:50:23 +0000140 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
141 unsigned getLocalStackSize() const { return LocalStackSize; }
142
Geoff Berry04bf91a2016-02-01 16:29:19 +0000143 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
144 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
145
Tim Northover3b0846e2014-05-24 12:50:23 +0000146 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
147 unsigned getNumLocalDynamicTLSAccesses() const {
148 return NumLocalDynamicTLSAccesses;
149 }
150
Jessica Paquette642f6c62018-04-03 21:56:10 +0000151 Optional<bool> hasRedZone() const { return HasRedZone; }
152 void setHasRedZone(bool s) { HasRedZone = s; }
Fangrui Songf78650a2018-07-30 19:41:25 +0000153
Tim Northover3b0846e2014-05-24 12:50:23 +0000154 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
155 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
156
157 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
158 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
159
160 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
161 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
162
163 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
164 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
165
166 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
167 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
168
Tim Northover1c353412018-10-24 20:19:09 +0000169 unsigned getJumpTableEntrySize(int Idx) const {
170 auto It = JumpTableEntryInfo.find(Idx);
171 if (It != JumpTableEntryInfo.end())
172 return It->second.first;
173 return 4;
174 }
175 MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
176 return JumpTableEntryInfo.find(Idx)->second.second;
177 }
178 void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
179 JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
180 }
181
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000182 using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
Tim Northover3b0846e2014-05-24 12:50:23 +0000183
184 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
185
186 // Shortcuts for LOH related types.
187 class MILOHDirective {
188 MCLOHType Kind;
189
190 /// Arguments of this directive. Order matters.
191 SmallVector<const MachineInstr *, 3> Args;
192
193 public:
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000194 using LOHArgs = ArrayRef<const MachineInstr *>;
Tim Northover3b0846e2014-05-24 12:50:23 +0000195
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000196 MILOHDirective(MCLOHType Kind, LOHArgs Args)
Tim Northover3b0846e2014-05-24 12:50:23 +0000197 : Kind(Kind), Args(Args.begin(), Args.end()) {
198 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
199 }
200
201 MCLOHType getKind() const { return Kind; }
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000202 LOHArgs getArgs() const { return Args; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000203 };
204
Eugene Zelenko96d933d2017-07-25 23:51:02 +0000205 using MILOHArgs = MILOHDirective::LOHArgs;
206 using MILOHContainer = SmallVector<MILOHDirective, 32>;
Tim Northover3b0846e2014-05-24 12:50:23 +0000207
208 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
209
210 /// Add a LOH directive of this @p Kind and this @p Args.
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000211 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000212 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
213 LOHRelated.insert(Args.begin(), Args.end());
214 }
215
Mandeep Singh Grang71e0cc22018-10-30 20:46:10 +0000216 SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
217 return ForwardedMustTailRegParms;
218 }
219
Tim Northover3b0846e2014-05-24 12:50:23 +0000220private:
221 // Hold the lists of LOHs.
222 MILOHContainer LOHContainerSet;
223 SetOfInstructions LOHRelated;
Tim Northover1c353412018-10-24 20:19:09 +0000224
225 DenseMap<int, std::pair<unsigned, MCSymbol *>> JumpTableEntryInfo;
Tim Northover3b0846e2014-05-24 12:50:23 +0000226};
Tim Northover3b0846e2014-05-24 12:50:23 +0000227
Eugene Zelenko049b0172017-01-06 00:30:53 +0000228} // end namespace llvm
229
230#endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H