Coverage Report

Created: 2019-02-20 00:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/DIE.h
Line
Count
Source (jump to first uncovered line)
1
//===- lib/CodeGen/DIE.h - DWARF Info Entries -------------------*- 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
// Data structures for DWARF info entries.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
14
#define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
15
16
#include "llvm/ADT/FoldingSet.h"
17
#include "llvm/ADT/PointerIntPair.h"
18
#include "llvm/ADT/PointerUnion.h"
19
#include "llvm/ADT/SmallVector.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/ADT/iterator.h"
22
#include "llvm/ADT/iterator_range.h"
23
#include "llvm/BinaryFormat/Dwarf.h"
24
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
25
#include "llvm/Support/AlignOf.h"
26
#include "llvm/Support/Allocator.h"
27
#include <cassert>
28
#include <cstddef>
29
#include <cstdint>
30
#include <iterator>
31
#include <new>
32
#include <type_traits>
33
#include <utility>
34
#include <vector>
35
36
namespace llvm {
37
38
class AsmPrinter;
39
class DIE;
40
class DIEUnit;
41
class MCExpr;
42
class MCSection;
43
class MCSymbol;
44
class raw_ostream;
45
46
//===--------------------------------------------------------------------===//
47
/// Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
48
class DIEAbbrevData {
49
  /// Dwarf attribute code.
50
  dwarf::Attribute Attribute;
51
52
  /// Dwarf form code.
53
  dwarf::Form Form;
54
55
  /// Dwarf attribute value for DW_FORM_implicit_const
56
  int64_t Value = 0;
57
58
public:
59
  DIEAbbrevData(dwarf::Attribute A, dwarf::Form F)
60
1.70M
      : Attribute(A), Form(F) {}
61
  DIEAbbrevData(dwarf::Attribute A, int64_t V)
62
5
      : Attribute(A), Form(dwarf::DW_FORM_implicit_const), Value(V) {}
63
64
  /// Accessors.
65
  /// @{
66
183k
  dwarf::Attribute getAttribute() const { return Attribute; }
67
272k
  dwarf::Form getForm() const { return Form; }
68
4
  int64_t getValue() const { return Value; }
69
  /// @}
70
71
  /// Used to gather unique data for the abbreviation folding set.
72
  void Profile(FoldingSetNodeID &ID) const;
73
};
74
75
//===--------------------------------------------------------------------===//
76
/// Dwarf abbreviation, describes the organization of a debug information
77
/// object.
78
class DIEAbbrev : public FoldingSetNode {
79
  /// Unique number for node.
80
  unsigned Number;
81
82
  /// Dwarf tag code.
83
  dwarf::Tag Tag;
84
85
  /// Whether or not this node has children.
86
  ///
87
  /// This cheats a bit in all of the uses since the values in the standard
88
  /// are 0 and 1 for no children and children respectively.
89
  bool Children;
90
91
  /// Raw data bytes for abbreviation.
92
  SmallVector<DIEAbbrevData, 12> Data;
93
94
public:
95
410k
  DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C) {}
96
97
  /// Accessors.
98
  /// @{
99
  dwarf::Tag getTag() const { return Tag; }
100
411k
  unsigned getNumber() const { return Number; }
101
  bool hasChildren() const { return Children; }
102
  const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
103
  void setChildrenFlag(bool hasChild) { Children = hasChild; }
104
21.9k
  void setNumber(unsigned N) { Number = N; }
105
  /// @}
106
107
  /// Adds another set of attribute information to the abbreviation.
108
1.70M
  void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
109
1.70M
    Data.push_back(DIEAbbrevData(Attribute, Form));
110
1.70M
  }
111
112
  /// Adds attribute with DW_FORM_implicit_const value
113
5
  void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value) {
114
5
    Data.push_back(DIEAbbrevData(Attribute, Value));
115
5
  }
116
117
  /// Used to gather unique data for the abbreviation folding set.
118
  void Profile(FoldingSetNodeID &ID) const;
119
120
  /// Print the abbreviation using the specified asm printer.
121
  void Emit(const AsmPrinter *AP) const;
122
123
  void print(raw_ostream &O) const;
124
  void dump() const;
125
};
126
127
//===--------------------------------------------------------------------===//
128
/// Helps unique DIEAbbrev objects and assigns abbreviation numbers.
129
///
130
/// This class will unique the DIE abbreviations for a llvm::DIE object and
131
/// assign a unique abbreviation number to each unique DIEAbbrev object it
132
/// finds. The resulting collection of DIEAbbrev objects can then be emitted
133
/// into the .debug_abbrev section.
134
class DIEAbbrevSet {
135
  /// The bump allocator to use when creating DIEAbbrev objects in the uniqued
136
  /// storage container.
137
  BumpPtrAllocator &Alloc;
138
  /// FoldingSet that uniques the abbreviations.
139
  FoldingSet<DIEAbbrev> AbbreviationsSet;
140
  /// A list of all the unique abbreviations in use.
141
  std::vector<DIEAbbrev *> Abbreviations;
142
143
public:
144
67.5k
  DIEAbbrevSet(BumpPtrAllocator &A) : Alloc(A) {}
145
  ~DIEAbbrevSet();
146
147
  /// Generate the abbreviation declaration for a DIE and return a pointer to
148
  /// the generated abbreviation.
149
  ///
150
  /// \param Die the debug info entry to generate the abbreviation for.
151
  /// \returns A reference to the uniqued abbreviation declaration that is
152
  /// owned by this class.
153
  DIEAbbrev &uniqueAbbreviation(DIE &Die);
154
155
  /// Print all abbreviations using the specified asm printer.
156
  void Emit(const AsmPrinter *AP, MCSection *Section) const;
157
};
158
159
//===--------------------------------------------------------------------===//
160
/// An integer value DIE.
161
///
162
class DIEInteger {
163
  uint64_t Integer;
164
165
public:
166
843k
  explicit DIEInteger(uint64_t I) : Integer(I) {}
167
168
  /// Choose the best form for integer.
169
625k
  static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
170
625k
    if (IsSigned) {
171
0
      const int64_t SignedInt = Int;
172
0
      if ((char)Int == SignedInt)
173
0
        return dwarf::DW_FORM_data1;
174
0
      if ((short)Int == SignedInt)
175
0
        return dwarf::DW_FORM_data2;
176
0
      if ((int)Int == SignedInt)
177
0
        return dwarf::DW_FORM_data4;
178
625k
    } else {
179
625k
      if ((unsigned char)Int == Int)
180
485k
        return dwarf::DW_FORM_data1;
181
140k
      if ((unsigned short)Int == Int)
182
140k
        return dwarf::DW_FORM_data2;
183
4
      if ((unsigned int)Int == Int)
184
0
        return dwarf::DW_FORM_data4;
185
4
    }
186
4
    return dwarf::DW_FORM_data8;
187
4
  }
