LLVM 24.0.0git
SyntheticTypeNameBuilder.h
Go to the documentation of this file.
1//===- SyntheticTypeNameBuilder.h -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===/
8
9#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_SYNTHETICTYPENAMEBUILDER_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_SYNTHETICTYPENAMEBUILDER_H
11
14#include "llvm/ADT/DenseMap.h"
16
17namespace llvm {
19
20namespace dwarf_linker {
21namespace parallel {
22struct LinkContext;
23class CompileUnit;
24
25/// The helper class to build type name based on DIE properties.
26/// It builds synthetic name based on explicit attributes: DW_AT_name,
27/// DW_AT_linkage_name or based on implicit attributes(DW_AT_decl*).
28/// Names for specific DIEs(like subprograms, template classes...) include
29/// additional attributes: subprogram parameters, template parameters,
30/// array ranges. Examples of built name:
31///
32/// class A { } : {8}A
33///
34/// namspace llvm { class A { } } : {1}llvm{8}A
35///
36/// template <int> structure B { } : {F}B<{0}int>
37///
38/// void foo ( int p1, float p3 ) : {a}void foo({0}int, {0}int)
39///
40/// int *ptr; : {c}ptr {0}int
41///
42/// int var; : {d}var
43///
44/// These names is used to refer DIEs describing types.
46public:
48
49 /// Create synthetic name for the specified DIE \p InputUnitEntryPair
50 /// and assign created name to the DIE type info. \p ChildIndex is used
51 /// to create name for ordered DIEs(function arguments f.e.).
52 Error assignName(UnitEntryPairTy InputUnitEntryPair,
53 std::optional<std::pair<size_t, size_t>> ChildIndex);
54
55protected:
56 /// Add array type dimension.
57 void addArrayDimension(UnitEntryPairTy InputUnitEntryPair);
58
59 /// Add signature( entry type plus type of parameters plus type of template
60 /// parameters(if \p addTemplateParameters is true).
61 Error addSignature(UnitEntryPairTy InputUnitEntryPair,
62 bool addTemplateParameters);
63
64 /// Add specified \p FunctionParameters to the built name.
68
69 /// Add specified \p TemplateParameters to the built name.
73
74 /// Analyze \p InputUnitEntryPair's ODR attributes and put names
75 /// of the referenced type dies to the built name.
77 bool AssignNameToTypeDescriptor,
79
80 /// Resolve the DIE that \p Attr of \p InputUnitEntryPair refers to.
81 /// \returns std::nullopt if there is nothing to follow.
83 resolveReference(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr);
84
85 /// Count a referenced DIE toward the recursion limit. Callers decrement
86 /// RecursionDepth once they are done with it.
88
89 /// Add names of parent dies to the built name.
90 Error addParentName(UnitEntryPairTy &InputUnitEntryPair);
91
92 /// \returns synthetic name of the specified \p DieEntry.
93 /// The name is constructed from the dwarf::DW_AT_decl_file
94 /// and dwarf::DW_AT_decl_line attributes.
96 bool &HasDeclFileName);
97
98 /// Add a fixed-size digest of the contents of the unnamed type \p
99 /// InputUnitEntryPair, so the names of the types referring to it do not grow
100 /// with its size or nesting depth.
101 Error addUnnamedTypeContents(UnitEntryPairTy InputUnitEntryPair);
102
103 /// Add the type \p InputUnitEntryPair refers to, without parent scopes. A
104 /// type nested in an unnamed type would need the name being built.
105 Error addUnqualifiedTypeName(UnitEntryPairTy InputUnitEntryPair);
106
107 /// Add type prefix to the built name.
108 void addTypePrefix(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry);
109
110 /// Add type name to the built name.
111 Error addTypeName(UnitEntryPairTy InputUnitEntryPair, bool AddParentNames);
112
113 /// Analyze \p InputUnitEntryPair for the type name and possibly assign
114 /// built type name to the DIE's type info.
115 /// NOTE: while analyzing types we may create different kind of names
116 /// for the same type depending on whether the type is part of another type.
117 /// f.e. DW_TAG_formal_parameter would receive "{02}01" name when
118 /// examined alone. Or "{0}int" name when it is a part of a function name:
119 /// {a}void foo({0}int). The \p AssignNameToTypeDescriptor tells whether
120 /// the type name is part of another type name and then should not be assigned
121 /// to DIE type descriptor.
122 Error addDIETypeName(UnitEntryPairTy InputUnitEntryPair,
123 std::optional<std::pair<size_t, size_t>> ChildIndex,
124 bool AssignNameToTypeDescriptor);
125
126 /// Add ordered name to the built name.
127 void addOrderedName(std::pair<size_t, size_t> ChildIdx);
128
129 /// Add value name to the built name.
130 void addValueName(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr);
131
132 /// Buffer keeping bult name.
134
135 /// Digests of the contents of unnamed types, by DIE.
137
138 /// Recursion counter
139 size_t RecursionDepth = 0;
140
141 /// Bounds RecursionDepth, which malformed input can make unbounded.
142 static constexpr size_t MaxRecursionDepth = 1000;
143
144 /// Type pool
146};
147
148/// This class helps to assign indexes for DIE children.
149/// Indexes are used to create type name for children which
150/// should be presented in the original order(function parameters,
151/// array dimensions, enumeration members, class/structure members).
153public:
155 const DWARFDebugInfoEntry *DieEntry);
156
157 /// Returns index of the specified child and width of hexadecimal
158 /// representation.
159 std::optional<std::pair<size_t, size_t>>
160 getChildIndex(CompileUnit &CU, const DWARFDebugInfoEntry *ChildDieEntry);
161
162protected:
163 using OrderedChildrenIndexesArrayTy = std::array<size_t, 8>;
164
165 std::optional<size_t> tagToArrayIndex(CompileUnit &CU,
166 const DWARFDebugInfoEntry *DieEntry);
167
168 bool NeedCountChildren = false;
171};
172
173} // end of namespace parallel
174} // end of namespace dwarf_linker
175} // end of namespace llvm
176
177#endif // LLVM_LIB_DWARFLINKER_PARALLEL_SYNTHETICTYPENAMEBUILDER_H
This file defines the DenseMap class.
This file defines the SmallVector class.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Stores all information related to a compile unit, be it in its original instance of the object file o...
OrderedChildrenIndexAssigner(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
std::optional< size_t > tagToArrayIndex(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
std::optional< std::pair< size_t, size_t > > getChildIndex(CompileUnit &CU, const DWARFDebugInfoEntry *ChildDieEntry)
Returns index of the specified child and width of hexadecimal representation.
Error addReferencedODRDies(UnitEntryPairTy InputUnitEntryPair, bool AssignNameToTypeDescriptor, ArrayRef< dwarf::Attribute > ODRAttrs)
Analyze InputUnitEntryPair's ODR attributes and put names of the referenced type dies to the built na...
Error addTemplateParamNames(CompileUnit &CU, SmallVector< const DWARFDebugInfoEntry *, 10 > &TemplateParameters)
Add specified TemplateParameters to the built name.
Error incrementRecursionDepth()
Count a referenced DIE toward the recursion limit.
Error addParentName(UnitEntryPairTy &InputUnitEntryPair)
Add names of parent dies to the built name.
Error addUnqualifiedTypeName(UnitEntryPairTy InputUnitEntryPair)
Add the type InputUnitEntryPair refers to, without parent scopes.
Error addSignature(UnitEntryPairTy InputUnitEntryPair, bool addTemplateParameters)
Add signature( entry type plus type of parameters plus type of template parameters(if addTemplatePara...
Error addParamNames(CompileUnit &CU, SmallVector< const DWARFDebugInfoEntry *, 20 > &FunctionParameters)
Add specified FunctionParameters to the built name.
void addDieNameFromDeclFileAndDeclLine(UnitEntryPairTy &InputUnitEntryPair, bool &HasDeclFileName)
Error addUnnamedTypeContents(UnitEntryPairTy InputUnitEntryPair)
Add a fixed-size digest of the contents of the unnamed type InputUnitEntryPair, so the names of the t...
Expected< std::optional< UnitEntryPairTy > > resolveReference(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Resolve the DIE that Attr of InputUnitEntryPair refers to.
void addOrderedName(std::pair< size_t, size_t > ChildIdx)
Add ordered name to the built name.
Error assignName(UnitEntryPairTy InputUnitEntryPair, std::optional< std::pair< size_t, size_t > > ChildIndex)
Create synthetic name for the specified DIE InputUnitEntryPair and assign created name to the DIE typ...
Error addDIETypeName(UnitEntryPairTy InputUnitEntryPair, std::optional< std::pair< size_t, size_t > > ChildIndex, bool AssignNameToTypeDescriptor)
Analyze InputUnitEntryPair for the type name and possibly assign built type name to the DIE's type in...
static constexpr size_t MaxRecursionDepth
Bounds RecursionDepth, which malformed input can make unbounded.
Error addTypeName(UnitEntryPairTy InputUnitEntryPair, bool AddParentNames)
Add type name to the built name.
DenseMap< const DWARFDebugInfoEntry *, std::string > ContentsDigests
Digests of the contents of unnamed types, by DIE.
void addArrayDimension(UnitEntryPairTy InputUnitEntryPair)
Add array type dimension.
void addValueName(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Add value name to the built name.
void addTypePrefix(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
Add type prefix to the built name.
A type key is text interleaved with references to other type entries.
Definition TypePool.h:36
TypePool keeps type descriptors which contain partially cloned DIE correspinding to each type.
Definition TypePool.h:148
Attribute
Attributes.
Definition Dwarf.h:125
This is an optimization pass for GlobalISel generic memory operations.
This is a helper structure which keeps a debug info entry with it's containing compilation unit.