[llvm] [LLVM[NFC] Refactor to allow debug_names entries to conatain DIE offset (PR #69399)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 15:09:05 PDT 2023


================
@@ -252,20 +252,27 @@ class DWARF5AccelTableData : public AccelTableData {
 public:
   static uint32_t hash(StringRef Name) { return caseFoldingDjbHash(Name); }
 
-  DWARF5AccelTableData(const DIE &Die) : Die(Die) {}
+  DWARF5AccelTableData(const DIE &Die, const DwarfCompileUnit &CU);
 
 #ifndef NDEBUG
   void print(raw_ostream &OS) const override;
 #endif
 
-  const DIE &getDie() const { return Die; }
-  uint64_t getDieOffset() const { return Die.getOffset(); }
-  unsigned getDieTag() const { return Die.getTag(); }
+  uint64_t getDieOffset() const {
+    if (const DIE *const *TDie = std::get_if<const DIE *>(&OffsetVal))
+      return (*TDie)->getOffset();
+    return std::get<uint64_t>(OffsetVal);
+  }
+  unsigned getDieTag() const { return Tag; }
+  unsigned getUnitID() const { return UnitID; }
+  void normalizeDIEToOffset() { OffsetVal = getDieOffset(); }
 
 protected:
-  const DIE &Die;
+  std::variant<const DIE *, uint64_t> OffsetVal;
+  dwarf::Tag Tag;
+  unsigned UnitID;
----------------
dwblaikie wrote:

This is going to end up increasing the size of the struct from 8 bytes to  ((8(pointer/uint64)+8(discriminator and padding))+2(Tag)+2(padding)+4(uintID) == 24 bytes.
Might be worth skipping std::variant, so that the discriminator can be encoded in what's otherwise going to be 2 bytes of padding, then it'll only be 16 bytes (8(pointer/uint64)+2(discriminator)+2(tag)+4(uintID)) - and we could probably make uintIDs smaller, really - like they can probably be 16 bits just fine... (but that's a change for another time - it's fine here and wouldn't make the struct any smaller anyway)

https://github.com/llvm/llvm-project/pull/69399


More information about the llvm-commits mailing list