Coverage Report

Created: 2018-09-23 16:00

/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.64M
      : 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
187k
  dwarf::Attribute getAttribute() const { return Attribute; }
68
278k
  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
400k
  DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C) {}
97
98
  /// Accessors.
99
  /// @{
100
  dwarf::Tag getTag() const { return Tag; }
101
400k
  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.4k
  void setNumber(unsigned N) { Number = N; }
106
  /// @}
107
108
  /// Adds another set of attribute information to the abbreviation.
109
1.64M
  void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
110
1.64M
    Data.push_back(DIEAbbrevData(Attribute, Form));
111
1.64M
  }
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
65.2k
  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
823k
  explicit DIEInteger(uint64_t I) : Integer(I) {}
168
169
  /// Choose the best form for integer.
170
600k
  static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
171
600k
    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
600k
    } else {
180
600k
      if ((unsigned char)Int == Int)
181
475k
        return dwarf::DW_FORM_data1;
182
124k
      if ((unsigned short)Int == Int)
183
124k
        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
27
  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
559k
  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.7k
  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
101k
  DIEString(DwarfStringPoolEntryRef S) : S(S) {}
258
259
  /// Grab the string out of the object.
260
274
  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
474
  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
305k
  explicit DIEEntry(DIE &E) : Entry(&E) {}
300
301
304k
  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
336
  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
4.94M
  template <class T> void construct(T V) {
363
4.94M
    static_assert(std::is_standard_layout<T>::value ||
364
4.94M
                      std::is_pointer<T>::value,
365
4.94M
                  "Expected standard layout or pointer");
366
4.94M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
4.94M
  }
void llvm::DIEValue::construct<llvm::DIEInteger>(llvm::DIEInteger)
Line
Count
Source
362
1.87M
  template <class T> void construct(T V) {
363
1.87M
    static_assert(std::is_standard_layout<T>::value ||
364
1.87M
                      std::is_pointer<T>::value,
365
1.87M
                  "Expected standard layout or pointer");
366
1.87M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.87M
  }
void llvm::DIEValue::construct<llvm::DIEString>(llvm::DIEString)
Line
Count
Source
362
305k
  template <class T> void construct(T V) {
363
305k
    static_assert(std::is_standard_layout<T>::value ||
364
305k
                      std::is_pointer<T>::value,
365
305k
                  "Expected standard layout or pointer");
366
305k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
305k
  }
void llvm::DIEValue::construct<llvm::DIEExpr>(llvm::DIEExpr)
Line
Count
Source
362
81
  template <class T> void construct(T V) {
363
81
    static_assert(std::is_standard_layout<T>::value ||
364
81
                      std::is_pointer<T>::value,
365
81
                  "Expected standard layout or pointer");
366
81
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
81
  }
void llvm::DIEValue::construct<llvm::DIELabel>(llvm::DIELabel)
Line
Count
Source
362
1.66M
  template <class T> void construct(T V) {
363
1.66M
    static_assert(std::is_standard_layout<T>::value ||
364
1.66M
                      std::is_pointer<T>::value,
365
1.66M
                  "Expected standard layout or pointer");
366
1.66M
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.66M
  }
void llvm::DIEValue::construct<llvm::DIEDelta const*>(llvm::DIEDelta const*)
Line
Count
Source
362
179k
  template <class T> void construct(T V) {
363
179k
    static_assert(std::is_standard_layout<T>::value ||
364
179k
                      std::is_pointer<T>::value,
365
179k
                  "Expected standard layout or pointer");
366
179k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
179k
  }
void llvm::DIEValue::construct<llvm::DIEEntry>(llvm::DIEEntry)
Line
Count
Source
362
915k
  template <class T> void construct(T V) {
363
915k
    static_assert(std::is_standard_layout<T>::value ||
364
915k
                      std::is_pointer<T>::value,
365
915k
                  "Expected standard layout or pointer");
366
915k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
915k
  }
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.05k
  template <class T> void construct(T V) {
363
7.05k
    static_assert(std::is_standard_layout<T>::value ||
364
7.05k
                      std::is_pointer<T>::value,
365
7.05k
                  "Expected standard layout or pointer");
366
7.05k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
7.05k
  }
void llvm::DIEValue::construct<llvm::DIELocList>(llvm::DIELocList)
Line
Count
Source
362
1.01k
  template <class T> void construct(T V) {
363
1.01k
    static_assert(std::is_standard_layout<T>::value ||
364
1.01k
                      std::is_pointer<T>::value,
365
1.01k
                  "Expected standard layout or pointer");
366
1.01k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.01k
  }
void llvm::DIEValue::construct<llvm::DIEInlineString const*>(llvm::DIEInlineString const*)
Line
Count
Source
362
1.42k
  template <class T> void construct(T V) {
363
1.42k
    static_assert(std::is_standard_layout<T>::value ||
364
1.42k
                      std::is_pointer<T>::value,
365
1.42k
                  "Expected standard layout or pointer");
366
1.42k
    new (reinterpret_cast<void *>(Val.buffer)) T(V);
367
1.42k
  }
368
369
3.29M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEInteger* llvm::DIEValue::get<llvm::DIEInteger>()
Line
Count
Source
369
1.25M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEString* llvm::DIEValue::get<llvm::DIEString>()
Line
Count
Source
369
203k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEExpr* llvm::DIEValue::get<llvm::DIEExpr>()
Line
Count
Source
369
54
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELabel* llvm::DIEValue::get<llvm::DIELabel>()
Line
Count
Source
369
1.10M
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEDelta const** llvm::DIEValue::get<llvm::DIEDelta const*>()
Line
Count
Source
369
119k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEEntry* llvm::DIEValue::get<llvm::DIEEntry>()
Line
Count
Source
369
610k
  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.74k
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIELocList* llvm::DIEValue::get<llvm::DIELocList>()
Line
Count
Source
369
675
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
llvm::DIEInlineString const** llvm::DIEValue::get<llvm::DIEInlineString const*>()
Line
Count
Source
369
948
  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
370
6.58M
  template <class T> const T *get() const {
371
6.58M
    return reinterpret_cast<const T *>(Val.buffer);
372
6.58M
  }
llvm::DIEInteger const* llvm::DIEValue::get<llvm::DIEInteger>() const
Line
Count
Source
370
2.49M
  template <class T> const T *get() const {
371
2.49M
    return reinterpret_cast<const T *>(Val.buffer);
372
2.49M
  }
llvm::DIEString const* llvm::DIEValue::get<llvm::DIEString>() const
Line
Count
Source
370
407k
  template <class T> const T *get() const {
371
407k
    return reinterpret_cast<const T *>(Val.buffer);
372
407k
  }
llvm::DIEExpr const* llvm::DIEValue::get<llvm::DIEExpr>() const
Line
Count
Source
370
108
  template <class T> const T *get() const {
371
108
    return reinterpret_cast<const T *>(Val.buffer);
372
108
  }
llvm::DIELabel const* llvm::DIEValue::get<llvm::DIELabel>() const
Line
Count
Source
370
2.21M
  template <class T> const T *get() const {
371
2.21M
    return reinterpret_cast<const T *>(Val.buffer);
372
2.21M
  }
llvm::DIEDelta const* const* llvm::DIEValue::get<llvm::DIEDelta const*>() const
Line
Count
Source
370
239k
  template <class T> const T *get() const {
371
239k
    return reinterpret_cast<const T *>(Val.buffer);
372
239k
  }
llvm::DIEEntry const* llvm::DIEValue::get<llvm::DIEEntry>() const
Line
Count
Source
370
1.21M
  template <class T> const T *get() const {
371
1.21M
    return reinterpret_cast<const T *>(Val.buffer);
372
1.21M
  }
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.34k
  template <class T> const T *get() const {
371
9.34k
    return reinterpret_cast<const T *>(Val.buffer);
372
9.34k
  }
llvm::DIELocList const* llvm::DIEValue::get<llvm::DIELocList>() const
Line
Count
Source
370
1.35k
  template <class T> const T *get() const {
371
1.35k
    return reinterpret_cast<const T *>(Val.buffer);
372
1.35k
  }
llvm::DIEInlineString const* const* llvm::DIEValue::get<llvm::DIEInlineString const*>() const
Line
Count
Source
370
1.89k
  template <class T> const T *get() const {
371
1.89k
    return reinterpret_cast<const T *>(Val.buffer);
372
1.89k
  }
373
3.29M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEInteger>()
Line
Count
Source
373
1.25M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEString>()
Line
Count
Source
373
203k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEExpr>()
Line
Count
Source
373
54
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELabel>()
Line
Count
Source
373
1.10M
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEDelta const*>()
Line
Count
Source
373
119k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEEntry>()
Line
Count
Source
373
610k
  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.74k
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIELocList>()
Line
Count
Source
373
675
  template <class T> void destruct() { get<T>()->~T(); }
void llvm::DIEValue::destruct<llvm::DIEInlineString const*>()
Line
Count
Source
373
948
  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.45M
  void destroyVal() {
381
3.45M
    switch (Ty) {
382
3.45M
    case isNone:
383
154k
      return;
384
3.45M
#define HANDLE_DIEVALUE_SMALL(T)                                               \
385
3.45M
  case is##T:                                                                  \
386
3.17M
    destruct<DIE##T>();                                                        \
387
3.17M
    return;
388
3.45M
#define HANDLE_DIEVALUE_LARGE(T)                                               \
389
3.45M
  case is##T:                                                                  \
390
127k
    destruct<const DIE##T *>();                                                \
391
127k
    return;
392
3.45M
#include 
"llvm/CodeGen/DIEValue.def"1.25M
393
3.45M
    }
394
3.45M
  }
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.29M
  void copyVal(const DIEValue &X) {
402
3.29M
    switch (Ty) {
403
3.29M
    case isNone:
404
0
      return;
405
3.29M
#define HANDLE_DIEVALUE_SMALL(T)                                               \
406
3.29M
  case is##T:                                                                  \
407
3.17M
    construct<DIE##T>(*X.get<DIE##T>());                                       \
408
3.17M
    return;
409
3.29M
#define HANDLE_DIEVALUE_LARGE(T)                                               \
410
3.29M
  case is##T:                                                                  \
411
127k
    construct<const DIE##T *>(*X.get<const DIE##T *>());                       \
412
127k
    return;
413
3.29M
#include 
"llvm/CodeGen/DIEValue.def"1.25M
414
3.29M
    }
415
3.29M
  }
416
417
public:
418
154k
  DIEValue() = default;
419
420
3.29M
  DIEValue(const DIEValue &X) : Ty(X.Ty), Attribute(X.Attribute), Form(X.Form) {
421
3.29M
    copyVal(X);
422
3.29M
  }
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.45M
  ~DIEValue() { destroyVal(); }
434
435
#define HANDLE_DIEVALUE_SMALL(T)                                               \
436
  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V)      \
