13#ifndef LLVM_CODEGEN_DIE_H
14#define LLVM_CODEGEN_DIE_H
42class DwarfCompileUnit;
121 Data.push_back(AbbrevData);
148 std::vector<DIEAbbrev *> Abbreviations;
178 const int64_t SignedInt =
Int;
179 if ((int8_t)
Int == SignedInt)
180 return dwarf::DW_FORM_data1;
181 if ((int16_t)
Int == SignedInt)
182 return dwarf::DW_FORM_data2;
183 if ((int32_t)
Int == SignedInt)
184 return dwarf::DW_FORM_data4;
187 return dwarf::DW_FORM_data1;
189 return dwarf::DW_FORM_data2;
191 return dwarf::DW_FORM_data4;
193 return dwarf::DW_FORM_data8;
247 static constexpr unsigned ULEB128PadSize = 4;
251 :
CU(TheCU), Index(
Idx) {}
307 template <
typename Allocator>
387#define HANDLE_DIEVALUE(T) is##T,
388#include "llvm/CodeGen/DIEValue.def"
402 AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
403 DIEDelta *, DIEEntry, DIEBlock *, DIELoc *,
404 DIELocList, DIEBaseTypeRef *, DIEAddrOffset *>;
406 static_assert(
sizeof(ValTy) <=
sizeof(
uint64_t) ||
407 sizeof(ValTy) <=
sizeof(
void *),
408 "Expected all large types to be stored via pointer");
413 template <
class T>
void construct(
T V) {
414 static_assert(std::is_standard_layout<T>::value ||
415 std::is_pointer<T>::value,
416 "Expected standard layout or pointer");
417 new (
reinterpret_cast<void *
>(&Val))
T(
V);
420 template <
class T>
T *get() {
return reinterpret_cast<T *
>(&Val); }
421 template <
class T>
const T *get()
const {
422 return reinterpret_cast<const T *
>(&Val);
424 template <
class T>
void destruct() { get<T>()->~T(); }
435#define HANDLE_DIEVALUE_SMALL(T) \
437 destruct<DIE##T>(); \
439#define HANDLE_DIEVALUE_LARGE(T) \
441 destruct<const DIE##T *>(); \
443#include "llvm/CodeGen/DIEValue.def"
456#define HANDLE_DIEVALUE_SMALL(T) \
458 construct<DIE##T>(*X.get<DIE##T>()); \
460#define HANDLE_DIEVALUE_LARGE(T) \
462 construct<const DIE##T *>(*X.get<const DIE##T *>()); \
464#include "llvm/CodeGen/DIEValue.def"
488#define HANDLE_DIEVALUE_SMALL(T) \
489 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V) \
490 : Ty(is##T), Attribute(Attribute), Form(Form) { \
491 construct<DIE##T>(V); \
493#define HANDLE_DIEVALUE_LARGE(T) \
494 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V) \
495 : Ty(is##T), Attribute(Attribute), Form(Form) { \
496 assert(V && "Expected valid value"); \
497 construct<const DIE##T *>(V); \
499#include "llvm/CodeGen/DIEValue.def"
506 explicit operator bool()
const {
return Ty; }
509#define HANDLE_DIEVALUE_SMALL(T) \
510 const DIE##T &getDIE##T() const { \
511 assert(getType() == is##T && "Expected " #T); \
512 return *get<DIE##T>(); \
514#define HANDLE_DIEVALUE_LARGE(T) \
515 const DIE##T &getDIE##T() const { \
516 assert(getType() == is##T && "Expected " #T); \
517 return **get<const DIE##T *>(); \
519#include "llvm/CodeGen/DIEValue.def"
525 LLVM_ABI unsigned sizeOf(
const dwarf::FormParams &FormParams)
const;
537 return Next.getInt() ? nullptr :
Next.getPointer();
549 assert(
N.Next.getPointer() == &
N &&
"Expected unlinked node");
550 assert(
N.Next.getInt() ==
true &&
"Expected unlinked node");
560 assert(
N.Next.getPointer() == &
N &&
"Expected unlinked node");
561 assert(
N.Next.getInt() ==
true &&
"Expected unlinked node");
564 N.Next.setPointerAndInt(
Last->
Next.getPointer(),
false);
582 return *
static_cast<T *
>(
Last ?
Last->
Next.getPointer() :
nullptr);
585 return *
static_cast<T *
>(
Last ?
Last->
Next.getPointer() :
nullptr);
592 T *FirstNode =
static_cast<T *
>(
Other.Last->Next.getPointer());
593 T *IterNode = FirstNode;
596 T *TmpNode = IterNode;
597 IterNode =
static_cast<T *
>(IterNode->Next.getPointer());
600 TmpNode->Next.setPointerAndInt(TmpNode,
true);
602 }
while (IterNode != FirstNode);
604 Other.Last =
nullptr;
615 while (cur && cur->
Next.getPointer()) {
616 if (cur->
Next.getPointer() == &
N) {
617 cur->
Next.setPointer(cur->
Next.getPointer()->Next.getPointer());
620 cur = cur->
Next.getPointer();
642 explicit operator bool()
const {
return N; }
651 const Node *N =
nullptr;
664 explicit operator bool()
const {
return N; }
713 std::forward_iterator_tag, DIEValue> {
718 std::forward_iterator_tag,
DIEValue>;
729 const_value_iterator, ListTy::const_iterator,
730 std::forward_iterator_tag, const DIEValue> {
733 std::forward_iterator_tag,
const DIEValue>;
767 DIEValue(NewAttribute, Form, std::forward<T>(NewValue));
802 for (
auto &node :
List) {
803 if (node.V.getAttribute() ==
Attribute) {
804 return List.deleteNode(node);
836 unsigned AbbrevNumber = ~0u;
841 bool ForceChildren =
false;
868 assert(
Offset &&
"Offset being queried before it's been computed.");
873 assert(
Size &&
"Size being queried before it's been ocmputed.");
876 bool hasChildren()
const {
return ForceChildren || !Children.empty(); }
885 return make_range(Children.begin(), Children.end());
888 return make_range(Children.begin(), Children.end());
947 Children.push_back(*Child);
948 return Children.back();
954 Children.push_front(*Child);
955 return Children.front();
996 this->Section = Section;
1021 mutable unsigned Size = 0;
1035 if (DwarfVersion > 3)
1036 return dwarf::DW_FORM_exprloc;
1039 return dwarf::DW_FORM_block1;
1041 return dwarf::DW_FORM_block2;
1043 return dwarf::DW_FORM_block4;
1044 return dwarf::DW_FORM_block;
1057 mutable unsigned Size = 0;
1072 return dwarf::DW_FORM_block1;
1074 return dwarf::DW_FORM_block2;
1076 return dwarf::DW_FORM_block4;
1077 return dwarf::DW_FORM_block;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file contains constants used for implementing Dwarf debug support.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file defines a hash set that can be used to remove duplication of nodes in a graph.
This file defines the PointerIntPair class.
This file defines the PointerUnion class, which is a discriminated union of pointer types.
This file defines the SmallVector class.
This class is intended to be used as a driving class for all asm writers.
Allocate memory in an ever growing pool, as if by bump-pointer.
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
dwarf::Form getForm() const
dwarf::Attribute getAttribute() const
Accessors.
DIEAbbrevData(dwarf::Attribute A, int64_t V)
DIEAbbrevData(dwarf::Attribute A, dwarf::Form F)
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
LLVM_ABI void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
DIEAbbrevSet(BumpPtrAllocator &A)
LLVM_ABI DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation.
Dwarf abbreviation, describes the organization of a debug information object.
LLVM_ABI void print(raw_ostream &O) const
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
unsigned getNumber() const
LLVM_ABI void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
void AddAttribute(const DIEAbbrevData &AbbrevData)
Adds another set of attribute information to the abbreviation.
const SmallVectorImpl< DIEAbbrevData > & getData() const
DIEAbbrev(dwarf::Tag T, bool C)
void setChildrenFlag(bool hasChild)
dwarf::Tag getTag() const
Accessors.
void setNumber(unsigned N)
LLVM_ABI void dump() const
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
DIEAddrOffset(uint64_t Idx, const MCSymbol *Hi, const MCSymbol *Lo)
uint64_t getIndex() const
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
LLVM_ABI void print(raw_ostream &O) const
DIEBaseTypeRef(const DwarfCompileUnit *TheCU, uint64_t Idx)
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
sizeOf - Determine size of the base type reference in bytes.
DIEBlock - Represents a block of values.
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of block data in bytes.
void setSize(unsigned size)
dwarf::Form BestForm() const
BestForm - Choose the best form for data.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
A simple label difference DIE.
DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
A pointer to another debug information entry.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
LLVM_ABI void print(raw_ostream &O) const
const MCExpr * getValue() const
Get MCExpr.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
A container for inline string values.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
~DIEInlineString()=default
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
StringRef getString() const
Grab the string out of the object.
DIEInlineString(StringRef Str, Allocator &A)
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of integer value in bytes.
uint64_t getValue() const
void setValue(uint64_t Val)
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
const MCSymbol * getValue() const
Get MCSymbol.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of label value in bytes.
DIELabel(const MCSymbol *L)
Represents a pointer to a location list in the debug_loc section.
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
size_t getValue() const
Grab the current index out.
DIELoc - Represents an expression location.
void setSize(unsigned size)
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of location data in bytes.
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
A container for string pool string values.
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
DIEString(DwarfStringPoolEntryRef S)
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of delta value in bytes.
StringRef getString() const
Grab the string out of the object.
Represents a compile or type unit.
void setSection(MCSection *Section)
Set the section that this DIEUnit will be emitted into.
void operator=(const DIEUnit &&RHS)=delete
DIEUnit(DIEUnit &&RHS)=delete
void operator=(const DIEUnit &RHS)=delete
const DIE & getUnitDie() const
DIEUnit(const DIEUnit &RHS)=delete
virtual const MCSymbol * getCrossSectionRelativeBaseAddress() const
void setDebugSectionOffset(uint64_t O)
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
virtual ~DIEUnit()=default
.debug_info or .debug_types absolute section offset.
uint64_t getDebugSectionOffset() const
const_value_iterator()=default
const DIEValue & operator*() const
const_value_iterator(DIEValueList::value_iterator X)
const_value_iterator(ListTy::const_iterator X)
value_iterator(ListTy::iterator X)
DIEValue & operator*() const
bool deleteValue(dwarf::Attribute Attribute)
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
bool replaceValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, dwarf::Attribute NewAttribute, dwarf::Form Form, T &&NewValue)
bool replaceValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, dwarf::Form Form, T &&NewValue)
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
const_value_range values() const
value_iterator addValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
bool replaceValue(BumpPtrAllocator &Alloc, dwarf::Attribute Attribute, dwarf::Form Form, DIEValue &NewValue)
LLVM_ABI void print(raw_ostream &O) const
LLVM_ABI void emitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams) const
Return the size of a value in bytes.
dwarf::Form getForm() const
Type getType() const
Accessors.
DIEValue(const DIEValue &X)
DIEValue & operator=(const DIEValue &X)
dwarf::Attribute getAttribute() const
LLVM_ABI void dump() const
A structured debug information entry.
LLVM_ABI DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
LLVM_ABI void print(raw_ostream &O, unsigned IndentCount=0) const
unsigned getAbbrevNumber() const
const_child_range children() const
DIE & addChild(DIE *Child)
Add a child to the DIE.
DIE(const DIE &RHS)=delete
LLVM_ABI DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
LLVM_ABI unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
DIE & addChildFront(DIE *Child)
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
LLVM_ABI DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
DIE & operator=(const DIE &RHS)=delete
LLVM_ABI const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to.
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
void setOffset(unsigned O)
void setForceChildren(bool B)
LLVM_ABI uint64_t getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
dwarf::Tag getTag() const
LLVM_ABI void dump() const
DIE & operator=(const DIE &&RHS)=delete
LLVM_ABI DIE * getParent() const
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
StringRef getString() const
Node - This class is used to maintain the singly linked bucket list in a folding set.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
const T & operator*() const
bool operator==(const const_iterator &X) const
const_iterator(typename IntrusiveBackList< T >::iterator X)
const_iterator & operator++()
const_iterator(const T *N)
bool operator==(const iterator &X) const
void takeNodes(IntrusiveBackList< T > &Other)
static const_iterator toIterator(const T &N)
const_iterator begin() const
const_iterator end() const
static iterator toIterator(T &N)
Base class for the full range of assembler expressions which are needed for parsing.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
PointerIntPair - This class implements a pair of a pointer and small integer.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
CRTP base class for adapting an iterator to a different type.
const ListTy::iterator & wrapped() const
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
OutputIt copy(R &&Range, OutputIt Out)
BasicDIEUnit(dwarf::Tag UnitTag)
PointerIntPair< IntrusiveBackListNode *, 1 > Next
IntrusiveBackListNode * getNext() const