Coverage Report

Created: 2018-11-12 17:33

/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
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// Data structures for DWARF info entries.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
15
#define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
16
17
#include "llvm/ADT/FoldingSet.h"
18
#include "llvm/ADT/PointerIntPair.h"
19
#include "llvm/ADT/PointerUnion.h"
20
#include "llvm/ADT/SmallVector.h"
21
#include "llvm/ADT/StringRef.h"
22
#include "llvm/ADT/iterator.h"
23
#include "llvm/ADT/iterator_range.h"
24
#include "llvm/BinaryFormat/Dwarf.h"
25
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
26
#include "llvm/Support/AlignOf.h"
27
#include "llvm/Support/Allocator.h"
28
#include <cassert>
29
#include <cstddef>
30
#include <cstdint>
31
#include <iterator>
32
#include <new>
33
#include <type_traits>
34
#include <utility>
35
#include <vector>
36
37
namespace llvm {
38
39
class AsmPrinter;
40
class DIE;
41
class DIEUnit;
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.67M
      : 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
189k
  dwarf::Attribute getAttribute() const { return Attribute; }
68
282k
  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
407k
  DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C) {}
97
98
  /// Accessors.
99
  /// @{
100
  dwarf::Tag getTag() const { return Tag; }
101
407k
  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.6k
  void setNumber(unsigned N) { Number = N; }
106
  /// @}
107
108
  /// Adds another set of attribute information to the abbreviation.
109
1.67M
  void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
110
1.67M
    Data.push_back(DIEAbbrevData(Attribute, Form));
111
1.67M
  }
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
66.7k
  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
837k
  explicit DIEInteger(uint64_t I) : Integer(I) {}
168
169
  /// Choose the best form for integer.
170
613k
  static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
171
613k
    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
613k
    } else {
180
613k
      if ((unsigned char)Int == Int)
181
479k
        return dwarf::DW_FORM_data1;
182
133k
      if ((unsigned short)Int == Int)
183
133k
        return dwarf::DW_FORM_data2;
184
4
      if ((unsigned int)Int == Int)
185
0
        return dwarf::DW_FORM_data4;
186
4
    }
187
4
    return dwarf::DW_FORM_data8;
188
4
  }
189
190
285
  uint64_t getValue() const { return Integer; }
191
  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
35
  explicit DIEExpr(const MCExpr *E) : Expr(E) {}
206
207
  /// Get MCExpr.
208
  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
573k
  explicit DIELabel(const MCSymbol *L) : Label(L) {}
223
224
  /// Get MCSymbol.
225
  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 simple label difference DIE.
235
///
236
class DIEDelta {
237
  const MCSymbol *LabelHi;
238
  const MCSymbol *LabelLo;
239
240
public:
241
59.4k
  DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) : LabelHi(Hi), LabelLo(Lo) {}
242
243
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
244
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
245
246
  void print(raw_ostream &O) const;
