Skip to content

Commit 30b6aeb

Browse files
committed
[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.
1 parent c7d8581 commit 30b6aeb

File tree

1 file changed

+24
-5
lines changed
  • llvm/include/llvm/DebugInfo/LogicalView/Core

1 file changed

+24
-5
lines changed

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)