188
189
305
  uint64_t getValue() const { return Integer; }
190
  void setValue(uint64_t Val) { Integer = Val; }
191
192
  void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
193
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
194
195
  void print(raw_ostream &O) const;
196
};
197
198
//===--------------------------------------------------------------------===//
199
/// An expression DIE.
200
class DIEExpr {
201
  const MCExpr *Expr;
202
203
public:
204
33
  explicit DIEExpr(const MCExpr *E) : Expr(E) {}
205
206
  /// Get MCExpr.
207
  const MCExpr *getValue() const { return Expr; }
208
209
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
210
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
211
212
  void print(raw_ostream &O) const;
213
};
214
215
//===--------------------------------------------------------------------===//
216
/// A label DIE.
217
class DIELabel {
218
  const MCSymbol *Label;
219
220
public:
221
581k
  explicit DIELabel(const MCSymbol *L) : Label(L) {}
222
223
  /// Get MCSymbol.
224
  const MCSymbol *getValue() const { return Label; }
225
226
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
227
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
228
229
  void print(raw_ostream &O) const;
230
};
231
232
//===--------------------------------------------------------------------===//
233
/// A simple label difference DIE.
234
///
235
class DIEDelta {
236
  const MCSymbol *LabelHi;
237
  const MCSymbol *LabelLo;
238
239
public:
240
60.1k
  DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) : LabelHi(Hi), LabelLo(Lo) {}
241
242
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
243
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
244
245
  void print(raw_ostream &O) const;