247
};
248
249
//===--------------------------------------------------------------------===//
250
/// A container for string pool string values.
251
///
252
/// This class is used with the DW_FORM_strp and DW_FORM_GNU_str_index forms.
253
class DIEString {
254
  DwarfStringPoolEntryRef S;
255
256
public:
257
102k
  DIEString(DwarfStringPoolEntryRef S) : S(S) {}
258
259
  /// Grab the string out of the object.
260
287
  StringRef getString() const { return S.getString(); }
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 inline string values.
270
///
271
/// This class is used with the DW_FORM_string form.
272
class DIEInlineString {
273
  StringRef S;
274
275
public:
276
  template <typename Allocator>
277
479
  explicit DIEInlineString(StringRef Str, Allocator &A) : S(Str.copy(A)) {}
278
279
  ~DIEInlineString() = default;
280
281
  /// Grab the string out of the object.
282
0
  StringRef getString() const { return S; }
283
284
  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
285
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
286
287
  void print(raw_ostream &O) const;
288
};
289
290
//===--------------------------------------------------------------------===//
291
/// A pointer to another debug information entry.  An instance of this class can
292
/// also be used as a proxy for a debug information entry not yet defined
293
/// (ie. types.)
294
class DIEEntry {
295
  DIE *Entry;
296
297
public:
298
  DIEEntry() = delete;
299
311k
  explicit DIEEntry(DIE &E) : Entry(&E) {}
300
301
310k
  DIE &getEntry() const { return *Entry; }
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
/// Represents a pointer to a location list in the debug_loc
311
/// section.
312
class DIELocList {
313
  /// Index into the .debug_loc vector.
314
  size_t Index;
315
316
public:
317
345
  DIELocList(size_t I) : Index(I) {}
318
319
  /// Grab the current index out.
320
3
  size_t getValue() const { return Index; }
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
/// A debug information entry value. Some of these roughly correlate
330
/// to DWARF attribute classes.
331
class DIEBlock;
332
class DIELoc;
333
class DIEValue {
334
public:
335
  enum Type {
336
    isNone,
337
#define HANDLE_DIEVALUE(T) is##T,
338
#include "llvm/CodeGen/DIEValue.def"
339
  };
340
341
private:
342
  /// Type of data stored in the value.
343
  Type Ty = isNone;
344
  dwarf::Attribute Attribute = (dwarf::Attribute)0;
345
  dwarf::Form Form = (dwarf::Form)0;
346
347
  /// Storage for the value.
348
  ///
349
  /// All values that aren't standard layout (or are larger than 8 bytes)
350
  /// should be stored by reference instead of by value.
351
  using ValTy = AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
352
                                      DIEDelta *, DIEEntry, DIEBlock *,
353
                                      DIELoc *, DIELocList>;
354
355
  static_assert(sizeof(ValTy) <= sizeof(uint64_t) ||
356
                    sizeof(ValTy) <= sizeof(void *),
357
                "Expected all large types to be stored via pointer");
358
359
  /// Underlying stored value.
360
  ValTy Val;
361
362
5.04M
  template <class T> void construct(T V) {
363
5.04M
    static_assert(std::is_standard_layout<T>::value ||
364
5.04M
                      std::is_pointer<T>::value,
365
5.04M
                  "Expected standard layout or pointer");
366
5.04M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
5.04M
  }
void llvm::DIEValue::construct<llvm::DIEInteger>(llvm::DIEInteger)
Line
Count
Source
362
1.91M
  template <class T> void construct(T V) {
363
1.91M
    static_assert(std::is_standard_layout<T>::value ||
364
1.91M
                      std::is_pointer<T>::value,
365
1.91M
                  "Expected standard layout or pointer");
366
1.91M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.91M
  }
void llvm::DIEValue::construct<llvm::DIEString>(llvm::DIEString)
Line
Count
Source
362
307k
  template <class T> void construct(T V) {
363
307k
    static_assert(std::is_standard_layout<T>::value ||
364
307k
                      std::is_pointer<T>::value,
365
307k
                  "Expected standard layout or pointer");
366
307k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
307k
  }
void llvm::DIEValue::construct<llvm::DIEExpr>(llvm::DIEExpr)
Line
Count
Source
362
105
  template <class T> void construct(T V) {
363
105
    static_assert(std::is_standard_layout<T>::value ||
364
105
                      std::is_pointer<T>::value,
365
105
                  "Expected standard layout or pointer");
366
105
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
105
  }
void llvm::DIEValue::construct<llvm::DIELabel>(llvm::DIELabel)
Line
Count
Source
362
1.70M
  template <class T> void construct(T V) {
363
1.70M
    static_assert(std::is_standard_layout<T>::value ||
364
1.70M
                      std::is_pointer<T>::value,
365
1.70M
                  "Expected standard layout or pointer");
366
1.70M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.70M
  }
void llvm::DIEValue::construct<llvm::DIEDelta const*>(llvm::DIEDelta const*)
Line
Count
Source
362
178k
  template <class T> void construct(T V) {
363
178k
    static_assert(std::is_standard_layout<T>::value ||
364
178k
                      std::is_pointer<T>::value,
365
178k
                  "Expected standard layout or pointer");
366
178k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
178k
  }
void llvm::DIEValue::construct<llvm::DIEEntry>(llvm::DIEEntry)
Line
Count
Source
362
934k
  template <class T> void construct(T V) {
363
934k
    static_assert(std::is_standard_layout<T>::value ||
364
934k
                      std::is_pointer<T>::value,
365
934k
                  "Expected standard layout or pointer");
366
934k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
934k
  }
void llvm::DIEValue::construct<llvm::DIEBlock const*>(llvm::DIEBlock const*)
Line
Count
Source
362
2.60k
  template <class T> void construct(T V) {
363
2.60k
    static_assert(std::is_standard_layout<T>::value ||
364
2.60k
                      std::is_pointer<T>::value,
365
2.60k
                  "Expected standard layout or pointer");
366
2.60k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
2.60k
  }
void llvm::DIEValue::construct<llvm::DIELoc const*>(llvm::DIELoc const*)
Line
Count
Source
362
7.23k
  template <class T> void construct(T V) {
363
7.23k
    static_assert(std::is_standard_layout<T>::value ||
364
7.23k
                      std::is_pointer<T>::value,
365
7.23k
                  "Expected standard layout or pointer");
366
7.23k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
7.23k
  }
void llvm::DIEValue::construct<llvm::DIELocList>(llvm::DIELocList)
Line
Count
Source
362
1.03k
  template <class T> void construct(T V) {
363
1.03k
    static_assert(std::is_standard_layout<T>::value ||
364
1.03k
                      std::is_pointer<T>::value,
365
1.03k
                  "Expected standard layout or pointer");
366
1.03k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.03k
  }
void llvm::DIEValue::construct<llvm::DIEInlineString const*>(llvm::DIEInlineString const*)
Line
Count
Source
362
1.43k
  template <class T> void construct(T V) {
363
1.43k
    static_assert(std::is_standard_layout<T>::value ||
364
1.43k
                      std::is_pointer<T>::value,
365
1.43k
                  "Expected standard layout or pointer");
366
1.43k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.43k
  }
368
369
3.36M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEInteger* llvm::DIEValue::get<llvm::DIEInteger>()
Line
Count
Source
369
1.27M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEString* llvm::DIEValue::get<llvm::DIEString>()
Line
Count
Source
369
205k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEExpr* llvm::DIEValue::get<llvm::DIEExpr>()
Line
Count
Source
369
70
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELabel* llvm::DIEValue::get<llvm::DIELabel>()
Line
Count
Source
369
1.13M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEDelta const** llvm::DIEValue::get<llvm::DIEDelta const*>()
Line
Count
Source
369
118k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEEntry* llvm::DIEValue::get<llvm::DIEEntry>()
Line
Count
Source
369
623k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEBlock const** llvm::DIEValue::get<llvm::DIEBlock const*>()
Line
Count
Source
369
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
369
4.86k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELocList* llvm::DIEValue::get<llvm::DIELocList>()
Line
Count
Source
369
693
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEInlineString const** llvm::DIEValue::get<llvm::DIEInlineString const*>()
Line
Count
Source
369
958
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
370
6.72M
  template <class T> const T *get() const {
371
6.72M
    return reinterpret_cast<const T *>(Val.buffer);
372
6.72M
  }
llvm::DIEInteger const* llvm::DIEValue::get<llvm::DIEInteger>() const
Line
Count
Source
370
2.54M
  template <class T> const T *get() const {
371
2.54M
    return reinterpret_cast<const T *>(Val.buffer);
372
2.54M
  }
llvm::DIEString const* llvm::DIEValue::get<llvm::DIEString>() const
Line
Count
Source
370
410k
  template <class T> const T *get() const {
371
410k
    return reinterpret_cast<const T *>(Val.buffer);
372
410k
  }
llvm::DIEExpr const* llvm::DIEValue::get<llvm::DIEExpr>() const
Line
Count
Source
370
140
  template <class T> const T *get() const {
371
140
    return reinterpret_cast<const T *>(Val.buffer);
372
140
  }
llvm::DIELabel const* llvm::DIEValue::get<llvm::DIELabel>() const
Line
Count
Source
370
2.26M
  template <class T> const T *get() const {
371
2.26M
    return reinterpret_cast<const T *>(Val.buffer);
372
2.26M
  }
llvm::DIEDelta const* const* llvm::DIEValue::get<llvm::DIEDelta const*>() const
Line
Count
Source
370
237k
  template <class T> const T *get() const {
371
237k
    return reinterpret_cast<const T *>(Val.buffer);
372
237k
  }
llvm::DIEEntry const* llvm::DIEValue::get<llvm::DIEEntry>() const
Line
Count
Source
370
1.24M
  template <class T> const T *get() const {
371
1.24M
    return reinterpret_cast<const T *>(Val.buffer);
372
1.24M
  }
llvm::DIEBlock const* const* llvm::DIEValue::get<llvm::DIEBlock const*>() const
Line
Count
Source
370
2.64k
  template <class T> const T *get() const {
371
2.64k
    return reinterpret_cast<const T *>(Val.buffer);
372
2.64k
  }
llvm::DIELoc const* const* llvm::DIEValue::get<llvm::DIELoc const*>() const
Line
Count
Source
370
9.58k
  template <class T> const T *get() const {
371
9.58k
    return reinterpret_cast<const T *>(Val.buffer);
372
9.58k
  }
llvm::DIELocList const* llvm::DIEValue::get<llvm::DIELocList>() const
Line
Count
Source
370
1.38k
  template <class T> const T *get() const {
371
1.38k
    return reinterpret_cast<const T *>(Val.buffer);
372
1.38k
  }
llvm::DIEInlineString const* const* llvm::DIEValue::get<llvm::DIEInlineString const*>() const
Line
Count
Source
370
1.91k
  template <class T> const T *get() const {
371
1.91k
    return reinterpret_cast<const T *>(Val.buffer);
372
1.91k
  }
373
3.36M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEInteger>()
Line
Count
Source
373
1.27M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEString>()
Line
Count
Source
373
205k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEExpr>()
Line
Count
Source
373
70
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELabel>()
Line
Count
Source
373
1.13M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEDelta const*>()
Line
Count
Source
373
118k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEEntry>()
Line
Count
Source
373
623k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEBlock const*>()
Line
Count
Source
373
1.94k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELoc const*>()
Line
Count
Source
373
4.86k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELocList>()
Line
Count
Source
373
693
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEInlineString const*>()
Line
Count
Source
373
958
  template <class T> void destruct() { get<T>()->~T(); }
374
375
  /// Destroy the underlying value.
376
  ///
377
  /// This should get optimized down to a no-op.  We could skip it if we could
378
  /// add a static assert on \a std::is_trivially_copyable(), but we currently
379
  /// support versions of GCC that don't understand that.
380
3.52M
  void destroyVal() {
381
3.52M
    switch (Ty) {
382
3.52M
    case isNone:
383
155k
      return;
384
3.52M
#define HANDLE_DIEVALUE_SMALL(T)                                               \
385
3.52M
  case is##T:                                                                  \
386
3.24M
    destruct<DIE##T>();                                                        \
387
3.24M
    return;
388
3.52M
#define HANDLE_DIEVALUE_LARGE(T)                                               \
389
3.52M
  case is##T:                                                                  \
390
126k
    destruct<const DIE##T *>();                                                \
391
126k
    return;
392
3.52M
#include 
"llvm/CodeGen/DIEValue.def"1.27M
393
3.52M
    }
394
3.52M
  }
395
396
  /// Copy the underlying value.
397
  ///
398
  /// This should get optimized down to a simple copy.  We need to actually
399
  /// construct the value, rather than calling memcpy, to satisfy strict
400
  /// aliasing rules.
401
3.36M
  void copyVal(const DIEValue &X) {
402
3.36M
    switch (Ty) {
403
3.36M
    case isNone:
404
0
      return;
405
3.36M
#define HANDLE_DIEVALUE_SMALL(T)                                               \
406
3.36M
  case is##T:                                                                  \
407
3.24M
    construct<DIE##T>(*X.get<DIE##T>());                                       \
408
3.24M
    return;
409
3.36M
#define HANDLE_DIEVALUE_LARGE(T)                                               \
410
3.36M
  case is##T:                                                                  \
411
126k
    construct<const DIE##T *>(*X.get<const DIE##T *>());                       \
412
126k
    return;
413
3.36M
#include 
"llvm/CodeGen/DIEValue.def"1.27M
414
3.36M
    }
415
3.36M
  }
416
417
public:
418
155k
  DIEValue() = default;
419
420
3.36M
  DIEValue(const DIEValue &X) : Ty(X.Ty), Attribute(X.Attribute), Form(X.Form) {
421
3.36M
    copyVal(X);
422
3.36M
  }
423
424
1.43k
  DIEValue &operator=(const DIEValue &X) {
425
1.43k
    destroyVal();
426
1.43k
    Ty = X.Ty;
427
1.43k
    Attribute = X.Attribute;
428
1.43k
    Form = X.Form;
429
1.43k
    copyVal(X);
430
1.43k
    return *this;
431
1.43k
  }
432
433
3.52M
  ~DIEValue() { destroyVal(); }
434
435
#define HANDLE_DIEVALUE_SMALL(T)                                               \
436
  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V)      \
437
1.61M
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
1.61M
    construct<DIE##T>(V);                                                      \
439
1.61M
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInteger const&)
Line
Count
Source
437
638k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
638k
    construct<DIE##T>(V);                                                      \
439
638k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELabel const&)
Line
Count
Source
437
567k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
567k
    construct<DIE##T>(V);                                                      \
439
567k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELocList const&)
Line
Count
Source
437
345
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
345
    construct<DIE##T>(V);                                                      \
