18 #ifndef LLVM_CODEGEN_PBQP_COSTALLOCATOR_H
19 #define LLVM_CODEGEN_PBQP_COSTALLOCATOR_H
23 #include <type_traits>
28 template <
typename ValueT>
31 typedef std::shared_ptr<const ValueT>
PoolRef;
35 class PoolEntry :
public std::enable_shared_from_this<PoolEntry> {
37 template <
typename ValueKeyT>
39 : Pool(Pool), Value(std::move(Value)) {}
40 ~PoolEntry() { Pool.removeEntry(
this); }
41 const ValueT&
getValue()
const {
return Value; }
47 class PoolEntryDSInfo {
49 static inline PoolEntry* getEmptyKey() {
return nullptr; }
51 static inline PoolEntry* getTombstoneKey() {
52 return reinterpret_cast<PoolEntry*
>(
static_cast<uintptr_t
>(1));
55 template <
typename ValueKeyT>
56 static unsigned getHashValue(
const ValueKeyT &C) {
60 static unsigned getHashValue(PoolEntry *
P) {
61 return getHashValue(P->getValue());
64 static unsigned getHashValue(
const PoolEntry *P) {
65 return getHashValue(P->getValue());
68 template <
typename ValueKeyT1,
typename ValueKeyT2>
70 bool isEqual(
const ValueKeyT1 &C1,
const ValueKeyT2 &C2) {
74 template <
typename ValueKeyT>
75 static bool isEqual(
const ValueKeyT &C, PoolEntry *P) {
76 if (P == getEmptyKey() || P == getTombstoneKey())
78 return isEqual(C, P->getValue());
81 static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
82 if (P1 == getEmptyKey() || P1 == getTombstoneKey())
84 return isEqual(P1->getValue(), P2);
89 typedef DenseSet<PoolEntry*, PoolEntryDSInfo> EntrySetT;
93 void removeEntry(PoolEntry *P) { EntrySet.
erase(P); }
99 if (I != EntrySet.
end())
100 return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
102 auto P = std::make_shared<PoolEntry>(*
this, std::move(ValueKey));
104 return PoolRef(std::move(P), &P->getValue());
108 template <
typename VectorT,
typename MatrixT>
119 template <
typename VectorKeyT>
122 template <
typename MatrixKeyT>
125 VectorCostPool VectorPool;
126 MatrixCostPool MatrixPool;
MatrixPtr getMatrix(MatrixKeyT m)
PoolRef getValue(ValueKeyT ValueKey)
VectorCostPool::PoolRef VectorPtr
bool erase(const ValueT &V)
VectorPtr getVector(VectorKeyT v)
std::pair< iterator, bool > insert(const ValueT &V)
hash_code hash_value(const Vector &V)
Return a hash_value for the given vector.
std::shared_ptr< const ValueT > PoolRef
MatrixCostPool::PoolRef MatrixPtr
iterator find_as(const LookupKeyT &Val)
Alternative version of find() which allows a different, and possibly less expensive, key type.
LLVM Value Representation.