246
};
247
248
//===--------------------------------------------------------------------===//
249
/// A container for string pool string values.
250
///
251
/// This class is used with the DW_FORM_strp and DW_FORM_GNU_str_index forms.
252
class DIEString {
253
  DwarfStringPoolEntryRef S;
254
255
public:
256
99.8k
  DIEString(DwarfStringPoolEntryRef S) : S(S) {}
257
258
  /// Grab the string out of the object.
259
315
  StringRef getString() const { return S.getString(); }
260
261
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
262
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
263
264
  void print(raw_ostream &O) const;
265
};
266
267
//===--------------------------------------------------------------------===//
268
/// A container for inline string values.
269
///
270
/// This class is used with the DW_FORM_string form.
271
class DIEInlineString {
272
  StringRef S;
273
274
public:
275
  template <typename Allocator>
276
490
  explicit DIEInlineString(StringRef Str, Allocator &A) : S(Str.copy(A)) {}
277
278
  ~DIEInlineString() = default;
279
280
  /// Grab the string out of the object.
281
0
  StringRef getString() const { return S; }
282
283
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
284
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
285
286
  void print(raw_ostream &O) const;
287
};
288
289
//===--------------------------------------------------------------------===//
290
/// A pointer to another debug information entry.  An instance of this class can
291
/// also be used as a proxy for a debug information entry not yet defined
292
/// (ie. types.)
293
class DIEEntry {
294
  DIE *Entry;
295
296
public:
297
  DIEEntry() = delete;
298
317k
  explicit DIEEntry(DIE &E) : Entry(&E) {}
299
300
316k
  DIE &getEntry() const { return *Entry; }
301
302
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
303
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
304
305
  void print(raw_ostream &O) const;
306
};
307
308
//===--------------------------------------------------------------------===//
309
/// Represents a pointer to a location list in the debug_loc
310
/// section.
311
class DIELocList {
312
  /// Index into the .debug_loc vector.
313
  size_t Index;
314
315
public:
316
348
  DIELocList(size_t I) : Index(I) {}
317
318
  /// Grab the current index out.
319
3
  size_t getValue() const { return Index; }
320
321
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
322
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
323
324
  void print(raw_ostream &O) const;
325
};
326
327
//===--------------------------------------------------------------------===//
328
/// A debug information entry value. Some of these roughly correlate
329
/// to DWARF attribute classes.
330
class DIEBlock;
331
class DIELoc;
332
class DIEValue {
333
public:
334
  enum Type {
335
    isNone,
336
#define HANDLE_DIEVALUE(T) is##T,
337
#include "llvm/CodeGen/DIEValue.def"
338
  };
339
340
private:
341
  /// Type of data stored in the value.
342
  Type Ty = isNone;
343
  dwarf::Attribute Attribute = (dwarf::Attribute)0;
344
  dwarf::Form Form = (dwarf::Form)0;
345
346
  /// Storage for the value.
347
  ///
348
  /// All values that aren't standard layout (or are larger than 8 bytes)
349
  /// should be stored by reference instead of by value.
350
  using ValTy = AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
351
                                      DIEDelta *, DIEEntry, DIEBlock *,
352
                                      DIELoc *, DIELocList>;
353
354
  static_assert(sizeof(ValTy) <= sizeof(uint64_t) ||
355
                    sizeof(ValTy) <= sizeof(void *),
356
                "Expected all large types to be stored via pointer");
357
358
  /// Underlying stored value.
359
  ValTy Val;
360
361
5.11M
  template <class T> void construct(T V) {
362
5.11M
    static_assert(std::is_standard_layout<T>::value ||
363
5.11M
                      std::is_pointer<T>::value,
364
5.11M
                  "Expected standard layout or pointer");
365
5.11M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
5.11M
  }
void llvm::DIEValue::construct<llvm::DIEInteger>(llvm::DIEInteger)
Line
Count
Source
361
1.95M
  template <class T> void construct(T V) {
362
1.95M
    static_assert(std::is_standard_layout<T>::value ||
363
1.95M
                      std::is_pointer<T>::value,
364
1.95M
                  "Expected standard layout or pointer");
365
1.95M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
1.95M
  }
void llvm::DIEValue::construct<llvm::DIEString>(llvm::DIEString)
Line
Count
Source
361
299k
  template <class T> void construct(T V) {
362
299k
    static_assert(std::is_standard_layout<T>::value ||
363
299k
                      std::is_pointer<T>::value,
364
299k
                  "Expected standard layout or pointer");
365
299k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
299k
  }
void llvm::DIEValue::construct<llvm::DIEExpr>(llvm::DIEExpr)
Line
Count
Source
361
99
  template <class T> void construct(T V) {
362
99
    static_assert(std::is_standard_layout<T>::value ||
363
99
                      std::is_pointer<T>::value,
364
99
                  "Expected standard layout or pointer");
365
99
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
99
  }
void llvm::DIEValue::construct<llvm::DIELabel>(llvm::DIELabel)
Line
Count
Source
361
1.72M
  template <class T> void construct(T V) {
362
1.72M
    static_assert(std::is_standard_layout<T>::value ||
363
1.72M
                      std::is_pointer<T>::value,
364
1.72M
                  "Expected standard layout or pointer");
365
1.72M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
1.72M
  }
void llvm::DIEValue::construct<llvm::DIEDelta const*>(llvm::DIEDelta const*)
Line
Count
Source
361
180k
  template <class T> void construct(T V) {
362
180k
    static_assert(std::is_standard_layout<T>::value ||
363
180k
                      std::is_pointer<T>::value,
364
180k
                  "Expected standard layout or pointer");
365
180k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
180k
  }
void llvm::DIEValue::construct<llvm::DIEEntry>(llvm::DIEEntry)
Line
Count
Source
361
952k
  template <class T> void construct(T V) {
362
952k
    static_assert(std::is_standard_layout<T>::value ||
363
952k
                      std::is_pointer<T>::value,
364
952k
                  "Expected standard layout or pointer");
365
952k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
952k
  }
void llvm::DIEValue::construct<llvm::DIEBlock const*>(llvm::DIEBlock const*)
Line
Count
Source
361
2.60k
  template <class T> void construct(T V) {
362
2.60k
    static_assert(std::is_standard_layout<T>::value ||
363
2.60k
                      std::is_pointer<T>::value,
364
2.60k
                  "Expected standard layout or pointer");
365
2.60k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
2.60k
  }
void llvm::DIEValue::construct<llvm::DIELoc const*>(llvm::DIELoc const*)
Line
Count
Source
361
7.51k
  template <class T> void construct(T V) {
362
7.51k
    static_assert(std::is_standard_layout<T>::value ||
363
7.51k
                      std::is_pointer<T>::value,
364
7.51k
                  "Expected standard layout or pointer");
365
7.51k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
7.51k
  }
void llvm::DIEValue::construct<llvm::DIELocList>(llvm::DIELocList)
Line
Count
Source
361
1.04k
  template <class T> void construct(T V) {
362
1.04k
    static_assert(std::is_standard_layout<T>::value ||
363
1.04k
                      std::is_pointer<T>::value,
364
1.04k
                  "Expected standard layout or pointer");
365
1.04k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
1.04k
  }
void llvm::DIEValue::construct<llvm::DIEInlineString const*>(llvm::DIEInlineString const*)
Line
Count
Source
361
1.47k
  template <class T> void construct(T V) {
362
1.47k
    static_assert(std::is_standard_layout<T>::value ||
363
1.47k
                      std::is_pointer<T>::value,
364
1.47k
                  "Expected standard layout or pointer");
365
1.47k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
366
1.47k
  }
367
368
3.41M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEInteger* llvm::DIEValue::get<llvm::DIEInteger>()
Line
Count
Source
368
1.30M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEString* llvm::DIEValue::get<llvm::DIEString>()
Line
Count
Source
368
199k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEExpr* llvm::DIEValue::get<llvm::DIEExpr>()
Line
Count
Source
368
66
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELabel* llvm::DIEValue::get<llvm::DIELabel>()
Line
Count
Source
368
1.14M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEDelta const** llvm::DIEValue::get<llvm::DIEDelta const*>()
Line
Count
Source
368
120k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEEntry* llvm::DIEValue::get<llvm::DIEEntry>()
Line
Count
Source
368
634k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEBlock const** llvm::DIEValue::get<llvm::DIEBlock const*>()
Line
Count
Source
368
1.94k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELoc const** llvm::DIEValue::get<llvm::DIELoc const*>()
Line
Count
Source
368
5.05k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELocList* llvm::DIEValue::get<llvm::DIELocList>()
Line
Count
Source
368
699
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEInlineString const** llvm::DIEValue::get<llvm::DIEInlineString const*>()
Line
Count
Source
368
980
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
369
6.81M
  template <class T> const T *get() const {
370
6.81M
    return reinterpret_cast<const T *>(Val.buffer);
371
6.81M
  }
llvm::DIEInteger const* llvm::DIEValue::get<llvm::DIEInteger>() const
Line
Count
Source
369
2.59M
  template <class T> const T *get() const {
370
2.59M
    return reinterpret_cast<const T *>(Val.buffer);
371
2.59M
  }
llvm::DIEString const* llvm::DIEValue::get<llvm::DIEString>() const
Line
Count
Source
369
399k
  template <class T> const T *get() const {
370
399k
    return reinterpret_cast<const T *>(Val.buffer);
371
399k
  }
llvm::DIEExpr const* llvm::DIEValue::get<llvm::DIEExpr>() const
Line
Count
Source
369
132
  template <class T> const T *get() const {
370
132
    return reinterpret_cast<const T *>(Val.buffer);
371
132
  }
llvm::DIELabel const* llvm::DIEValue::get<llvm::DIELabel>() const
Line
Count
Source
369
2.29M
  template <class T> const T *get() const {
370
2.29M
    return reinterpret_cast<const T *>(Val.buffer);
371
2.29M
  }
llvm::DIEDelta const* const* llvm::DIEValue::get<llvm::DIEDelta const*>() const
Line
Count
Source
369
240k
  template <class T> const T *get() const {
370
240k
    return reinterpret_cast<const T *>(Val.buffer);
371
240k
  }
llvm::DIEEntry const* llvm::DIEValue::get<llvm::DIEEntry>() const
Line
Count
Source
369
1.26M
  template <class T> const T *get() const {
370
1.26M
    return reinterpret_cast<const T *>(Val.buffer);
371
1.26M
  }
llvm::DIEBlock const* const* llvm::DIEValue::get<llvm::DIEBlock const*>() const
Line
Count
Source
369
2.64k
  template <class T> const T *get() const {
370
2.64k
    return reinterpret_cast<const T *>(Val.buffer);
371
2.64k
  }
llvm::DIELoc const* const* llvm::DIEValue::get<llvm::DIELoc const*>() const
Line
Count
Source
369
9.96k
  template <class T> const T *get() const {
370
9.96k
    return reinterpret_cast<const T *>(Val.buffer);
371
9.96k
  }
llvm::DIELocList const* llvm::DIEValue::get<llvm::DIELocList>() const
Line
Count
Source
369
1.39k
  template <class T> const T *get() const {
370
1.39k
    return reinterpret_cast<const T *>(Val.buffer);
371
1.39k
  }
llvm::DIEInlineString const* const* llvm::DIEValue::get<llvm::DIEInlineString const*>() const
Line
Count
Source
369
1.96k
  template <class T> const T *get() const {
370
1.96k
    return reinterpret_cast<const T *>(Val.buffer);
371
1.96k
  }
372
3.41M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEInteger>()
Line
Count
Source
372
1.30M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEString>()
Line
Count
Source
372
199k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEExpr>()
Line
Count
Source
372
66
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELabel>()
Line
Count
Source
372
1.14M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEDelta const*>()
Line
Count
Source
372
120k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEEntry>()
Line
Count
Source
372
634k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEBlock const*>()
Line
Count
Source
372
1.94k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELoc const*>()
Line
Count
Source
372
5.05k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELocList>()
Line
Count
Source
372
699
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEInlineString const*>()
Line
Count
Source
372
980
  template <class T> void destruct() { get<T>()->~T(); }
373
374
  /// Destroy the underlying value.
375
  ///
376
  /// This should get optimized down to a no-op.  We could skip it if we could
377
  /// add a static assert on \a std::is_trivially_copyable(), but we currently
378
  /// support versions of GCC that don't understand that.
379
3.56M
  void destroyVal() {
380
3.56M
    switch (Ty) {
381
3.56M
    case isNone:
382
150k
      return;
383
3.56M
#define HANDLE_DIEVALUE_SMALL(T)                                               \
384
3.56M
  case is##T:                                                                  \
385
3.28M
    destruct<DIE##T>();                                                        \
386
3.28M
    return;
387
3.56M
#define HANDLE_DIEVALUE_LARGE(T)                                               \
388
3.56M
  case is##T:                                                                  \
389
128k
    destruct<const DIE##T *>();                                                \
390
128k
    return;
391
3.56M
#include 
"llvm/CodeGen/DIEValue.def"1.30M
392
3.56M
    }
393
3.56M
  }
394
395
  /// Copy the underlying value.
396
  ///
397
  /// This should get optimized down to a simple copy.  We need to actually
398
  /// construct the value, rather than calling memcpy, to satisfy strict
399
  /// aliasing rules.
400
3.41M
  void copyVal(const DIEValue &X) {
401
3.41M
    switch (Ty) {
402
3.41M
    case isNone:
403
0
      return;
404
3.41M
#define HANDLE_DIEVALUE_SMALL(T)                                               \
405
3.41M
  case is##T:                                                                  \
406
3.28M
    construct<DIE##T>(*X.get<DIE##T>());                                       \
407
3.28M
    return;
408
3.41M
#define HANDLE_DIEVALUE_LARGE(T)                                               \
409
3.41M
  case is##T:                                                                  \
410
128k
    construct<const DIE##T *>(*X.get<const DIE##T *>());                       \
411
128k
    return;
412
3.41M
#include 
"llvm/CodeGen/DIEValue.def"1.30M
413
3.41M
    }
414
3.41M
  }
415
416
public:
417
150k
  DIEValue() = default;
418
419
3.41M
  DIEValue(const DIEValue &X) : Ty(X.Ty), Attribute(X.Attribute), Form(X.Form) {
420
3.41M
    copyVal(X);
421
3.41M
  }
422
423
1.49k
  DIEValue &operator=(const DIEValue &X) {
424
1.49k
    destroyVal();
425
1.49k
    Ty = X.Ty;
426
1.49k
    Attribute = X.Attribute;
427
1.49k
    Form = X.Form;
428
1.49k
    copyVal(X);
429
1.49k
    return *this;
430
1.49k
  }
431
432
3.56M
  ~DIEValue() { destroyVal(); }
433
434
#define HANDLE_DIEVALUE_SMALL(T)                                               \
435
  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V)      \
