LLVM: include/llvm/CodeGen/PBQP/CostAllocator.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef LLVM_CODEGEN_PBQP_COSTALLOCATOR_H
18#define LLVM_CODEGEN_PBQP_COSTALLOCATOR_H
19
21#include
22#include
23#include
24
25namespace llvm {
27
29public:
30 using PoolRef = std::shared_ptr;
31
32private:
33 class PoolEntry : public std::enable_shared_from_this {
34 public:
35 template
37 : Pool(Pool), Value(std::move(Value)) {}
38
39 ~PoolEntry() { Pool.removeEntry(this); }
40
42
43 private:
46 };
47
48 class PoolEntryDSInfo {
49 public:
50 static inline PoolEntry *getEmptyKey() { return nullptr; }
51
52 static inline PoolEntry *getTombstoneKey() {
53 return reinterpret_cast<PoolEntry *>(static_cast<uintptr_t>(1));
54 }
55
56 template
57 static unsigned getHashValue(const ValueKeyT &C) {
59 }
60
61 static unsigned getHashValue(PoolEntry *P) {
62 return getHashValue(P->getValue());
63 }
64
65 static unsigned getHashValue(const PoolEntry *P) {
66 return getHashValue(P->getValue());
67 }
68
69 template <typename ValueKeyT1, typename ValueKeyT2>
70 static bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
71 return C1 == C2;
72 }
73
74 template
75 static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
76 if (P == getEmptyKey() || P == getTombstoneKey())
77 return false;
78 return isEqual(C, P->getValue());
79 }
80
81 static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
82 if (P1 == getEmptyKey() || P1 == getTombstoneKey())
83 return P1 == P2;
84 return isEqual(P1->getValue(), P2);
85 }
86 };
87
88 using EntrySetT = DenseSet<PoolEntry *, PoolEntryDSInfo>;
89
90 EntrySetT EntrySet;
91
92 void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
93
94public:
95 template PoolRef getValue(ValueKeyT ValueKey) {
97
98 if (I != EntrySet.end())
99 return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
100
101 auto P = std::make_shared(*this, std::move(ValueKey));
102 EntrySet.insert(P.get());
103 return PoolRef(P, &P->getValue());
104 }
105};
106
108private:
111
112public:
117
119 return VectorPool.getValue(std::move(v));
120 }
121
123 return MatrixPool.getValue(std::move(m));
124 }
125
126private:
127 VectorCostPool VectorPool;
128 MatrixCostPool MatrixPool;
129};
130
131}
132}
133
134#endif
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the DenseSet and SmallDenseSet classes.
Definition CostAllocator.h:107
VectorPtr getVector(VectorKeyT v)
Definition CostAllocator.h:118
typename MatrixCostPool::PoolRef MatrixPtr
Definition CostAllocator.h:116
MatrixPtr getMatrix(MatrixKeyT m)
Definition CostAllocator.h:122
VectorT Vector
Definition CostAllocator.h:113
MatrixT Matrix
Definition CostAllocator.h:114
typename VectorCostPool::PoolRef VectorPtr
Definition CostAllocator.h:115
Definition CostAllocator.h:28
PoolRef getValue(ValueKeyT ValueKey)
Definition CostAllocator.h:95
std::shared_ptr< const ValueT > PoolRef
Definition CostAllocator.h:30
LLVM Value Representation.
DenseSetIterator< false > iterator
@ C
The default llvm calling convention, compatible with C.
Definition CostAllocator.h:26
hash_code hash_value(const Vector &V)
Return a hash_value for the given vector.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value