437
1.58M
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
1.58M
    construct<DIE##T>(V);                                                      \
439
1.58M
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInteger const&)
Line
Count
Source
437
625k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
625k
    construct<DIE##T>(V);                                                      \
439
625k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELabel const&)
Line
Count
Source
437
553k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
553k
    construct<DIE##T>(V);                                                      \
439
553k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELocList const&)
Line
Count
Source
437
336
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
336
    construct<DIE##T>(V);                                                      \
439
336
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEExpr const&)
Line
Count
Source
437
27
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
27
    construct<DIE##T>(V);                                                      \
439
27
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEString const&)
Line
Count
Source
437
101k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
101k
    construct<DIE##T>(V);                                                      \
439
101k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEEntry const&)
Line
Count
Source
437
305k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
438
305k
    construct<DIE##T>(V);                                                      \
439
305k
  }
440
#define HANDLE_DIEVALUE_LARGE(T)                                               \
441
  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V)      \
442
63.2k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
63.2k
    assert(V && "Expected valid value");                                       \
444
63.2k
    construct<const DIE##T *>(V);                                              \
445
63.2k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEInlineString const*)
Line
Count
Source
442
474
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
474
    assert(V && "Expected valid value");                                       \
444
474
    construct<const DIE##T *>(V);                                              \
