Skip to content

Commit c4d7ea8

Browse files
authored
[llvm-debuginfo-analyzer] Apply various memory savings in Core/LVxxx base classes (#144399)
This small changelist reduces memory footprint of instances of the Core classes. Specifically, - For `LVProperties`, use underlying type of `uint32_t` if there are at most 32 properties to keep track of. Otherwise, fallback to the generic `std::bitset<N>`. The use of `llvm::SmallBitVector` is disregarded in this case, as the upper bound on the size of the bitset can be determined statically (no heap alloc ever needed). - Reorder members in `LVElement` s.t. padding between members is reduced. - `LVScopeCompileUnit`: fix a couple of members which should be `static constexpr` instead.
1 parent d10079e commit c4d7ea8

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

llvm/include/llvm/DebugInfo/LogicalView/Core/LVElement.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ class LLVM_ABI LVElement : public LVObject {
107107
IsAnonymous,
108108
LastEntry
109109
};
110-
// Typed bitvector with properties for this element.
111-
LVProperties<Property> Properties;
112110
static LVElementDispatch Dispatch;
113111

114-
/// RTTI.
115-
const LVSubclassID SubclassID;
116-
117112
// Indexes in the String Pool.
118113
size_t NameIndex = 0;
119114
size_t QualifiedNameIndex = 0;
120115
size_t FilenameIndex = 0;
121116

117+
// Typed bitvector with properties for this element.
118+
LVProperties<Property> Properties;
119+
/// RTTI.
120+
const LVSubclassID SubclassID;
121+
122122
uint16_t AccessibilityCode : 2; // DW_AT_accessibility.
123123
uint16_t InlineCode : 2; // DW_AT_inline.
124124
uint16_t VirtualityCode : 2; // DW_AT_virtuality.

llvm/include/llvm/DebugInfo/LogicalView/Core/LVScope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class LLVM_ABI LVScopeCompileUnit final : public LVScope {
473473

474474
// Record scope sizes indexed by lexical level.
475475
// Setting an initial size that will cover a very deep nested scopes.
476-
const size_t TotalInitialSize = 8;
476+
static constexpr size_t TotalInitialSize = 8;
477477
using LVTotalsEntry = std::pair<unsigned, float>;
478478
SmallVector<LVTotalsEntry> Totals;
479479
// Maximum seen lexical level. It is used to control how many entries
@@ -510,7 +510,7 @@ class LLVM_ABI LVScopeCompileUnit final : public LVScope {
510510
void addMapping(LVLine *Line, LVSectionIndex SectionIndex);
511511
LVLineRange lineRange(LVLocation *Location) const;
512512

513-
LVNameInfo NameNone = {UINT64_MAX, 0};
513+
static constexpr LVNameInfo NameNone = {UINT64_MAX, 0};
514514
void addPublicName(LVScope *Scope, LVAddress LowPC, LVAddress HighPC) {
515515
PublicNames.emplace(std::piecewise_construct, std::forward_as_tuple(Scope),
516516
std::forward_as_tuple(LowPC, HighPC - LowPC));

llvm/include/llvm/DebugInfo/LogicalView/Core/LVSupport.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313
#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
1414
#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
1515

16-
#include "llvm/ADT/SmallBitVector.h"
1716
#include "llvm/ADT/Twine.h"
1817
#include "llvm/DebugInfo/LogicalView/Core/LVStringPool.h"
1918
#include "llvm/Support/Compiler.h"
2019
#include "llvm/Support/Debug.h"
2120
#include "llvm/Support/Format.h"
2221
#include "llvm/Support/Path.h"
2322
#include "llvm/Support/raw_ostream.h"
23+
#include <bitset>
2424
#include <cctype>
2525
#include <map>
2626
#include <sstream>
27+
#include <type_traits>
2728

2829
namespace llvm {
2930
namespace logicalview {
@@ -38,14 +39,32 @@ using LVLexicalIndex =
3839

3940
// Used to record specific characteristics about the objects.
4041
template <typename T> class LVProperties {
41-
SmallBitVector Bits = SmallBitVector(static_cast<unsigned>(T::LastEntry) + 1);
42+
static constexpr unsigned N_PROPS = static_cast<unsigned>(T::LastEntry);
43+
// Use uint32_t as the underlying type if the `T` enum has at most 32
44+
// enumerators; otherwise, fallback to the generic `std::bitset` case.
45+
std::conditional_t<(N_PROPS > 32), std::bitset<N_PROPS>, uint32_t> Bits{};
4246

4347
public:
4448
LVProperties() = default;
4549

46-
void set(T Idx) { Bits[static_cast<unsigned>(Idx)] = 1; }
47-
void reset(T Idx) { Bits[static_cast<unsigned>(Idx)] = 0; }
48-
bool get(T Idx) const { return Bits[static_cast<unsigned>(Idx)]; }
50+
void set(T Idx) {
51+
if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
52+
Bits |= 1 << static_cast<unsigned>(Idx);
53+
else
54+
Bits.set(static_cast<unsigned>(Idx));
55+
}
56+
void reset(T Idx) {
57+
if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
58+
Bits &= ~(1 << static_cast<unsigned>(Idx));
59+
else
60+
Bits.reset(static_cast<unsigned>(Idx));
61+
}
62+
bool get(T Idx) const {
63+
if constexpr (std::is_same_v<decltype(Bits), uint32_t>)
64+
return Bits & (1 << static_cast<unsigned>(Idx));
65+
else
66+
return Bits[static_cast<unsigned>(Idx)];
67+
}
4968
};
5069

5170
// Generate get, set and reset 'bool' functions for LVProperties instances.

0 commit comments

Comments
 (0)