Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
Line
Count
Source
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"
20
#include "llvm/CodeGen/CallingConvLower.h"
21
#include "llvm/CodeGen/MachineFunction.h"
22
#include "llvm/MC/MCLinkerOptimizationHint.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.
31
class AArch64FunctionInfo final : public MachineFunctionInfo {
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
109
  // Offset from SP-at-entry to the tagged base pointer.
110
  // Tagged base pointer is set up to point to the first (lowest address) tagged
111
  // stack slot.
112
  unsigned TaggedBasePointerOffset;
113
114
public:
115
  AArch64FunctionInfo() = default;
116
117
257k
  explicit AArch64FunctionInfo(MachineFunction &MF) {
118
257k
    (void)MF;
119
257k
120
257k
    // If we already know that the function doesn't have a redzone, set
121
257k
    // HasRedZone here.
122
257k
    if (MF.getFunction().hasFnAttribute(Attribute::NoRedZone))
123
231
      HasRedZone = false;
124
257k
  }
125
126
52.7k
  unsigned getBytesInStackArgArea() const { return BytesInStackArgArea; }
127
37.3k
  void setBytesInStackArgArea(unsigned bytes) { BytesInStackArgArea = bytes; }
128
129
313k
  unsigned getArgumentStackToRestore() const { return ArgumentStackToRestore; }
130
21
  void setArgumentStackToRestore(unsigned bytes) {
131
21
    ArgumentStackToRestore = bytes;
132
21
  }
133
134
852k
  bool hasStackFrame() const { return HasStackFrame; }
135
198k
  void setHasStackFrame(bool s) { HasStackFrame = s; }
136
137
165k
  bool isStackRealigned() const { return StackRealigned; }
138
51
  void setStackRealigned(bool s) { StackRealigned = s; }
139
140
1.42M
  bool hasCalleeSaveStackFreeSpace() const {
141
1.42M
    return CalleeSaveStackHasFreeSpace;
142
1.42M
  }
143
279k
  void setCalleeSaveStackHasFreeSpace(bool s) {
144
279k
    CalleeSaveStackHasFreeSpace = s;
145
279k
  }
146
147
129
  bool isSplitCSR() const { return IsSplitCSR; }
148
8
  void setIsSplitCSR(bool s) { IsSplitCSR = s; }
149
150
257k
  void setLocalStackSize(unsigned Size) { LocalStackSize = Size; }
151
903k
  unsigned getLocalStackSize() const { return LocalStackSize; }
152
153
279k
  void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
154
1.76M
  unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
155
156
12
  void incNumLocalDynamicTLSAccesses() { ++NumLocalDynamicTLSAccesses; }
157
13.7k
  unsigned getNumLocalDynamicTLSAccesses() const {
158
13.7k
    return NumLocalDynamicTLSAccesses;
159
13.7k
  }
160
161
149
  Optional<bool> hasRedZone() const { return HasRedZone; }
162
257k
  void setHasRedZone(bool s) { HasRedZone = s; }
163
164
124
  int getVarArgsStackIndex() const { return VarArgsStackIndex; }
165
142
  void setVarArgsStackIndex(int Index) { VarArgsStackIndex = Index; }
166
167
17
  int getVarArgsGPRIndex() const { return VarArgsGPRIndex; }
168
28
  void setVarArgsGPRIndex(int Index) { VarArgsGPRIndex = Index; }
169
170
621
  unsigned getVarArgsGPRSize() const { return VarArgsGPRSize; }
171
28
  void setVarArgsGPRSize(unsigned Size) { VarArgsGPRSize = Size; }
172
173
5
  int getVarArgsFPRIndex() const { return VarArgsFPRIndex; }
174
8
  void setVarArgsFPRIndex(int Index) { VarArgsFPRIndex = Index; }
175
176
6
  unsigned getVarArgsFPRSize() const { return VarArgsFPRSize; }
177
8
  void setVarArgsFPRSize(unsigned Size) { VarArgsFPRSize = Size; }
178
179
36.9k
  unsigned getSRetReturnReg() const { return SRetReturnReg; }
180
3
  void setSRetReturnReg(unsigned Reg) { SRetReturnReg = Reg; }
181
182
38.6k
  unsigned getJumpTableEntrySize(int Idx) const {
183
38.6k
    auto It = JumpTableEntryInfo.find(Idx);
184
38.6k
    if (It != JumpTableEntryInfo.end())
185
38.4k
      return It->second.first;
186
159
    return 4;
187
159
  }
188
38.4k
  MCSymbol *getJumpTableEntryPCRelSymbol(int Idx) const {
189
38.4k
    return JumpTableEntryInfo.find(Idx)->second.second;
190
38.4k
  }
191
2.40k
  void setJumpTableEntryInfo(int Idx, unsigned Size, MCSymbol *PCRelSym) {
192
2.40k
    JumpTableEntryInfo[Idx] = std::make_pair(Size, PCRelSym);
193
2.40k
  }
194
195
  using SetOfInstructions = SmallPtrSet<const MachineInstr *, 16>;
196
197
14.8M
  const SetOfInstructions &getLOHRelated() const { return LOHRelated; }
198
199
  // Shortcuts for LOH related types.
200
  class MILOHDirective {
201
    MCLOHType Kind;
202
203
    /// Arguments of this directive. Order matters.
204
    SmallVector<const MachineInstr *, 3> Args;
205
206
  public:
207
    using LOHArgs = ArrayRef<const MachineInstr *>;
208
209
    MILOHDirective(MCLOHType Kind, LOHArgs Args)
210
636k
        : Kind(Kind), Args(Args.begin(), Args.end()) {
211
636k
      assert(isValidMCLOHType(Kind) && "Invalid LOH directive type!");
212
636k
    }
213
214
636k
    MCLOHType getKind() const { return Kind; }
215
636k
    LOHArgs getArgs() const { return Args; }
216
  };
217
218
  using MILOHArgs = MILOHDirective::LOHArgs;
219
  using MILOHContainer = SmallVector<MILOHDirective, 32>;
220
221
140k
  const MILOHContainer &getLOHContainer() const { return LOHContainerSet; }
222
223
  /// Add a LOH directive of this @p Kind and this @p Args.
224
636k
  void addLOHDirective(MCLOHType Kind, MILOHArgs Args) {
225
636k
    LOHContainerSet.push_back(MILOHDirective(Kind, Args));
226
636k
    LOHRelated.insert(Args.begin(), Args.end());
227
636k
  }
228
229
4
  SmallVectorImpl<ForwardedRegister> &getForwardedMustTailRegParms() {
230
4
    return ForwardedMustTailRegParms;
231
4
  }
232
233
12
  unsigned getTaggedBasePointerOffset() const {
234
12
    return TaggedBasePointerOffset;
235
12
  }
236
257k
  void setTaggedBasePointerOffset(unsigned Offset) {
237
257k
    TaggedBasePointerOffset = Offset;
238
257k
  }
239
240
private:
241
  // Hold the lists of LOHs.
242
  MILOHContainer LOHContainerSet;
243
  SetOfInstructions LOHRelated;
244
245
  DenseMap<int, std::pair<unsigned, MCSymbol *>> JumpTableEntryInfo;
246
};
247
248
} // end namespace llvm
249
250
#endif // LLVM_LIB_TARGET_AARCH64_AARCH64MACHINEFUNCTIONINFO_H