[llvm] [llvm-debuginfo-analyzer] Apply various memory savings in Core/LVxxx base classes (PR #144399)
Javier Lopez-Gomez via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 17 09:00:15 PDT 2025
https://github.com/jalopezg-git updated https://github.com/llvm/llvm-project/pull/144399
>From 4363916ccefe0d57a8c8b8a7d4bef50560001222 Mon Sep 17 00:00:00 2001
From: Javier Lopez-Gomez <javier.lopez.gomez at proton.me>
Date: Tue, 17 Jun 2025 17:58:13 +0200
Subject: [PATCH 1/3] [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 | 29 +++++++++++++++----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
index 01137f80c0f8b..058ca2da9a960 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h
@@ -13,7 +13,6 @@
#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
-#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/DebugInfo/LogicalView/Core/LVStringPool.h"
#include "llvm/Support/Compiler.h"
@@ -21,9 +20,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 +39,32 @@ 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);
+ // Use uint32_t as the underlying type if the `T` enum has at most 32
+ // enumerators; otherwise, fallback to the generic `std::bitset` case.
+ 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.
>From 09dbffd654d2f43c8e93c9fc0f7be0f4f70d06b3 Mon Sep 17 00:00:00 2001
From: Javier Lopez-Gomez <javier.lopez.gomez at proton.me>
Date: Tue, 17 Jun 2025 17:58:13 +0200
Subject: [PATCH 2/3] [llvm-debuginfo-analyzer] Reorder LVElement members in
order to minimize padding
---
.../llvm/DebugInfo/LogicalView/Core/LVElement.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h
index b4501db190fe5..0e7be45abfef4 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h
@@ -107,18 +107,18 @@ class LLVM_ABI LVElement : public LVObject {
IsAnonymous,
LastEntry
};
- // Typed bitvector with properties for this element.
- LVProperties<Property> Properties;
static LVElementDispatch Dispatch;
- /// RTTI.
- const LVSubclassID SubclassID;
-
// Indexes in the String Pool.
size_t NameIndex = 0;
size_t QualifiedNameIndex = 0;
size_t FilenameIndex = 0;
+ // Typed bitvector with properties for this element.
+ LVProperties<Property> Properties;
+ /// RTTI.
+ const LVSubclassID SubclassID;
+
uint16_t AccessibilityCode : 2; // DW_AT_accessibility.
uint16_t InlineCode : 2; // DW_AT_inline.
uint16_t VirtualityCode : 2; // DW_AT_virtuality.
>From 909a38ef2be4d129b5341887a3b402ff554a5863 Mon Sep 17 00:00:00 2001
From: Javier Lopez-Gomez <javier.lopez.gomez at proton.me>
Date: Tue, 17 Jun 2025 17:58:13 +0200
Subject: [PATCH 3/3] [llvm-debuginfo-analyzer] Fix a couple of member
declarations in LVScopeCompileUnit
---
llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h
index 5715a37185b2b..a453923d032e4 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h
@@ -473,7 +473,7 @@ class LLVM_ABI LVScopeCompileUnit final : public LVScope {
// Record scope sizes indexed by lexical level.
// Setting an initial size that will cover a very deep nested scopes.
- const size_t TotalInitialSize = 8;
+ static constexpr size_t TotalInitialSize = 8;
using LVTotalsEntry = std::pair<unsigned, float>;
SmallVector<LVTotalsEntry> Totals;
// Maximum seen lexical level. It is used to control how many entries
@@ -510,7 +510,7 @@ class LLVM_ABI LVScopeCompileUnit final : public LVScope {
void addMapping(LVLine *Line, LVSectionIndex SectionIndex);
LVLineRange lineRange(LVLocation *Location) const;
- LVNameInfo NameNone = {UINT64_MAX, 0};
+ static constexpr LVNameInfo NameNone = {UINT64_MAX, 0};
void addPublicName(LVScope *Scope, LVAddress LowPC, LVAddress HighPC) {
PublicNames.emplace(std::piecewise_construct, std::forward_as_tuple(Scope),
std::forward_as_tuple(LowPC, HighPC - LowPC));
More information about the llvm-commits
mailing list