439
345
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEExpr const&)
Line
Count
Source
437
35
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
35
    construct<DIE##T>(V);                                                      \
439
35
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEString const&)
Line
Count
Source
437
102k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
102k
    construct<DIE##T>(V);                                                      \
439
102k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEEntry const&)
Line
Count
Source
437
311k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
311k
    construct<DIE##T>(V);                                                      \
439
311k
  }
440
#define HANDLE_DIEVALUE_LARGE(T)                                               \
441
  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V)      \
442
63.0k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
63.0k
    assert(V && "Expected valid value");                                       \
444
63.0k
    construct<const DIE##T *>(V);                                              \
445
63.0k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInlineString const*)
Line
Count
Source
442
479
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
479
    assert(V && "Expected valid value");                                       \
444
479
    construct<const DIE##T *>(V);                                              \
445
479
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEDelta const*)
Line
Count
Source
442
59.4k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
59.4k
    assert(V && "Expected valid value");                                       \
444
59.4k
    construct<const DIE##T *>(V);                                              \
445
59.4k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELoc const*)
Line
Count
Source
442
2.36k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
2.36k
    assert(V && "Expected valid value");                                       \
444
2.36k
    construct<const DIE##T *>(V);                                              \
445
2.36k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEBlock const*)
Line
Count
Source
442
661
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
661
    assert(V && "Expected valid value");                                       \
