[Lldb-commits] [PATCH] D110397: [nfc] [lldb] DWZ 02/17: Refactor DIERef for a key in llvm::DenseMap

Jan Kratochvil via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 24 03:05:55 PDT 2021


jankratochvil created this revision.
jankratochvil added reviewers: labath, clayborg.
jankratochvil added a project: LLDB.
Herald added a subscriber: JDevlieghere.
jankratochvil requested review of this revision.

Next patch XXX will use DIERef as a key in `llvm::DenseMap`, therefore we need to be able to effectively calculate hash of a `DIERef`.

My question about upstreaming of this patchset. <https://reviews.llvm.org/D96236#3020116>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110397

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DIERef.h


Index: lldb/source/Plugins/SymbolFile/DWARF/DIERef.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DIERef.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DIERef.h
@@ -29,35 +29,60 @@
 
   DIERef(llvm::Optional<uint32_t> dwo_num, Section section,
          dw_offset_t die_offset)
-      : m_dwo_num(dwo_num.getValueOr(0)), m_dwo_num_valid(bool(dwo_num)),
-        m_section(section), m_die_offset(die_offset) {
+      : m_u(dwo_num, section), m_die_offset(die_offset) {
     assert(this->dwo_num() == dwo_num && "Dwo number out of range?");
   }
 
   llvm::Optional<uint32_t> dwo_num() const {
-    if (m_dwo_num_valid)
-      return m_dwo_num;
+    if (m_u.s.dwo_num_valid)
+      return m_u.s.dwo_num;
     return llvm::None;
   }
 
-  Section section() const { return static_cast<Section>(m_section); }
+  Section section() const { return static_cast<Section>(m_u.s.section); }
 
   dw_offset_t die_offset() const { return m_die_offset; }
 
   bool operator<(DIERef other) const {
-    if (m_dwo_num_valid != other.m_dwo_num_valid)
-      return m_dwo_num_valid < other.m_dwo_num_valid;
-    if (m_dwo_num_valid && (m_dwo_num != other.m_dwo_num))
-      return m_dwo_num < other.m_dwo_num;
-    if (m_section != other.m_section)
-      return m_section < other.m_section;
+    if (m_u.s.dwo_num_valid != other.m_u.s.dwo_num_valid)
+      return m_u.s.dwo_num_valid < other.m_u.s.dwo_num_valid;
+    // Assuming if not m_u.s.dwo_num_valid then m_u.s.dwo_num is zero.
+    if (m_u.s.dwo_num != other.m_u.s.dwo_num)
+      return m_u.s.dwo_num < other.m_u.s.dwo_num;
+    if (m_u.s.section != other.m_u.s.section)
+      return m_u.s.section < other.m_u.s.section;
     return m_die_offset < other.m_die_offset;
   }
 
+  bool operator==(DIERef other) const {
+    if (m_u.s.dwo_num_valid != other.m_u.s.dwo_num_valid)
+      return m_u.s.dwo_num_valid == other.m_u.s.dwo_num_valid;
+    // Assuming if not m_u.s.dwo_num_valid then m_u.s.dwo_num is zero.
+    if (m_u.s.dwo_num != other.m_u.s.dwo_num)
+      return m_u.s.dwo_num == other.m_u.s.dwo_num;
+    if (m_u.s.section != other.m_u.s.section)
+      return m_u.s.section == other.m_u.s.section;
+    return m_die_offset == other.m_die_offset;
+  }
+
 private:
-  uint32_t m_dwo_num : 30;
-  uint32_t m_dwo_num_valid : 1;
-  uint32_t m_section : 1;
+  uint32_t get_hash_value() const {
+    return llvm::detail::combineHashValue(m_u.hash_bits, m_die_offset);
+  }
+
+  union U {
+    struct S {
+      uint32_t dwo_num : 30;
+      uint32_t dwo_num_valid : 1;
+      uint32_t section : 1;
+      S(llvm::Optional<uint32_t> dwo_num_, Section section_)
+          : dwo_num(dwo_num_.getValueOr(0)), dwo_num_valid(bool(dwo_num_)),
+            section(section_) {}
+    } s;
+    uint32_t hash_bits;
+    U(llvm::Optional<uint32_t> dwo_num, Section section)
+        : s(dwo_num, section) {}
+  } m_u;
   dw_offset_t m_die_offset;
 };
 static_assert(sizeof(DIERef) == 8, "");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110397.374786.patch
Type: text/x-patch
Size: 2988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210924/a93b91b1/attachment.bin>


More information about the lldb-commits mailing list