LLVM  9.0.0svn
AArch64MachineFunctionInfo.h
Go to the documentation of this file.
1 //=- AArch64MachineFunctionInfo.h - AArch64 machine function info -*- C++ -*-=//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares AArch64-specific per-machine-function information.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
15 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h"
23 #include <cassert>
24 
25 namespace llvm {
26 
27 class MachineInstr;
28 
29 /// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
30 /// contains private AArch64-specific information for each MachineFunction.
32  /// 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.
41  unsigned BytesInStackArgArea = 0;
42 
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.
46  unsigned ArgumentStackToRestore = 0;
47 
48  /// HasStackFrame - True if this function has a stack frame. Set by
49  /// determineCalleeSaves().
50  bool HasStackFrame = false;
51 
52  /// Amount of stack frame size, not including callee-saved registers.
53  unsigned LocalStackSize;
54 
55  /// Amount of stack frame size used for saving callee-saved registers.
56  unsigned CalleeSavedStackSize;
57 
58  /// Number of TLS accesses using the special (combinable)
59  /// _TLS_MODULE_BASE_ symbol.
60  unsigned NumLocalDynamicTLSAccesses = 0;
61 
62  /// FrameIndex for start of varargs area for arguments passed on the
63  /// stack.
64  int VarArgsStackIndex = 0;
65 
66  /// FrameIndex for start of varargs area for arguments passed in
67  /// general purpose registers.
68  int VarArgsGPRIndex = 0;
69 
70  /// Size of the varargs area for arguments passed in general purpose
71  /// registers.
72  unsigned VarArgsGPRSize = 0;
73 
74  /// FrameIndex for start of varargs area for arguments passed in
75  /// floating-point registers.
76  int VarArgsFPRIndex = 0;
77 
78  /// Size of the varargs area for arguments passed in floating-point
79  /// registers.
80  unsigned VarArgsFPRSize = 0;
81 
82  /// True if this function has a subset of CSRs that is handled explicitly via
83  /// copies.
84  bool IsSplitCSR = false;
85 
86  /// 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.
88  bool StackRealigned = false;
89 
90  /// True when the callee-save stack area has unused gaps that may be used for
91  /// other stack allocations.
92  bool CalleeSaveStackHasFreeSpace = false;
93 
94  /// SRetReturnReg - sret lowering includes returning the value of the
95  /// returned struct in a register. This field holds the virtual register into
96  /// which the sret argument is passed.
97  unsigned SRetReturnReg = 0;
98 
99  /// Has a value when it is known whether or not the function uses a
100  /// redzone, and no value otherwise.
101  /// Initialized during frame lowering, unless the function has the noredzone
102  /// attribute, in which case it is set to false at construction.
103  Optional<bool> HasRedZone;
104 
105  /// ForwardedMustTailRegParms - A list of virtual and physical registers
106  /// that must be forwarded to every musttail call.
107  SmallVector<ForwardedRegister, 1> ForwardedMustTailRegParms;
108 public:
109  AArch64FunctionInfo() = default;
110 
112  (void)MF;
113 
114  // If we already know that the function doesn't have a redzone, set
115  // HasRedZone here.
116  if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
117  HasRedZone = false;
118  }
119 
120  unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
121  void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
122 
123  unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
124  void setArgumentStackToRestore(unsigned bytes) {
125  ArgumentStackToRestore = bytes;
126  }
127 
128  bool hasStackFrame() const { return HasStackFrame; }
129  void setHasStackFrame(bool s) { HasStackFrame = s; }
130 
131  bool isStackRealigned() const { return StackRealigned; }
132  void setStackRealigned(bool s) { StackRealigned = s; }
133 
135  return CalleeSaveStackHasFreeSpace;
136  }
138  CalleeSaveStackHasFreeSpace = s;
139  }
140 
141  bool isSplitCSR() const { return IsSplitCSR; }
142  void setIsSplitCSR(bool s) { IsSplitCSR = s; }
143 
144  void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
145  unsigned getLocalStackSize() const { return LocalStackSize; }
146 
147  void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
148  unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
149 
150  void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
151  unsigned getNumLocalDynamicTLSAccesses() const {
152  return NumLocalDynamicTLSAccesses;
153  }
154 
155  Optional<bool> hasRedZone() const { return HasRedZone; }
156  void setHasRedZone(bool s) { HasRedZone = s; }
157 
158  int getVarArgsStackIndex() const { return VarArgsStackIndex; }
159  void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
160 
161  int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
162  void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
163 
164  unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
165  void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
166 
167  int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
168  void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
169 
170  unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
171  void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
172 
173  unsigned getSRetReturnReg() const { return SRetReturnReg; }
174  void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
175 
176  unsigned getJumpTableEntrySize(int Idx) const {
177  auto It = JumpTableEntryInfo.find(Idx);
178  if (It != JumpTableEntryInfo.end())
179  return It->second.first;
180  return 4;
181  }
183  return JumpTableEntryInfo.find(Idx)->second.second;
184  }
185  void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
186  JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
187  }
188 
190 
191  const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
192 
193  // Shortcuts for LOH related types.
195  MCLOHType Kind;
196 
197  /// Arguments of this directive. Order matters.
199 
200  public:
202 
204  : Kind(Kind), Args(Args.begin(), Args.end()) {
205  assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
206  }
207 
208  MCLOHType getKind() const { return Kind; }
209  LOHArgs getArgs() const { return Args; }
210  };
211 
214 
215  const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
216 
217  /// Add a LOH directive of this @p Kind and this @p Args.
219  LOHContainerSet.push_back(MILOHDirective(Kind, Args));
220  LOHRelated.insert(Args.begin(), Args.end());
221  }
222 
224  return ForwardedMustTailRegParms;
225  }
226 
227 private:
228  // Hold the lists of LOHs.
229  MILOHContainer LOHContainerSet;
230  SetOfInstructions LOHRelated;
231 
233 };
234 
235 } // end namespace llvm
236 
237 #endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
iterator begin() const
Definition: ArrayRef.h:136
unsigned Reg
unsigned getJumpTableEntrySize(int Idx) const
const SetOfInstructions & getLOHRelated() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.h:323
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
void setArgumentStackToRestore(unsigned bytes)
AArch64FunctionInfo(MachineFunction &MF)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym)
MCLOHType
Linker Optimization Hint Type.
SmallVectorImpl< ForwardedRegister > & getForwardedMustTailRegParms()
MCSymbol * getJumpTableEntryPCRelSymbol(int Idx) const
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
iterator end() const
Definition: ArrayRef.h:137
const Function & getFunction() const
Return the LLVM function that this machine code represents.
Optional< bool > hasRedZone() const
const MILOHContainer & getLOHContainer() const
static bool isValidMCLOHType(unsigned Kind)
uint32_t Size
Definition: Profile.cpp:46
void setBytesInStackArgArea(unsigned bytes)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void addLOHDirective(MCLOHType Kind, MILOHArgs Args)
Add a LOH directive of this Kind and this Args.
void setCalleeSavedStackSize(unsigned Size)