[llvm] 4f576ea - [Debuginfo][NFC] Avoid double calling of DWARFDie::find(DW_AT_name).
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 04:00:57 PDT 2020
Author: Alexey Lapshin
Date: 2020-05-03T14:00:25+03:00
New Revision: 4f576ea731efca6dffd595d1f6dcc77256073d19
URL: https://github.com/llvm/llvm-project/commit/4f576ea731efca6dffd595d1f6dcc77256073d19
DIFF: https://github.com/llvm/llvm-project/commit/4f576ea731efca6dffd595d1f6dcc77256073d19.diff
LOG: [Debuginfo][NFC] Avoid double calling of DWARFDie::find(DW_AT_name).
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
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
llvm/lib/DWARFLinker/DWARFLinker.cpp
llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
index 158bd82edee0..05a6056e8e21 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
@@ -241,10 +241,22 @@ class DWARFDie {
/// 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
diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 6444af9046b8..2c3e2023bced 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -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))
diff --git a/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp b/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
index 077fd4494241..c9a5da6676b3 100644
--- a/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinkerDeclContext.cpp
@@ -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;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 624a79e30464..f93f32917c33 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -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 {
More information about the llvm-commits
mailing list