444
661
    construct<const DIE##T *>(V);                                              \
445
661
  }
446
#include "llvm/CodeGen/DIEValue.def"
447
448
  /// Accessors.
449
  /// @{
450
529
  Type getType() const { return Ty; }
451
3.61M
  dwarf::Attribute getAttribute() const { return Attribute; }
452
3.35M
  dwarf::Form getForm() const { return Form; }
453
154k
  explicit operator bool() const { return Ty; }
454
  /// @}
455
456
#define HANDLE_DIEVALUE_SMALL(T)                                               \
457
3.23M
  const DIE##T &getDIE##T() const {                                            \
458
3.23M
    assert(getType() == is##T && "Expected " #T);                              \
459
3.23M
    return *get<DIE##T>();                                                     \
460
3.23M
  }
llvm::DIEValue::getDIEInteger() const
Line
Count
Source
457
1.26M
  const DIE##T &getDIE##T() const {                                            \
458
1.26M
    assert(getType() == is##T && "Expected " #T);                              \
459
1.26M
    return *get<DIE##T>();                                                     \
460
1.26M
  }
llvm::DIEValue::getDIEString() const
Line
Count
Source
457
205k
  const DIE##T &getDIE##T() const {                                            \
458
205k
    assert(getType() == is##T && "Expected " #T);                              \
459
205k
    return *get<DIE##T>();                                                     \
460
205k
  }
llvm::DIEValue::getDIEExpr() const
Line
Count
Source
457
70
  const DIE##T &getDIE##T() const {                                            \
458
70
    assert(getType() == is##T && "Expected " #T);                              \
459
70
    return *get<DIE##T>();                                                     \
460
70
  }
llvm::DIEValue::getDIELabel() const
Line
Count
Source
457
1.13M
  const DIE##T &getDIE##T() const {                                            \
458
1.13M
    assert(getType() == is##T && "Expected " #T);                              \
459
1.13M
    return *get<DIE##T>();                                                     \
460
1.13M
  }
llvm::DIEValue::getDIEEntry() const
Line
Count
Source
457
622k
  const DIE##T &getDIE##T() const {                                            \
458
622k
    assert(getType() == is##T && "Expected " #T);                              \
459
622k
    return *get<DIE##T>();                                                     \
460
622k
  }
llvm::DIEValue::getDIELocList() const
Line
Count
Source
457
693
  const DIE##T &getDIE##T() const {                                            \
458
693
    assert(getType() == is##T && "Expected " #T);                              \
459
693
    return *get<DIE##T>();                                                     \
460
693
  }
461
#define HANDLE_DIEVALUE_LARGE(T)                                               \
462
125k
  const DIE##T &getDIE##T() const {                                            \
463
125k
    assert(getType() == is##T && "Expected " #T);                              \
464
125k
    return **get<const DIE##T *>();                                            \
465
125k
  }
llvm::DIEValue::getDIEDelta() const
Line
Count
Source
462
118k
  const DIE##T &getDIE##T() const {                                            \
463
118k
    assert(getType() == is##T && "Expected " #T);                              \
464
118k
    return **get<const DIE##T *>();                                            \
465
118k
  }
llvm::DIEValue::getDIEBlock() const
Line
Count
Source
462
697
  const DIE##T &getDIE##T() const {                                            \
463
697
    assert(getType() == is##T && "Expected " #T);                              \
464
697
    return **get<const DIE##T *>();                                            \
465
697
  }
llvm::DIEValue::getDIELoc() const
Line
Count
Source
462
4.71k
  const DIE##T &getDIE##T() const {                                            \
463
4.71k
    assert(getType() == is##T && "Expected " #T);                              \
464
4.71k
    return **get<const DIE##T *>();                                            \
465
4.71k
  }
llvm::DIEValue::getDIEInlineString() const
Line
Count
Source
462
958
  const DIE##T &getDIE##T() const {                                            \
463
958
    assert(getType() == is##T && "Expected " #T);                              \
464
958
    return **get<const DIE##T *>();                                            \
465
958
  }