436
1.64M
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
1.64M
    construct<DIE##T>(V);                                                      \
438
1.64M
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInteger const&)
Line
Count
Source
436
651k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
651k
    construct<DIE##T>(V);                                                      \
438
651k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELabel const&)
Line
Count
Source
436
573k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
573k
    construct<DIE##T>(V);                                                      \
438
573k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELocList const&)
Line
Count
Source
436
348
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
348
    construct<DIE##T>(V);                                                      \
438
348
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEExpr const&)
Line
Count
Source
436
33
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
33
    construct<DIE##T>(V);                                                      \
438
33
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEString const&)
Line
Count
Source
436
99.8k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
99.8k
    construct<DIE##T>(V);                                                      \
438
99.8k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEEntry const&)
Line
Count
Source
436
317k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
437
317k
    construct<DIE##T>(V);                                                      \
438
317k
  }
439
#define HANDLE_DIEVALUE_LARGE(T)                                               \
440
  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V)      \
441
63.7k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
442
63.7k
    assert(V && "Expected valid value");                                       \
443
63.7k
    construct<const DIE##T *>(V);                                              \
444
63.7k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInlineString const*)
Line
Count
Source
441
490
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
442
490
    assert(V && "Expected valid value");                                       \
443
490
    construct<const DIE##T *>(V);                                              \
444
490
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEDelta const*)
Line
Count
Source
441
60.1k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
442
60.1k
    assert(V && "Expected valid value");                                       \
443
60.1k
    construct<const DIE##T *>(V);                                              \
444
60.1k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELoc const*)
Line
Count
Source
441
2.46k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
442
2.46k
    assert(V && "Expected valid value");                                       \
443
2.46k
    construct<const DIE##T *>(V);                                              \
444
2.46k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEBlock const*)
Line
Count
Source
441
661
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
442
661
    assert(V && "Expected valid value");                                       \
443
661
    construct<const DIE##T *>(V);                                              \
444
661
  }
445
#include "llvm/CodeGen/DIEValue.def"
446
447
  /// Accessors.
448
  /// @{
449
570
  Type getType() const { return Ty; }
450
3.64M
  dwarf::Attribute getAttribute() const { return Attribute; }
451
3.39M
  dwarf::Form getForm() const { return Form; }
452
149k
  explicit operator bool() const { return Ty; }
453
  /// @}
454
455
#define HANDLE_DIEVALUE_SMALL(T)                                               \
456
3.27M
  const DIE##T &getDIE##T() const {                                            \
457
3.27M
    assert(getType() == is##T && "Expected " #T);                              \
458
3.27M
    return *get<DIE##T>();                                                     \
459
3.27M
  }
llvm::DIEValue::getDIEInteger() const
Line
Count
Source
456
1.29M
  const DIE##T &getDIE##T() const {                                            \
457
1.29M
    assert(getType() == is##T && "Expected " #T);                              \
458
1.29M
    return *get<DIE##T>();                                                     \
459
1.29M
  }
llvm::DIEValue::getDIEString() const
Line
Count
Source
456
199k
  const DIE##T &getDIE##T() const {                                            \
457
199k
    assert(getType() == is##T && "Expected " #T);                              \
458
199k
    return *get<DIE##T>();                                                     \
459
199k
  }
llvm::DIEValue::getDIEExpr() const
Line
Count
Source
456
66
  const DIE##T &getDIE##T() const {                                            \
