1 //===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Data structures for DWARF info entries.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H
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/CodeGen/DwarfStringPoolEntry.h"
25 #include "llvm/Support/AlignOf.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/Dwarf.h"
33 #include <type_traits>
46 //===--------------------------------------------------------------------===//
47 /// Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
49 /// Dwarf attribute code.
50 dwarf::Attribute Attribute;
56 DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {}
60 dwarf::Attribute getAttribute() const { return Attribute; }
61 dwarf::Form getForm() const { return Form; }
64 /// Used to gather unique data for the abbreviation folding set.
65 void Profile(FoldingSetNodeID &ID) const;
68 //===--------------------------------------------------------------------===//
69 /// Dwarf abbreviation, describes the organization of a debug information
71 class DIEAbbrev : public FoldingSetNode {
72 /// Unique number for node.
78 /// Whether or not this node has children.
80 /// This cheats a bit in all of the uses since the values in the standard
81 /// are 0 and 1 for no children and children respectively.
84 /// Raw data bytes for abbreviation.
85 SmallVector<DIEAbbrevData, 12> Data;
88 DIEAbbrev(dwarf::Tag T, bool C) : Tag(T), Children(C) {}
92 dwarf::Tag getTag() const { return Tag; }
93 unsigned getNumber() const { return Number; }
94 bool hasChildren() const { return Children; }
95 const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
96 void setChildrenFlag(bool hasChild) { Children = hasChild; }
97 void setNumber(unsigned N) { Number = N; }
100 /// Adds another set of attribute information to the abbreviation.
101 void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
102 Data.push_back(DIEAbbrevData(Attribute, Form));
105 /// Used to gather unique data for the abbreviation folding set.
106 void Profile(FoldingSetNodeID &ID) const;
108 /// Print the abbreviation using the specified asm printer.
109 void Emit(const AsmPrinter *AP) const;
111 void print(raw_ostream &O);
115 //===--------------------------------------------------------------------===//
116 /// Helps unique DIEAbbrev objects and assigns abbreviation numbers.
118 /// This class will unique the DIE abbreviations for a llvm::DIE object and
119 /// assign a unique abbreviation number to each unique DIEAbbrev object it
120 /// finds. The resulting collection of DIEAbbrev objects can then be emitted
121 /// into the .debug_abbrev section.
123 /// The bump allocator to use when creating DIEAbbrev objects in the uniqued
124 /// storage container.
125 BumpPtrAllocator &Alloc;
126 /// \brief FoldingSet that uniques the abbreviations.
127 llvm::FoldingSet<DIEAbbrev> AbbreviationsSet;
128 /// A list of all the unique abbreviations in use.
129 std::vector<DIEAbbrev *> Abbreviations;
132 DIEAbbrevSet(BumpPtrAllocator &A) : Alloc(A) {}
134 /// Generate the abbreviation declaration for a DIE and return a pointer to
135 /// the generated abbreviation.
137 /// \param Die the debug info entry to generate the abbreviation for.
138 /// \returns A reference to the uniqued abbreviation declaration that is
139 /// owned by this class.
140 DIEAbbrev &uniqueAbbreviation(DIE &Die);
142 /// Print all abbreviations using the specified asm printer.
143 void Emit(const AsmPrinter *AP, MCSection *Section) const;
146 //===--------------------------------------------------------------------===//
147 /// An integer value DIE.
153 explicit DIEInteger(uint64_t I) : Integer(I) {}
155 /// Choose the best form for integer.
156 static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
158 const int64_t SignedInt = Int;
159 if ((char)Int == SignedInt)
160 return dwarf::DW_FORM_data1;
161 if ((short)Int == SignedInt)
162 return dwarf::DW_FORM_data2;
163 if ((int)Int == SignedInt)
164 return dwarf::DW_FORM_data4;
166 if ((unsigned char)Int == Int)
167 return dwarf::DW_FORM_data1;
168 if ((unsigned short)Int == Int)
169 return dwarf::DW_FORM_data2;
170 if ((unsigned int)Int == Int)
171 return dwarf::DW_FORM_data4;
173 return dwarf::DW_FORM_data8;
176 uint64_t getValue() const { return Integer; }
177 void setValue(uint64_t Val) { Integer = Val; }
179 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
180 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
182 void print(raw_ostream &O) const;
185 //===--------------------------------------------------------------------===//
186 /// An expression DIE.
191 explicit DIEExpr(const MCExpr *E) : Expr(E) {}
194 const MCExpr *getValue() const { return Expr; }
196 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
197 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
199 void print(raw_ostream &O) const;
202 //===--------------------------------------------------------------------===//
205 const MCSymbol *Label;
208 explicit DIELabel(const MCSymbol *L) : Label(L) {}
211 const MCSymbol *getValue() const { return Label; }
213 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
214 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
216 void print(raw_ostream &O) const;
219 //===--------------------------------------------------------------------===//
220 /// A simple label difference DIE.
223 const MCSymbol *LabelHi;
224 const MCSymbol *LabelLo;
227 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) : LabelHi(Hi), LabelLo(Lo) {}
229 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
230 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
232 void print(raw_ostream &O) const;
235 //===--------------------------------------------------------------------===//
236 /// A container for string pool string values.
238 /// This class is used with the DW_FORM_strp and DW_FORM_GNU_str_index forms.
240 DwarfStringPoolEntryRef S;
243 DIEString(DwarfStringPoolEntryRef S) : S(S) {}
245 /// Grab the string out of the object.
246 StringRef getString() const { return S.getString(); }
248 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
249 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
251 void print(raw_ostream &O) const;
254 //===--------------------------------------------------------------------===//
255 /// A container for inline string values.
257 /// This class is used with the DW_FORM_string form.
258 class DIEInlineString {
262 template <typename Allocator>
263 explicit DIEInlineString(StringRef Str, Allocator &A) : S(Str.copy(A)) {}
265 ~DIEInlineString() = default;
267 /// Grab the string out of the object.
268 StringRef getString() const { return S; }
270 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
271 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
273 void print(raw_ostream &O) const;
276 //===--------------------------------------------------------------------===//
277 /// A pointer to another debug information entry. An instance of this class can
278 /// also be used as a proxy for a debug information entry not yet defined
287 explicit DIEEntry(DIE &E) : Entry(&E) {}
289 DIE &getEntry() const { return *Entry; }
291 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
292 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
294 void print(raw_ostream &O) const;
297 //===--------------------------------------------------------------------===//
298 /// Represents a pointer to a location list in the debug_loc
301 /// Index into the .debug_loc vector.
305 DIELocList(size_t I) : Index(I) {}
307 /// Grab the current index out.
308 size_t getValue() const { return Index; }
310 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
311 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
313 void print(raw_ostream &O) const;
316 //===--------------------------------------------------------------------===//
317 /// A debug information entry value. Some of these roughly correlate
318 /// to DWARF attribute classes.
325 #define HANDLE_DIEVALUE(T) is##T,
326 #include "llvm/CodeGen/DIEValue.def"
330 /// Type of data stored in the value.
332 dwarf::Attribute Attribute = (dwarf::Attribute)0;
333 dwarf::Form Form = (dwarf::Form)0;
335 /// Storage for the value.
337 /// All values that aren't standard layout (or are larger than 8 bytes)
338 /// should be stored by reference instead of by value.
339 typedef AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
340 DIEDelta *, DIEEntry, DIEBlock *, DIELoc *,
343 static_assert(sizeof(ValTy) <= sizeof(uint64_t) ||
344 sizeof(ValTy) <= sizeof(void *),
345 "Expected all large types to be stored via pointer");
347 /// Underlying stored value.
350 template <class T> void construct(T V) {
351 static_assert(std::is_standard_layout<T>::value ||
352 std::is_pointer<T>::value,
353 "Expected standard layout or pointer");
354 new (reinterpret_cast<void *>(Val.buffer)) T(V);
357 template <class T> T *get() { return reinterpret_cast<T *>(Val.buffer); }
358 template <class T> const T *get() const {
359 return reinterpret_cast<const T *>(Val.buffer);
361 template <class T> void destruct() { get<T>()->~T(); }
363 /// Destroy the underlying value.
365 /// This should get optimized down to a no-op. We could skip it if we could
366 /// add a static assert on \a std::is_trivially_copyable(), but we currently
367 /// support versions of GCC that don't understand that.
372 #define HANDLE_DIEVALUE_SMALL(T) \
376 #define HANDLE_DIEVALUE_LARGE(T) \
378 destruct<const DIE##T *>();
380 #include "llvm/CodeGen/DIEValue.def"
384 /// Copy the underlying value.
386 /// This should get optimized down to a simple copy. We need to actually
387 /// construct the value, rather than calling memcpy, to satisfy strict
389 void copyVal(const DIEValue &X) {
393 #define HANDLE_DIEVALUE_SMALL(T) \
395 construct<DIE##T>(*X.get<DIE##T>()); \
397 #define HANDLE_DIEVALUE_LARGE(T) \
399 construct<const DIE##T *>(*X.get<const DIE##T *>()); \
401 #include "llvm/CodeGen/DIEValue.def"
406 DIEValue() = default;
408 DIEValue(const DIEValue &X) : Ty(X.Ty), Attribute(X.Attribute), Form(X.Form) {
412 DIEValue &operator=(const DIEValue &X) {
415 Attribute = X.Attribute;
421 ~DIEValue() { destroyVal(); }
423 #define HANDLE_DIEVALUE_SMALL(T) \
424 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V) \
425 : Ty(is##T), Attribute(Attribute), Form(Form) { \
426 construct<DIE##T>(V); \
428 #define HANDLE_DIEVALUE_LARGE(T) \
429 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V) \
430 : Ty(is##T), Attribute(Attribute), Form(Form) { \
431 assert(V && "Expected valid value"); \
432 construct<const DIE##T *>(V); \
434 #include "llvm/CodeGen/DIEValue.def"
438 Type getType() const { return Ty; }
439 dwarf::Attribute getAttribute() const { return Attribute; }
440 dwarf::Form getForm() const { return Form; }
441 explicit operator bool() const { return Ty; }
444 #define HANDLE_DIEVALUE_SMALL(T) \
445 const DIE##T &getDIE##T() const { \
446 assert(getType() == is##T && "Expected " #T); \
447 return *get<DIE##T>(); \
449 #define HANDLE_DIEVALUE_LARGE(T) \
450 const DIE##T &getDIE##T() const { \
451 assert(getType() == is##T && "Expected " #T); \
452 return **get<const DIE##T *>(); \
454 #include "llvm/CodeGen/DIEValue.def"
456 /// Emit value via the Dwarf writer.
457 void EmitValue(const AsmPrinter *AP) const;
459 /// Return the size of a value in bytes.
460 unsigned SizeOf(const AsmPrinter *AP) const;
462 void print(raw_ostream &O) const;
466 struct IntrusiveBackListNode {
467 PointerIntPair<IntrusiveBackListNode *, 1> Next;
469 IntrusiveBackListNode() : Next(this, true) {}
471 IntrusiveBackListNode *getNext() const {
472 return Next.getInt() ? nullptr : Next.getPointer();
476 struct IntrusiveBackListBase {
477 typedef IntrusiveBackListNode Node;
478 Node *Last = nullptr;
480 bool empty() const { return !Last; }
481 void push_back(Node &N) {
482 assert(N.Next.getPointer() == &N && "Expected unlinked node");
483 assert(N.Next.getInt() == true && "Expected unlinked node");
487 Last->Next.setPointerAndInt(&N, false);
493 template <class T> class IntrusiveBackList : IntrusiveBackListBase {
495 using IntrusiveBackListBase::empty;
496 void push_back(T &N) { IntrusiveBackListBase::push_back(N); }
497 T &back() { return *static_cast<T *>(Last); }
498 const T &back() const { return *static_cast<T *>(Last); }
500 class const_iterator;
502 : public iterator_facade_base<iterator, std::forward_iterator_tag, T> {
503 friend class const_iterator;
507 iterator() = default;
508 explicit iterator(T *N) : N(N) {}
510 iterator &operator++() {
515 explicit operator bool() const { return N; }
516 T &operator*() const { return *static_cast<T *>(N); }
518 bool operator==(const iterator &X) const { return N == X.N; }
519 bool operator!=(const iterator &X) const { return N != X.N; }
523 : public iterator_facade_base<const_iterator, std::forward_iterator_tag,
525 const Node *N = nullptr;
528 const_iterator() = default;
529 // Placate MSVC by explicitly scoping 'iterator'.
530 const_iterator(typename IntrusiveBackList<T>::iterator X) : N(X.N) {}
531 explicit const_iterator(const T *N) : N(N) {}
533 const_iterator &operator++() {
538 explicit operator bool() const { return N; }
539 const T &operator*() const { return *static_cast<const T *>(N); }
541 bool operator==(const const_iterator &X) const { return N == X.N; }
542 bool operator!=(const const_iterator &X) const { return N != X.N; }
546 return Last ? iterator(static_cast<T *>(Last->Next.getPointer())) : end();
548 const_iterator begin() const {
549 return const_cast<IntrusiveBackList *>(this)->begin();
551 iterator end() { return iterator(); }
552 const_iterator end() const { return const_iterator(); }
554 static iterator toIterator(T &N) { return iterator(&N); }
555 static const_iterator toIterator(const T &N) { return const_iterator(&N); }
558 /// A list of DIE values.
560 /// This is a singly-linked list, but instead of reversing the order of
561 /// insertion, we keep a pointer to the back of the list so we can push in
564 /// There are two main reasons to choose a linked list over a customized
565 /// vector-like data structure.
567 /// 1. For teardown efficiency, we want DIEs to be BumpPtrAllocated. Using a
568 /// linked list here makes this way easier to accomplish.
569 /// 2. Carrying an extra pointer per \a DIEValue isn't expensive. 45% of DIEs
570 /// have 2 or fewer values, and 90% have 5 or fewer. A vector would be
571 /// over-allocated by 50% on average anyway, the same cost as the
572 /// linked-list node.
574 struct Node : IntrusiveBackListNode {
576 explicit Node(DIEValue V) : V(V) {}
579 typedef IntrusiveBackList<Node> ListTy;
583 class const_value_iterator;
585 : public iterator_adaptor_base<value_iterator, ListTy::iterator,
586 std::forward_iterator_tag, DIEValue> {
587 friend class const_value_iterator;
588 typedef iterator_adaptor_base<value_iterator, ListTy::iterator,
589 std::forward_iterator_tag,
590 DIEValue> iterator_adaptor;
593 value_iterator() = default;
594 explicit value_iterator(ListTy::iterator X) : iterator_adaptor(X) {}
596 explicit operator bool() const { return bool(wrapped()); }
597 DIEValue &operator*() const { return wrapped()->V; }
600 class const_value_iterator : public iterator_adaptor_base<
601 const_value_iterator, ListTy::const_iterator,
602 std::forward_iterator_tag, const DIEValue> {
603 typedef iterator_adaptor_base<const_value_iterator, ListTy::const_iterator,
604 std::forward_iterator_tag,
605 const DIEValue> iterator_adaptor;
608 const_value_iterator() = default;
609 const_value_iterator(DIEValueList::value_iterator X)
610 : iterator_adaptor(X.wrapped()) {}
611 explicit const_value_iterator(ListTy::const_iterator X)
612 : iterator_adaptor(X) {}
614 explicit operator bool() const { return bool(wrapped()); }
615 const DIEValue &operator*() const { return wrapped()->V; }
618 typedef iterator_range<value_iterator> value_range;
619 typedef iterator_range<const_value_iterator> const_value_range;
621 value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V) {
622 List.push_back(*new (Alloc) Node(V));
623 return value_iterator(ListTy::toIterator(List.back()));
626 value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute,
627 dwarf::Form Form, T &&Value) {
628 return addValue(Alloc, DIEValue(Attribute, Form, std::forward<T>(Value)));
631 value_range values() {
632 return make_range(value_iterator(List.begin()), value_iterator(List.end()));
634 const_value_range values() const {
635 return make_range(const_value_iterator(List.begin()),
636 const_value_iterator(List.end()));
640 //===--------------------------------------------------------------------===//
641 /// A structured debug information entry. Has an abbreviation which
642 /// describes its organization.
643 class DIE : IntrusiveBackListNode, public DIEValueList {
644 friend class IntrusiveBackList<DIE>;
645 friend class DIEUnit;
647 /// Dwarf unit relative offset.
649 /// Size of instance + children.
651 unsigned AbbrevNumber = ~0u;
653 dwarf::Tag Tag = (dwarf::Tag)0;
654 /// Set to true to force a DIE to emit an abbreviation that says it has
655 /// children even when it doesn't. This is used for unit testing purposes.
658 IntrusiveBackList<DIE> Children;
660 /// The owner is either the parent DIE for children of other DIEs, or a
661 /// DIEUnit which contains this DIE as its unit DIE.
662 PointerUnion<DIE *, DIEUnit *> Owner;
665 explicit DIE(dwarf::Tag Tag) : Offset(0), Size(0), Tag(Tag),
666 ForceChildren(false) {}
669 static DIE *get(BumpPtrAllocator &Alloc, dwarf::Tag Tag) {
670 return new (Alloc) DIE(Tag);
673 DIE(const DIE &RHS) = delete;
674 DIE(DIE &&RHS) = delete;
675 void operator=(const DIE &RHS) = delete;
676 void operator=(const DIE &&RHS) = delete;
679 unsigned getAbbrevNumber() const { return AbbrevNumber; }
680 dwarf::Tag getTag() const { return Tag; }
681 /// Get the compile/type unit relative offset of this DIE.
682 unsigned getOffset() const { return Offset; }
683 unsigned getSize() const { return Size; }
684 bool hasChildren() const { return ForceChildren || !Children.empty(); }
685 void setForceChildren(bool B) { ForceChildren = B; }
687 typedef IntrusiveBackList<DIE>::iterator child_iterator;
688 typedef IntrusiveBackList<DIE>::const_iterator const_child_iterator;
689 typedef iterator_range<child_iterator> child_range;
690 typedef iterator_range<const_child_iterator> const_child_range;
692 child_range children() {
693 return make_range(Children.begin(), Children.end());
695 const_child_range children() const {
696 return make_range(Children.begin(), Children.end());
699 DIE *getParent() const;
701 /// Generate the abbreviation for this DIE.
703 /// Calculate the abbreviation for this, which should be uniqued and
704 /// eventually used to call \a setAbbrevNumber().
705 DIEAbbrev generateAbbrev() const;
707 /// Set the abbreviation number for this DIE.
708 void setAbbrevNumber(unsigned I) { AbbrevNumber = I; }
710 /// Get the absolute offset within the .debug_info or .debug_types section
712 unsigned getDebugSectionOffset() const;
714 /// Compute the offset of this DIE and all its children.
716 /// This function gets called just before we are going to generate the debug
717 /// information and gives each DIE a chance to figure out its CU relative DIE
718 /// offset, unique its abbreviation and fill in the abbreviation code, and
719 /// return the unit offset that points to where the next DIE will be emitted
720 /// within the debug unit section. After this function has been called for all
721 /// DIE objects, the DWARF can be generated since all DIEs will be able to
722 /// properly refer to other DIE objects since all DIEs have calculated their
725 /// \param AP AsmPrinter to use when calculating sizes.
726 /// \param AbbrevSet the abbreviation used to unique DIE abbreviations.
727 /// \param CUOffset the compile/type unit relative offset in bytes.
728 /// \returns the offset for the DIE that follows this DIE within the
729 /// current compile/type unit.
730 unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP,
731 DIEAbbrevSet &AbbrevSet, unsigned CUOffset);
733 /// Climb up the parent chain to get the compile unit or type unit DIE that
734 /// this DIE belongs to.
736 /// \returns the compile or type unit DIE that owns this DIE, or NULL if
737 /// this DIE hasn't been added to a unit DIE.
738 const DIE *getUnitDie() const;
740 /// Climb up the parent chain to get the compile unit or type unit that this
743 /// \returns the DIEUnit that represents the compile or type unit that owns
744 /// this DIE, or NULL if this DIE hasn't been added to a unit DIE.
745 const DIEUnit *getUnit() const;
747 void setOffset(unsigned O) { Offset = O; }
748 void setSize(unsigned S) { Size = S; }
750 /// Add a child to the DIE.
751 DIE &addChild(DIE *Child) {
752 assert(!Child->getParent() && "Child should be orphaned");
754 Children.push_back(*Child);
755 return Children.back();
758 /// Find a value in the DIE with the attribute given.
760 /// Returns a default-constructed DIEValue (where \a DIEValue::getType()
761 /// gives \a DIEValue::isNone) if no such attribute exists.
762 DIEValue findAttribute(dwarf::Attribute Attribute) const;
764 void print(raw_ostream &O, unsigned IndentCount = 0) const;
768 //===--------------------------------------------------------------------===//
769 /// Represents a compile or type unit.
771 /// The compile unit or type unit DIE. This variable must be an instance of
772 /// DIE so that we can calculate the DIEUnit from any DIE by traversing the
773 /// parent backchain and getting the Unit DIE, and then casting itself to a
774 /// DIEUnit. This allows us to be able to find the DIEUnit for any DIE without
775 /// having to store a pointer to the DIEUnit in each DIE instance.
777 /// The section this unit will be emitted in. This may or may not be set to
778 /// a valid section depending on the client that is emitting DWARF.
780 uint64_t Offset; /// .debug_info or .debug_types absolute section offset.
781 uint32_t Length; /// The length in bytes of all of the DIEs in this unit.
782 const uint16_t Version; /// The Dwarf version number for this unit.
783 const uint8_t AddrSize; /// The size in bytes of an address for this unit.
785 DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag);
786 DIEUnit(const DIEUnit &RHS) = delete;
787 DIEUnit(DIEUnit &&RHS) = delete;
788 void operator=(const DIEUnit &RHS) = delete;
789 void operator=(const DIEUnit &&RHS) = delete;
790 /// Set the section that this DIEUnit will be emitted into.
792 /// This function is used by some clients to set the section. Not all clients
793 /// that emit DWARF use this section variable.
794 void setSection(MCSection *Section) {
795 assert(!this->Section);
796 this->Section = Section;
799 /// Return the section that this DIEUnit will be emitted into.
801 /// \returns Section pointer which can be NULL.
802 MCSection *getSection() const { return Section; }
803 void setDebugSectionOffset(unsigned O) { Offset = O; }
804 unsigned getDebugSectionOffset() const { return Offset; }
805 void setLength(uint64_t L) { Length = L; }
806 uint64_t getLength() const { return Length; }
807 uint16_t getDwarfVersion() const { return Version; }
808 uint16_t getAddressSize() const { return AddrSize; }
809 DIE &getUnitDie() { return Die; }
810 const DIE &getUnitDie() const { return Die; }
814 //===--------------------------------------------------------------------===//
815 /// DIELoc - Represents an expression location.
817 class DIELoc : public DIEValueList {
818 mutable unsigned Size; // Size in bytes excluding size header.
821 DIELoc() : Size(0) {}
823 /// ComputeSize - Calculate the size of the location expression.
825 unsigned ComputeSize(const AsmPrinter *AP) const;
827 /// BestForm - Choose the best form for data.
829 dwarf::Form BestForm(unsigned DwarfVersion) const {
830 if (DwarfVersion > 3)
831 return dwarf::DW_FORM_exprloc;
832 // Pre-DWARF4 location expressions were blocks and not exprloc.
833 if ((unsigned char)Size == Size)
834 return dwarf::DW_FORM_block1;
835 if ((unsigned short)Size == Size)
836 return dwarf::DW_FORM_block2;
837 if ((unsigned int)Size == Size)
838 return dwarf::DW_FORM_block4;
839 return dwarf::DW_FORM_block;
842 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
843 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
845 void print(raw_ostream &O) const;
848 //===--------------------------------------------------------------------===//
849 /// DIEBlock - Represents a block of values.
851 class DIEBlock : public DIEValueList {
852 mutable unsigned Size; // Size in bytes excluding size header.
855 DIEBlock() : Size(0) {}
857 /// ComputeSize - Calculate the size of the location expression.
859 unsigned ComputeSize(const AsmPrinter *AP) const;
861 /// BestForm - Choose the best form for data.
863 dwarf::Form BestForm() const {
864 if ((unsigned char)Size == Size)
865 return dwarf::DW_FORM_block1;
866 if ((unsigned short)Size == Size)
867 return dwarf::DW_FORM_block2;
868 if ((unsigned int)Size == Size)
869 return dwarf::DW_FORM_block4;
870 return dwarf::DW_FORM_block;
873 void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const;
874 unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
876 void print(raw_ostream &O) const;
879 } // end namespace llvm
881 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H