Skip to content

Commit 10483a3

Browse files
authored
Remove boost from BitVectorSet (#788)
* Remove boost from BitVectorSet * Minor deboostifying * Apply review comment on Bit-index-inbounds check + simplify operator<<
1 parent 010d706 commit 10483a3

7 files changed

Lines changed: 274 additions & 337 deletions

File tree

include/phasar/DataFlow/IfdsIde/Solver/Compressor.h

Lines changed: 1 addition & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -3,158 +3,12 @@
33

44
#include "phasar/DB/ProjectIRDBBase.h"
55
#include "phasar/Utils/ByRef.h"
6-
#include "phasar/Utils/TypeTraits.h"
7-
8-
#include "llvm/ADT/DenseMap.h"
9-
#include "llvm/ADT/DenseMapInfo.h"
10-
#include "llvm/ADT/SmallVector.h"
6+
#include "phasar/Utils/Compressor.h"
117

128
#include <cstdint>
13-
#include <deque>
14-
#include <functional>
15-
#include <optional>
169
#include <type_traits>
1710

1811
namespace psr {
19-
template <typename T, typename Enable = void> class Compressor;
20-
21-
/// \brief A utility class that assigns a sequential Id to every inserted
22-
/// object.
23-
///
24-
/// This specialization handles types that can be efficiently passed by value
25-
template <typename T>
26-
class Compressor<T, std::enable_if_t<CanEfficientlyPassByValue<T>>> {
27-
public:
28-
void reserve(size_t Capacity) {
29-
assert(Capacity <= UINT32_MAX);
30-
ToInt.reserve(Capacity);
31-
FromInt.reserve(Capacity);
32-
}
33-
34-
uint32_t getOrInsert(T Elem) {
35-
auto [It, Inserted] = ToInt.try_emplace(Elem, ToInt.size());
36-
if (Inserted) {
37-
FromInt.push_back(Elem);
38-
}
39-
return It->second;
40-
}
41-
42-
std::optional<uint32_t> getOrNull(T Elem) const {
43-
if (auto It = ToInt.find(Elem); It != ToInt.end()) {
44-
return It->second;
45-
}
46-
return std::nullopt;
47-
}
48-
49-
T operator[](size_t Idx) const noexcept {
50-
assert(Idx < FromInt.size());
51-
return FromInt[Idx];
52-
}
53-
54-
[[nodiscard]] size_t size() const noexcept { return FromInt.size(); }
55-
[[nodiscard]] size_t capacity() const noexcept {
56-
return FromInt.capacity() +
57-
ToInt.getMemorySize() / sizeof(typename decltype(ToInt)::value_type);
58-
}
59-
60-
auto begin() const noexcept { return FromInt.begin(); }
61-
auto end() const noexcept { return FromInt.end(); }
62-
63-
private:
64-
llvm::DenseMap<T, uint32_t> ToInt;
65-
llvm::SmallVector<T, 0> FromInt;
66-
};
67-
68-
/// \brief A utility class that assigns a sequential Id to every inserted
69-
/// object.
70-
///
71-
/// This specialization handles types that cannot be efficiently passed by value
72-
template <typename T>
73-
class Compressor<T, std::enable_if_t<!CanEfficientlyPassByValue<T>>> {
74-
public:
75-
void reserve(size_t Capacity) {
76-
assert(Capacity <= UINT32_MAX);
77-
ToInt.reserve(Capacity);
78-
}
79-
80-
/// Returns the index of the given element in the compressors storage. If the
81-
/// element isn't present yet, it will be added first and its index will
82-
/// then be returned.
83-
uint32_t getOrInsert(const T &Elem) {
84-
if (auto It = ToInt.find(&Elem); It != ToInt.end()) {
85-
return It->second;
86-
}
87-
auto Ret = FromInt.size();
88-
auto *Ins = &FromInt.emplace_back(Elem);
89-
ToInt[Ins] = Ret;
90-
return Ret;
91-
}
92-
93-
/// Returns the index of the given element in the compressors storage. If the
94-
/// element isn't present yet, it will be added first and its index will
95-
/// then be returned.
96-
uint32_t getOrInsert(T &&Elem) {
97-
if (auto It = ToInt.find(&Elem); It != ToInt.end()) {
98-
return It->second;
99-
}
100-
auto Ret = FromInt.size();
101-
auto *Ins = &FromInt.emplace_back(std::move(Elem));
102-
ToInt[Ins] = Ret;
103-
return Ret;
104-
}
105-
106-
/// Returns the index of the given element in the compressors storage. If the
107-
/// element isn't present, std::nullopt will be returned
108-
std::optional<uint32_t> getOrNull(const T &Elem) const {
109-
if (auto It = ToInt.find(&Elem); It != ToInt.end()) {
110-
return It->second;
111-
}
112-
return std::nullopt;
113-
}
114-
115-
const T &operator[](size_t Idx) const noexcept {
116-
assert(Idx < FromInt.size());
117-
return FromInt[Idx];
118-
}
119-
120-
[[nodiscard]] size_t size() const noexcept { return FromInt.size(); }
121-
[[nodiscard]] size_t capacity() const noexcept {
122-
return FromInt.size() +
123-
ToInt.getMemorySize() / sizeof(typename decltype(ToInt)::value_type);
124-
}
125-
126-
auto begin() const noexcept { return FromInt.begin(); }
127-
auto end() const noexcept { return FromInt.end(); }
128-
129-
private:
130-
struct DSI : llvm::DenseMapInfo<const T *> {
131-
static auto getHashValue(const T *Elem) noexcept {
132-
assert(Elem != nullptr);
133-
if constexpr (has_llvm_dense_map_info<T>) {
134-
return llvm::DenseMapInfo<T>::getHashValue(*Elem);
135-
} else {
136-
return std::hash<T>{}(*Elem);
137-
}
138-
}
139-
static auto isEqual(const T *LHS, const T *RHS) noexcept {
140-
if (LHS == RHS) {
141-
return true;
142-
}
143-
if (LHS == DSI::getEmptyKey() || LHS == DSI::getTombstoneKey() ||
144-
RHS == DSI::getEmptyKey() || RHS == DSI::getTombstoneKey()) {
145-
return false;
146-
}
147-
if constexpr (has_llvm_dense_map_info<T>) {
148-
return llvm::DenseMapInfo<T>::isEqual(*LHS, *RHS);
149-
} else {
150-
return *LHS == *RHS;
151-
}
152-
}
153-
};
154-
155-
std::deque<T> FromInt;
156-
llvm::DenseMap<const T *, uint32_t, DSI> ToInt;
157-
};
15812

15913
struct NoneCompressor final {
16014
constexpr NoneCompressor() noexcept = default;

include/phasar/DataFlow/Mono/Contexts/CallStringCTX.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
#include "phasar/Utils/Printer.h"
55

6+
#include "llvm/ADT/Hashing.h"
67
#include "llvm/Support/raw_ostream.h"
78

8-
#include "boost/functional/hash.hpp"
9-
109
#include <deque>
1110
#include <functional>
1211
#include <initializer_list>
@@ -94,11 +93,9 @@ namespace std {
9493

9594
template <typename N, unsigned K> struct hash<psr::CallStringCTX<N, K>> {
9695
size_t operator()(const psr::CallStringCTX<N, K> &CS) const noexcept {
97-
boost::hash<std::deque<N>> HashDeque;
98-
std::hash<unsigned> HashUnsigned;
99-
size_t U = HashUnsigned(K);
100-
size_t H = HashDeque(CS.CallString);
101-
return U ^ (H << 1);
96+
auto H =
97+
llvm::hash_combine_range(CS.CallString.begin(), CS.CallString.end());
98+
return llvm::hash_combine(K, H);
10299
}
103100
};
104101

0 commit comments

Comments
 (0)