[llvm] r313635 - dwarfdump: Delay parsing abbreviations until they're needed

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 08:13:55 PDT 2017


Author: dblaikie
Date: Tue Sep 19 08:13:55 2017
New Revision: 313635

URL: http://llvm.org/viewvc/llvm-project?rev=313635&view=rev
Log:
dwarfdump: Delay parsing abbreviations until they're needed

This speeds up dumping specific DIEs by not parsing abbreviations for
units that are not used.

(this is also handy to have in eventually to speed up llvm-symbolizer
for .dwp files, where parsing most of the DWP file can be avoided by
using the index)

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h?rev=313635&r1=313634&r2=313635&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h Tue Sep 19 08:13:55 2017
@@ -56,8 +56,9 @@ class DWARFDebugAbbrev {
   using DWARFAbbreviationDeclarationSetMap =
       std::map<uint64_t, DWARFAbbreviationDeclarationSet>;
 
-  DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
+  mutable DWARFAbbreviationDeclarationSetMap AbbrDeclSets;
   mutable DWARFAbbreviationDeclarationSetMap::const_iterator PrevAbbrOffsetPos;
+  mutable Optional<DataExtractor> Data;
 
 public:
   DWARFDebugAbbrev();
@@ -66,10 +67,11 @@ public:
   getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
 
   void dump(raw_ostream &OS) const;
+  void parse() const;
   void extract(DataExtractor Data);
-  bool empty() const { return begin() == end(); }
 
   DWARFAbbreviationDeclarationSetMap::const_iterator begin() const {
+    parse();
     return AbbrDeclSets.begin();
   }
 

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h?rev=313635&r1=313634&r2=313635&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFUnit.h Tue Sep 19 08:13:55 2017
@@ -139,7 +139,8 @@ class DWARFUnit {
 
   uint32_t Offset;
   uint32_t Length;
-  const DWARFAbbreviationDeclarationSet *Abbrevs;
+  mutable const DWARFAbbreviationDeclarationSet *Abbrevs;
+  uint64_t AbbrOffset;
   uint8_t UnitType;
   llvm::Optional<BaseAddress> BaseAddr;
   /// The compile unit debug information entry items.
@@ -231,9 +232,7 @@ public:
     return FormParams.getDwarfOffsetByteSize();
   }
 
-  const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
-    return Abbrevs;
-  }
+  const DWARFAbbreviationDeclarationSet *getAbbreviations() const;
 
   uint8_t getUnitType() const { return UnitType; }
 

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp?rev=313635&r1=313634&r2=313635&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp Tue Sep 19 08:13:55 2017
@@ -68,9 +68,7 @@ DWARFAbbreviationDeclarationSet::getAbbr
   return &Decls[AbbrCode - FirstAbbrCode];
 }
 
-DWARFDebugAbbrev::DWARFDebugAbbrev() {
-  clear();
-}
+DWARFDebugAbbrev::DWARFDebugAbbrev() { clear(); }
 
 void DWARFDebugAbbrev::clear() {
   AbbrDeclSets.clear();
@@ -79,18 +77,29 @@ void DWARFDebugAbbrev::clear() {
 
 void DWARFDebugAbbrev::extract(DataExtractor Data) {
   clear();
+  this->Data = Data;
+}
 
+void DWARFDebugAbbrev::parse() const {
+  if (!Data)
+    return;
   uint32_t Offset = 0;
   DWARFAbbreviationDeclarationSet AbbrDecls;
-  while (Data.isValidOffset(Offset)) {
+  auto I = AbbrDeclSets.begin();
+  while (Data->isValidOffset(Offset)) {
+    while (I != AbbrDeclSets.end() && I->first < Offset)
+      ++I;
     uint32_t CUAbbrOffset = Offset;
-    if (!AbbrDecls.extract(Data, &Offset))
+    if (!AbbrDecls.extract(*Data, &Offset))
       break;
-    AbbrDeclSets[CUAbbrOffset] = std::move(AbbrDecls);
+    AbbrDeclSets.insert(I, std::make_pair(CUAbbrOffset, std::move(AbbrDecls)));
   }
+  Data = None;
 }
 
 void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
+  parse();
+
   if (AbbrDeclSets.empty()) {
     OS << "< EMPTY >\n";
     return;
@@ -115,5 +124,16 @@ DWARFDebugAbbrev::getAbbreviationDeclara
     return &(Pos->second);
   }
 
+  if (Data && CUAbbrOffset < Data->getData().size()) {
+    uint32_t Offset = CUAbbrOffset;
+    DWARFAbbreviationDeclarationSet AbbrDecls;
+    if (!AbbrDecls.extract(*Data, &Offset))
+      return nullptr;
+    PrevAbbrOffsetPos =
+        AbbrDeclSets.insert(std::make_pair(CUAbbrOffset, std::move(AbbrDecls)))
+            .first;
+    return &PrevAbbrOffsetPos->second;
+  }
+
   return nullptr;
 }

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp?rev=313635&r1=313634&r2=313635&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFUnit.cpp Tue Sep 19 08:13:55 2017
@@ -94,7 +94,6 @@ bool DWARFUnit::extractImpl(DataExtracto
   // FIXME: Support DWARF64.
   FormParams.Format = DWARF32;
   FormParams.Version = debug_info.getU16(offset_ptr);
-  uint64_t AbbrOffset;
   if (FormParams.Version >= 5) {
     UnitType = debug_info.getU8(offset_ptr);
     FormParams.AddrSize = debug_info.getU8(offset_ptr);
@@ -124,9 +123,7 @@ bool DWARFUnit::extractImpl(DataExtracto
 
   // Keep track of the highest DWARF version we encounter across all units.
   Context.setMaxVersionIfGreater(getVersion());
-
-  Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
-  return Abbrevs != nullptr;
+  return true;
 }
 
 bool DWARFUnit::extract(DataExtractor debug_info, uint32_t *offset_ptr) {
@@ -452,3 +449,9 @@ DWARFDie DWARFUnit::getSibling(const DWA
   }
   return DWARFDie();
 }
+
+const DWARFAbbreviationDeclarationSet *DWARFUnit::getAbbreviations() const {
+  if (!Abbrevs)
+    Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
+  return Abbrevs;
+}




More information about the llvm-commits mailing list