457
66
    assert(getType() == is##T && "Expected " #T);                              \
458
66
    return *get<DIE##T>();                                                     \
459
66
  }
llvm::DIEValue::getDIELabel() const
Line
Count
Source
456
1.14M
  const DIE##T &getDIE##T() const {                                            \
457
1.14M
    assert(getType() == is##T && "Expected " #T);                              \
458
1.14M
    return *get<DIE##T>();                                                     \
459
1.14M
  }
llvm::DIEValue::getDIEEntry() const
Line
Count
Source
456
633k
  const DIE##T &getDIE##T() const {                                            \
457
633k
    assert(getType() == is##T && "Expected " #T);                              \
458
633k
    return *get<DIE##T>();                                                     \
459
633k
  }
llvm::DIEValue::getDIELocList() const
Line
Count
Source
456
699
  const DIE##T &getDIE##T() const {                                            \
457
699
    assert(getType() == is##T && "Expected " #T);                              \
458
699
    return *get<DIE##T>();                                                     \
459
699
  }
460
#define HANDLE_DIEVALUE_LARGE(T)                                               \
461
126k
  const DIE##T &getDIE##T() const {                                            \
462
126k
    assert(getType() == is##T && "Expected " #T);                              \
463
126k
    return **get<const DIE##T *>();                                            \
464
126k
  }
llvm::DIEValue::getDIEDelta() const
Line
Count
Source
461
120k
  const DIE##T &getDIE##T() const {                                            \
462
120k
    assert(getType() == is##T && "Expected " #T);                              \
463
120k
    return **get<const DIE##T *>();                                            \
464
120k
  }
llvm::DIEValue::getDIEBlock() const
Line
Count
Source
461
697
  const DIE##T &getDIE##T() const {                                            \
462
697
    assert(getType() == is##T && "Expected " #T);                              \
463
697
    return **get<const DIE##T *>();                                            \
464
697
  }
llvm::DIEValue::getDIELoc() const
Line
Count
Source
461
4.91k
  const DIE##T &getDIE##T() const {                                            \
462
4.91k
    assert(getType() == is##T && "Expected " #T);                              \
463
4.91k
    return **get<const DIE##T *>();                                            \
464
4.91k
  }
llvm::DIEValue::getDIEInlineString() const
Line
Count
Source
461
980
  const DIE##T &getDIE##T() const {                                            \
462
980
    assert(getType() == is##T && "Expected " #T);                              \
463
980
    return **get<const DIE##T *>();                                            \
464
980
  }
465
#include "llvm/CodeGen/DIEValue.def"
466
467
  /// Emit value via the Dwarf writer.
468
  void EmitValue(const AsmPrinter *AP) const;
469
470
  /// Return the size of a value in bytes.
471
  unsigned SizeOf(const AsmPrinter *AP) const;
472
473
  void print(raw_ostream &O) const;
474
  void dump() const;
475
};
476
477
struct IntrusiveBackListNode {
478
  PointerIntPair<IntrusiveBackListNode *, 1> Next;
479
480
2.11M
  IntrusiveBackListNode() : Next(this, true) {}
481
482
6.16M
  IntrusiveBackListNode *getNext() const {
483
6.16M
    return Next.getInt() ? 
nullptr1.74M
:
Next.getPointer()4.42M
;
484
6.16M
  }
485
};
486
487
struct IntrusiveBackListBase {
488
  using Node = IntrusiveBackListNode;
489
490
  Node *Last = nullptr;
491
492
1.22M
  bool empty() const { return !Last; }
493
494
2.11M
  void push_back(Node &N) {
495
2.11M
    assert(N.Next.getPointer() == &N && "Expected unlinked node");
496
2.11M
    assert(N.Next.getInt() == true && "Expected unlinked node");
497
2.11M
498
2.11M
    if (Last) {
499
1.51M
      N.Next = Last->Next;
500
1.51M
      Last->Next.setPointerAndInt(&N, false);
501
1.51M
    }
502
2.11M
    Last = &N;
503
2.11M
  }
504
};
505
506
template <class T> class IntrusiveBackList : IntrusiveBackListBase {
507
public:
508
  using IntrusiveBackListBase::empty;
509
510
2.11M
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::push_back(llvm::DIEValueList::Node&)
Line
Count
Source
510
1.70M
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
llvm::IntrusiveBackList<llvm::DIE>::push_back(llvm::DIE&)
Line
Count
Source
510
406k
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
511
2.11M
  T &back() { return *static_cast<T *>(Last); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::back()
Line
Count
Source
511
1.70M
  T &back() { return *static_cast<T *>(Last); }
llvm::IntrusiveBackList<llvm::DIE>::back()
Line
Count
Source
511
406k
  T &back() { return *static_cast<T *>(Last); }
512
  const T &back() const { return *static_cast<T *>(Last); }
513
514
  class const_iterator;
515
  class iterator
516
      : public iterator_facade_base<iterator, std::forward_iterator_tag, T> {
517
    friend class const_iterator;
518
519
    Node *N = nullptr;
520
521
  public:
522
603k
    iterator() = default;
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::iterator()
Line
Count
Source
522
416k
    iterator() = default;
llvm::IntrusiveBackList<llvm::DIE>::iterator::iterator()
Line
Count
Source
522
187k
    iterator() = default;
523
3.45M
    explicit iterator(T *N) : N(N) {}
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::iterator(llvm::DIEValueList::Node*)
Line
Count
Source
523
3.08M
    explicit iterator(T *N) : N(N) {}
llvm::IntrusiveBackList<llvm::DIE>::iterator::iterator(llvm::DIE*)
Line
Count
Source
523
374k
    explicit iterator(T *N) : N(N) {}
524
525
2.09M
    iterator &operator++() {
526
2.09M
      N = N->getNext();
527
2.09M
      return *this;
528
2.09M
    }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator++()
Line
Count
Source
525
1.69M
    iterator &operator++() {
526
1.69M
      N = N->getNext();
527
1.69M
      return *this;
528
1.69M
    }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator++()
Line
Count
Source
525
405k
    iterator &operator++() {
526
405k
      N = N->getNext();
527
405k
      return *this;
528
405k
    }
529
530
0
    explicit operator bool() const { return N; }
531
2.09M
    T &operator*() const { return *static_cast<T *>(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator*() const
Line
Count
Source
531
1.69M
    T &operator*() const { return *static_cast<T *>(N); }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator*() const
Line
Count
Source
531
405k
    T &operator*() const { return *static_cast<T *>(N); }
532
533
2.10M
    bool operator==(const iterator &X) const { return N == X.N; }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator==(llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator const&) const
Line
Count
Source
533
2.10M
    bool operator==(const iterator &X) const { return N == X.N; }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator==(llvm::IntrusiveBackList<llvm::DIE>::iterator const&) const
Line
Count
Source
533
92
    bool operator==(const iterator &X) const { return N == X.N; }
534
591k
    bool operator!=(const iterator &X) const { return N != X.N; }
535
  };
536
537
  class const_iterator
538
      : public iterator_facade_base<const_iterator, std::forward_iterator_tag,
539
                                    const T> {
540
    const Node *N = nullptr;
541
542
  public:
543
1.14M
    const_iterator() = default;
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::const_iterator()
Line
Count
Source
543
961k
    const_iterator() = default;
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::const_iterator()
Line
Count
Source
543
187k
    const_iterator() = default;
544
    // Placate MSVC by explicitly scoping 'iterator'.
545
1.14M
    const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {}
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::const_iterator(llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator)
Line
Count
Source
545
961k
    const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {}
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::const_iterator(llvm::IntrusiveBackList<llvm::DIE>::iterator)
Line
Count
Source
545
187k
    const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {}
546
    explicit const_iterator(const T *N) : N(N) {}
547
548
4.06M
    const_iterator &operator++() {
549
4.06M
      N = N->getNext();
550
4.06M
      return *this;
551
4.06M
    }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::operator++()
Line
Count
Source
548
3.66M
    const_iterator &operator++() {
549
3.66M
      N = N->getNext();
550
3.66M
      return *this;
551
3.66M
    }
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::operator++()
Line
Count
Source
548
406k
    const_iterator &operator++() {
549
406k
      N = N->getNext();
550
406k
      return *this;
551
406k
    }
552
553
0
    explicit operator bool() const { return N; }
554
4.06M
    const T &operator*() const { return *static_cast<const T *>(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::operator*() const
Line
Count
Source
554
3.66M
    const T &operator*() const { return *static_cast<const T *>(N); }
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::operator*() const
Line
Count
Source
554
406k
    const T &operator*() const { return *static_cast<const T *>(N); }
555
556
4.62M
    bool operator==(const const_iterator &X) const { return N == X.N; }
557
594k
    bool operator!=(const const_iterator &X) const { return N != X.N; }
558
  };
559
560
1.74M
  iterator begin() {
561
1.74M
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))1.74M
:
end()538
;
562
1.74M
  }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::begin()
Line
Count
Source
560
1.37M
  iterator begin() {
561
1.37M
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))1.37M
:
end()360
;
562
1.37M
  }
llvm::IntrusiveBackList<llvm::DIE>::begin()
Line
Count
Source
560
374k
  iterator begin() {
561
374k
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))374k
:
end()178
;
562
374k
  }
