Coverage Report

Created: 2019-07-24 05:18

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