Advertisement
Guest User

Untitled

a guest
Jun 14th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.98 KB | None | 0 0
  1. commit fb7ed39d06385c3271282c461f647ead7f7b09b8
  2. Author: David Blaikie <[email protected]>
  3. Date:   Tue Apr 25 22:15:33 2023 +0000
  4.  
  5.     [DebugInfo]Lazy parse abbrevs when symbolizing
  6.    
  7.     This speeds up llvm-symbolizer on code without .debug_aranges - we don't
  8.     need to parse all the abbrevs for every CU, just usually the first
  9.     abbrev for most CUs, then more abbrevs for any CU we go look into for
  10.     symbolizing.
  11.    
  12.     I don't think this makes enough of a difference to worry too much about - but
  13.     throwing it out there since I wrote it while exploring things.
  14.    
  15.     Differential Revision: https://reviews.llvm.org/D149208
  16.  
  17. diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
  18. index 52a88f2c390a..439804642770 100644
  19. --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
  20. +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h
  21. @@ -12,8 +12,8 @@
  22.  #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
  23.  #include "llvm/Support/DataExtractor.h"
  24.  #include <cstdint>
  25. +#include <deque>
  26.  #include <map>
  27. -#include <vector>
  28.  
  29.  namespace llvm {
  30.  
  31. @@ -21,20 +21,21 @@ class raw_ostream;
  32.  
  33.  class DWARFAbbreviationDeclarationSet {
  34.    uint64_t Offset;
  35. +  mutable uint64_t CurOffset;
  36.    /// Code of the first abbreviation, if all abbreviations in the set have
  37.    /// consecutive codes. UINT32_MAX otherwise.
  38. -  uint32_t FirstAbbrCode;
  39. -  std::vector<DWARFAbbreviationDeclaration> Decls;
  40. +  mutable uint32_t FirstAbbrCode;
  41. +  mutable std::deque<DWARFAbbreviationDeclaration> Decls;
  42. +  mutable std::optional<DataExtractor> Data;
  43.  
  44. -  using const_iterator =
  45. -      std::vector<DWARFAbbreviationDeclaration>::const_iterator;
  46. +  using const_iterator = decltype(Decls)::const_iterator;
  47.  
  48.  public:
  49.    DWARFAbbreviationDeclarationSet();
  50.  
  51.    uint64_t getOffset() const { return Offset; }
  52.    void dump(raw_ostream &OS) const;
  53. -  bool extract(DataExtractor Data, uint64_t *OffsetPtr);
  54. +  bool extract(DataExtractor Data, uint64_t *OffsetPtr, bool Lazy = false);
  55.  
  56.    const DWARFAbbreviationDeclaration *
  57.    getAbbreviationDeclaration(uint32_t AbbrCode) const;
  58. @@ -65,7 +66,7 @@ public:
  59.    DWARFDebugAbbrev();
  60.  
  61.    const DWARFAbbreviationDeclarationSet *
  62. -  getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const;
  63. +  getAbbreviationDeclarationSet(uint64_t CUAbbrOffset, bool Lazy = false) const;
  64.  
  65.    void dump(raw_ostream &OS) const;
  66.    void parse() const;
  67. diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  68. index b4978cc80d1b..943bab49ba85 100644
  69. --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  70. +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
  71. @@ -402,7 +402,8 @@ public:
  72.  
  73.    uint64_t getAbbreviationsOffset() const { return Header.getAbbrOffset(); }
  74.  
  75. -  const DWARFAbbreviationDeclarationSet *getAbbreviations() const;
  76. +  const DWARFAbbreviationDeclarationSet *
  77. +  getAbbreviations(bool Lazy = false) const;
  78.  
  79.    static bool isMatchingUnitTypeAndTag(uint8_t UnitType, dwarf::Tag Tag) {
  80.      switch (UnitType) {
  81. diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
  82. index 3ea3818e7cc3..d260934feef8 100644
  83. --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
  84. +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugAbbrev.cpp
  85. @@ -22,14 +22,15 @@ DWARFAbbreviationDeclarationSet::DWARFAbbreviationDeclarationSet() {
  86.  void DWARFAbbreviationDeclarationSet::clear() {
  87.    Offset = 0;
  88.    FirstAbbrCode = 0;
  89. +  Data = std::nullopt;
  90. +  CurOffset = 0;
  91.    Decls.clear();
  92.  }
  93.  
  94.  bool DWARFAbbreviationDeclarationSet::extract(DataExtractor Data,
  95. -                                              uint64_t *OffsetPtr) {
  96. +                                              uint64_t *OffsetPtr, bool Lazy) {
  97.    clear();
  98. -  const uint64_t BeginOffset = *OffsetPtr;
  99. -  Offset = BeginOffset;
  100. +  Offset = *OffsetPtr;
  101.    DWARFAbbreviationDeclaration AbbrDecl;
  102.    uint32_t PrevAbbrCode = 0;
  103.    while (AbbrDecl.extract(Data, OffsetPtr)) {
  104. @@ -43,8 +44,13 @@ bool DWARFAbbreviationDeclarationSet::extract(DataExtractor Data,
  105.      }
  106.      PrevAbbrCode = AbbrDecl.getCode();
  107.      Decls.push_back(std::move(AbbrDecl));
  108. +    if (Lazy) {
  109. +      this->Data = Data;
  110. +      CurOffset = *OffsetPtr;
  111. +      return true;
  112. +    }
  113.    }
  114. -  return BeginOffset != *OffsetPtr;
  115. +  return Offset != *OffsetPtr;
  116.  }
  117.  
  118.  void DWARFAbbreviationDeclarationSet::dump(raw_ostream &OS) const {
  119. @@ -60,11 +66,31 @@ DWARFAbbreviationDeclarationSet::getAbbreviationDeclaration(
  120.        if (Decl.getCode() == AbbrCode)
  121.          return &Decl;
  122.      }
  123. -    return nullptr;
  124. +  } else if (AbbrCode >= FirstAbbrCode &&
  125. +             AbbrCode < FirstAbbrCode + Decls.size()) {
  126. +    return &Decls[AbbrCode - FirstAbbrCode];
  127.    }
  128. -  if (AbbrCode < FirstAbbrCode || AbbrCode >= FirstAbbrCode + Decls.size())
  129. -    return nullptr;
  130. -  return &Decls[AbbrCode - FirstAbbrCode];
  131. +  if (Data) {
  132. +    DWARFAbbreviationDeclaration AbbrDecl;
  133. +    uint32_t PrevAbbrCode = 0;
  134. +    while (AbbrDecl.extract(*Data, &CurOffset)) {
  135. +      if (FirstAbbrCode == 0) {
  136. +        FirstAbbrCode = AbbrDecl.getCode();
  137. +      } else {
  138. +        if (PrevAbbrCode + 1 != AbbrDecl.getCode()) {
  139. +          // Codes are not consecutive, can't do O(1) lookups.
  140. +          FirstAbbrCode = UINT32_MAX;
  141. +        }
  142. +      }
  143. +      PrevAbbrCode = AbbrDecl.getCode();
  144. +      Decls.push_back(std::move(AbbrDecl));
  145. +      if (AbbrDecl.getCode())
  146. +        return &Decls.back();
  147. +    }
  148. +    CurOffset = 0;
  149. +    Data = std::nullopt;
  150. +  }
  151. +  return nullptr;
  152.  }
  153.  
  154.  std::string DWARFAbbreviationDeclarationSet::getCodeRange() const {
  155. @@ -139,8 +165,9 @@ void DWARFDebugAbbrev::dump(raw_ostream &OS) const {
  156.    }
  157.  }
  158.  
  159. -const DWARFAbbreviationDeclarationSet*
  160. -DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const {
  161. +const DWARFAbbreviationDeclarationSet *
  162. +DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset,
  163. +                                                bool Lazy) const {
  164.    const auto End = AbbrDeclSets.end();
  165.    if (PrevAbbrOffsetPos != End && PrevAbbrOffsetPos->first == CUAbbrOffset) {
  166.      return &(PrevAbbrOffsetPos->second);
  167. @@ -155,7 +182,7 @@ DWARFDebugAbbrev::getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const {
  168.    if (Data && CUAbbrOffset < Data->getData().size()) {
  169.      uint64_t Offset = CUAbbrOffset;
  170.      DWARFAbbreviationDeclarationSet AbbrDecls;
  171. -    if (!AbbrDecls.extract(*Data, &Offset))
  172. +    if (!AbbrDecls.extract(*Data, &Offset, Lazy))
  173.        return nullptr;
  174.      PrevAbbrOffsetPos =
  175.          AbbrDeclSets.insert(std::make_pair(CUAbbrOffset, std::move(AbbrDecls)))
  176. diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
  177. index 4f0a6d96ace9..aa6406859ed2 100644
  178. --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
  179. +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugInfoEntry.cpp
  180. @@ -40,7 +40,7 @@ bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
  181.      AbbrevDecl = nullptr;
  182.      return true;
  183.    }
  184. -  const auto *AbbrevSet = U.getAbbreviations();
  185. +  const auto *AbbrevSet = U.getAbbreviations(/*Lazy=*/true);
  186.    if (!AbbrevSet) {
  187.      U.getContext().getWarningHandler()(
  188.          createStringError(errc::invalid_argument,
  189. diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
  190. index 2fc26fd86ba3..33f1f05a2199 100644
  191. --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
  192. +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
  193. @@ -1039,9 +1039,11 @@ DWARFUnit::getLastChildEntry(const DWARFDebugInfoEntry *Die) const {
  194.    return nullptr;
  195.  }
  196.  
  197. -const DWARFAbbreviationDeclarationSet *DWARFUnit::getAbbreviations() const {
  198. +const DWARFAbbreviationDeclarationSet *
  199. +DWARFUnit::getAbbreviations(bool Lazy) const {
  200.    if (!Abbrevs)
  201. -    Abbrevs = Abbrev->getAbbreviationDeclarationSet(getAbbreviationsOffset());
  202. +    Abbrevs =
  203. +        Abbrev->getAbbreviationDeclarationSet(getAbbreviationsOffset(), Lazy);
  204.    return Abbrevs;
  205.  }
  206.  
  207.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement