labath created this revision.
labath added reviewers: clayborg, JDevlieghere, aprantl.
Herald added a subscriber: arphaman.
labath added a parent revision: D63428: DWARF: Add "dwo_num" field to the 
DIERef class.

Reduce the size of the manual index by storing the entries in a more
compact form. This introduces the CompressedRef class, which is similar
to the DIERef class, but it is more compact because it lacks the
unit_offset field (which is not necessary now, as the unit is uniquely
identified by the rest of the fields). The user_id_t representation
would have the same size, but I did not use that here because:

- it's more complicated to convert it to/from a DIERef
- it's more clunky to handle as it is just an integer

The new class is for internal use only. It is converted to a regular
DIERef before returning it to the outside world.


https://reviews.llvm.org/D63491

Files:
  source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
  source/Plugins/SymbolFile/DWARF/NameToDIE.h

Index: source/Plugins/SymbolFile/DWARF/NameToDIE.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/NameToDIE.h
+++ source/Plugins/SymbolFile/DWARF/NameToDIE.h
@@ -46,8 +46,39 @@
                              const DIERef &die_ref)> const
               &callback) const;
 
-protected:
-  lldb_private::UniqueCStringMap<DIERef> m_map;
+private:
+  class CompressedRef {
+  public:
+    CompressedRef(const DIERef &ref)
+        : m_dwo_num(ref.dwo_num().getValueOr(invalid_dwo_num)),
+          m_section(ref.section()), m_die_offset(ref.die_offset()) {}
+
+    operator DIERef() const {
+      return DIERef(dwo_num(), section(), llvm::None, die_offset());
+    }
+
+    llvm::Optional<uint32_t> dwo_num() const {
+      if (m_dwo_num < invalid_dwo_num)
+        return m_dwo_num;
+      return llvm::None;
+    }
+
+    DIERef::Section section() const {
+      return static_cast<DIERef::Section>(m_section);
+    }
+
+    dw_offset_t die_offset() const { return m_die_offset; }
+
+  private:
+    static constexpr uint32_t invalid_dwo_num = 0x7fffffff;
+
+    unsigned m_dwo_num : 31;
+    unsigned m_section : 1;
+    dw_offset_t m_die_offset;
+  };
+  static_assert(sizeof(CompressedRef) == 8, "");
+
+  lldb_private::UniqueCStringMap<CompressedRef> m_map;
 };
 
 #endif // SymbolFileDWARF_NameToDIE_h_
Index: source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
@@ -23,17 +23,24 @@
 }
 
 void NameToDIE::Insert(ConstString name, const DIERef &die_ref) {
-  assert(die_ref.unit_offset().hasValue());
   m_map.Append(name, die_ref);
 }
 
 size_t NameToDIE::Find(ConstString name, DIEArray &info_array) const {
-  return m_map.GetValues(name, info_array);
+  std::vector<CompressedRef> compressed;
+  size_t result = m_map.GetValues(name, compressed);
+  for (const CompressedRef &ref : compressed)
+    info_array.push_back(ref);
+  return result;
 }
 
 size_t NameToDIE::Find(const RegularExpression &regex,
                        DIEArray &info_array) const {
-  return m_map.GetValues(regex, info_array);
+  std::vector<CompressedRef> compressed;
+  size_t result = m_map.GetValues(regex, compressed);
+  for (const CompressedRef &ref : compressed)
+    info_array.push_back(ref);
+  return result;
 }
 
 size_t NameToDIE::FindAllEntriesForUnit(const DWARFUnit &unit,
@@ -41,11 +48,12 @@
   const size_t initial_size = info_array.size();
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
-    const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
-    if (unit.GetSymbolFileDWARF().GetDwoNum() == die_ref.dwo_num() &&
-        unit.GetDebugSection() == die_ref.section() &&
-        unit.GetOffset() == *die_ref.unit_offset())
-      info_array.push_back(die_ref);
+    const CompressedRef &ref = m_map.GetValueAtIndexUnchecked(i);
+    if (unit.GetSymbolFileDWARF().GetDwoNum() == ref.dwo_num() &&
+        unit.GetDebugSection() == ref.section() &&
+        unit.GetOffset() <= ref.die_offset() &&
+        ref.die_offset() < unit.GetNextUnitOffset())
+      info_array.push_back(ref);
   }
   return info_array.size() - initial_size;
 }
@@ -53,7 +61,7 @@
 void NameToDIE::Dump(Stream *s) {
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
-    s->Format("{0} \"{1}\"\n", m_map.GetValueAtIndexUnchecked(i),
+    s->Format("{0} \"{1}\"\n", DIERef(m_map.GetValueAtIndexUnchecked(i)),
               m_map.GetCStringAtIndexUnchecked(i));
   }
 }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to