13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H 14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H 32 #include <type_traits> 41 class DwarfCompileUnit;
61 : Attribute(A), Form(F) {}
63 : Attribute(A), Form(dwarf::DW_FORM_implicit_const), Value(V) {}
142 std::vector<DIEAbbrev *> Abbreviations;
172 const int64_t SignedInt = Int;
173 if ((
char)Int == SignedInt)
174 return dwarf::DW_FORM_data1;
175 if ((
short)Int == SignedInt)
176 return dwarf::DW_FORM_data2;
177 if ((
int)Int == SignedInt)
178 return dwarf::DW_FORM_data4;
180 if ((
unsigned char)Int == Int)
181 return dwarf::DW_FORM_data1;
182 if ((
unsigned short)Int == Int)
183 return dwarf::DW_FORM_data2;
184 if ((
unsigned int)Int == Int)
185 return dwarf::DW_FORM_data4;
187 return dwarf::DW_FORM_data8;
237 const uint64_t
Index;
242 : CU(TheCU), Index(Idx) {}
295 template <
typename Allocator>
356 #define HANDLE_DIEVALUE(T) is##T, 357 #include "llvm/CodeGen/DIEValue.def" 370 using ValTy = AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
371 DIEDelta *, DIEEntry, DIEBlock *,
372 DIELoc *, DIELocList, DIEBaseTypeRef *>;
374 static_assert(
sizeof(ValTy) <=
sizeof(uint64_t) ||
375 sizeof(ValTy) <=
sizeof(
void *),
376 "Expected all large types to be stored via pointer");
381 template <
class T>
void construct(
T V) {
382 static_assert(std::is_standard_layout<T>::value ||
383 std::is_pointer<T>::value,
384 "Expected standard layout or pointer");
385 new (
reinterpret_cast<void *
>(Val.buffer))
T(V);
388 template <
class T>
T *
get() {
return reinterpret_cast<T *
>(Val.buffer); }
389 template <
class T>
const T *
get()
const {
390 return reinterpret_cast<const T *
>(Val.buffer);
392 template <
class T>
void destruct() { get<T>()->~
T(); }
403 #define HANDLE_DIEVALUE_SMALL(T) \ 405 destruct<DIE##T>(); \ 407 #define HANDLE_DIEVALUE_LARGE(T) \ 409 destruct<const DIE##T *>(); \ 411 #include "llvm/CodeGen/DIEValue.def" 420 void copyVal(
const DIEValue &
X) {
424 #define HANDLE_DIEVALUE_SMALL(T) \ 426 construct<DIE##T>(*X.get<DIE##T>()); \ 428 #define HANDLE_DIEVALUE_LARGE(T) \ 430 construct<const DIE##T *>(*X.get<const DIE##T *>()); \ 432 #include "llvm/CodeGen/DIEValue.def" 437 DIEValue() =
default;
446 Attribute = X.Attribute;
454 #define HANDLE_DIEVALUE_SMALL(T) \ 455 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V) \ 456 : Ty(is##T), Attribute(Attribute), Form(Form) { \ 457 construct<DIE##T>(V); \ 459 #define HANDLE_DIEVALUE_LARGE(T) \ 460 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V) \ 461 : Ty(is##T), Attribute(Attribute), Form(Form) { \ 462 assert(V && "Expected valid value"); \ 463 construct<const DIE##T *>(V); \ 465 #include "llvm/CodeGen/DIEValue.def" 472 explicit operator bool()
const {
return Ty; }
475 #define HANDLE_DIEVALUE_SMALL(T) \ 476 const DIE##T &getDIE##T() const { \ 477 assert(getType() == is##T && "Expected " #T); \ 478 return *get<DIE##T>(); \ 480 #define HANDLE_DIEVALUE_LARGE(T) \ 481 const DIE##T &getDIE##T() const { \ 482 assert(getType() == is##T && "Expected " #T); \ 483 return **get<const DIE##T *>(); \ 485 #include "llvm/CodeGen/DIEValue.def" 488 void EmitValue(
const AsmPrinter *AP)
const;
491 unsigned SizeOf(
const AsmPrinter *AP)
const;
493 void print(raw_ostream &
O)
const;
512 bool empty()
const {
return !Last; }
515 assert(N.
Next.getPointer() == &N &&
"Expected unlinked node");
516 assert(N.
Next.getInt() ==
true &&
"Expected unlinked node");
520 Last->
Next.setPointerAndInt(&N,
false);
526 assert(N.
Next.getPointer() == &N &&
"Expected unlinked node");
527 assert(N.
Next.getInt() ==
true &&
"Expected unlinked node");
530 N.
Next.setPointerAndInt(Last->
Next.getPointer(),
false);
531 Last->
Next.setPointerAndInt(&N,
true);
544 T &
back() {
return *
static_cast<T *
>(Last); }
545 const T &
back()
const {
return *
static_cast<T *
>(Last); }
547 return *
static_cast<T *
>(Last ? Last->Next.getPointer() :
nullptr);
550 return *
static_cast<T *
>(Last ? Last->Next.getPointer() :
nullptr);
554 for (
auto &
N : Other) {
555 N.Next.setPointerAndInt(&
N,
true);
558 Other.Last =
nullptr;
577 explicit operator bool()
const {
return N; }
587 const Node *
N =
nullptr;
600 explicit operator bool()
const {
return N; }
608 return Last ? iterator(static_cast<T *>(Last->Next.getPointer())) :
end();
613 iterator
end() {
return iterator(); }
650 std::forward_iterator_tag, DIEValue> {
655 std::forward_iterator_tag,
DIEValue>;
658 value_iterator() =
default;
661 explicit operator bool()
const {
return bool(wrapped()); }
666 const_value_iterator, ListTy::const_iterator,
667 std::forward_iterator_tag, const DIEValue> {
670 std::forward_iterator_tag,
const DIEValue>;
673 const_value_iterator() =
default;
679 explicit operator bool()
const {
return bool(wrapped()); }
680 const DIEValue &
operator*()
const {
return wrapped()->V; }
693 return addValue(Alloc,
DIEValue(Attribute, Form, std::forward<T>(
Value)));
720 unsigned AbbrevNumber = ~0u;
725 bool ForceChildren =
false;
737 DIE(
const DIE &RHS) =
delete;
739 DIE &operator=(
const DIE &RHS) =
delete;
740 DIE &operator=(
const DIE &&RHS) =
delete;
743 return new (Alloc)
DIE(Tag);
780 unsigned getDebugSectionOffset()
const;
798 unsigned computeOffsetsAndAbbrevs(
const AsmPrinter *AP,
806 const DIE *getUnitDie()
const;
823 return Children.
back();
830 return Children.
front();
858 const uint8_t AddrSize;
866 void operator=(
const DIEUnit &RHS) =
delete;
867 void operator=(
const DIEUnit &&RHS) =
delete;
897 :
DIEUnit(Version, AddrSize, UnitTag) {}
904 mutable unsigned Size = 0;
911 unsigned ComputeSize(
const AsmPrinter *AP)
const;
916 if (DwarfVersion > 3)
917 return dwarf::DW_FORM_exprloc;
919 if ((
unsigned char)Size == Size)
920 return dwarf::DW_FORM_block1;
921 if ((
unsigned short)Size == Size)
922 return dwarf::DW_FORM_block2;
923 if ((
unsigned int)Size == Size)
924 return dwarf::DW_FORM_block4;
925 return dwarf::DW_FORM_block;
938 mutable unsigned Size = 0;
941 DIEBlock() =
default;
945 unsigned ComputeSize(
const AsmPrinter *AP)
const;
950 if ((
unsigned char)Size == Size)
951 return dwarf::DW_FORM_block1;
952 if ((
unsigned short)Size == Size)
953 return dwarf::DW_FORM_block2;
954 if ((
unsigned int)Size == Size)
955 return dwarf::DW_FORM_block4;
956 return dwarf::DW_FORM_block;
967 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DIE_H StringRef getString() const
uint16_t getAddressSize() const
Instances of this class represent a uniqued identifier for a section in the current translation unit...
void takeNodes(IntrusiveBackList< T > &Other)
const_iterator end(StringRef path)
Get end iterator over path.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
DIEString(DwarfStringPoolEntryRef S)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
DIELoc - Represents an expression location.
This class represents lattice values for constants.
PointerTy getPointer() const
DIELabel(const MCSymbol *L)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
const_child_range children() const
DIEValue(const DIEValue &X)
void push_back(const T &Elt)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
bool operator!=(const const_iterator &X) const
static const_iterator toIterator(const T &N)
DIEAbbrev(dwarf::Tag T, bool C)
unsigned getDebugSectionOffset() const
const_value_iterator(DIEValueList::value_iterator X)
block Block Frequency true
Node(Kind K_, Cache RHSComponentCache_=Cache::No, Cache ArrayCache_=Cache::No, Cache FunctionCache_=Cache::No)
const DIE & getUnitDie() const
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
Represents a pointer to a location list in the debug_loc section.
value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
StringRef getString() const
Grab the string out of the object.
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
size_t getValue() const
Grab the current index out.
void setForceChildren(bool B)
DIEInlineString(StringRef Str, Allocator &A)
DIE & addChildFront(DIE *Child)
const MCExpr * getValue() const
Get MCExpr.
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
dwarf::Form getForm() const
const_iterator & operator++()
const_iterator(typename IntrusiveBackList< T >::iterator X)
void setNumber(unsigned N)
bool operator!=(const iterator &X) const
DIE & addChild(DIE *Child)
Add a child to the DIE.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
uint16_t getDwarfVersion() const
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
A pointer to another debug information entry.
virtual const MCSymbol * getCrossSectionRelativeBaseAddress() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
PointerIntPair - This class implements a pair of a pointer and small integer.
static iterator toIterator(T &N)
Allocate memory in an ever growing pool, as if by bump-pointer.
CRTP base class for adapting an iterator to a different type.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DIEAbbrevSet(BumpPtrAllocator &A)
const DIEValue & operator*() const
A container for inline string values.
A structured debug information entry.
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
DIEBaseTypeRef(const DwarfCompileUnit *TheCU, uint64_t Idx)
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
This class is intended to be used as a driving class for all asm writers.
dwarf::Attribute getAttribute() const
Accessors.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
const MCSymbol * getValue() const
Get MCSymbol.
bool operator==(const const_iterator &X) const
A container for string pool string values.
void setDebugSectionOffset(unsigned O)
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
A simple label difference DIE.
DIEAbbrevData(dwarf::Attribute A, int64_t V)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const_iterator begin() const
dwarf::Tag getTag() const
Accessors.
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Represents a compile or type unit.
const_iterator end() const
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
const T & operator*() const
dwarf::Tag getTag() const
String pool entry reference.
uint64_t getValue() const
static constexpr unsigned ULEB128PadSize
DIEValue & operator=(const DIEValue &X)
const_value_range values() const
Dwarf abbreviation, describes the organization of a debug information object.
void setSection(MCSection *Section)
Set the section that this DIEUnit will be emitted into.
DIEValue & operator*() const
Node - This class is used to maintain the singly linked bucket list in a folding set.
dwarf::Form BestForm() const
BestForm - Choose the best form for data.
void setOffset(unsigned O)
value_iterator(ListTy::iterator X)
uint64_t getLength() const
void setLength(uint64_t L)
PointerIntPair< IntrusiveBackListNode *, 1 > Next
const_value_iterator(ListTy::const_iterator X)
BasicDIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
void setChildrenFlag(bool hasChild)
const_iterator(const T *N)
bool operator==(const iterator &X) const
dwarf::Attribute getAttribute() const
unsigned getAbbrevNumber() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Type getType() const
Accessors.
const SmallVectorImpl< DIEAbbrevData > & getData() const
LLVM Value Representation.
unsigned getNumber() const
static const Function * getParent(const Value *V)
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
StringRef - Represent a constant reference to a string, i.e.
DIEAbbrevData(dwarf::Attribute A, dwarf::Form F)
DIEBlock - Represents a block of values.
dwarf::Form getForm() const
OutputIt copy(R &&Range, OutputIt Out)
IntrusiveBackListNode * getNext() const
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
void setValue(uint64_t Val)
StringRef getString() const
Grab the string out of the object.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...