563
1.14M
  const_iterator begin() const {
564
1.14M
    return const_cast<IntrusiveBackList *>(this)->begin();
565
1.14M
  }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::begin() const
Line
Count
Source
563
961k
  const_iterator begin() const {
564
961k
    return const_cast<IntrusiveBackList *>(this)->begin();
565
961k
  }
llvm::IntrusiveBackList<llvm::DIE>::begin() const
Line
Count
Source
563
187k
  const_iterator begin() const {
564
187k
    return const_cast<IntrusiveBackList *>(this)->begin();
565
187k
  }
566
600k
  iterator end() { return iterator(); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::end()
Line
Count
Source
566
413k
  iterator end() { return iterator(); }
llvm::IntrusiveBackList<llvm::DIE>::end()
Line
Count
Source
566
187k
  iterator end() { return iterator(); }
567
1.14M
  const_iterator end() const { return const_iterator(); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::end() const
Line
Count
Source
567
961k
  const_iterator end() const { return const_iterator(); }
llvm::IntrusiveBackList<llvm::DIE>::end() const
Line
Count
Source
567
187k
  const_iterator end() const { return const_iterator(); }
568
569
1.70M
  static iterator toIterator(T &N) { return iterator(&N); }
570
  static const_iterator toIterator(const T &N) { return const_iterator(&N); }
571
};
572
573
/// A list of DIE values.
574
///
575
/// This is a singly-linked list, but instead of reversing the order of
576
/// insertion, we keep a pointer to the back of the list so we can push in
577
/// order.
578
///
579
/// There are two main reasons to choose a linked list over a customized
580
/// vector-like data structure.
581
///
582
///  1. For teardown efficiency, we want DIEs to be BumpPtrAllocated.  Using a
583
///     linked list here makes this way easier to accomplish.
584
///  2. Carrying an extra pointer per \a DIEValue isn't expensive.  45% of DIEs
585
///     have 2 or fewer values, and 90% have 5 or fewer.  A vector would be
586
///     over-allocated by 50% on average anyway, the same cost as the
587
///     linked-list node.
588
class DIEValueList {
589
  struct Node : IntrusiveBackListNode {
590
    DIEValue V;
591
592
1.70M
    explicit Node(DIEValue V) : V(V) {}
593
  };
594
595
  using ListTy = IntrusiveBackList<Node>;
596
597
  ListTy List;
598
599
public:
600
  class const_value_iterator;
601
  class value_iterator
602
      : public iterator_adaptor_base<value_iterator, ListTy::iterator,
603
                                     std::forward_iterator_tag, DIEValue> {
604
    friend class const_value_iterator;
605
606
    using iterator_adaptor =
607
        iterator_adaptor_base<value_iterator, ListTy::iterator,
608
                              std::forward_iterator_tag, DIEValue>;
609
610
  public:
611
2.68k
    value_iterator() = default;
612
2.53M
    explicit value_iterator(ListTy::iterator X) : iterator_adaptor(X) {}
613
614
0
    explicit operator bool() const { return bool(wrapped()); }
615
1.69M
    DIEValue &operator*() const { return wrapped()->V; }
616
  };
617
618
  class const_value_iterator : public iterator_adaptor_base<
619
                                   const_value_iterator, ListTy::const_iterator,
620
                                   std::forward_iterator_tag, const DIEValue> {
621
    using iterator_adaptor =
622
        iterator_adaptor_base<const_value_iterator, ListTy::const_iterator,
623
                              std::forward_iterator_tag, const DIEValue>;
624
625
  public:
626
    const_value_iterator() = default;
627
    const_value_iterator(DIEValueList::value_iterator X)
628
        : iterator_adaptor(X.wrapped()) {}
629
    explicit const_value_iterator(ListTy::const_iterator X)
630
1.92M
        : iterator_adaptor(X) {}
631
632
0
    explicit operator bool() const { return bool(wrapped()); }
633
3.66M
    const DIEValue &operator*() const { return wrapped()->V; }
634
  };
635
636
  using value_range = iterator_range<value_iterator>;
637
  using const_value_range = iterator_range<const_value_iterator>;
638
639
1.70M
  value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V) {
640
1.70M
    List.push_back(*new (Alloc) Node(V));
641
1.70M
    return value_iterator(ListTy::toIterator(List.back()));
642
1.70M
  }
643
  template <class T>
644
  value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute,
645
1.70M
                    dwarf::Form Form, T &&Value) {
646
1.70M
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
1.70M
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEInteger>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInteger&&)
Line
Count
Source
645
650k
                    dwarf::Form Form, T &&Value) {
646
650k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
650k
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIELabel>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELabel&&)
Line
Count
Source
645
573k
                    dwarf::Form Form, T &&Value) {
646
573k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
573k
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIELocList>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELocList&&)
Line
Count
Source
645
348
                    dwarf::Form Form, T &&Value) {
646
348
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
348
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEExpr>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEExpr&&)
Line
Count
Source
645
33
                    dwarf::Form Form, T &&Value) {
646
33
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
33
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEInlineString*>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInlineString*&&)
Line
Count
Source
645
490
                    dwarf::Form Form, T &&Value) {
646
490
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
490
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEString>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEString&&)
Line
Count
Source
645
99.8k
                    dwarf::Form Form, T &&Value) {
646
99.8k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
99.8k
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEDelta*>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEDelta*&&)
Line
Count
Source
645
60.1k
                    dwarf::Form Form, T &&Value) {
646
60.1k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
60.1k
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEEntry&>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEEntry&&&)
Line
Count
Source
645
316k
                    dwarf::Form Form, T &&Value) {
646
316k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
316k
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIELoc*&>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELoc*&&&)
Line
Count
Source
645
2.37k
                    dwarf::Form Form, T &&Value) {
646
2.37k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
2.37k
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEBlock*&>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEBlock*&&&)
Line
Count
Source
645
38
                    dwarf::Form Form, T &&Value) {
646
38
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
38
  }