445
474
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIEDelta const*)
Line
Count
Source
442
59.7k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
59.7k
    assert(V && "Expected valid value");                                       \
444
59.7k
    construct<const DIE##T *>(V);                                              \
445
59.7k
  }
llvm::DIEValue::DIEValue(llvm::dwarf::Attribute, llvm::dwarf::Form, llvm::DIELoc const*)
Line
Count
Source
442
2.30k
      : Ty(is##T), Attribute(Attribute), Form(Form) {                          \
443
2.30k
    assert(V && "Expected valid value");                                       \
444
2.30k
    construct<const DIE##T *>(V);                                              \
445
2.30k
  }
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
525
  Type getType() const { return Ty; }
451
3.54M
  dwarf::Attribute getAttribute() const { return Attribute; }
452
3.28M
  dwarf::Form getForm() const { return Form; }
453
153k
  explicit operator bool() const { return Ty; }
454
  /// @}
455
456
#define HANDLE_DIEVALUE_SMALL(T)                                               \
457
3.16M
  const DIE##T &getDIE##T() const {                                            \
458
3.16M
    assert(getType() == is##T && "Expected " #T);                              \
459
3.16M
    return *get<DIE##T>();                                                     \
460
3.16M
  }
llvm::DIEValue::getDIEInteger() const
Line
Count
Source
457
1.24M
  const DIE##T &getDIE##T() const {                                            \
