16using namespace dwarf_linker;
17using namespace dwarf_linker::parallel;
21 std::optional<std::pair<size_t, size_t>> ChildIndex) {
25 "Cann't assign name for non-type DIE");
43 if (CurChild->getTag() == dwarf::DW_TAG_subrange_type ||
44 CurChild->getTag() == dwarf::DW_TAG_generic_subrange) {
46 if (std::optional<DWARFFormValue> Val =
47 InputUnitEntryPair.
CU->
find(CurChild, dwarf::DW_AT_count)) {
48 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
50 }
else if (std::optional<int64_t> ConstVal =
51 Val->getAsSignedConstant()) {
63 bool addTemplateParameters) {
77 if (addTemplateParameters &&
78 (ChildTag == dwarf::DW_TAG_template_type_parameter ||
79 ChildTag == dwarf::DW_TAG_template_value_parameter))
81 else if (ChildTag == dwarf::DW_TAG_formal_parameter ||
82 ChildTag == dwarf::DW_TAG_unspecified_parameters)
84 else if (addTemplateParameters &&
85 ChildTag == dwarf::DW_TAG_GNU_template_parameter_pack) {
90 TemplateParameters.
push_back(CurGNUChild);
91 }
else if (ChildTag == dwarf::DW_TAG_GNU_formal_parameter_pack) {
96 FunctionParameters.
push_back(CurGNUChild);
133 if (!TemplateParameters.
empty()) {
139 if (Parameter->getTag() == dwarf::DW_TAG_template_value_parameter) {
140 if (std::optional<DWARFFormValue> Val =
141 CU.find(Parameter, dwarf::DW_AT_const_value)) {
142 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant())
144 else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant())
159 std::pair<size_t, size_t> ChildIdx) {
168static std::optional<UnitEntryPairTy>
171 case dwarf::DW_TAG_null:
172 case dwarf::DW_TAG_compile_unit:
173 case dwarf::DW_TAG_partial_unit:
174 case dwarf::DW_TAG_type_unit:
175 case dwarf::DW_TAG_skeleton_unit: {
178 case dwarf::DW_TAG_namespace: {
180 if (UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_extension))
184 if (!UnitEntryPair.
CU->
find(UnitEntryPair.
DieEntry, dwarf::DW_AT_name))
187 return UnitEntryPair;
190 return UnitEntryPair;
196 std::optional<UnitEntryPairTy> UnitEntryPair = InputUnitEntryPair.
getParent();
205 UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry)) {
214 Parents.push_back(*UnitEntryPair);
216 UnitEntryPair = UnitEntryPair->getParent();
224 }
while (!UnitEntryPair->CU->getDieTypeEntry(UnitEntryPair->DieEntry));
241 if (std::optional<DWARFFormValue> DeclFileVal = InputUnitEntryPair.
CU->
find(
242 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_file)) {
243 if (std::optional<DWARFFormValue> DeclLineVal = InputUnitEntryPair.
CU->
find(
244 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_decl_line)) {
245 if (std::optional<std::pair<StringRef, StringRef>> DirAndFilename =
251 if (std::optional<uint64_t> DeclLineIntVal =
257 HasDeclFileName =
true;
265 if (std::optional<DWARFFormValue> Val =
267 if (std::optional<uint64_t> ConstVal = Val->getAsUnsignedConstant()) {
270 }
else if (std::optional<int64_t> ConstVal = Val->getAsSignedConstant()) {
280 bool FirstIteration =
true;
282 if (std::optional<DWARFFormValue> AttrValue =
284 std::optional<UnitEntryPairTy> RefDie =
291 if (!RefDie->DieEntry)
293 "Cann't resolve DIE reference");
301 std::errc::invalid_argument,
302 "Cann't parse input DWARF. Recursive dependence.");
305 addDIETypeName(*RefDie, std::nullopt, AssignNameToTypeDescriptor))
308 FirstIteration =
false;
316 bool AddParentNames) {
317 bool HasLinkageName =
false;
318 bool HasShortName =
false;
319 bool HasTemplatesInShortName =
false;
320 bool HasDeclFileName =
false;
323 if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
325 {dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_AT_linkage_name})) {
328 HasLinkageName =
true;
329 }
else if (std::optional<DWARFFormValue> Val = InputUnitEntryPair.
CU->
find(
330 InputUnitEntryPair.
DieEntry, dwarf::DW_AT_name)) {
336 HasTemplatesInShortName =
337 Name.ends_with(
">") &&
Name.count(
"<") != 0 && !
Name.ends_with(
"<=>");
345 case dwarf::DW_TAG_union_type:
346 case dwarf::DW_TAG_interface_type:
347 case dwarf::DW_TAG_class_type:
348 case dwarf::DW_TAG_structure_type:
349 case dwarf::DW_TAG_subroutine_type:
350 case dwarf::DW_TAG_subprogram: {
352 dwarf::DW_AT_artificial))
360 addSignature(InputUnitEntryPair, !HasTemplatesInShortName))
363 case dwarf::DW_TAG_coarray_type:
364 case dwarf::DW_TAG_array_type: {
367 case dwarf::DW_TAG_subrange_type: {
370 case dwarf::DW_TAG_template_value_parameter: {
371 if (!HasTemplatesInShortName) {
373 addValueName(InputUnitEntryPair, dwarf::DW_AT_const_value);
382 if (!HasLinkageName && !HasShortName && !HasDeclFileName) {
395 std::optional<std::pair<size_t, size_t>> ChildIndex,
396 bool AssignNameToTypeDescriptor) {
397 std::optional<UnitEntryPairTy> UnitEntryPair =
407 if (AssignNameToTypeDescriptor) {
420 if (AssignNameToTypeDescriptor) {
434 switch (DieEntry->
getTag()) {
435 case dwarf::DW_TAG_base_type: {
438 case dwarf::DW_TAG_namespace: {
441 case dwarf::DW_TAG_formal_parameter: {
445 case dwarf::DW_TAG_unspecified_parameters: {
448 case dwarf::DW_TAG_template_type_parameter: {
452 case dwarf::DW_TAG_template_value_parameter: {
455 case dwarf::DW_TAG_GNU_formal_parameter_pack: {
458 case dwarf::DW_TAG_GNU_template_parameter_pack: {
461 case dwarf::DW_TAG_inheritance: {
464 case dwarf::DW_TAG_array_type: {
467 case dwarf::DW_TAG_class_type: {
470 case dwarf::DW_TAG_enumeration_type: {
473 case dwarf::DW_TAG_imported_declaration: {
476 case dwarf::DW_TAG_member: {
479 case dwarf::DW_TAG_pointer_type: {
482 case dwarf::DW_TAG_reference_type: {
485 case dwarf::DW_TAG_string_type: {
488 case dwarf::DW_TAG_structure_type: {
491 case dwarf::DW_TAG_subroutine_type: {
494 case dwarf::DW_TAG_typedef: {
497 case dwarf::DW_TAG_union_type: {
500 case dwarf::DW_TAG_variant: {
503 case dwarf::DW_TAG_inlined_subroutine: {
506 case dwarf::DW_TAG_module: {
509 case dwarf::DW_TAG_ptr_to_member_type: {
512 case dwarf::DW_TAG_set_type: {
515 case dwarf::DW_TAG_subrange_type: {
518 case dwarf::DW_TAG_with_stmt: {
521 case dwarf::DW_TAG_access_declaration: {
524 case dwarf::DW_TAG_catch_block: {
527 case dwarf::DW_TAG_const_type: {
530 case dwarf::DW_TAG_constant: {
533 case dwarf::DW_TAG_enumerator: {
536 case dwarf::DW_TAG_file_type: {
539 case dwarf::DW_TAG_friend: {
542 case dwarf::DW_TAG_namelist: {
545 case dwarf::DW_TAG_namelist_item: {
548 case dwarf::DW_TAG_packed_type: {
551 case dwarf::DW_TAG_subprogram: {
554 case dwarf::DW_TAG_thrown_type: {
557 case dwarf::DW_TAG_variant_part: {
560 case dwarf::DW_TAG_variable: {
563 case dwarf::DW_TAG_volatile_type: {
566 case dwarf::DW_TAG_dwarf_procedure: {
569 case dwarf::DW_TAG_restrict_type: {
572 case dwarf::DW_TAG_interface_type: {
575 case dwarf::DW_TAG_imported_module: {
578 case dwarf::DW_TAG_unspecified_type: {
581 case dwarf::DW_TAG_imported_unit: {
584 case dwarf::DW_TAG_condition: {
587 case dwarf::DW_TAG_shared_type: {
590 case dwarf::DW_TAG_rvalue_reference_type: {
593 case dwarf::DW_TAG_template_alias: {
596 case dwarf::DW_TAG_coarray_type: {
599 case dwarf::DW_TAG_generic_subrange: {
602 case dwarf::DW_TAG_dynamic_type: {
605 case dwarf::DW_TAG_atomic_type: {
608 case dwarf::DW_TAG_call_site: {
611 case dwarf::DW_TAG_call_site_parameter: {
614 case dwarf::DW_TAG_immutable_type: {
617 case dwarf::DW_TAG_entry_point: {
620 case dwarf::DW_TAG_label: {
623 case dwarf::DW_TAG_lexical_block: {
626 case dwarf::DW_TAG_common_block: {
629 case dwarf::DW_TAG_common_inclusion: {
632 case dwarf::DW_TAG_try_block: {
636 case dwarf::DW_TAG_null: {
639 case dwarf::DW_TAG_compile_unit: {
642 case dwarf::DW_TAG_partial_unit: {
645 case dwarf::DW_TAG_type_unit: {
648 case dwarf::DW_TAG_skeleton_unit: {
662 switch (DieEntry->
getTag()) {
663 case dwarf::DW_TAG_array_type:
664 case dwarf::DW_TAG_coarray_type:
665 case dwarf::DW_TAG_class_type:
666 case dwarf::DW_TAG_common_block:
667 case dwarf::DW_TAG_lexical_block:
668 case dwarf::DW_TAG_structure_type:
669 case dwarf::DW_TAG_subprogram:
670 case dwarf::DW_TAG_subroutine_type:
671 case dwarf::DW_TAG_union_type:
672 case dwarf::DW_TAG_GNU_template_template_param:
673 case dwarf::DW_TAG_GNU_formal_parameter_pack: {
676 case dwarf::DW_TAG_enumeration_type: {
688 CurChild && CurChild->getAbbreviationDeclarationPtr();
689 CurChild =
CU.getSiblingEntry(CurChild)) {
695 "Wrong index for ChildIndexesWidth");
702 size_t digitsCounter = 1;
703 size_t NumToCompare = 15;
705 while (NumToCompare < Width) {
710 Width = digitsCounter;
720 switch (DieEntry->
getTag()) {
721 case dwarf::DW_TAG_unspecified_parameters:
722 case dwarf::DW_TAG_formal_parameter:
724 case dwarf::DW_TAG_template_value_parameter:
725 case dwarf::DW_TAG_template_type_parameter:
727 case dwarf::DW_TAG_enumeration_type:
728 if (std::optional<uint32_t> ParentIdx = DieEntry->
getParentIdx()) {
729 if (*ParentIdx &&
CU.getDebugInfoEntry(*ParentIdx)->getTag() ==
730 dwarf::DW_TAG_array_type)
734 case dwarf::DW_TAG_subrange_type:
736 case dwarf::DW_TAG_generic_subrange:
738 case dwarf::DW_TAG_enumerator:
740 case dwarf::DW_TAG_namelist_item:
742 case dwarf::DW_TAG_member:
749std::optional<std::pair<size_t, size_t>>
757 "Wrong index for ChildIndexesWidth");
759 "Index width exceeds 16 digits.");
761 std::pair<size_t, size_t> Result = std::make_pair(
Analysis containing CSE Info
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static std::optional< UnitEntryPairTy > getTypeDeduplicationCandidate(UnitEntryPairTy UnitEntryPair)
static dwarf::Attribute TypeAttr[]
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
DWARFDebugInfoEntry - A DIE with only the minimum required data.
dwarf::Tag getTag() const
std::optional< uint32_t > getParentIdx() const
Returns index of the parent die.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
StringRef substr(size_t Start, size_t N=StringRef::npos) const
Return a reference to the substring from [Start, Start + N).
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Stores all information related to a compile unit, be it in its original instance of the object file o...
std::optional< std::pair< StringRef, StringRef > > getDirAndFilenameFromLineTable(const DWARFFormValue &FileIdxValue)
Returns directory and file from the line table by index.
std::optional< UnitEntryPairTy > resolveDIEReference(const DWARFFormValue &RefValue, ResolveInterCUReferencesMode CanResolveInterCUReferences)
Resolve the DIE attribute reference that has been extracted in RefValue.
OrderedChildrenIndexesArrayTy ChildIndexesWidth
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.
OrderedChildrenIndexesArrayTy OrderedChildIdxs
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 addParentName(UnitEntryPairTy &InputUnitEntryPair)
Add names of parent dies to the built name.
void addOrderedName(CompileUnit &CU, const DWARFDebugInfoEntry *DieEntry)
Add ordered name to the built name.
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)
TypePool & TypePoolRef
Type pool.
size_t RecursionDepth
Recursion counter.
void addTypePrefix(const DWARFDebugInfoEntry *DieEntry)
Add type prefix to the built name.
SmallString< 1000 > SyntheticName
Buffer keeping bult 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...
Error addTypeName(UnitEntryPairTy InputUnitEntryPair, bool AddParentNames)
Add type name to the built name.
void addArrayDimension(UnitEntryPairTy InputUnitEntryPair)
Add array type dimension.
void addValueName(UnitEntryPairTy InputUnitEntryPair, dwarf::Attribute Attr)
Add value name to the built name.
TypeEntry * insert(StringRef Name)
A raw_ostream that writes to an std::string.
TypeEntry * getDieTypeEntry(uint32_t Idx)
Idx index of the DIE.
DIEInfo & getDIEInfo(unsigned Idx)
Idx index of the DIE.
void setDieTypeEntry(uint32_t Idx, TypeEntry *Entry)
Idx index of the DIE.
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
std::optional< DWARFFormValue > find(uint32_t DieIdx, ArrayRef< dwarf::Attribute > Attrs) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ArrayRef< dwarf::Attribute > getODRAttributes()
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto reverse(ContainerTy &&C)
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
Information gathered about source DIEs.
This is a helper structure which keeps a debug info entry with it's containing compilation unit.
std::optional< UnitEntryPairTy > getParent()
UnitEntryPairTy getNamespaceOrigin()
const DWARFDebugInfoEntry * DieEntry