LLVM: include/llvm/ExecutionEngine/Orc/SymbolStringPool.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H
14#define LLVM_EXECUTIONENGINE_ORC_SYMBOLSTRINGPOOL_H
15
20#include
21#include
22
23namespace llvm {
24
26
27namespace orc {
28
32
33
38
39
42
43public:
44
46
47
49
50
52
53
54 bool empty() const;
55
56private:
58
59 using RefCountType = std::atomic<size_t>;
62 mutable std::mutex PoolMutex;
63 PoolMap Pool;
64};
65
66
67
68
69
70
71
72
78
79public:
82
83 explicit operator bool() const { return S; }
84
86
89 }
90
94
98
101
102#ifndef NDEBUG
103
104
105
106
110#endif
111
112protected:
113 using PoolEntry = SymbolStringPool::PoolMapEntry;
115
117
119 std::numeric_limits<uintptr_t>::max()
121
123 (std::numeric_limits<uintptr_t>::max() - 1)
125
127 (std::numeric_limits<uintptr_t>::max() - 3)
129
130
132 return ((reinterpret_cast<uintptr_t>(P) - 1) & InvalidPtrMask) !=
134 }
135
139
141};
142
143
148
149public:
155
157
159 decRef();
161 incRef();
162 return *this;
163 }
164
166
168 decRef();
169 S = nullptr;
171 return *this;
172 }
173
175
176private:
178
179 void incRef() {
182 }
183
184 void decRef() {
186 assert(S->getValue() && "Releasing SymbolStringPtr with zero ref count");
188 }
189 }
190
193 }
194
197 }
198};
199
200
201
203public:
204 using PoolEntry = SymbolStringPool::PoolMapEntry;
205
207
208
212
213
219
221
222
223
225
226
227
233
234 void retain() { ++E->getValue(); }
236
237private:
239};
240
241
242
243
244
245
246
247
248
249
250
251
252
255
256public:
260
261 using SymbolStringPtrBase::operator=;
262
263private:
265
269 }
270
274 }
275};
276
280 "SymbolStringPtr constructed from invalid non-owning pointer.");
281
283 ++S->getValue();
284}
285
287#ifndef NDEBUG
289 assert(Pool.empty() && "Dangling references at pool destruction time");
290#endif
291}
292
294 std::lock_guardstd::mutex Lock(PoolMutex);
296 bool Added;
297 std::tie(I, Added) = Pool.try_emplace(S, 0);
299}
300
302 std::lock_guardstd::mutex Lock(PoolMutex);
303 for (auto I = Pool.begin(), E = Pool.end(); I != E;) {
304 auto Tmp = I++;
305 if (Tmp->second == 0)
306 Pool.erase(Tmp);
307 }
308}
309
311 std::lock_guardstd::mutex Lock(PoolMutex);
312 return Pool.empty();
313}
314
315inline size_t
318}
319
321 const SymbolStringPtrBase &Sym);
322
326
327}
328
329template <>
331
333 return orc::SymbolStringPtr::getEmptyVal();
334 }
335
337 return orc::SymbolStringPtr::getTombstoneVal();
338 }
339
343
347 }
348};
349
351
353 return orc::NonOwningSymbolStringPtr::getEmptyVal();
354 }
355
357 return orc::NonOwningSymbolStringPtr::getTombstoneVal();
358 }
359
364
368 }
369};
370
371}
372
373#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
const ValueTy & getValue() const
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringMapIterBase< RefCountType, false > iterator
StringRef - Represent a constant reference to a string, i.e.
An opaque object representing a hash code.
Non-owning SymbolStringPool entry pointer.
Definition SymbolStringPool.h:253
NonOwningSymbolStringPtr()=default
SymbolStringPool::PoolMapEntry PoolEntry
Definition SymbolStringPool.h:204
SymbolStringPtr copyToSymbolStringPtr()
Creates a SymbolStringPtr for this entry, with the SymbolStringPtr retaining the entry as usual.
Definition SymbolStringPool.h:224
void retain()
Definition SymbolStringPool.h:234
void release()
Definition SymbolStringPool.h:235
static SymbolStringPoolEntryUnsafe from(const SymbolStringPtrBase &S)
Create an unsafe pool entry ref without changing the ref-count.
Definition SymbolStringPool.h:209
SymbolStringPoolEntryUnsafe(PoolEntry *E)
Definition SymbolStringPool.h:206
PoolEntry * rawPtr()
Definition SymbolStringPool.h:220
static SymbolStringPoolEntryUnsafe take(SymbolStringPtr &&S)
Consumes the given SymbolStringPtr without releasing the pool entry.
Definition SymbolStringPool.h:214
SymbolStringPtr moveToSymbolStringPtr()
Creates a SymbolStringPtr for this entry without performing a retain operation during construction.
Definition SymbolStringPool.h:228
String pool for symbol names used by the JIT.
Definition SymbolStringPool.h:34
LLVM_ABI friend raw_ostream & operator<<(raw_ostream &OS, const SymbolStringPool &SSP)
Dump a SymbolStringPool. Useful for debugging dangling-pointer crashes.
SymbolStringPtr intern(StringRef S)
Create a symbol string pointer from the given string.
Definition SymbolStringPool.h:293
bool empty() const
Returns true if the pool is empty.
Definition SymbolStringPool.h:310
friend class SymbolStringPoolEntryUnsafe
Definition SymbolStringPool.h:37
friend class SymbolStringPtrBase
Definition SymbolStringPool.h:36
friend class SymbolStringPoolTest
Definition SymbolStringPool.h:35
~SymbolStringPool()
Destroy a SymbolStringPool.
Definition SymbolStringPool.h:286
void clearDeadEntries()
Remove from the pool any entries that are no longer referenced.
Definition SymbolStringPool.h:301
Base class for both owning and non-owning symbol-string ptrs.
Definition SymbolStringPool.h:73
PoolEntry * PoolEntryPtr
Definition SymbolStringPool.h:114
static bool isRealPoolEntry(PoolEntryPtr P)
Definition SymbolStringPool.h:131
friend bool operator!=(SymbolStringPtrBase LHS, SymbolStringPtrBase RHS)
Definition SymbolStringPool.h:91
bool poolEntryIsAlive() const
Definition SymbolStringPool.h:107
SymbolStringPtrBase()=default
friend class SymbolStringPool
Definition SymbolStringPool.h:74
friend bool operator<(SymbolStringPtrBase LHS, SymbolStringPtrBase RHS)
Definition SymbolStringPool.h:95
friend bool operator==(SymbolStringPtrBase LHS, SymbolStringPtrBase RHS)
Definition SymbolStringPool.h:87
static constexpr uintptr_t InvalidPtrMask
Definition SymbolStringPool.h:126
LLVM_ABI friend raw_ostream & operator<<(raw_ostream &OS, const SymbolStringPtrBase &Sym)
size_t getRefCount() const
Definition SymbolStringPool.h:136
StringRef operator*() const
Definition SymbolStringPool.h:85
static constexpr uintptr_t EmptyBitPattern
Definition SymbolStringPool.h:118
static constexpr uintptr_t TombstoneBitPattern
Definition SymbolStringPool.h:122
PoolEntryPtr S
Definition SymbolStringPool.h:140
friend class SymbolStringPoolEntryUnsafe
Definition SymbolStringPool.h:75
SymbolStringPtrBase(PoolEntryPtr S)
Definition SymbolStringPool.h:116
SymbolStringPool::PoolMapEntry PoolEntry
Definition SymbolStringPool.h:113
SymbolStringPtrBase(std::nullptr_t)
Definition SymbolStringPool.h:81
Pointer to a pooled string representing a symbol name.
Definition SymbolStringPool.h:144
friend class SymbolStringPool
Definition SymbolStringPool.h:145
SymbolStringPtr()=default
SymbolStringPtr(const SymbolStringPtr &Other)
Definition SymbolStringPool.h:152
SymbolStringPtr(std::nullptr_t)
Definition SymbolStringPool.h:151
friend class SymbolStringPoolEntryUnsafe
Definition SymbolStringPool.h:146
SymbolStringPtr & operator=(SymbolStringPtr &&Other)
Definition SymbolStringPool.h:167
~SymbolStringPtr()
Definition SymbolStringPool.h:174
SymbolStringPtr & operator=(const SymbolStringPtr &Other)
Definition SymbolStringPool.h:158
SymbolStringPtr(SymbolStringPtr &&Other)
Definition SymbolStringPool.h:165
This class implements an extremely fast bulk output stream that can only output to a stream.
hash_code hash_value(const orc::SymbolStringPtrBase &S)
Definition SymbolStringPool.h:323
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const SymbolNameSet &Symbols)
Render a SymbolNameSet.
This is an optimization pass for GlobalISel generic memory operations.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static orc::NonOwningSymbolStringPtr getEmptyKey()
Definition SymbolStringPool.h:352
static bool isEqual(const orc::SymbolStringPtrBase &LHS, const orc::SymbolStringPtrBase &RHS)
Definition SymbolStringPool.h:365
static unsigned getHashValue(const orc::SymbolStringPtrBase &V)
Definition SymbolStringPool.h:360
static orc::NonOwningSymbolStringPtr getTombstoneKey()
Definition SymbolStringPool.h:356
static orc::SymbolStringPtr getEmptyKey()
Definition SymbolStringPool.h:332
static bool isEqual(const orc::SymbolStringPtrBase &LHS, const orc::SymbolStringPtrBase &RHS)
Definition SymbolStringPool.h:344
static unsigned getHashValue(const orc::SymbolStringPtrBase &V)
Definition SymbolStringPool.h:340
static orc::SymbolStringPtr getTombstoneKey()
Definition SymbolStringPool.h:336
An information struct used to provide DenseMap with the various necessary components for a given valu...
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...