466
#include "llvm/CodeGen/DIEValue.def"
467
468
  /// Emit value via the Dwarf writer.
469
  void EmitValue(const AsmPrinter *AP) const;
470
471
  /// Return the size of a value in bytes.
472
  unsigned SizeOf(const AsmPrinter *AP) const;
473
474
  void print(raw_ostream &O) const;
475
  void dump() const;
476
};
477
478
struct IntrusiveBackListNode {
479
  PointerIntPair<IntrusiveBackListNode *, 1> Next;
480
481
2.08M
  IntrusiveBackListNode() : Next(this, true) {}
482
483
6.10M
  IntrusiveBackListNode *getNext() const {
484
6.10M
    return Next.getInt() ? 
nullptr1.73M
:
Next.getPointer()4.36M
;
485
6.10M
  }
486
};
487
488
struct IntrusiveBackListBase {
489
  using Node = IntrusiveBackListNode;
490
491
  Node *Last = nullptr;
492
493
1.21M
  bool empty() const { return !Last; }
494
495
2.08M
  void push_back(Node &N) {
496
2.08M
    assert(N.Next.getPointer() == &N && "Expected unlinked node");
497
2.08M
    assert(N.Next.getInt() == true && "Expected unlinked node");
498
2.08M
499
2.08M
    if (Last) {
500
1.49M
      N.Next = Last->Next;
501
1.49M
      Last->Next.setPointerAndInt(&N, false);
502
1.49M
    }
503
2.08M
    Last = &N;
504
2.08M
  }
505
};
506
507
template <class T> class IntrusiveBackList : IntrusiveBackListBase {
508
public:
509
  using IntrusiveBackListBase::empty;
510
511
2.08M
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::push_back(llvm::DIEValueList::Node&)
Line
Count
Source
511
1.68M
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
llvm::IntrusiveBackList<llvm::DIE>::push_back(llvm::DIE&)
Line
Count
Source
511
403k
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
512
2.08M
  T &back() { return *static_cast<T *>(Last); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::back()
Line
Count
Source
512
1.68M
  T &back() { return *static_cast<T *>(Last); }
llvm::IntrusiveBackList<llvm::DIE>::back()
Line
Count
Source
512
403k
  T &back() { return *static_cast<T *>(Last); }
513
  const T &back() const { return *static_cast<T *>(Last); }
514
515
  class const_iterator;
516
  class iterator
517
      : public iterator_facade_base<iterator, std::forward_iterator_tag, T> {
518
    friend class const_iterator;
519
520
    Node *N = nullptr;
521
522
  public:
523
592k
    iterator() = default;
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::iterator()
Line
Count
Source
523
407k
    iterator() = default;
llvm::IntrusiveBackList<llvm::DIE>::iterator::iterator()
Line
Count
Source
523
184k
    iterator() = default;
524
3.41M
    explicit iterator(T *N) : N(N) {}
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::iterator(llvm::DIEValueList::Node*)
Line
Count
Source
524
3.04M
    explicit iterator(T *N) : N(N) {}
llvm::IntrusiveBackList<llvm::DIE>::iterator::iterator(llvm::DIE*)
Line
Count
Source
524
369k
    explicit iterator(T *N) : N(N) {}
525
526
2.07M
    iterator &operator++() {
527
2.07M
      N = N->getNext();
528
2.07M
      return *this;
529
2.07M
    }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator++()
Line
Count
Source
526
1.66M
    iterator &operator++() {
527
1.66M
      N = N->getNext();
528
1.66M
      return *this;
529
1.66M
    }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator++()
Line
Count
Source
526
401k
    iterator &operator++() {
527
401k
      N = N->getNext();
528
401k
      return *this;
529
401k
    }
530
531
0
    explicit operator bool() const { return N; }
532
2.07M
    T &operator*() const { return *static_cast<T *>(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator*() const
Line
Count
Source
532
1.66M
    T &operator*() const { return *static_cast<T *>(N); }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator*() const
Line
Count
Source
532
401k
    T &operator*() const { return *static_cast<T *>(N); }
533
534
2.07M
    bool operator==(const iterator &X) const { return N == X.N; }
535
586k
    bool operator!=(const iterator &X) const { return N != X.N; }
536
  };
537
538
  class const_iterator
539
      : public iterator_facade_base<const_iterator, std::forward_iterator_tag,
540
                                    const T> {
541
    const Node *N = nullptr;
542
543
  public:
544
1.14M
    const_iterator() = default;
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::const_iterator()
Line
Count
Source
544
960k
    const_iterator() = default;
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::const_iterator()
Line
Count
Source
544
185k
    const_iterator() = default;
545
    // Placate MSVC by explicitly scoping 'iterator'.
546
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
546
960k
    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
546
185k
    const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {}
547
    explicit const_iterator(const T *N) : N(N) {}
548
549
4.02M
    const_iterator &operator++() {
550
4.02M
      N = N->getNext();
551
4.02M
      return *this;
552
4.02M
    }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::operator++()
Line
Count
Source
549
3.62M
    const_iterator &operator++() {
550
3.62M
      N = N->getNext();
551
3.62M
      return *this;
552
3.62M
    }
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::operator++()
Line
Count
Source
549
403k
    const_iterator &operator++() {
550
403k
      N = N->getNext();
551
403k
      return *this;
552
403k
    }
553
554
0
    explicit operator bool() const { return N; }
555
4.02M
    const T &operator*() const { return *static_cast<const T *>(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::operator*() const
Line
Count
Source
555
3.62M
    const T &operator*() const { return *static_cast<const T *>(N); }
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::operator*() const
Line
Count
Source
555
403k
    const T &operator*() const { return *static_cast<const T *>(N); }
556
557
4.58M
    bool operator==(const const_iterator &X) const { return N == X.N; }
558
588k
    bool operator!=(const const_iterator &X) const { return N != X.N; }
559
  };
560
561
1.73M
  iterator begin() {
562
1.73M
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))1.73M
:
end()499
;
563
1.73M
  }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::begin()
Line
Count
Source
561
1.36M
  iterator begin() {
562
1.36M
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))1.36M
:
end()331
;
563
1.36M
  }
llvm::IntrusiveBackList<llvm::DIE>::begin()
Line
Count
Source
561
370k
  iterator begin() {
562
370k
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))369k
:
end()168
;
563
370k
  }
