LLVM  4.0.0
DIE.h
Go to the documentation of this file.
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"
19 #include "llvm/ADT/PointerUnion.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/ADT/iterator.h"
25 #include "llvm/Support/AlignOf.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/Dwarf.h"
28 #include <cassert>
29 #include <cstddef>
30 #include <cstdint>
31 #include <iterator>
32 #include <new>
33 #include <type_traits>
34 #include <vector>
35 
36 namespace llvm {
37 
38 class AsmPrinter;
39 class DIE;
40 class DIEUnit;
41 class MCExpr;
42 class MCSection;
43 class MCSymbol;
44 class raw_ostream;
45 
46 //===--------------------------------------------------------------------===//
47 /// Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
49  /// Dwarf attribute code.
51 
52  /// Dwarf form code.
54 
55  /// Dwarf attribute value for DW_FORM_implicit_const
56  int64_t Value;
57 
58 public:
60  : Attribute(A), Form(F), Value(0) {}
62  : Attribute(A), Form(dwarf::DW_FORM_implicit_const), Value(V) {}
63 
64  /// Accessors.
65  /// @{
67  dwarf::Form getForm() const { return Form; }
68  int64_t getValue() const { return Value; }
69  /// @}
70 
71  /// Used to gather unique data for the abbreviation folding set.
72  void Profile(FoldingSetNodeID &ID) const;
73 };
74 
75 //===--------------------------------------------------------------------===//
76 /// Dwarf abbreviation, describes the organization of a debug information
77 /// object.
78 class DIEAbbrev : public FoldingSetNode {
79  /// Unique number for node.
80  unsigned Number;
81 
82  /// Dwarf tag code.
84 
85  /// Whether or not this node has children.
86  ///
87  /// This cheats a bit in all of the uses since the values in the standard
88  /// are 0 and 1 for no children and children respectively.
89  bool Children;
90 
91  /// Raw data bytes for abbreviation.
93 
94 public:
95  DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C) {}
96 
97  /// Accessors.
98  /// @{
99  dwarf::Tag getTag() const { return Tag; }
100  unsigned getNumber() const { return Number; }
101  bool hasChildren() const { return Children; }
102  const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
103  void setChildrenFlag(bool hasChild) { Children = hasChild; }
104  void setNumber(unsigned N) { Number = N; }
105  /// @}
106 
107  /// Adds another set of attribute information to the abbreviation.
109  Data.push_back(DIEAbbrevData(Attribute, Form));
110  }
111 
112  /// Adds attribute with DW_FORM_implicit_const value
114  Data.push_back(DIEAbbrevData(Attribute, Value));
115  }
116 
117  /// Used to gather unique data for the abbreviation folding set.
118  void Profile(FoldingSetNodeID &ID) const;
119 
120  /// Print the abbreviation using the specified asm printer.
121  void Emit(const AsmPrinter *AP) const;
122 
123  void print(raw_ostream &O);
124  void dump();
125 };
126 
127 //===--------------------------------------------------------------------===//
128 /// Helps unique DIEAbbrev objects and assigns abbreviation numbers.
129 ///
130 /// This class will unique the DIE abbreviations for a llvm::DIE object and
131 /// assign a unique abbreviation number to each unique DIEAbbrev object it
132 /// finds. The resulting collection of DIEAbbrev objects can then be emitted
133 /// into the .debug_abbrev section.
135  /// The bump allocator to use when creating DIEAbbrev objects in the uniqued
136  /// storage container.
137  BumpPtrAllocator &Alloc;
138  /// \brief FoldingSet that uniques the abbreviations.
139  llvm::FoldingSet<DIEAbbrev> AbbreviationsSet;
140  /// A list of all the unique abbreviations in use.
141  std::vector<DIEAbbrev *> Abbreviations;
142 
143 public:
145  ~DIEAbbrevSet();
146  /// Generate the abbreviation declaration for a DIE and return a pointer to
147  /// the generated abbreviation.
148  ///
149  /// \param Die the debug info entry to generate the abbreviation for.
150  /// \returns A reference to the uniqued abbreviation declaration that is
151  /// owned by this class.
153 
154  /// Print all abbreviations using the specified asm printer.
155  void Emit(const AsmPrinter *AP, MCSection *Section) const;
156 };
157 
158 //===--------------------------------------------------------------------===//
159 /// An integer value DIE.
160 ///
161 class DIEInteger {
162  uint64_t Integer;
163 
164 public:
165  explicit DIEInteger(uint64_t I) : Integer(I) {}
166 
167  /// Choose the best form for integer.
168  static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
169  if (IsSigned) {
170  const int64_t SignedInt = Int;
171  if ((char)Int == SignedInt)
172  return dwarf::DW_FORM_data1;
173  if ((short)Int == SignedInt)
174  return dwarf::DW_FORM_data2;
175  if ((int)Int == SignedInt)
176  return dwarf::DW_FORM_data4;
177  } else {
178  if ((unsigned char)Int == Int)
179  return dwarf::DW_FORM_data1;
180  if ((unsigned short)Int == Int)
181  return dwarf::DW_FORM_data2;
182  if ((unsigned int)Int == Int)
183  return dwarf::DW_FORM_data4;
184  }
185  return dwarf::DW_FORM_data8;
186  }
187 
188  uint64_t getValue() const { return Integer; }
189  void setValue(uint64_t Val) { Integer = Val; }
190 
191  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
192  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
193 
194  void print(raw_ostream &O) const;
195 };
196 
197 //===--------------------------------------------------------------------===//
198 /// An expression DIE.
199 class DIEExpr {
200  const MCExpr *Expr;
201 
202 public:
203  explicit DIEExpr(const MCExpr *E) : Expr(E) {}
204 
205  /// Get MCExpr.
206  const MCExpr *getValue() const { return Expr; }
207 
208  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
209  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
210 
211  void print(raw_ostream &O) const;
212 };
213 
214 //===--------------------------------------------------------------------===//
215 /// A label DIE.
216 class DIELabel {
217  const MCSymbol *Label;
218 
219 public:
220  explicit DIELabel(const MCSymbol *L) : Label(L) {}
221 
222  /// Get MCSymbol.
223  const MCSymbol *getValue() const { return Label; }
224 
225  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
226  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
227 
228  void print(raw_ostream &O) const;
229 };
230 
231 //===--------------------------------------------------------------------===//
232 /// A simple label difference DIE.
233 ///
234 class DIEDelta {
235  const MCSymbol *LabelHi;
236  const MCSymbol *LabelLo;
237 
238 public:
239  DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) : LabelHi(Hi), LabelLo(Lo) {}
240 
241  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
242  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
243 
244  void print(raw_ostream &O) const;
245 };
246 
247 //===--------------------------------------------------------------------===//
248 /// A container for string pool string values.
249 ///
250 /// This class is used with the DW_FORM_strp and DW_FORM_GNU_str_index forms.
251 class DIEString {
253 
254 public:
256 
257  /// Grab the string out of the object.
258  StringRef getString() const { return S.getString(); }
259 
260  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
261  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
262 
263  void print(raw_ostream &O) const;
264 };
265 
266 //===--------------------------------------------------------------------===//
267 /// A container for inline string values.
268 ///
269 /// This class is used with the DW_FORM_string form.
271  StringRef S;
272 
273 public:
274  template <typename Allocator>
275  explicit DIEInlineString(StringRef Str, Allocator &A) : S(Str.copy(A)) {}
276 
277  ~DIEInlineString() = default;
278 
279  /// Grab the string out of the object.
280  StringRef getString() const { return S; }
281 
282  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
283  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
284 
285  void print(raw_ostream &O) const;
286 };
287 
288 //===--------------------------------------------------------------------===//
289 /// A pointer to another debug information entry. An instance of this class can
290 /// also be used as a proxy for a debug information entry not yet defined
291 /// (ie. types.)
292 class DIE;
293 class DIEEntry {
294  DIE *Entry;
295 
296  DIEEntry() = delete;
297 
298 public:
299  explicit DIEEntry(DIE &E) : Entry(&E) {}
300 
301  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  DIELocList(size_t I) : Index(I) {}
318 
319  /// Grab the current index out.
320  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 {
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  typedef AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
352  DIEDelta *, DIEEntry, DIEBlock *, DIELoc *,
353  DIELocList>
354  ValTy;
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  template <class T> void construct(T V) {
363  static_assert(std::is_standard_layout<T>::value ||
364  std::is_pointer<T>::value,
365  "Expected standard layout or pointer");
366  new (reinterpret_cast<void *>(Val.buffer)) T(V);
367  }
368 
369  template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
370  template <class T> const T *get() const {
371  return reinterpret_cast<const T *>(Val.buffer);
372  }
373  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  void destroyVal() {
381  switch (Ty) {
382  case isNone:
383  return;
384 #define HANDLE_DIEVALUE_SMALL(T) \
385  case is##T: \
386  destruct<DIE##T>();
387  return;
388 #define HANDLE_DIEVALUE_LARGE(T) \
389  case is##T: \
390  destruct<const DIE##T *>();
391  return;
392 #include "llvm/CodeGen/DIEValue.def"
393  }
394  }
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  void copyVal(const DIEValue &X) {
402  switch (Ty) {
403  case isNone:
404  return;
405 #define HANDLE_DIEVALUE_SMALL(T) \
406  case is##T: \
407  construct<DIE##T>(*X.get<DIE##T>()); \
408  return;
409 #define HANDLE_DIEVALUE_LARGE(T) \
410  case is##T: \
411  construct<const DIE##T *>(*X.get<const DIE##T *>()); \
412  return;
413 #include "llvm/CodeGen/DIEValue.def"
414  }
415  }
416 
417 public:
418  DIEValue() = default;
419 
420  DIEValue(const DIEValue &X) : Ty(X.Ty), Attribute(X.Attribute), Form(X.Form) {
421  copyVal(X);
422  }
423 
425  destroyVal();
426  Ty = X.Ty;
427  Attribute = X.Attribute;
428  Form = X.Form;
429  copyVal(X);
430  return *this;
431  }
432 
433  ~DIEValue() { destroyVal(); }
434 
435 #define HANDLE_DIEVALUE_SMALL(T) \
436  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V) \
437  : Ty(is##T), Attribute(Attribute), Form(Form) { \
438  construct<DIE##T>(V); \
439  }
440 #define HANDLE_DIEVALUE_LARGE(T) \
441  DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V) \
442  : Ty(is##T), Attribute(Attribute), Form(Form) { \
443  assert(V && "Expected valid value"); \
444  construct<const DIE##T *>(V); \
445  }
446 #include "llvm/CodeGen/DIEValue.def"
447 
448  /// Accessors.
449  /// @{
450  Type getType() const { return Ty; }
452  dwarf::Form getForm() const { return Form; }
453  explicit operator bool() const { return Ty; }
454  /// @}
455 
456 #define HANDLE_DIEVALUE_SMALL(T) \
457  const DIE##T &getDIE##T() const { \
458  assert(getType() == is##T && "Expected " #T); \
459  return *get<DIE##T>(); \
460  }
461 #define HANDLE_DIEVALUE_LARGE(T) \
462  const DIE##T &getDIE##T() const { \
463  assert(getType() == is##T && "Expected " #T); \
464  return **get<const DIE##T *>(); \
465  }
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 
480 
482 
484  return Next.getInt() ? nullptr : Next.getPointer();
485  }
486 };
487 
490  Node *Last = nullptr;
491 
492  bool empty() const { return !Last; }
493  void push_back(Node &N) {
494  assert(N.Next.getPointer() == &N && "Expected unlinked node");
495  assert(N.Next.getInt() == true && "Expected unlinked node");
496 
497  if (Last) {
498  N.Next = Last->Next;
499  Last->Next.setPointerAndInt(&N, false);
500  }
501  Last = &N;
502  }
503 };
504 
505 template <class T> class IntrusiveBackList : IntrusiveBackListBase {
506 public:
509  T &back() { return *static_cast<T *>(Last); }
510  const T &back() const { return *static_cast<T *>(Last); }
511 
512  class const_iterator;
513  class iterator
514  : public iterator_facade_base<iterator, std::forward_iterator_tag, T> {
515  friend class const_iterator;
516  Node *N = nullptr;
517 
518  public:
519  iterator() = default;
520  explicit iterator(T *N) : N(N) {}
521 
523  N = N->getNext();
524  return *this;
525  }
526 
527  explicit operator bool() const { return N; }
528  T &operator*() const { return *static_cast<T *>(N); }
529 
530  bool operator==(const iterator &X) const { return N == X.N; }
531  bool operator!=(const iterator &X) const { return N != X.N; }
532  };
533 
535  : public iterator_facade_base<const_iterator, std::forward_iterator_tag,
536  const T> {
537  const Node *N = nullptr;
538 
539  public:
540  const_iterator() = default;
541  // Placate MSVC by explicitly scoping 'iterator'.
543  explicit const_iterator(const T *N) : N(N) {}
544 
546  N = N->getNext();
547  return *this;
548  }
549 
550  explicit operator bool() const { return N; }
551  const T &operator*() const { return *static_cast<const T *>(N); }
552 
553  bool operator==(const const_iterator &X) const { return N == X.N; }
554  bool operator!=(const const_iterator &X) const { return N != X.N; }
555  };
556 
557  iterator begin() {
558  return Last ? iterator(static_cast<T *>(Last->Next.getPointer())) : end();
559  }
560  const_iterator begin() const {
561  return const_cast<IntrusiveBackList *>(this)->begin();
562  }
563  iterator end() { return iterator(); }
564  const_iterator end() const { return const_iterator(); }
565 
566  static iterator toIterator(T &N) { return iterator(&N); }
567  static const_iterator toIterator(const T &N) { return const_iterator(&N); }
568 };
569 
570 /// A list of DIE values.
571 ///
572 /// This is a singly-linked list, but instead of reversing the order of
573 /// insertion, we keep a pointer to the back of the list so we can push in
574 /// order.
575 ///
576 /// There are two main reasons to choose a linked list over a customized
577 /// vector-like data structure.
578 ///
579 /// 1. For teardown efficiency, we want DIEs to be BumpPtrAllocated. Using a
580 /// linked list here makes this way easier to accomplish.
581 /// 2. Carrying an extra pointer per \a DIEValue isn't expensive. 45% of DIEs
582 /// have 2 or fewer values, and 90% have 5 or fewer. A vector would be
583 /// over-allocated by 50% on average anyway, the same cost as the
584 /// linked-list node.
586  struct Node : IntrusiveBackListNode {
587  DIEValue V;
588  explicit Node(DIEValue V) : V(V) {}
589  };
590 
592  ListTy List;
593 
594 public:
595  class const_value_iterator;
597  : public iterator_adaptor_base<value_iterator, ListTy::iterator,
598  std::forward_iterator_tag, DIEValue> {
599  friend class const_value_iterator;
600  typedef iterator_adaptor_base<value_iterator, ListTy::iterator,
601  std::forward_iterator_tag,
603 
604  public:
605  value_iterator() = default;
606  explicit value_iterator(ListTy::iterator X) : iterator_adaptor(X) {}
607 
608  explicit operator bool() const { return bool(wrapped()); }
609  DIEValue &operator*() const { return wrapped()->V; }
610  };
611 
613  const_value_iterator, ListTy::const_iterator,
614  std::forward_iterator_tag, const DIEValue> {
616  std::forward_iterator_tag,
617  const DIEValue> iterator_adaptor;
618 
619  public:
620  const_value_iterator() = default;
622  : iterator_adaptor(X.wrapped()) {}
624  : iterator_adaptor(X) {}
625 
626  explicit operator bool() const { return bool(wrapped()); }
627  const DIEValue &operator*() const { return wrapped()->V; }
628  };
629 
632 
634  List.push_back(*new (Alloc) Node(V));
635  return value_iterator(ListTy::toIterator(List.back()));
636  }
637  template <class T>
639  dwarf::Form Form, T &&Value) {
640  return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
641  }
642 
644  return make_range(value_iterator(List.begin()), value_iterator(List.end()));
645  }
647  return make_range(const_value_iterator(List.begin()),
648  const_value_iterator(List.end()));
649  }
650 };
651 
652 //===--------------------------------------------------------------------===//
653 /// A structured debug information entry. Has an abbreviation which
654 /// describes its organization.
656  friend class IntrusiveBackList<DIE>;
657  friend class DIEUnit;
658 
659  /// Dwarf unit relative offset.
660  unsigned Offset;
661  /// Size of instance + children.
662  unsigned Size;
663  unsigned AbbrevNumber = ~0u;
664  /// Dwarf tag code.
666  /// Set to true to force a DIE to emit an abbreviation that says it has
667  /// children even when it doesn't. This is used for unit testing purposes.
668  bool ForceChildren;
669  /// Children DIEs.
670  IntrusiveBackList<DIE> Children;
671 
672  /// The owner is either the parent DIE for children of other DIEs, or a
673  /// DIEUnit which contains this DIE as its unit DIE.
675 
676  DIE() = delete;
677  explicit DIE(dwarf::Tag Tag) : Offset(0), Size(0), Tag(Tag),
678  ForceChildren(false) {}
679 
680 public:
681  static DIE *get(BumpPtrAllocator &Alloc, dwarf::Tag Tag) {
682  return new (Alloc) DIE(Tag);
683  }
684 
685  DIE(const DIE &RHS) = delete;
686  DIE(DIE &&RHS) = delete;
687  void operator=(const DIE &RHS) = delete;
688  void operator=(const DIE &&RHS) = delete;
689 
690  // Accessors.
691  unsigned getAbbrevNumber() const { return AbbrevNumber; }
692  dwarf::Tag getTag() const { return Tag; }
693  /// Get the compile/type unit relative offset of this DIE.
694  unsigned getOffset() const { return Offset; }
695  unsigned getSize() const { return Size; }
696  bool hasChildren() const { return ForceChildren || !Children.empty(); }
697  void setForceChildren(bool B) { ForceChildren = B; }
698 
703 
705  return make_range(Children.begin(), Children.end());
706  }
708  return make_range(Children.begin(), Children.end());
709  }
710 
711  DIE *getParent() const;
712 
713  /// Generate the abbreviation for this DIE.
714  ///
715  /// Calculate the abbreviation for this, which should be uniqued and
716  /// eventually used to call \a setAbbrevNumber().
717  DIEAbbrev generateAbbrev() const;
718 
719  /// Set the abbreviation number for this DIE.
720  void setAbbrevNumber(unsigned I) { AbbrevNumber = I; }
721 
722  /// Get the absolute offset within the .debug_info or .debug_types section
723  /// for this DIE.
724  unsigned getDebugSectionOffset() const;
725 
726  /// Compute the offset of this DIE and all its children.
727  ///
728  /// This function gets called just before we are going to generate the debug
729  /// information and gives each DIE a chance to figure out its CU relative DIE
730  /// offset, unique its abbreviation and fill in the abbreviation code, and
731  /// return the unit offset that points to where the next DIE will be emitted
732  /// within the debug unit section. After this function has been called for all
733  /// DIE objects, the DWARF can be generated since all DIEs will be able to
734  /// properly refer to other DIE objects since all DIEs have calculated their
735  /// offsets.
736  ///
737  /// \param AP AsmPrinter to use when calculating sizes.
738  /// \param AbbrevSet the abbreviation used to unique DIE abbreviations.
739  /// \param CUOffset the compile/type unit relative offset in bytes.
740  /// \returns the offset for the DIE that follows this DIE within the
741  /// current compile/type unit.
742  unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP,
743  DIEAbbrevSet &AbbrevSet, unsigned CUOffset);
744 
745  /// Climb up the parent chain to get the compile unit or type unit DIE that
746  /// this DIE belongs to.
747  ///
748  /// \returns the compile or type unit DIE that owns this DIE, or NULL if
749  /// this DIE hasn't been added to a unit DIE.
750  const DIE *getUnitDie() const;
751 
752  /// Climb up the parent chain to get the compile unit or type unit that this
753  /// DIE belongs to.
754  ///
755  /// \returns the DIEUnit that represents the compile or type unit that owns
756  /// this DIE, or NULL if this DIE hasn't been added to a unit DIE.
757  const DIEUnit *getUnit() const;
758 
759  void setOffset(unsigned O) { Offset = O; }
760  void setSize(unsigned S) { Size = S; }
761 
762  /// Add a child to the DIE.
763  DIE &addChild(DIE *Child) {
764  assert(!Child->getParent() && "Child should be orphaned");
765  Child->Owner = this;
766  Children.push_back(*Child);
767  return Children.back();
768  }
769 
770  /// Find a value in the DIE with the attribute given.
771  ///
772  /// Returns a default-constructed DIEValue (where \a DIEValue::getType()
773  /// gives \a DIEValue::isNone) if no such attribute exists.
775 
776  void print(raw_ostream &O, unsigned IndentCount = 0) const;
777  void dump();
778 };
779 
780 //===--------------------------------------------------------------------===//
781 /// Represents a compile or type unit.
782 class DIEUnit {
783  /// The compile unit or type unit DIE. This variable must be an instance of
784  /// DIE so that we can calculate the DIEUnit from any DIE by traversing the
785  /// parent backchain and getting the Unit DIE, and then casting itself to a
786  /// DIEUnit. This allows us to be able to find the DIEUnit for any DIE without
787  /// having to store a pointer to the DIEUnit in each DIE instance.
788  DIE Die;
789  /// The section this unit will be emitted in. This may or may not be set to
790  /// a valid section depending on the client that is emitting DWARF.
791  MCSection *Section;
792  uint64_t Offset; /// .debug_info or .debug_types absolute section offset.
793  uint32_t Length; /// The length in bytes of all of the DIEs in this unit.
794  const uint16_t Version; /// The Dwarf version number for this unit.
795  const uint8_t AddrSize; /// The size in bytes of an address for this unit.
796 public:
797  DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag);
798  DIEUnit(const DIEUnit &RHS) = delete;
799  DIEUnit(DIEUnit &&RHS) = delete;
800  void operator=(const DIEUnit &RHS) = delete;
801  void operator=(const DIEUnit &&RHS) = delete;
802  /// Set the section that this DIEUnit will be emitted into.
803  ///
804  /// This function is used by some clients to set the section. Not all clients
805  /// that emit DWARF use this section variable.
806  void setSection(MCSection *Section) {
807  assert(!this->Section);
808  this->Section = Section;
809  }
810 
811  /// Return the section that this DIEUnit will be emitted into.
812  ///
813  /// \returns Section pointer which can be NULL.
814  MCSection *getSection() const { return Section; }
815  void setDebugSectionOffset(unsigned O) { Offset = O; }
816  unsigned getDebugSectionOffset() const { return Offset; }
817  void setLength(uint64_t L) { Length = L; }
818  uint64_t getLength() const { return Length; }
819  uint16_t getDwarfVersion() const { return Version; }
820  uint16_t getAddressSize() const { return AddrSize; }
821  DIE &getUnitDie() { return Die; }
822  const DIE &getUnitDie() const { return Die; }
823 };
824 
825 
826 //===--------------------------------------------------------------------===//
827 /// DIELoc - Represents an expression location.
828 //
829 class DIELoc : public DIEValueList {
830  mutable unsigned Size; // Size in bytes excluding size header.
831 
832 public:
833  DIELoc() : Size(0) {}
834 
835  /// ComputeSize - Calculate the size of the location expression.
836  ///
837  unsigned ComputeSize(const AsmPrinter *AP) const;
838 
839  /// BestForm - Choose the best form for data.
840  ///
842  if (DwarfVersion > 3)
843  return dwarf::DW_FORM_exprloc;
844  // Pre-DWARF4 location expressions were blocks and not exprloc.
845  if ((unsigned char)Size == Size)
846  return dwarf::DW_FORM_block1;
847  if ((unsigned short)Size == Size)
848  return dwarf::DW_FORM_block2;
849  if ((unsigned int)Size == Size)
850  return dwarf::DW_FORM_block4;
851  return dwarf::DW_FORM_block;
852  }
853 
854  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
855  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
856 
857  void print(raw_ostream &O) const;
858 };
859 
860 //===--------------------------------------------------------------------===//
861 /// DIEBlock - Represents a block of values.
862 //
863 class DIEBlock : public DIEValueList {
864  mutable unsigned Size; // Size in bytes excluding size header.
865 
866 public:
867  DIEBlock() : Size(0) {}
868 
869  /// ComputeSize - Calculate the size of the location expression.
870  ///
871  unsigned ComputeSize(const AsmPrinter *AP) const;
872 
873  /// BestForm - Choose the best form for data.
874  ///
876  if ((unsigned char)Size == Size)
877  return dwarf::DW_FORM_block1;
878  if ((unsigned short)Size == Size)
879  return dwarf::DW_FORM_block2;
880  if ((unsigned int)Size == Size)
881  return dwarf::DW_FORM_block4;
882  return dwarf::DW_FORM_block;
883  }
884 
885  void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
886  unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
887 
888  void print(raw_ostream &O) const;
889 };
890 
891 } // end namespace llvm
892 
893 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
MachineLoop * L
const T & back() const
Definition: DIE.h:510
const_iterator begin() const
Definition: DIE.h:560
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition: DIE.cpp:167
iterator begin()
Definition: DIE.h:557
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
iterator_range< const_child_iterator > const_child_range
Definition: DIE.h:702
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit block data.
Definition: DIE.cpp:773
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
Definition: DIE.cpp:633
DIEString(DwarfStringPoolEntryRef S)
Definition: DIE.h:255
void setSize(unsigned S)
Definition: DIE.h:760
DIELoc - Represents an expression location.
Definition: DIE.h:829
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition: DIE.cpp:558
iterator end()
Definition: DIE.h:563
DIELabel(const MCSymbol *L)
Definition: DIE.h:220
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
IntrusiveBackListNode * getNext() const
Definition: DIE.h:483
DIE & getEntry() const
Definition: DIE.h:301
void EmitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition: DIE.cpp:306
DIEValue(const DIEValue &X)
Definition: DIE.h:420
void print(raw_ostream &O) const
Definition: DIE.cpp:475
Attribute
Attributes.
Definition: Dwarf.h:94
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
child_range children()
Definition: DIE.h:704
static const_iterator toIterator(const T &N)
Definition: DIE.h:567
DIEAbbrev(dwarf::Tag T, bool C)
Definition: DIE.h:95
bool hasChildren() const
Definition: DIE.h:101
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
Definition: DIE.h:841
const_value_iterator(DIEValueList::value_iterator X)
Definition: DIE.h:621
void print(raw_ostream &O) const
Definition: DIE.cpp:526
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
Definition: DIE.h:108
Represents a pointer to a location list in the debug_loc section.
Definition: DIE.h:312
void dump()
Definition: DIE.cpp:253
value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
Definition: DIE.h:638
iterator_range< value_iterator > value_range
Definition: DIE.h:630
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:53
const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to...
Definition: DIE.cpp:184
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
Definition: DIE.h:48
void print(raw_ostream &O, unsigned IndentCount=0) const
Definition: DIE.cpp:228
size_t getValue() const
Grab the current index out.
Definition: DIE.h:320
const_child_range children() const
Definition: DIE.h:707
const DIE & getUnitDie() const
Definition: DIE.h:822
DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Definition: DIE.h:239
void setForceChildren(bool B)
Definition: DIE.h:697
DIEInlineString(StringRef Str, Allocator &A)
Definition: DIE.h:275
dwarf::Form getForm() const
Definition: DIE.h:67
bool empty() const
Definition: DIE.h:492
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
Definition: DIE.h:113
String pool entry reference.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:32
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:582
bool operator==(const iterator &X) const
Definition: DIE.h:530
const_iterator & operator++()
Definition: DIE.h:545
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit location data.
Definition: DIE.cpp:722
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:672
#define F(x, y, z)
Definition: MD5.cpp:51
const_iterator(typename IntrusiveBackList< T >::iterator X)
Definition: DIE.h:542
bool operator==(const const_iterator &X) const
Definition: DIE.h:553
void setNumber(unsigned N)
Definition: DIE.h:104
const MCSymbol * getValue() const
Get MCSymbol.
Definition: DIE.h:223
#define T
A list of DIE values.
Definition: DIE.h:585
Function Alias Analysis false
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:617
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition: DIE.cpp:486
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:763
dwarf::Tag getTag() const
Definition: DIE.h:692
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:65
uint16_t getDwarfVersion() const
Definition: DIE.h:819
void print(raw_ostream &O) const
Definition: DIE.cpp:824
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:134
void push_back(T &N)
Definition: DIE.h:508
~DIEValue()
Definition: DIE.h:433
~DIEInlineString()=default
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void dump() const
Definition: DIE.cpp:344
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:316
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of label value in bytes.
Definition: DIE.cpp:518
bool hasChildren() const
Definition: DIE.h:696
unsigned getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition: DIE.cpp:178
DIEValue()=default
PointerIntPair - This class implements a pair of a pointer and small integer.
static iterator toIterator(T &N)
Definition: DIE.h:566
StringRef getString() const
Grab the string out of the object.
Definition: DIE.h:280
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
unsigned getAbbrevNumber() const
Definition: DIE.h:691
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:195
value_range values()
Definition: DIE.h:643
DIEAbbrevSet(BumpPtrAllocator &A)
Definition: DIE.h:144
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition: DIE.cpp:202
A container for inline string values.
Definition: DIE.h:270
DIE * getParent() const
Definition: DIE.cpp:163
A structured debug information entry.
Definition: DIE.h:655
void print(raw_ostream &O) const
Definition: DIE.cpp:600
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition: DIE.cpp:534
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition: DIE.cpp:151
DIE & getUnitDie()
Definition: DIE.h:821
const_value_range values() const
Definition: DIE.h:646
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
Definition: DIE.h:168
bool operator!=(const iterator &X) const
Definition: DIE.h:531
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:67
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of integer value in bytes.
Definition: DIE.cpp:420
void push_back(Node &N)
Definition: DIE.h:493
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of block data in bytes.
Definition: DIE.cpp:788
An expression DIE.
Definition: DIE.h:199
Greedy Register Allocator
void print(raw_ostream &O) const
Definition: DIE.cpp:799
uint32_t Offset
cl::opt< int > DwarfVersion("dwarf-version", cl::desc("Dwarf version"), cl::init(0))
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
unsigned getSize() const
Definition: DIE.h:695
A label DIE.
Definition: DIE.h:216
DIELocList(size_t I)
Definition: DIE.h:317
void print(raw_ostream &O) const
Definition: DIE.cpp:701
iterator_range< child_iterator > child_range
Definition: DIE.h:701
void print(raw_ostream &O)
Definition: DIE.cpp:97
void dump()
Definition: DIE.cpp:116
int64_t getValue() const
Definition: DIE.h:68
A container for string pool string values.
Definition: DIE.h:251
void operator=(const DIEUnit &RHS)=delete
void setDebugSectionOffset(unsigned O)
Definition: DIE.h:815
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:419
unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition: DIE.cpp:257
uint64_t getValue() const
Definition: DIE.h:188
void print(raw_ostream &O) const
Definition: DIE.cpp:623
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:817
A simple label difference DIE.
Definition: DIE.h:234
const DIEValue & operator*() const
Definition: DIE.h:627
DIEAbbrevData(dwarf::Attribute A, int64_t V)
Definition: DIE.h:61
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
dwarf::Attribute getAttribute() const
Accessors.
Definition: DIE.h:66
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition: DIE.cpp:492
uint16_t getAddressSize() const
Definition: DIE.h:820
const DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to...
Definition: DIE.cpp:195
unsigned getDebugSectionOffset() const
Definition: DIE.h:816
DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
The size in bytes of an address for this unit.
Definition: DIE.cpp:296
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
DIEInteger(uint64_t I)
Definition: DIE.h:165
StringRef getString() const
Grab the string out of the object.
Definition: DIE.h:258
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:694
Represents a compile or type unit.
Definition: DIE.h:782
dwarf::Attribute getAttribute() const
Definition: DIE.h:451
dwarf::Form getForm() const
Definition: DIE.h:452
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
Node - This class is used to maintain the singly linked bucket list in a folding set.
Definition: FoldingSet.h:139
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:40
uint64_t getLength() const
Definition: DIE.h:818
IntrusiveBackList< DIE >::iterator child_iterator
Definition: DIE.h:699
void operator=(const DIE &RHS)=delete
bool operator!=(const const_iterator &X) const
Definition: DIE.h:554
A range adaptor for a pair of iterators.
DIEValue & operator*() const
Definition: DIE.h:609
unsigned SizeOf(const AsmPrinter *AP) const
Return the size of a value in bytes.
Definition: DIE.cpp:318
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:607
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of location data in bytes.
Definition: DIE.cpp:739
DIEExpr(const MCExpr *E)
Definition: DIE.h:203
DIEValue & operator=(const DIEValue &X)
Definition: DIE.h:424
DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation...
Definition: DIE.cpp:127
Basic Alias true
An integer value DIE.
Definition: DIE.h:161
const T & operator*() const
Definition: DIE.h:551
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:78
void setSection(MCSection *Section)
Set the section that this DIEUnit will be emitted into.
Definition: DIE.h:806
IntrusiveBackList< DIE >::const_iterator const_child_iterator
Definition: DIE.h:700
dwarf::Form BestForm() const
BestForm - Choose the best form for data.
Definition: DIE.h:875
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition: DIE.cpp:354
void setOffset(unsigned O)
Definition: DIE.h:759
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
value_iterator(ListTy::iterator X)
Definition: DIE.h:606
void setLength(uint64_t L)
Definition: DIE.h:817
PointerIntPair< IntrusiveBackListNode *, 1 > Next
Definition: DIE.h:479
const_value_iterator(ListTy::const_iterator X)
Definition: DIE.h:623
const MCExpr * getValue() const
Get MCExpr.
Definition: DIE.h:206
const SmallVectorImpl< DIEAbbrevData > & getData() const
Definition: DIE.h:102
void setChildrenFlag(bool hasChild)
Definition: DIE.h:103
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:807
void print(raw_ostream &O) const
Definition: DIE.cpp:548
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:508
DIEEntry(DIE &E)
Definition: DIE.h:299
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
Definition: DIE.h:814
void print(raw_ostream &O) const
Definition: DIE.cpp:752
Type getType() const
Accessors.
Definition: DIE.h:450
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
IntrusiveBackListNode Node
Definition: DIE.h:489
dwarf::Tag getTag() const
Accessors.
Definition: DIE.h:99
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:762
LLVM Value Representation.
Definition: Value.h:71
DIELoc()
Definition: DIE.h:833
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition: DIE.h:720
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:711
const_iterator end() const
Definition: DIE.h:564
void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
Definition: DIE.cpp:64
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
DIEAbbrevData(dwarf::Attribute A, dwarf::Form F)
Definition: DIE.h:59
DIEBlock - Represents a block of values.
Definition: DIE.h:863
void print(raw_ostream &O) const
Definition: DIE.cpp:500
void print(raw_ostream &O) const
Definition: DIE.cpp:331
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
DIEBlock()
Definition: DIE.h:867
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
Definition: DIE.h:633
void setValue(uint64_t Val)
Definition: DIE.h:189
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:540
unsigned getNumber() const
Definition: DIE.h:100
A discriminated union of two pointer types, with the discriminator in the low bit of the pointer...
Definition: PointerUnion.h:87
iterator_range< const_value_iterator > const_value_range
Definition: DIE.h:631