458
1.24M
    assert(getType() == is##T && "Expected " #T);                              \
459
1.24M
    return *get<DIE##T>();                                                     \
460
1.24M
  }
llvm::DIEValue::getDIEString() const
Line
Count
Source
457
203k
  const DIE##T &getDIE##T() const {                                            \
458
203k
    assert(getType() == is##T && "Expected " #T);                              \
459
203k
    return *get<DIE##T>();                                                     \
460
203k
  }
llvm::DIEValue::getDIEExpr() const
Line
Count
Source
457
54
  const DIE##T &getDIE##T() const {                                            \
458
54
    assert(getType() == is##T && "Expected " #T);                              \
459
54
    return *get<DIE##T>();                                                     \
460
54
  }
llvm::DIEValue::getDIELabel() const
Line
Count
Source
457
1.10M
  const DIE##T &getDIE##T() const {                                            \
458
1.10M
    assert(getType() == is##T && "Expected " #T);                              \
459
1.10M
    return *get<DIE##T>();                                                     \
460
1.10M
  }
llvm::DIEValue::getDIEEntry() const
Line
Count
Source
457
609k
  const DIE##T &getDIE##T() const {                                            \
458
609k
    assert(getType() == is##T && "Expected " #T);                              \
459
609k
    return *get<DIE##T>();                                                     \
460
609k
  }
llvm::DIEValue::getDIELocList() const
Line
Count
Source
457
675
  const DIE##T &getDIE##T() const {                                            \
458
675
    assert(getType() == is##T && "Expected " #T);                              \
459
675
    return *get<DIE##T>();                                                     \
460
675
  }
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
119k
  const DIE##T &getDIE##T() const {                                            \
463
119k
    assert(getType() == is##T && "Expected " #T);                              \
464
119k
    return **get<const DIE##T *>();                                            \
465
119k
  }
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.59k
  const DIE##T &getDIE##T() const {                                            \
463
4.59k
    assert(getType() == is##T && "Expected " #T);                              \
464
4.59k
    return **get<const DIE##T *>();                                            \
465
4.59k
  }
llvm::DIEValue::getDIEInlineString() const
Line
Count
Source
462
948
  const DIE##T &getDIE##T() const {                                            \
463
948
    assert(getType() == is##T && "Expected " #T);                              \
464
948
    return **get<const DIE##T *>();                                            \
465
948
  }
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.04M
  IntrusiveBackListNode() : Next(this, true) {}
482
483
5.98M
  IntrusiveBackListNode *getNext() const {
484
5.98M
    return Next.getInt() ? 
nullptr1.70M
:
Next.getPointer()4.28M
;
485
5.98M
  }