564
1.14M
  const_iterator begin() const {
565
1.14M
    return const_cast<IntrusiveBackList *>(this)->begin();
566
1.14M
  }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::begin() const
Line
Count
Source
564
960k
  const_iterator begin() const {
565
960k
    return const_cast<IntrusiveBackList *>(this)->begin();
566
960k
  }
llvm::IntrusiveBackList<llvm::DIE>::begin() const
Line
Count
Source
564
185k
  const_iterator begin() const {
565
185k
    return const_cast<IntrusiveBackList *>(this)->begin();
566
185k
  }
567
589k
  iterator end() { return iterator(); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::end()
Line
Count
Source
567
405k
  iterator end() { return iterator(); }
llvm::IntrusiveBackList<llvm::DIE>::end()
Line
Count
Source
567
184k
  iterator end() { return iterator(); }
568
1.14M
  const_iterator end() const { return const_iterator(); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::end() const
Line
Count
Source
568
960k
  const_iterator end() const { return const_iterator(); }
llvm::IntrusiveBackList<llvm::DIE>::end() const
Line
Count
Source
568
185k
  const_iterator end() const { return const_iterator(); }
569
570
1.68M
  static iterator toIterator(T &N) { return iterator(&N); }
571
  static const_iterator toIterator(const T &N) { return const_iterator(&N); }
572
};
573
574
/// A list of DIE values.
575
///
576
/// This is a singly-linked list, but instead of reversing the order of
577
/// insertion, we keep a pointer to the back of the list so we can push in
578
/// order.
579
///
580
/// There are two main reasons to choose a linked list over a customized
581
/// vector-like data structure.
582
///
583
///  1. For teardown efficiency, we want DIEs to be BumpPtrAllocated.  Using a
584
///     linked list here makes this way easier to accomplish.
585
///  2. Carrying an extra pointer per \a DIEValue isn't expensive.  45% of DIEs
586
///     have 2 or fewer values, and 90% have 5 or fewer.  A vector would be
587
///     over-allocated by 50% on average anyway, the same cost as the
588
///     linked-list node.
589
class DIEValueList {
590
  struct Node : IntrusiveBackListNode {
591
    DIEValue V;
592
593
1.68M
    explicit Node(DIEValue V) : V(V) {}
594
  };
595
596
  using ListTy = IntrusiveBackList<Node>;
597
598
  ListTy List;
599
600
public:
601
  class const_value_iterator;
602
  class value_iterator
603
      : public iterator_adaptor_base<value_iterator, ListTy::iterator,
604
                                     std::forward_iterator_tag, DIEValue> {
605
    friend class const_value_iterator;
606
607
    using iterator_adaptor =
608
        iterator_adaptor_base<value_iterator, ListTy::iterator,
609
                              std::forward_iterator_tag, DIEValue>;
610
611
  public:
612
2.71k
    value_iterator() = default;
613
2.49M
    explicit value_iterator(ListTy::iterator X) : iterator_adaptor(X) {}
614
615
0
    explicit operator bool() const { return bool(wrapped()); }
616
1.66M
    DIEValue &operator*() const { return wrapped()->V; }
617
  };
618
619
  class const_value_iterator : public iterator_adaptor_base<
620
                                   const_value_iterator, ListTy::const_iterator,
621
                                   std::forward_iterator_tag, const DIEValue> {
622
    using iterator_adaptor =
623
        iterator_adaptor_base<const_value_iterator, ListTy::const_iterator,
624
                              std::forward_iterator_tag, const DIEValue>;
625
626
  public:
627
    const_value_iterator() = default;
628
    const_value_iterator(DIEValueList::value_iterator X)
629
        : iterator_adaptor(X.wrapped()) {}
630
    explicit const_value_iterator(ListTy::const_iterator X)
631
1.92M
        : iterator_adaptor(X) {}
632
633
0
    explicit operator bool() const { return bool(wrapped()); }
634
3.62M
    const DIEValue &operator*() const { return wrapped()->V; }
635
  };
636
637
  using value_range = iterator_range<value_iterator>;
638
  using const_value_range = iterator_range<const_value_iterator>;
639
640
1.68M
  value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V) {
641
1.68M
    List.push_back(*new (Alloc) Node(V));
642
1.68M
    return value_iterator(ListTy::toIterator(List.back()));
643
1.68M
  }
644
  template <class T>
645
  value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute,
646
1.68M
                    dwarf::Form Form, T &&Value) {
647
1.68M
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
1.68M
  }
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
646
637k
                    dwarf::Form Form, T &&Value) {
647
637k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
637k
  }
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
646
567k
                    dwarf::Form Form, T &&Value) {
647
567k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
567k
  }
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
646
345
                    dwarf::Form Form, T &&Value) {
647
345
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
345
  }
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
646
35
                    dwarf::Form Form, T &&Value) {
647
35
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
35
  }
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
646
479
                    dwarf::Form Form, T &&Value) {
647
479
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
479
  }
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
646
102k
                    dwarf::Form Form, T &&Value) {
647
102k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
102k
  }
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
646
59.4k
                    dwarf::Form Form, T &&Value) {
647
59.4k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
59.4k
  }
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
646
310k
                    dwarf::Form Form, T &&Value) {
647
310k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
310k
  }
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
646
2.28k
                    dwarf::Form Form, T &&Value) {
647
2.28k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
2.28k
  }
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
646
38
                    dwarf::Form Form, T &&Value) {
647
38
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
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
646
977
                    dwarf::Form Form, T &&Value) {
647
977
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
977
  }
