[llvm] [BOLT][DWARF] Add support to debug_names for DW_AT_abstract_origin/DW_AT_specification (PR #85485)

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 18 13:10:59 PDT 2024


================
@@ -295,11 +303,33 @@ DWARF5AcceleratorTable::addAccelTableEntry(
     return It.Values.back();
   };
 
-  std::optional<BOLTDWARF5AccelTableData *> NameEntry =
-      addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_name));
-  std::optional<BOLTDWARF5AccelTableData *> LinkageNameEntry =
-      addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
-  return NameEntry ? NameEntry : LinkageNameEntry;
+  // Minor optimization not to add entry twice for DW_TAG_namespace if it has no
+  // DW_AT_name.
+  if (!(Die.getTag() == dwarf::DW_TAG_namespace &&
+        !Die.findAttribute(dwarf::Attribute::DW_AT_name)))
+    addEntry(Die.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
+  // For the purposes of determining whether a debugging information entry has a
+  // particular attribute (such as DW_AT_name), if debugging information entry A
+  // has a DW_AT_specification or DW_AT_abstract_origin attribute pointing to
+  // another debugging information entry B, any attributes of B are considered
+  // to be part of A.
+  if (DIEValue AbstrOrigin =
+          Die.findAttribute(dwarf::Attribute::DW_AT_abstract_origin)) {
+    const DIEEntry &DIEENtry = AbstrOrigin.getDIEEntry();
+    DIE &EntryDie = DIEENtry.getEntry();
+    addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
+    return addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_name));
+  }
+  if (DIEValue AbstrOrigin =
+          Die.findAttribute(dwarf::Attribute::DW_AT_specification)) {
+    const DIEEntry &DIEENtry = AbstrOrigin.getDIEEntry();
+    DIE &EntryDie = DIEENtry.getEntry();
+    addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_linkage_name));
+    return addEntry(EntryDie.findAttribute(dwarf::Attribute::DW_AT_name));
+  }
----------------
maksfb wrote:

Can you please refactor to de-dup the code?

https://github.com/llvm/llvm-project/pull/85485


More information about the llvm-commits mailing list