13#ifndef LLVM_CODEGEN_DIE_H
14#define LLVM_CODEGEN_DIE_H
62 : Attribute(
A), Form(
F) {}
64 : Attribute(
A), Form(
dwarf::DW_FORM_implicit_const), Value(V) {}
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;
240 static constexpr unsigned ULEB128PadSize = 4;
244 :
CU(TheCU), Index(Idx) {}
300 template <
typename Allocator>
362 : Addr(Idx), Offset(
Hi,
Lo) {}
380#define HANDLE_DIEVALUE(T) is##T,
381#include "llvm/CodeGen/DIEValue.def"
395 AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
396 DIEDelta *, DIEEntry, DIEBlock *, DIELoc *,
397 DIELocList, DIEBaseTypeRef *, DIEAddrOffset *>;
399 static_assert(
sizeof(ValTy) <=
sizeof(
uint64_t) ||
400 sizeof(ValTy) <=
sizeof(
void *),
401 "Expected all large types to be stored via pointer");
406 template <
class T>
void construct(
T V) {
407 static_assert(std::is_standard_layout<T>::value ||
408 std::is_pointer<T>::value,
409 "Expected standard layout or pointer");
410 new (
reinterpret_cast<void *
>(&Val))
T(
V);
413 template <
class T>
T *get() {
return reinterpret_cast<T *
>(&Val); }
414 template <
class T>
const T *get()
const {
415 return reinterpret_cast<const T *
>(&Val);
417 template <
class T>
void destruct() { get<T>()->~T(); }
428#define HANDLE_DIEVALUE_SMALL(T) \
430 destruct<DIE##T>(); \
432#define HANDLE_DIEVALUE_LARGE(T) \
434 destruct<const DIE##T *>(); \
436#include "llvm/CodeGen/DIEValue.def"
449#define HANDLE_DIEVALUE_SMALL(T) \
451 construct<DIE##T>(*X.get<DIE##T>()); \
453#define HANDLE_DIEVALUE_LARGE(T) \
455 construct<const DIE##T *>(*X.get<const DIE##T *>()); \
457#include "llvm/CodeGen/DIEValue.def"
473 Attribute =
X.Attribute;
481#define HANDLE_DIEVALUE_SMALL(T) \
482 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T &V) \
483 : Ty(is##T), Attribute(Attribute), Form(Form) { \
484 construct<DIE##T>(V); \
486#define HANDLE_DIEVALUE_LARGE(T) \
487 DIEValue(dwarf::Attribute Attribute, dwarf::Form Form, const DIE##T *V) \
488 : Ty(is##T), Attribute(Attribute), Form(Form) { \
489 assert(V && "Expected valid value"); \
490 construct<const DIE##T *>(V); \
492#include "llvm/CodeGen/DIEValue.def"
499 explicit operator bool()
const {
return Ty; }
502#define HANDLE_DIEVALUE_SMALL(T) \
503 const DIE##T &getDIE##T() const { \
504 assert(getType() == is##T && "Expected " #T); \
505 return *get<DIE##T>(); \
507#define HANDLE_DIEVALUE_LARGE(T) \
508 const DIE##T &getDIE##T() const { \
509 assert(getType() == is##T && "Expected " #T); \
510 return **get<const DIE##T *>(); \
512#include "llvm/CodeGen/DIEValue.def"
530 return Next.getInt() ? nullptr :
Next.getPointer();
542 assert(
N.Next.getPointer() == &
N &&
"Expected unlinked node");
543 assert(
static_cast<bool>(
N.Next.getInt()) ==
true &&
544 "Expected unlinked node");
548 Last->Next.setPointerAndInt(&
N,
false);
554 assert(
N.Next.getPointer() == &
N &&
"Expected unlinked node");
555 assert(
static_cast<bool>(
N.Next.getInt()) ==
true &&
556 "Expected unlinked node");
559 N.Next.setPointerAndInt(
Last->Next.getPointer(),
false);
560 Last->Next.setPointerAndInt(&
N,
true);
574 while (Cur->
Next.getPointer() != &
N) {
575 Cur = Cur->
Next.getPointer();
576 if (Cur->
Next.getInt())
584 Cur->
Next.setPointerAndInt(
Target->Next.getPointer(),
true);
587 Cur->
Next.setPointer(
Target->Next.getPointer());
605 return *
static_cast<T *
>(
Last ?
Last->Next.getPointer() :
nullptr);
608 return *
static_cast<T *
>(
Last ?
Last->Next.getPointer() :
nullptr);
615 T *FirstNode =
static_cast<T *
>(
Other.Last->Next.getPointer());
616 T *IterNode = FirstNode;
619 T *TmpNode = IterNode;
620 IterNode =
static_cast<T *
>(IterNode->Next.getPointer());
623 TmpNode->Next.setPointerAndInt(TmpNode,
true);
625 }
while (IterNode != FirstNode);
627 Other.Last =
nullptr;
649 explicit operator bool()
const {
return N; }
658 const Node *N =
nullptr;
671 explicit operator bool()
const {
return N; }
678 return Last ? iterator(
static_cast<T *
>(
Last->Next.getPointer())) :
end();
683 iterator
end() {
return iterator(); }
684 const_iterator
end()
const {
return const_iterator(); }
720 std::forward_iterator_tag, DIEValue> {
723 using iterator_adaptor =
725 std::forward_iterator_tag,
DIEValue>;
736 const_value_iterator, ListTy::const_iterator,
737 std::forward_iterator_tag, const DIEValue> {
738 using iterator_adaptor =
740 std::forward_iterator_tag,
const DIEValue>;
747 : iterator_adaptor(
X) {}
757 List.push_back(*
new (
Alloc) Node(V));
774 DIEValue(NewAttribute, Form, std::forward<T>(NewValue));
809 for (
auto &node : List) {
810 if (node.V.getAttribute() ==
Attribute) {
811 return List.deleteNode(node);
843 unsigned AbbrevNumber = ~0u;
848 bool ForceChildren =
false;
875 assert(Offset &&
"Offset being queried before it's been computed.");
880 assert(Size &&
"Size being queried before it's been ocmputed.");
883 bool hasChildren()
const {
return ForceChildren || !Children.empty(); }
892 return make_range(Children.begin(), Children.end());
895 return make_range(Children.begin(), Children.end());
954 Children.push_back(*Child);
955 return Children.back();
961 Children.push_front(*Child);
962 return Children.front();
1003 this->Section = Section;
1028 mutable unsigned Size = 0;
1042 if (DwarfVersion > 3)
1043 return dwarf::DW_FORM_exprloc;
1046 return dwarf::DW_FORM_block1;
1048 return dwarf::DW_FORM_block2;
1050 return dwarf::DW_FORM_block4;
1051 return dwarf::DW_FORM_block;
1064 mutable unsigned Size = 0;
1079 return dwarf::DW_FORM_block1;
1081 return dwarf::DW_FORM_block2;
1083 return dwarf::DW_FORM_block4;
1084 return dwarf::DW_FORM_block;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains constants used for implementing Dwarf debug support.
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.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
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.
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.
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
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.
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
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.
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)
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.
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.
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
LLVM_ABI DIEUnit(dwarf::Tag UnitTag)
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)
friend class const_value_iterator
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)
iterator_range< value_iterator > value_range
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
const_value_range values() const
iterator_range< const_value_iterator > const_value_range
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
IntrusiveBackList< DIE >::const_iterator const_child_iterator
unsigned getAbbrevNumber() const
const_child_range children() const
IntrusiveBackList< DIE >::iterator child_iterator
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.
iterator_range< child_iterator > child_range
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.
iterator_range< const_child_iterator > const_child_range
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.
This class is used to gather all the unique data bits of a node.
const T & operator*() const
const_iterator(IntrusiveBackList< T >::iterator X)
bool operator==(const const_iterator &X) const
const_iterator & operator++()
const_iterator(const T *N)
bool operator==(const iterator &X) const
friend class const_iterator
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)
bool deleteNode(Node &N)
Deletes node N from the list. Note this runs in O(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 bits of the poi...
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.
Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
LLVM Value Representation.
const ListTy::iterator & wrapped() const
iterator_adaptor_base()=default
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.
Calculates the starting offsets for various sections within the .debug_names section.
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)
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
FoldingSetImpl< T, Trait > FoldingSet
This template class is used to instantiate a specialized implementation of the folding set to the nod...
BasicDIEUnit(dwarf::Tag UnitTag)
bool deleteNode(Node &N)
Delete node N by walking through the list until N's predecessor is found.
IntrusiveBackListNode Node
PointerIntPair< IntrusiveBackListNode *, 1 > Next
IntrusiveBackListNode * getNext() const