649
650
404k
  value_range values() {
651
404k
    return make_range(value_iterator(List.begin()), value_iterator(List.end()));
652
404k
  }
653
960k
  const_value_range values() const {
654
960k
    return make_range(const_value_iterator(List.begin()),
655
960k
                      const_value_iterator(List.end()));
656
960k
  }
657
};
658
659
//===--------------------------------------------------------------------===//
660
/// A structured debug information entry.  Has an abbreviation which
661
/// describes its organization.
662
class DIE : IntrusiveBackListNode, public DIEValueList {
663
  friend class IntrusiveBackList<DIE>;
664
  friend class DIEUnit;
665
666
  /// Dwarf unit relative offset.
667
  unsigned Offset = 0;
668
  /// Size of instance + children.
669
  unsigned Size = 0;
670
  unsigned AbbrevNumber = ~0u;
671
  /// Dwarf tag code.
672
  dwarf::Tag Tag = (dwarf::Tag)0;
673
  /// Set to true to force a DIE to emit an abbreviation that says it has
674
  /// children even when it doesn't. This is used for unit testing purposes.
675
  bool ForceChildren = false;
676
  /// Children DIEs.
677
  IntrusiveBackList<DIE> Children;
678
679
  /// The owner is either the parent DIE for children of other DIEs, or a
680
  /// DIEUnit which contains this DIE as its unit DIE.
681
  PointerUnion<DIE *, DIEUnit *> Owner;
682
683
406k
  explicit DIE(dwarf::Tag Tag) : Tag(Tag) {}
684
685
public:
686
  DIE() = delete;
687
  DIE(const DIE &RHS) = delete;
688
  DIE(DIE &&RHS) = delete;
689
  DIE &operator=(const DIE &RHS) = delete;
690
  DIE &operator=(const DIE &&RHS) = delete;
691
692
403k
  static DIE *get(BumpPtrAllocator &Alloc, dwarf::Tag Tag) {
693
403k
    return new (Alloc) DIE(Tag);
694
403k
  }
695
696
  // Accessors.
697
815k
  unsigned getAbbrevNumber() const { return AbbrevNumber; }
698
4.78M
  dwarf::Tag getTag() const { return Tag; }
699
  /// Get the compile/type unit relative offset of this DIE.
700
1.99M
  unsigned getOffset() const { return Offset; }
701
11.5k
  unsigned getSize() const { return Size; }
702
1.21M
  bool hasChildren() const { return ForceChildren || !Children.empty(); }
703
  void setForceChildren(bool B) { ForceChildren = B; }
704
705
  using child_iterator = IntrusiveBackList<DIE>::iterator;
706
  using const_child_iterator = IntrusiveBackList<DIE>::const_iterator;
707
  using child_range = iterator_range<child_iterator>;
708
  using const_child_range = iterator_range<const_child_iterator>;
709
710
184k
  child_range children() {
711
184k
    return make_range(Children.begin(), Children.end());
712
184k
  }
713
185k
  const_child_range children() const {
714
185k
    return make_range(Children.begin(), Children.end());
715
185k
  }
716
717
  DIE *getParent() const;
718
719
  /// Generate the abbreviation for this DIE.
720
  ///
721
  /// Calculate the abbreviation for this, which should be uniqued and
722
  /// eventually used to call \a setAbbrevNumber().
723
  DIEAbbrev generateAbbrev() const;
724
725
  /// Set the abbreviation number for this DIE.
726
406k
  void setAbbrevNumber(unsigned I) { AbbrevNumber = I; }
727
728
  /// Get the absolute offset within the .debug_info or .debug_types section
729
  /// for this DIE.
730
  unsigned getDebugSectionOffset() const;
731
732
  /// Compute the offset of this DIE and all its children.
733
  ///
734
  /// This function gets called just before we are going to generate the debug
735
  /// information and gives each DIE a chance to figure out its CU relative DIE
736
  /// offset, unique its abbreviation and fill in the abbreviation code, and
737
  /// return the unit offset that points to where the next DIE will be emitted
738
  /// within the debug unit section. After this function has been called for all
739
  /// DIE objects, the DWARF can be generated since all DIEs will be able to
740
  /// properly refer to other DIE objects since all DIEs have calculated their
741
  /// offsets.
742
  ///
743
  /// \param AP AsmPrinter to use when calculating sizes.
744
  /// \param AbbrevSet the abbreviation used to unique DIE abbreviations.
745
  /// \param CUOffset the compile/type unit relative offset in bytes.
746
  /// \returns the offset for the DIE that follows this DIE within the
747
  /// current compile/type unit.
748
  unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP,
749
                                    DIEAbbrevSet &AbbrevSet, unsigned CUOffset);
750
751
  /// Climb up the parent chain to get the compile unit or type unit DIE that
752
  /// this DIE belongs to.
753
  ///
754
  /// \returns the compile or type unit DIE that owns this DIE, or NULL if
755
  /// this DIE hasn't been added to a unit DIE.
756
  const DIE *getUnitDie() const;
757
758
  /// Climb up the parent chain to get the compile unit or type unit that this
759
  /// DIE belongs to.
760
  ///
761
  /// \returns the DIEUnit that represents the compile or type unit that owns
762
  /// this DIE, or NULL if this DIE hasn't been added to a unit DIE.
763
  const DIEUnit *getUnit() const;
764
765
406k
  void setOffset(unsigned O) { Offset = O; }
766
406k
  void setSize(unsigned S) { Size = S; }
767
768
  /// Add a child to the DIE.
