13
13
#ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
14
14
#define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSUPPORT_H
15
15
16
- #include " llvm/ADT/SmallBitVector.h"
17
16
#include " llvm/ADT/Twine.h"
18
17
#include " llvm/DebugInfo/LogicalView/Core/LVStringPool.h"
19
18
#include " llvm/Support/Compiler.h"
20
19
#include " llvm/Support/Debug.h"
21
20
#include " llvm/Support/Format.h"
22
21
#include " llvm/Support/Path.h"
23
22
#include " llvm/Support/raw_ostream.h"
23
+ #include < bitset>
24
24
#include < cctype>
25
25
#include < map>
26
26
#include < sstream>
27
+ #include < type_traits>
27
28
28
29
namespace llvm {
29
30
namespace logicalview {
@@ -38,14 +39,32 @@ using LVLexicalIndex =
38
39
39
40
// Used to record specific characteristics about the objects.
40
41
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{};
42
46
43
47
public:
44
48
LVProperties () = default ;
45
49
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
+ }
49
68
};
50
69
51
70
// Generate get, set and reset 'bool' functions for LVProperties instances.
0 commit comments