[llvm] 811b60f - llvm-dwarfdump: Speed up type unit lookup using the TUIndex or a cache
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 5 20:44:07 PST 2022
Author: David Blaikie
Date: 2022-01-05T20:41:07-08:00
New Revision: 811b60f0b99dad4b2989d21dde38d49155b0c4f9
URL: https://github.com/llvm/llvm-project/commit/811b60f0b99dad4b2989d21dde38d49155b0c4f9
DIFF: https://github.com/llvm/llvm-project/commit/811b60f0b99dad4b2989d21dde38d49155b0c4f9.diff
LOG: llvm-dwarfdump: Speed up type unit lookup using the TUIndex or a cache
Use the TUIndex in a DWP file if present, otherwise (in .o, .dwo, and
non-split linked executables) cache a DenseMap for lookup of type units.
Added:
Modified:
llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
index 24714ac3d101f..e82faf6eeb243 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -52,6 +52,7 @@ class raw_ostream;
/// information parsing. The actual data is supplied through DWARFObj.
class DWARFContext : public DIContext {
DWARFUnitVector NormalUnits;
+ Optional<DenseMap<uint64_t, DWARFTypeUnit*>> NormalTypeUnits;
std::unique_ptr<DWARFUnitIndex> CUIndex;
std::unique_ptr<DWARFGdbIndex> GdbIndex;
std::unique_ptr<DWARFUnitIndex> TUIndex;
@@ -70,6 +71,7 @@ class DWARFContext : public DIContext {
std::unique_ptr<AppleAcceleratorTable> AppleObjC;
DWARFUnitVector DWOUnits;
+ Optional<DenseMap<uint64_t, DWARFTypeUnit*>> DWOTypeUnits;
std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
std::unique_ptr<DWARFDebugMacro> MacroDWO;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index 34c42025109de..ef50ad53650a5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -695,14 +695,30 @@ void DWARFContext::dump(
DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version, uint64_t Hash,
bool IsDWO) {
- // FIXME: Check for/use the tu_index here, if there is one.
- for (const auto &U : IsDWO ? dwo_units() : normal_units()) {
- if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get())) {
- if (TU->getTypeHash() == Hash)
- return TU;
+ parseDWOUnits(LazyParse);
+
+ if (const auto &TUI = getTUIndex()) {
+ if (const auto *R = TUI.getFromHash(Hash))
+ return dyn_cast_or_null<DWARFTypeUnit>(
+ DWOUnits.getUnitForIndexEntry(*R));
+ return nullptr;
+ }
+
+ struct UnitContainers {
+ const DWARFUnitVector &Units;
+ Optional<DenseMap<uint64_t, DWARFTypeUnit *>> ⤅
+ };
+ UnitContainers Units = IsDWO ? UnitContainers{DWOUnits, DWOTypeUnits}
+ : UnitContainers{NormalUnits, NormalTypeUnits};
+ if (!Units.Map) {
+ Units.Map.emplace();
+ for (const auto &U : IsDWO ? dwo_units() : normal_units()) {
+ if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get()))
+ (*Units.Map)[TU->getTypeHash()] = TU;
}
}
- return nullptr;
+
+ return (*Units.Map)[Hash];
}
DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
More information about the llvm-commits
mailing list