llvm::DIEValueList::value_iterator llvm::DIEValueList::addValue<llvm::DIEEntry>(llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul>&, llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEEntry&&)
Line
Count
Source
645
977
                    dwarf::Form Form, T &&Value) {
646
977
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
647
977
  }
648
649
413k
  value_range values() {
650
413k
    return make_range(value_iterator(List.begin()), value_iterator(List.end()));
651
413k
  }
652
961k
  const_value_range values() const {
653
961k
    return make_range(const_value_iterator(List.begin()),
654
961k
                      const_value_iterator(List.end()));
655
961k
  }
656
};
657
658
//===--------------------------------------------------------------------===//
659
/// A structured debug information entry.  Has an abbreviation which
660
/// describes its organization.
661
class DIE : IntrusiveBackListNode, public DIEValueList {
662
  friend class IntrusiveBackList<DIE>;
663
  friend class DIEUnit;
664
665
  /// Dwarf unit relative offset.
666
  unsigned Offset = 0;
667
  /// Size of instance + children.
668
  unsigned Size = 0;
669
  unsigned AbbrevNumber = ~0u;
670
  /// Dwarf tag code.
671
  dwarf::Tag Tag = (dwarf::Tag)0;
672
  /// Set to true to force a DIE to emit an abbreviation that says it has
673
  /// children even when it doesn't. This is used for unit testing purposes.
674
  bool ForceChildren = false;
675
  /// Children DIEs.
676
  IntrusiveBackList<DIE> Children;
677
678
  /// The owner is either the parent DIE for children of other DIEs, or a
679
  /// DIEUnit which contains this DIE as its unit DIE.
680
  PointerUnion<DIE *, DIEUnit *> Owner;
681
682
409k
  explicit DIE(dwarf::Tag Tag) : Tag(Tag) {}
683
684
public:
685
  DIE() = delete;
686
  DIE(const DIE &RHS) = delete;
687
  DIE(DIE &&RHS) = delete;
688
  DIE &operator=(const DIE &RHS) = delete;
689
  DIE &operator=(const DIE &&RHS) = delete;
690
691
406k
  static DIE *get(BumpPtrAllocator &Alloc, dwarf::Tag Tag) {
692
406k
    return new (Alloc) DIE(Tag);
693
406k
  }
694
695
  // Accessors.
696
822k
  unsigned getAbbrevNumber() const { return AbbrevNumber; }
697
4.91M
  dwarf::Tag getTag() const { return Tag; }
698
  /// Get the compile/type unit relative offset of this DIE.
699
2.03M
  unsigned getOffset() const { return Offset; }
700
9.07k
  unsigned getSize() const { return Size; }
701
1.22M
  bool hasChildren() const { return ForceChildren || !Children.empty(); }
702
  void setForceChildren(bool B) { ForceChildren = B; }
703
704
  using child_iterator = IntrusiveBackList<DIE>::iterator;
705
  using const_child_iterator = IntrusiveBackList<DIE>::const_iterator;
706
  using child_range = iterator_range<child_iterator>;
707
  using const_child_range = iterator_range<const_child_iterator>;
708
709
187k
  child_range children() {
710
187k
    return make_range(Children.begin(), Children.end());
711
187k
  }
712
187k
  const_child_range children() const {
713
187k
    return make_range(Children.begin(), Children.end());
714
187k
  }
715
716
  DIE *getParent() const;
717
718
  /// Generate the abbreviation for this DIE.
719
  ///
720
  /// Calculate the abbreviation for this, which should be uniqued and
721
  /// eventually used to call \a setAbbrevNumber().
722
  DIEAbbrev generateAbbrev() const;
723
724
  /// Set the abbreviation number for this DIE.
725
409k
  void setAbbrevNumber(unsigned I) { AbbrevNumber = I; }
726
727
  /// Get the absolute offset within the .debug_info or .debug_types section
728
  /// for this DIE.
729
  unsigned getDebugSectionOffset() const;
730
731
  /// Compute the offset of this DIE and all its children.
732
  ///
733
  /// This function gets called just before we are going to generate the debug
734
  /// information and gives each DIE a chance to figure out its CU relative DIE
735
  /// offset, unique its abbreviation and fill in the abbreviation code, and
736
  /// return the unit offset that points to where the next DIE will be emitted
737
  /// within the debug unit section. After this function has been called for all
738
  /// DIE objects, the DWARF can be generated since all DIEs will be able to
739
  /// properly refer to other DIE objects since all DIEs have calculated their
740
  /// offsets.
741
  ///
742
  /// \param AP AsmPrinter to use when calculating sizes.
743
  /// \param AbbrevSet the abbreviation used to unique DIE abbreviations.
744
  /// \param CUOffset the compile/type unit relative offset in bytes.
745
  /// \returns the offset for the DIE that follows this DIE within the
746
  /// current compile/type unit.
747
  unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP,
748
                                    DIEAbbrevSet &AbbrevSet, unsigned CUOffset);
