blob: f0bffe544158c01c29d89adc6ef06318464473f0 [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"
Tim Northover3b0846e2014-05-24 12:50:23 +000018#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/CodeGen/MachineFunction.h"
21#include "llvm/MC/MCLinkerOptimizationHint.h"
Eugene Zelenko049b0172017-01-06 00:30:53 +000022#include <cassert>
Tim Northover3b0846e2014-05-24 12:50:23 +000023
24namespace llvm {
25
26/// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
27/// contains private AArch64-specific information for each MachineFunction.
Ahmed Bougacha5e402ee2016-07-27 14:31:46 +000028class AArch64FunctionInfo final : public MachineFunctionInfo {
Tim Northover3b0846e2014-05-24 12:50:23 +000029 /// 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.
32 ///
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
37 /// callee.
Eugene Zelenko049b0172017-01-06 00:30:53 +000038 unsigned BytesInStackArgArea = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000039
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.
Eugene Zelenko049b0172017-01-06 00:30:53 +000043 unsigned ArgumentStackToRestore = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000044
45 /// HasStackFrame - True if this function has a stack frame. Set by
JF Bastienc8f48c12015-07-14 23:06:07 +000046 /// determineCalleeSaves().
Eugene Zelenko049b0172017-01-06 00:30:53 +000047 bool HasStackFrame = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000048
49 /// \brief Amount of stack frame size, not including callee-saved registers.
50 unsigned LocalStackSize;
51
Geoff Berry04bf91a2016-02-01 16:29:19 +000052 /// \brief Amount of stack frame size used for saving callee-saved registers.
53 unsigned CalleeSavedStackSize;
54
Tim Northover3b0846e2014-05-24 12:50:23 +000055 /// \brief Number of TLS accesses using the special (combinable)
56 /// _TLS_MODULE_BASE_ symbol.
Eugene Zelenko049b0172017-01-06 00:30:53 +000057 unsigned NumLocalDynamicTLSAccesses = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000058
59 /// \brief FrameIndex for start of varargs area for arguments passed on the
60 /// stack.
Eugene Zelenko049b0172017-01-06 00:30:53 +000061 int VarArgsStackIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000062
63 /// \brief FrameIndex for start of varargs area for arguments passed in
64 /// general purpose registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000065 int VarArgsGPRIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000066
67 /// \brief Size of the varargs area for arguments passed in general purpose
68 /// registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000069 unsigned VarArgsGPRSize = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000070
71 /// \brief FrameIndex for start of varargs area for arguments passed in
72 /// floating-point registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000073 int VarArgsFPRIndex = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000074
75 /// \brief Size of the varargs area for arguments passed in floating-point
76 /// registers.
Eugene Zelenko049b0172017-01-06 00:30:53 +000077 unsigned VarArgsFPRSize = 0;
Tim Northover3b0846e2014-05-24 12:50:23 +000078
Manman Rencbe4f942015-12-16 21:04:19 +000079 /// True if this function has a subset of CSRs that is handled explicitly via
80 /// copies.
Eugene Zelenko049b0172017-01-06 00:30:53 +000081 bool IsSplitCSR = false;
Manman Rencbe4f942015-12-16 21:04:19 +000082
Chad Rosier6d986552016-03-14 18:17:41 +000083 /// 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.
Eugene Zelenko049b0172017-01-06 00:30:53 +000085 bool StackRealigned = false;
Chad Rosier6d986552016-03-14 18:17:41 +000086
Geoff Berry66f6b652016-06-02 16:22:07 +000087 /// True when the callee-save stack area has unused gaps that may be used for
88 /// other stack allocations.
Eugene Zelenko049b0172017-01-06 00:30:53 +000089 bool CalleeSaveStackHasFreeSpace = false;
Geoff Berry66f6b652016-06-02 16:22:07 +000090
Tim Northover3b0846e2014-05-24 12:50:23 +000091public:
Eugene Zelenko049b0172017-01-06 00:30:53 +000092 AArch64FunctionInfo() = default;
Tim Northover3b0846e2014-05-24 12:50:23 +000093
Eugene Zelenko049b0172017-01-06 00:30:53 +000094 explicit AArch64FunctionInfo(MachineFunction &MF) {
Tim Northover3b0846e2014-05-24 12:50:23 +000095 (void)MF;
96 }
97
98 unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
99 void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
100
101 unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
102 void setArgumentStackToRestore(unsigned bytes) {
103 ArgumentStackToRestore = bytes;
104 }
105
106 bool hasStackFrame() const { return HasStackFrame; }
107 void setHasStackFrame(bool s) { HasStackFrame = s; }
108
Chad Rosier6d986552016-03-14 18:17:41 +0000109 bool isStackRealigned() const { return StackRealigned; }
110 void setStackRealigned(bool s) { StackRealigned = s; }
111
Geoff Berry66f6b652016-06-02 16:22:07 +0000112 bool hasCalleeSaveStackFreeSpace() const {
113 return CalleeSaveStackHasFreeSpace;
114 }
115 void setCalleeSaveStackHasFreeSpace(bool s) {
116 CalleeSaveStackHasFreeSpace = s;
117 }
118
Manman Rencbe4f942015-12-16 21:04:19 +0000119 bool isSplitCSR() const { return IsSplitCSR; }
120 void setIsSplitCSR(bool s) { IsSplitCSR = s; }
121
Tim Northover3b0846e2014-05-24 12:50:23 +0000122 void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
123 unsigned getLocalStackSize() const { return LocalStackSize; }
124
Geoff Berry04bf91a2016-02-01 16:29:19 +0000125 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
126 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
127
Tim Northover3b0846e2014-05-24 12:50:23 +0000128 void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
129 unsigned getNumLocalDynamicTLSAccesses() const {
130 return NumLocalDynamicTLSAccesses;
131 }
132
133 int getVarArgsStackIndex() const { return VarArgsStackIndex; }
134 void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
135
136 int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
137 void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
138
139 unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
140 void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
141
142 int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
143 void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
144
145 unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
146 void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
147
148 typedef SmallPtrSet<const MachineInstr *, 16> SetOfInstructions;
149
150 const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
151
152 // Shortcuts for LOH related types.
153 class MILOHDirective {
154 MCLOHType Kind;
155
156 /// Arguments of this directive. Order matters.
157 SmallVector<const MachineInstr *, 3> Args;
158
159 public:
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000160 typedef ArrayRef<const MachineInstr *> LOHArgs;
Tim Northover3b0846e2014-05-24 12:50:23 +0000161
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000162 MILOHDirective(MCLOHType Kind, LOHArgs Args)
Tim Northover3b0846e2014-05-24 12:50:23 +0000163 : Kind(Kind), Args(Args.begin(), Args.end()) {
164 assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
165 }
166
167 MCLOHType getKind() const { return Kind; }
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000168 LOHArgs getArgs() const { return Args; }
Tim Northover3b0846e2014-05-24 12:50:23 +0000169 };
170
171 typedef MILOHDirective::LOHArgs MILOHArgs;
172 typedef SmallVector<MILOHDirective, 32> MILOHContainer;
173
174 const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
175
176 /// Add a LOH directive of this @p Kind and this @p Args.
Benjamin Kramer3bc1edf2016-07-02 11:41:39 +0000177 void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
Tim Northover3b0846e2014-05-24 12:50:23 +0000178 LOHContainerSet.push_back(MILOHDirective(Kind, Args));
179 LOHRelated.insert(Args.begin(), Args.end());
180 }
181
182private:
183 // Hold the lists of LOHs.
184 MILOHContainer LOHContainerSet;
185 SetOfInstructions LOHRelated;
186};
Tim Northover3b0846e2014-05-24 12:50:23 +0000187
Eugene Zelenko049b0172017-01-06 00:30:53 +0000188} // end namespace llvm
189
190#endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H