486
};
487
488
struct IntrusiveBackListBase {
489
  using Node = IntrusiveBackListNode;
490
491
  Node *Last = nullptr;
492
493
1.19M
  bool empty() const { return !Last; }
494
495
2.04M
  void push_back(Node &N) {
496
2.04M
    assert(N.Next.getPointer() == &N && "Expected unlinked node");
497
2.04M
    assert(N.Next.getInt() == true && "Expected unlinked node");
498
2.04M
499
2.04M
    if (Last) {
500
1.46M
      N.Next = Last->Next;
501
1.46M
      Last->Next.setPointerAndInt(&N, false);
502
1.46M
    }
503
2.04M
    Last = &N;
504
2.04M
  }
505
};
506
507
template <class T> class IntrusiveBackList : IntrusiveBackListBase {
508
public:
509
  using IntrusiveBackListBase::empty;
510
511
2.04M
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::push_back(llvm::DIEValueList::Node&)
Line
Count
Source
511
1.64M
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
llvm::IntrusiveBackList<llvm::DIE>::push_back(llvm::DIE&)
Line
Count
Source
511
396k
  void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
512
2.04M
  T &back() { return *static_cast<T *>(Last); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::back()
Line
Count
Source
512
1.64M
  T &back() { return *static_cast<T *>(Last); }
llvm::IntrusiveBackList<llvm::DIE>::back()
Line
Count
Source
512
396k
  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
579k
    iterator() = default;
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::iterator()
Line
Count
Source
523
400k
    iterator() = default;
llvm::IntrusiveBackList<llvm::DIE>::iterator::iterator()
Line
Count
Source
523
178k
    iterator() = default;
524
3.35M
    explicit iterator(T *N) : N(N) {}
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::iterator(llvm::DIEValueList::Node*)
Line
Count
Source
524
2.99M
    explicit iterator(T *N) : N(N) {}
llvm::IntrusiveBackList<llvm::DIE>::iterator::iterator(llvm::DIE*)
Line
Count
Source
524
358k
    explicit iterator(T *N) : N(N) {}
525
526
2.02M
    iterator &operator++() {
527
2.02M
      N = N->getNext();
528
2.02M
      return *this;
529
2.02M
    }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator++()
Line
Count
Source
526
1.63M
    iterator &operator++() {
527
1.63M
      N = N->getNext();
528
1.63M
      return *this;
529
1.63M
    }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator++()
Line
Count
Source
526
394k
    iterator &operator++() {
527
394k
      N = N->getNext();
528
394k
      return *this;
529
394k
    }
530
531
0
    explicit operator bool() const { return N; }
532
2.03M
    T &operator*() const { return *static_cast<T *>(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::iterator::operator*() const
Line
Count
Source
532
1.63M
    T &operator*() const { return *static_cast<T *>(N); }
llvm::IntrusiveBackList<llvm::DIE>::iterator::operator*() const
Line
Count
Source
532
394k
    T &operator*() const { return *static_cast<T *>(N); }
533
534
2.03M
    bool operator==(const iterator &X) const { return N == X.N; }
535
573k
    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.12M
    const_iterator() = default;
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::const_iterator()
Line
Count
Source
544
945k
    const_iterator() = default;
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::const_iterator()
Line
Count
Source
544
179k
    const_iterator() = default;
545
    // Placate MSVC by explicitly scoping 'iterator'.
546
1.12M
    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
945k
    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
179k
    const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {}
547
    explicit const_iterator(const T *N) : N(N) {}
548
549
3.95M
    const_iterator &operator++() {
550
3.95M
      N = N->getNext();
551
3.95M
      return *this;
552
3.95M
    }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::operator++()
Line
Count
Source
549
3.55M
    const_iterator &operator++() {
550
3.55M
      N = N->getNext();
551
3.55M
      return *this;
552
3.55M
    }
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::operator++()
Line
Count
Source
549
396k
    const_iterator &operator++() {
550
396k
      N = N->getNext();
551
396k
      return *this;
552
396k
    }
553
554
0
    explicit operator bool() const { return N; }
555
3.95M
    const T &operator*() const { return *static_cast<const T *>(N); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::const_iterator::operator*() const
Line
Count
Source
555
3.55M
    const T &operator*() const { return *static_cast<const T *>(N); }
llvm::IntrusiveBackList<llvm::DIE>::const_iterator::operator*() const
Line
Count
Source
555
396k
    const T &operator*() const { return *static_cast<const T *>(N); }
556
557
4.50M
    bool operator==(const const_iterator &X) const { return N == X.N; }
558
576k
    bool operator!=(const const_iterator &X) const { return N != X.N; }
559
  };
560
561
1.70M
  iterator begin() {
562
1.70M
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))1.70M
:
end()499
;
563
1.70M
  }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::begin()
Line
Count
Source
561
1.34M
  iterator begin() {
562
1.34M
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))1.34M
:
end()331
;
563
1.34M
  }
llvm::IntrusiveBackList<llvm::DIE>::begin()
Line
Count
Source
561
358k
  iterator begin() {
562
358k
    return Last ? 
iterator(static_cast<T *>(Last->Next.getPointer()))358k
:
end()168
;
563
358k
  }
564
1.12M
  const_iterator begin() const {
565
1.12M
    return const_cast<IntrusiveBackList *>(this)->begin();
566
1.12M
  }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::begin() const
Line
Count
Source
564
945k
  const_iterator begin() const {
565
945k
    return const_cast<IntrusiveBackList *>(this)->begin();
566
945k
  }
llvm::IntrusiveBackList<llvm::DIE>::begin() const
Line
Count
Source
564
179k
  const_iterator begin() const {
565
179k
    return const_cast<IntrusiveBackList *>(this)->begin();
566
179k
  }
