[Debuginfo][NFC] Avoid double calling of DWARFDie::find(DW_AT_name).
authorAlexey Lapshin <a.v.lapshin@mail.ru>
Thu, 30 Apr 2020 11:05:17 +0000 (14:05 +0300)
committerAlexey Lapshin <a.v.lapshin@mail.ru>
Sun, 3 May 2020 11:00:25 +0000 (14:00 +0300)
Summary:
Current implementation of DWARFDie::getName(DINameKind Kind) could
lead to double call to DWARFDie::find(DW_AT_name) in following
scenario:

getName(LinkageName);
getName(ShortName);

getName(LinkageName) calls find(DW_AT_name) if linkage name is not
found. Then, it is called again in getName(ShortName). This patch
alows to request LinkageName and ShortName separately
to avoid extra call to find(DW_AT_name).

It helps D74169 to parse clang debuginfo faster(~1%).

Reviewers: clayborg, dblaikie

Differential Revision: https://reviews.llvm.org/D79173

llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

index 158bd82..05a6056 100644 (file)
@@ -241,10 +241,22 @@ public:
   /// Returns null if no name is found.
   const char *getSubroutineName(DINameKind Kind) const;
 
-  /// Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin
-  /// references if necessary. Returns null if no name is found.
+  /// Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin
+  /// references if necessary. For the LinkageName case it additionaly searches
+  /// for ShortName if LinkageName is not found.
+  /// Returns null if no name is found.
   const char *getName(DINameKind Kind) const;
 
+  /// Return the DIE short name resolving DW_AT_specification or
+  /// DW_AT_abstract_origin references if necessary. Returns null if no name
+  /// is found.
+  const char *getShortName() const;
+
+  /// Return the DIE linkage name resolving DW_AT_specification or
+  /// DW_AT_abstract_origin references if necessary. Returns null if no name
+  /// is found.
+  const char *getLinkageName() const;
+
   /// Returns the declaration line (start line) for a DIE, assuming it specifies
   /// a subprogram. This may be fetched from specification or abstract origin
   /// for this subprogram by resolving DW_AT_sepcification or
index 6444af9..2c3e202 100644 (file)
@@ -160,16 +160,17 @@ bool DWARFLinker::DIECloner::getDIENames(const DWARFDie &Die,
   if (Die.getTag() == dwarf::DW_TAG_lexical_block)
     return false;
 
-  // FIXME: a bit wasteful as the first getName might return the
-  // short name.
   if (!Info.MangledName)
-    if (const char *MangledName = Die.getName(DINameKind::LinkageName))
+    if (const char *MangledName = Die.getLinkageName())
       Info.MangledName = StringPool.getEntry(MangledName);
 
   if (!Info.Name)
-    if (const char *Name = Die.getName(DINameKind::ShortName))
+    if (const char *Name = Die.getShortName())
       Info.Name = StringPool.getEntry(Name);
 
+  if (!Info.MangledName)
+    Info.MangledName = Info.Name;
+
   if (StripTemplate && Info.Name && Info.MangledName != Info.Name) {
     StringRef Name = Info.Name.getString();
     if (Optional<StringRef> StrippedName = StripTemplateParameters(Name))
index 077fd44..c9a5da6 100644 (file)
@@ -80,8 +80,12 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
     break;
   }
 
-  const char *Name = DIE.getName(DINameKind::LinkageName);
-  const char *ShortName = DIE.getName(DINameKind::ShortName);
+  const char *Name = DIE.getLinkageName();
+  const char *ShortName = DIE.getShortName();
+
+  if (!Name)
+    Name = ShortName;
+
   StringRef NameRef;
   StringRef ShortNameRef;
   StringRef FileRef;
index 624a79e..f93f329 100644 (file)
@@ -531,14 +531,26 @@ const char *DWARFDie::getName(DINameKind Kind) const {
     return nullptr;
   // Try to get mangled name only if it was asked for.
   if (Kind == DINameKind::LinkageName) {
-    if (auto Name = dwarf::toString(
-            findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}),
-            nullptr))
+    if (auto Name = getLinkageName())
       return Name;
   }
-  if (auto Name = dwarf::toString(findRecursively(DW_AT_name), nullptr))
-    return Name;
-  return nullptr;
+  return getShortName();
+}
+
+const char *DWARFDie::getShortName() const {
+  if (!isValid())
+    return nullptr;
+
+  return dwarf::toString(findRecursively(dwarf::DW_AT_name), nullptr);
+}
+
+const char *DWARFDie::getLinkageName() const {
+  if (!isValid())
+    return nullptr;
+
+  return dwarf::toString(findRecursively({dwarf::DW_AT_MIPS_linkage_name,
+                                          dwarf::DW_AT_linkage_name}),
+                         nullptr);
 }
 
 uint64_t DWARFDie::getDeclLine() const {