749
750
  /// Climb up the parent chain to get the compile unit or type unit DIE that
751
  /// this DIE belongs to.
752
  ///
753
  /// \returns the compile or type unit DIE that owns this DIE, or NULL if
754
  /// this DIE hasn't been added to a unit DIE.
755
  const DIE *getUnitDie() const;
756
757
  /// Climb up the parent chain to get the compile unit or type unit that this
758
  /// DIE belongs to.
759
  ///
760
  /// \returns the DIEUnit that represents the compile or type unit that owns
761
  /// this DIE, or NULL if this DIE hasn't been added to a unit DIE.
762
  const DIEUnit *getUnit() const;
763
764
409k
  void setOffset(unsigned O) { Offset = O; }
765
409k
  void setSize(unsigned S) { Size = S; }
766
767
  /// Add a child to the DIE.
768
406k
  DIE &addChild(DIE *Child) {
769
406k
    assert(!Child->getParent() && "Child should be orphaned");
770
406k
    Child->Owner = this;
771
406k
    Children.push_back(*Child);
772
406k
    return Children.back();
773
406k
  }
774
775
  /// Find a value in the DIE with the attribute given.
776
  ///
777
  /// Returns a default-constructed DIEValue (where \a DIEValue::getType()
778
  /// gives \a DIEValue::isNone) if no such attribute exists.
779
  DIEValue findAttribute(dwarf::Attribute Attribute) const;
780
781
  void print(raw_ostream &O, unsigned IndentCount = 0) const;
782
  void dump() const;
783
};
784
785
//===--------------------------------------------------------------------===//
786
/// Represents a compile or type unit.
787
class DIEUnit {
788
  /// The compile unit or type unit DIE. This variable must be an instance of
789
  /// DIE so that we can calculate the DIEUnit from any DIE by traversing the
790
  /// parent backchain and getting the Unit DIE, and then casting itself to a
791
  /// DIEUnit. This allows us to be able to find the DIEUnit for any DIE without
792
  /// having to store a pointer to the DIEUnit in each DIE instance.
793
  DIE Die;
794
  /// The section this unit will be emitted in. This may or may not be set to
795
  /// a valid section depending on the client that is emitting DWARF.
796
  MCSection *Section;
797
  uint64_t Offset; /// .debug_info or .debug_types absolute section offset.
798
  uint32_t Length; /// The length in bytes of all of the DIEs in this unit.
799
  const uint16_t Version; /// The Dwarf version number for this unit.
800
  const uint8_t AddrSize; /// The size in bytes of an address for this unit.
801
protected:
802
2.94k
  virtual ~DIEUnit() = default;
803
804
public:
805
  DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag);
806
  DIEUnit(const DIEUnit &RHS) = delete;
807
  DIEUnit(DIEUnit &&RHS) = delete;
808
  void operator=(const DIEUnit &RHS) = delete;
809
  void operator=(const DIEUnit &&RHS) = delete;
810
  /// Set the section that this DIEUnit will be emitted into.
811
  ///
812
  /// This function is used by some clients to set the section. Not all clients
813
  /// that emit DWARF use this section variable.
814
2.66k
  void setSection(MCSection *Section) {
815
2.66k
    assert(!this->Section);
816
2.66k
    this->Section = Section;
817
2.66k
  }
818
819
30
  virtual const MCSymbol *getCrossSectionRelativeBaseAddress() const {
820
30
    return nullptr;
821
30
  }
822
823
  /// Return the section that this DIEUnit will be emitted into.
824
  ///
825
  /// \returns Section pointer which can be NULL.
826
2.66k
  MCSection *getSection() const { return Section; }
827
2.65k
  void setDebugSectionOffset(unsigned O) { Offset = O; }
828
342k
  unsigned getDebugSectionOffset() const { return Offset; }
829
  void setLength(uint64_t L) { Length = L; }
830
  uint64_t getLength() const { return Length; }
831
  uint16_t getDwarfVersion() const { return Version; }
832
  uint16_t getAddressSize() const { return AddrSize; }
833
432k
  DIE &getUnitDie() { return Die; }
834
0
  const DIE &getUnitDie() const { return Die; }
835
};
836
837
struct BasicDIEUnit final : DIEUnit {
838
  BasicDIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
839
      : DIEUnit(Version, AddrSize, UnitTag) {}
840
};
841
842
//===--------------------------------------------------------------------===//
843
/// DIELoc - Represents an expression location.
844
//
845
class DIELoc : public DIEValueList {
846
  mutable unsigned Size = 0; // Size in bytes excluding size header.
847
848
public:
849
2.49k
  DIELoc() = default;
850
851
  /// ComputeSize - Calculate the size of the location expression.
852
  ///
853
  unsigned ComputeSize(const AsmPrinter *AP) const;
854
855
  /// BestForm - Choose the best form for data.
856
  ///
857
2.37k
  dwarf::Form BestForm(unsigned DwarfVersion) const {
858
2.37k
    if (DwarfVersion > 3)
859
1.94k
      return dwarf::DW_FORM_exprloc;
860
428
    // Pre-DWARF4 location expressions were blocks and not exprloc.
861
428
    if ((unsigned char)Size == Size)
862
428
      return dwarf::DW_FORM_block1;
863
0
    if ((unsigned short)Size == Size)
864
0
      return dwarf::DW_FORM_block2;
865
0
    if ((unsigned int)Size == Size)
866
0
      return dwarf::DW_FORM_block4;
867
0
    return dwarf::DW_FORM_block;
868
0
  }
869
870
  void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
871
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
872
873
  void print(raw_ostream &O) const;
874
};
875
876
//===--------------------------------------------------------------------===//
877
/// DIEBlock - Represents a block of values.
878
//
879
class DIEBlock : public DIEValueList {
880
  mutable unsigned Size = 0; // Size in bytes excluding size header.
881
882
public:
883
661
  DIEBlock() = default;
884
885
  /// ComputeSize - Calculate the size of the location expression.
886
  ///
887
  unsigned ComputeSize(const AsmPrinter *AP) const;
888
889
  /// BestForm - Choose the best form for data.
890
  ///
891
1
  dwarf::Form BestForm() const {
892
1
    if ((unsigned char)Size == Size)
893
1
      return dwarf::DW_FORM_block1;
894
0
    if ((unsigned short)Size == Size)
895
0
      return dwarf::DW_FORM_block2;
896
0
    if ((unsigned int)Size == Size)
897
0
      return dwarf::DW_FORM_block4;
898
0
    return dwarf::DW_FORM_block;
899
0
  }
900
901
  void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
902
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
903
904
  void print(raw_ostream &O) const;
905
};
906
907
} // end namespace llvm
908
909
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H