567
577k
  iterator end() { return iterator(); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::end()
Line
Count
Source
567
398k
  iterator end() { return iterator(); }
llvm::IntrusiveBackList<llvm::DIE>::end()
Line
Count
Source
567
178k
  iterator end() { return iterator(); }
568
1.12M
  const_iterator end() const { return const_iterator(); }
llvm::IntrusiveBackList<llvm::DIEValueList::Node>::end() const
Line
Count
Source
568
945k
  const_iterator end() const { return const_iterator(); }
llvm::IntrusiveBackList<llvm::DIE>::end() const
Line
Count
Source
568
179k
  const_iterator end() const { return const_iterator(); }
569
570
1.64M
  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.64M
    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.68k
    value_iterator() = default;
613
2.44M
    explicit value_iterator(ListTy::iterator X) : iterator_adaptor(X) {}
614
615
0
    explicit operator bool() const { return bool(wrapped()); }
616
1.63M
    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.89M
        : iterator_adaptor(X) {}
632
633
0
    explicit operator bool() const { return bool(wrapped()); }
634
3.55M
    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.64M
  value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V) {
641
1.64M
    List.push_back(*new (Alloc) Node(V));
642
1.64M
    return value_iterator(ListTy::toIterator(List.back()));
643
1.64M
  }
644
  template <class T>
645
  value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute,
646
1.64M
                    dwarf::Form Form, T &&Value) {
647
1.64M
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
1.64M
  }
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
624k
                    dwarf::Form Form, T &&Value) {
647
624k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
624k
  }
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
553k
                    dwarf::Form Form, T &&Value) {
647
553k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
553k
  }
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
336
                    dwarf::Form Form, T &&Value) {
647
336
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
336
  }
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
27
                    dwarf::Form Form, T &&Value) {
647
27
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
27
  }
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
474
                    dwarf::Form Form, T &&Value) {
647
474
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
474
  }
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
101k
                    dwarf::Form Form, T &&Value) {
647
101k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
101k
  }
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.7k
                    dwarf::Form Form, T &&Value) {
647
59.7k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
59.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
646
304k
                    dwarf::Form Form, T &&Value) {
647
304k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
304k
  }
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.22k
                    dwarf::Form Form, T &&Value) {
647
2.22k
    return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
648
2.22k
  }
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
397k
  value_range values() {
651
397k
    return make_range(value_iterator(List.begin()), value_iterator(List.end()));
652
397k
  }
653
945k
  const_value_range values() const {
654
945k
    return make_range(const_value_iterator(List.begin()),
655
945k
                      const_value_iterator(List.end()));
656
945k
  }
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
399k
  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
396k
  static DIE *get(BumpPtrAllocator &Alloc, dwarf::Tag Tag) {
693
396k
    return new (Alloc) DIE(Tag);
694
396k
  }
695
696
  // Accessors.
697
801k
  unsigned getAbbrevNumber() const { return AbbrevNumber; }
698
4.61M
  dwarf::Tag getTag() const { return Tag; }
699
  /// Get the compile/type unit relative offset of this DIE.
700
1.95M
  unsigned getOffset() const { return Offset; }
701
11.3k
  unsigned getSize() const { return Size; }
702
1.19M
  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
178k
  child_range children() {
711
178k
    return make_range(Children.begin(), Children.end());
712
178k
  }
713
179k
  const_child_range children() const {
714
179k
    return make_range(Children.begin(), Children.end());
715
179k
  }
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
399k
  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
399k
  void setOffset(unsigned O) { Offset = O; }
766
399k
  void setSize(unsigned S) { Size = S; }
767
768
  /// Add a child to the DIE.
769
396k
  DIE &addChild(DIE *Child) {
770
396k
    assert(!Child->getParent() && "Child should be orphaned");
771
396k
    Child->Owner = this;
772
396k
    Children.push_back(*Child);
773
396k
    return Children.back();
774
396k
  }
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.66k
  void setSection(MCSection *Section) {
816
2.66k
    assert(!this->Section);
817
2.66k
    this->Section = Section;
818
2.66k
  }
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.66k
  MCSection *getSection() const { return Section; }
828
2.65k
  void setDebugSectionOffset(unsigned O) { Offset = O; }
829
332k
  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
417k
  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.31k
  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.22k
  dwarf::Form BestForm(unsigned DwarfVersion) const {
859
2.22k
    if (DwarfVersion > 3)
860
1.79k
      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