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