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"
17
18namespace llvm {
20
21namespace dwarf_linker {
22namespace parallel {
23struct LinkContext;
24class TypeTableUnit;
25class CompileUnit;
26
27/// The helper class to build type name based on DIE properties.
28/// It builds synthetic name based on explicit attributes: DW_AT_name,
29/// DW_AT_linkage_name or based on implicit attributes(DW_AT_decl*).
30/// Names for specific DIEs(like subprograms, template classes...) include
31/// additional attributes: subprogram parameters, template parameters,
32/// array ranges. Examples of built name:
33///
34/// class A { } : {8}A
35///
36/// namspace llvm { class A { } } : {1}llvm{8}A
37///
38/// template <int> structure B { } : {F}B<{0}int>
39///
40/// void foo ( int p1, float p3 ) : {a}void foo({0}int, {0}int)
41///
42/// int *ptr; : {c}ptr {0}int
43///
44/// int var; : {d}var
45///
46/// These names is used to refer DIEs describing types.
48public:
50
51 /// Create synthetic name for the specified DIE \p InputUnitEntryPair
52 /// and assign created name to the DIE type info. \p ChildIndex is used
53 /// to create name for ordered DIEs(function arguments f.e.).
54 Error assignName(UnitEntryPairTy InputUnitEntryPair,
55 std::optional<std::pair<size_t, size_t>> ChildIndex);
56
57protected:
58 /// Add array type dimension.
59 void addArrayDimension(UnitEntryPairTy InputUnitEntryPair);
60
61 /// Add signature( entry type plus type of parameters plus type of template
62 /// parameters(if \p addTemplateParameters is true).
63 Error addSignature(UnitEntryPairTy InputUnitEntryPair,
64 bool addTemplateParameters);
65
66 /// Add specified \p FunctionParameters to the built name.
70
71 /// Add specified \p TemplateParameters to the built name.
75
76 /// Analyze \p InputUnitEntryPair's ODR attributes and put names
77 /// of the referenced type dies to the built name.
79 bool AssignNameToTypeDescriptor,
81
82 /// Resolve the DIE that \p Attr of \p InputUnitEntryPair refers to.
83 /// \returns std::nullopt if there is nothing to follow.
85 resolveReference(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr);
86
87 /// Count a referenced DIE toward the recursion limit. Callers decrement
88 /// RecursionDepth once they are done with it.
90
91 /// Add names of parent dies to the built name.
92 Error addParentName(UnitEntryPairTy &InputUnitEntryPair);
93
94 /// \returns synthetic name of the specified \p DieEntry.
95 /// The name is constructed from the dwarf::DW_AT_decl_file
96 /// and dwarf::DW_AT_decl_line attributes.
98 bool &HasDeclFileName);
99
100 /// Add a fixed-size digest of the contents of the unnamed type \p
101 /// InputUnitEntryPair, so the names of the types referring to it do not grow
102 /// with its size or nesting depth.
103 Error addUnnamedTypeContents(UnitEntryPairTy InputUnitEntryPair);
104
105 /// Add the type \p InputUnitEntryPair refers to, without parent scopes. A
106 /// type nested in an unnamed type would need the name being built.
107 Error addUnqualifiedTypeName(UnitEntryPairTy InputUnitEntryPair);
108
109 /// Add type prefix to the built name.
110 void addTypePrefix(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry);
111
112 /// Add type name to the built name.
113 Error addTypeName(UnitEntryPairTy InputUnitEntryPair, bool AddParentNames);
114
115 /// Analyze \p InputUnitEntryPair for the type name and possibly assign
116 /// built type name to the DIE's type info.
117 /// NOTE: while analyzing types we may create different kind of names
118 /// for the same type depending on whether the type is part of another type.
119 /// f.e. DW_TAG_formal_parameter would receive "{02}01" name when
120 /// examined alone. Or "{0}int" name when it is a part of a function name:
121 /// {a}void foo({0}int). The \p AssignNameToTypeDescriptor tells whether
122 /// the type name is part of another type name and then should not be assigned
123 /// to DIE type descriptor.
124 Error addDIETypeName(UnitEntryPairTy InputUnitEntryPair,
125 std::optional<std::pair<size_t, size_t>> ChildIndex,
126 bool AssignNameToTypeDescriptor);
127
128 /// Add ordered name to the built name.
129 void addOrderedName(std::pair<size_t, size_t> ChildIdx);
130
131 /// Add value name to the built name.
132 void addValueName(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr);
133
134 /// Buffer keeping bult name.
136
137 /// Digests of the contents of unnamed types, by DIE.
139
140 /// Recursion counter
141 size_t RecursionDepth = 0;
142
143 /// Bounds RecursionDepth, which malformed input can make unbounded.
144 static constexpr size_t MaxRecursionDepth = 1000;
145
146 /// Type pool
148};
149
150/// This class helps to assign indexes for DIE children.
151/// Indexes are used to create type name for children which
152/// should be presented in the original order(function parameters,
153/// array dimensions, enumeration members, class/structure members).
155public:
157 const DWARFDebugInfoEntry *DieEntry);
158
159 /// Returns index of the specified child and width of hexadecimal
160 /// representation.
161 std::optional<std::pair<size_t, size_t>>
162 getChildIndex(CompileUnit &CU, const DWARFDebugInfoEntry *ChildDieEntry);
163
164protected:
165 using OrderedChildrenIndexesArrayTy = std::array<size_t, 8>;
166
167 std::optional<size_t> tagToArrayIndex(CompileUnit &CU,
168 const DWARFDebugInfoEntry *DieEntry);
169
170 bool NeedCountChildren = false;
173};
174
175} // end of namespace parallel
176} // end of namespace dwarf_linker
177} // end of namespace llvm
178
179#endif // LLVM_LIB_DWARFLINKER_PARALLEL_SYNTHETICTYPENAMEBUILDER_H
This file defines the DenseMap class.
This file defines the SmallString 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
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
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.
SmallString< 1000 > SyntheticName
Buffer keeping bult name.
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.
TypePool keeps type descriptors which contain partially cloned DIE correspinding to each type.
Definition TypePool.h:129
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.