[llvm] [llvm-debuginfo-analyzer] Reduce size of `LVProperties` where possible (PR #144399)

Javier Lopez-Gomez via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 16 10:32:44 PDT 2025


https://github.com/jalopezg-git created https://github.com/llvm/llvm-project/pull/144399

Use underlying type of `uint32_t` if there are at most 32 properties
to keep track of.  Otherwise, switch to `std::bitset<N>`.
This effectively reduces the size of `LVObject` from 48 to 40 bytes.

>From 5e0f5e5ef3a55b760a2dcdc5c1e23381bf1fa2de Mon Sep 17 00:00:00 2001
From: Javier Lopez-Gomez <javier.lopez.gomez at proton.me>
Date: Mon, 16 Jun 2025 19:30:20 +0200
Subject: [PATCH] [llvm-debuginfo-analyzer] Reduce size of `LVProperties` where
 possible

Use underlying type of `uint32_t` if there are at most 32 properties
to keep track of.  Otherwise, switch to `std::bitset<N>`.
This effectively reduces the size of `LVObject` from 48 to 40 bytes.
---
 .../DebugInfo/LogicalView/Core/LVSupport.h    | 26 ++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
index 01137f80c0f8b..4fb7d1d13e513 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
@@ -21,9 +21,11 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include <bitset>
 #include <cctype>
 #include <map>
 #include <sstream>
+#include <type_traits>
 
 namespace llvm {
 namespace logicalview {
@@ -38,14 +40,30 @@ using LVLexicalIndex =
 
 // Used to record specific characteristics about the objects.
 template <typename T> class LVProperties {
-  SmallBitVector Bits = SmallBitVector(static_cast<unsigned>(T::LastEntry) + 1);
+  static constexpr unsigned N_PROPS = static_cast<unsigned>(T::LastEntry);
+  std::conditional_t<(N_PROPS > 32), std::bitset<N_PROPS>, uint32_t> Bits{};
 
 public:
   LVProperties() = default;
 
-  void set(T Idx) { Bits[static_cast<unsigned>(Idx)] = 1; }
-  void reset(T Idx) { Bits[static_cast<unsigned>(Idx)] = 0; }
-  bool get(T Idx) const { return Bits[static_cast<unsigned>(Idx)]; }
+  void set(T Idx) {
+    if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
+      Bits |= 1 << static_cast<unsigned>(Idx);
+    else
+      Bits.set(static_cast<unsigned>(Idx));
+  }
+  void reset(T Idx) {
+    if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
+      Bits &= ~(1 << static_cast<unsigned>(Idx));
+    else
+      Bits.reset(static_cast<unsigned>(Idx));
+  }
+  bool get(T Idx) const {
+    if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
+      return Bits & (1 << static_cast<unsigned>(Idx));
+    else
+      return Bits[static_cast<unsigned>(Idx)];
+  }
 };
 
 // Generate get, set and reset 'bool' functions for LVProperties instances.



More information about the llvm-commits mailing list