769
403k
  DIE &addChild(DIE *Child) {
770
403k
    assert(!Child->getParent() && "Child should be orphaned");
771
403k
    Child->Owner = this;
772
403k
    Children.push_back(*Child);
773
403k
    return Children.back();
774
403k
  }
775
776
  /// Find a value in the DIE with the attribute given.
777
  ///
778
  /// Returns a default-constructed DIEValue (where \a DIEValue::getType()
779
  /// gives \a DIEValue::isNone) if no such attribute exists.
780
  DIEValue findAttribute(dwarf::Attribute Attribute) const;
781
782
  void print(raw_ostream &O, unsigned IndentCount = 0) const;
783
  void dump() const;
784
};
785
786
//===--------------------------------------------------------------------===//
787
/// Represents a compile or type unit.
788
class DIEUnit {
789
  /// The compile unit or type unit DIE. This variable must be an instance of
790
  /// DIE so that we can calculate the DIEUnit from any DIE by traversing the
791
  /// parent backchain and getting the Unit DIE, and then casting itself to a
792
  /// DIEUnit. This allows us to be able to find the DIEUnit for any DIE without
793
  /// having to store a pointer to the DIEUnit in each DIE instance.
794
  DIE Die;
795
  /// The section this unit will be emitted in. This may or may not be set to
796
  /// a valid section depending on the client that is emitting DWARF.
797
  MCSection *Section;
798
  uint64_t Offset; /// .debug_info or .debug_types absolute section offset.
799
  uint32_t Length; /// The length in bytes of all of the DIEs in this unit.
800
  const uint16_t Version; /// The Dwarf version number for this unit.
801
  const uint8_t AddrSize; /// The size in bytes of an address for this unit.
802
protected:
803
  ~DIEUnit() = default;
804
805
public:
806
  DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag);
807
  DIEUnit(const DIEUnit &RHS) = delete;
808
  DIEUnit(DIEUnit &&RHS) = delete;
809
  void operator=(const DIEUnit &RHS) = delete;
810
  void operator=(const DIEUnit &&RHS) = delete;
811
  /// Set the section that this DIEUnit will be emitted into.
812
  ///
813
  /// This function is used by some clients to set the section. Not all clients
814
  /// that emit DWARF use this section variable.
815
2.69k
  void setSection(MCSection *Section) {
816
2.69k
    assert(!this->Section);
817
2.69k
    this->Section = Section;
818
2.69k
  }
819
820
30
  virtual const MCSymbol *getCrossSectionRelativeBaseAddress() const {
821
30
    return nullptr;
822
30
  }
823
824
  /// Return the section that this DIEUnit will be emitted into.
825
  ///
826
  /// \returns Section pointer which can be NULL.
827
2.69k
  MCSection *getSection() const { return Section; }
828
2.68k
  void setDebugSectionOffset(unsigned O) { Offset = O; }
829
338k
  unsigned getDebugSectionOffset() const { return Offset; }
830
  void setLength(uint64_t L) { Length = L; }
831
  uint64_t getLength() const { return Length; }
832
  uint16_t getDwarfVersion() const { return Version; }
833
  uint16_t getAddressSize() const { return AddrSize; }
834
424k
  DIE &getUnitDie() { return Die; }
835
0
  const DIE &getUnitDie() const { return Die; }
836
};
837
838
struct BasicDIEUnit final : DIEUnit {
839
  BasicDIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
840
      : DIEUnit(Version, AddrSize, UnitTag) {}
841
};
842
843
//===--------------------------------------------------------------------===//
844
/// DIELoc - Represents an expression location.
845
//
846
class DIELoc : public DIEValueList {
847
  mutable unsigned Size = 0; // Size in bytes excluding size header.
848
849
public:
850
2.39k
  DIELoc() = default;
851
852
  /// ComputeSize - Calculate the size of the location expression.
853
  ///
854
  unsigned ComputeSize(const AsmPrinter *AP) const;
855
856
  /// BestForm - Choose the best form for data.
857
  ///
858
2.28k
  dwarf::Form BestForm(unsigned DwarfVersion) const {
859
2.28k
    if (DwarfVersion > 3)
860
1.85k
      return dwarf::DW_FORM_exprloc;
861
425
    // Pre-DWARF4 location expressions were blocks and not exprloc.
862
425
    if ((unsigned char)Size == Size)
863
425
      return dwarf::DW_FORM_block1;
864
0
    if ((unsigned short)Size == Size)
865
0
      return dwarf::DW_FORM_block2;
866
0
    if ((unsigned int)Size == Size)
867
0
      return dwarf::DW_FORM_block4;
868
0
    return dwarf::DW_FORM_block;
869
0
  }
870
871
  void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
872
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
873
874
  void print(raw_ostream &O) const;
875
};
876
877
//===--------------------------------------------------------------------===//
878
/// DIEBlock - Represents a block of values.
879
//
880
class DIEBlock : public DIEValueList {
881
  mutable unsigned Size = 0; // Size in bytes excluding size header.
882
883
public:
884
661
  DIEBlock() = default;
885
886
  /// ComputeSize - Calculate the size of the location expression.
887
  ///
888
  unsigned ComputeSize(const AsmPrinter *AP) const;
889
890
  /// BestForm - Choose the best form for data.
891
  ///
892
1
  dwarf::Form BestForm() const {
893
1
    if ((unsigned char)Size == Size)
894
1
      return dwarf::DW_FORM_block1;
895
0
    if ((unsigned short)Size == Size)
896
0
      return dwarf::DW_FORM_block2;
897
0
    if ((unsigned int)Size == Size)
898
0
      return dwarf::DW_FORM_block4;
899
0
    return dwarf::DW_FORM_block;
900
0
  }
901
902
  void EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
903
  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
904
905
  void print(raw_ostream &O) const;
906
};
907
908
} // end namespace llvm
909
910
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H