[llvm] r309507 - DebugInfo: Use DWP cu_index to speed up symbolizing (as intended)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 30 01:12:07 PDT 2017


Author: dblaikie
Date: Sun Jul 30 01:12:07 2017
New Revision: 309507

URL: http://llvm.org/viewvc/llvm-project?rev=309507&view=rev
Log:
DebugInfo: Use DWP cu_index to speed up symbolizing (as intended)

I was a bit lazy when I first implemented this & skipped the index
lookup - obviously for large files this becomes pretty crucial, so here
we go, do the index lookup. Speeds up large DWP symbolizing by... lots.
(20m -> 20s, actually, maybe more in a release build (that was a release
build without index lookup, compared to a debug/non-release build with
the index usage))

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h?rev=309507&r1=309506&r2=309507&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnitIndex.h Sun Jul 30 01:12:07 2017
@@ -83,9 +83,12 @@ public:
   DWARFUnitIndex(DWARFSectionKind InfoColumnKind)
       : InfoColumnKind(InfoColumnKind) {}
 
+  explicit operator bool() const { return Header.NumBuckets; }
+
   bool parse(DataExtractor IndexData);
   void dump(raw_ostream &OS) const;
   const Entry *getFromOffset(uint32_t Offset) const;
+  const Entry *getFromHash(uint64_t Offset) const;
 
   ArrayRef<DWARFSectionKind> getColumnKinds() const {
     return makeArrayRef(ColumnKinds.get(), Header.NumColumns);

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=309507&r1=309506&r2=309507&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Sun Jul 30 01:12:07 2017
@@ -400,8 +400,17 @@ void DWARFContext::dump(raw_ostream &OS,
 }
 
 DWARFCompileUnit *DWARFContext::getDWOCompileUnitForHash(uint64_t Hash) {
-  // FIXME: Improve this for the case where this DWO file is really a DWP file
-  // with an index - use the index for lookup instead of a linear search.
+  if (const auto &CUI = getCUIndex()) {
+    if (const auto *R = CUI.getFromHash(Hash))
+      if (auto CUOff = R->getOffset(DW_SECT_INFO))
+        return CUs.getUnitForOffset(CUOff->Offset);
+    return nullptr;
+  }
+
+  // If there's no index, just search through the CUs in the DWO - there's
+  // probably only one unless this is something like LTO - though an in-process
+  // built/cached lookup table could be used in that case to improve repeated
+  // lookups of different CUs in the DWO.
   for (const auto &DWOCU : dwo_compile_units())
     if (DWOCU->getDWOId() == Hash)
       return DWOCU.get();

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp?rev=309507&r1=309506&r2=309507&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnitIndex.cpp Sun Jul 30 01:12:07 2017
@@ -123,7 +123,7 @@ StringRef DWARFUnitIndex::getColumnHeade
 }
 
 void DWARFUnitIndex::dump(raw_ostream &OS) const {
-  if (!Header.NumBuckets)
+  if (!*this)
     return;
 
   Header.dump(OS);
@@ -170,3 +170,17 @@ DWARFUnitIndex::getFromOffset(uint32_t O
         return &Rows[i];
   return nullptr;
 }
+
+const DWARFUnitIndex::Entry *DWARFUnitIndex::getFromHash(uint64_t S) const {
+  uint64_t Mask = Header.NumBuckets - 1;
+
+  auto H = S & Mask;
+  auto HP = ((S >> 32) & Mask) | 1;
+  while (Rows[H].getSignature() != S && Rows[H].getSignature() != 0)
+    H = (H + HP) & Mask;
+
+  if (Rows[H].getSignature() != S)
+    return nullptr;
+
+  return &Rows[H];
+}




More information about the llvm-commits mailing list