Skip to content

Commit 811b60f

Browse files
committed
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.
1 parent 33529ba commit 811b60f

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class raw_ostream;
5252
/// information parsing. The actual data is supplied through DWARFObj.
5353
class DWARFContext : public DIContext {
5454
DWARFUnitVector NormalUnits;
55+
Optional<DenseMap<uint64_t, DWARFTypeUnit*>> NormalTypeUnits;
5556
std::unique_ptr<DWARFUnitIndex> CUIndex;
5657
std::unique_ptr<DWARFGdbIndex> GdbIndex;
5758
std::unique_ptr<DWARFUnitIndex> TUIndex;
@@ -70,6 +71,7 @@ class DWARFContext : public DIContext {
7071
std::unique_ptr<AppleAcceleratorTable> AppleObjC;
7172

7273
DWARFUnitVector DWOUnits;
74+
Optional<DenseMap<uint64_t, DWARFTypeUnit*>> DWOTypeUnits;
7375
std::unique_ptr<DWARFDebugAbbrev> AbbrevDWO;
7476
std::unique_ptr<DWARFDebugMacro> MacinfoDWO;
7577
std::unique_ptr<DWARFDebugMacro> MacroDWO;

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,30 @@ void DWARFContext::dump(
695695

696696
DWARFTypeUnit *DWARFContext::getTypeUnitForHash(uint16_t Version, uint64_t Hash,
697697
bool IsDWO) {
698-
// FIXME: Check for/use the tu_index here, if there is one.
699-
for (const auto &U : IsDWO ? dwo_units() : normal_units()) {
700-
if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get())) {
701-
if (TU->getTypeHash() == Hash)
702-
return TU;
698+
parseDWOUnits(LazyParse);
699+
700+
if (const auto &TUI = getTUIndex()) {
701+
if (const auto *R = TUI.getFromHash(Hash))
702+
return dyn_cast_or_null<DWARFTypeUnit>(
703+
DWOUnits.getUnitForIndexEntry(*R));
704+
return nullptr;
705+
}
706+
707+
struct UnitContainers {
708+
const DWARFUnitVector &Units;
709+
Optional<DenseMap<uint64_t, DWARFTypeUnit *>> &Map;
710+
};
711+
UnitContainers Units = IsDWO ? UnitContainers{DWOUnits, DWOTypeUnits}
712+
: UnitContainers{NormalUnits, NormalTypeUnits};
713+
if (!Units.Map) {
714+
Units.Map.emplace();
715+
for (const auto &U : IsDWO ? dwo_units() : normal_units()) {
716+
if (DWARFTypeUnit *TU = dyn_cast<DWARFTypeUnit>(U.get()))
717+
(*Units.Map)[TU->getTypeHash()] = TU;
703718
}
704719
}
705-
return nullptr;
720+
721+
return (*Units.Map)[Hash];
706722
}
707723

708724
DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {

0 commit comments

Comments
 (0)