9#ifndef LLVM_ADT_TRIERAWHASHMAP_H
10#define LLVM_ADT_TRIERAWHASHMAP_H
74 template <
class T>
struct AllocValueType {
76 alignas(
T)
char Content[
sizeof(
T)];
88 offsetof(AllocValueType<T>, Content);
91 static void *
operator new(
size_t Size) { return ::operator
new(
Size); }
92 void operator delete(
void *
Ptr) { ::operator
delete(
Ptr); }
94#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
107 void *
get()
const {
return I == -2u ? P :
nullptr; }
114 explicit
PointerBase(
void *Content) : P(Content), I(-2u) {}
117 bool isHint()
const {
return I != -1u &&
I != -2u; }
130 function_ref<
const uint8_t *(
void *Mem, ArrayRef<uint8_t> Hash)>
136 size_t ContentAllocSize,
size_t ContentAllocAlign,
size_t ContentOffset,
137 std::optional<size_t> NumRootBits = std::nullopt,
138 std::optional<size_t> NumSubtrieBits = std::nullopt);
171 const unsigned short ContentAllocSize;
172 const unsigned short ContentAllocAlign;
173 const unsigned short ContentOffset;
174 unsigned short NumRootBits;
175 unsigned short NumSubtrieBits;
179 std::atomic<ImplType *> ImplPtr;
185template <
class T,
size_t NumHashBytes>
188 using HashT = std::array<uint8_t, NumHashBytes>;
206 struct EmplaceTag {};
207 template <
class... ArgsT>
218 using ThreadSafeTrieRawHashMapBase::operator
delete;
221#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
228 template <
class ValueT>
class PointerImpl :
PointerBase {
231 ValueT *
get()
const {
232 return reinterpret_cast<ValueT *
>(PointerBase::get());
240 ValueT *operator->()
const {
244 explicit operator bool()
const {
return get(); }
246 PointerImpl() =
default;
255 class pointer :
public PointerImpl<value_type> {
280 assert(Mem &&
"Constructor already called, or moved away");
284 assert(Mem &&
"Constructor already called, or moved away");
288 assert(Mem &&
"Constructor already called, or moved away");
289 return assign(::new (Mem)
290 value_type(Hash,
typename value_type::EmplaceTag{},
291 std::forward<ArgsT>(Args)...));
295 : Mem(
RHS.Mem), Result(
RHS.Result), Hash(
RHS.Hash) {
309 : Mem(Mem), Result(Result), Hash(Hash) {
310 assert(Hash.size() ==
sizeof(
HashT) &&
"Invalid hash");
311 assert(Mem &&
"Invalid memory for construction");
325 value_type *Result =
nullptr;
326 OnConstruct(LazyValueConstructor(Mem, Result, Hash));
327 return Result->Hash.data();
333 return insertLazy(const_pointer(), Hash, OnConstruct);
336 pointer
insert(const_pointer Hint, value_type &&HashedData) {
337 return insertLazy(Hint, HashedData.Hash, [&](LazyValueConstructor
C) {
338 C(std::move(HashedData.Data));
342 pointer
insert(const_pointer Hint,
const value_type &HashedData) {
344 [&](LazyValueConstructor
C) { C(HashedData.Data); });
348 assert(Hash.
size() == std::tuple_size<HashT>::value);
353 assert(Hash.
size() == std::tuple_size<HashT>::value);
358 std::optional<size_t> NumSubtrieBits = std::nullopt)
362 NumRootBits, NumSubtrieBits) {}
365 if constexpr (std::is_trivially_destructible<value_type>::value)
369 [](
void *
P) {
static_cast<value_type *
>(
P)->~value_type(); });
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
#define offsetof(TYPE, MEMBER)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
PointerBase() noexcept=default
friend class ThreadSafeTrieRawHashMapBase
LLVM_ABI PointerBase getNextTrie(PointerBase P) const
LLVM_ABI unsigned getNumTries() const
LLVM_ABI unsigned getNumBits(PointerBase P) const
ThreadSafeTrieRawHashMapBase & operator=(const ThreadSafeTrieRawHashMapBase &)=delete
LLVM_ABI unsigned getNumSlotUsed(PointerBase P) const
LLVM_ABI ~ThreadSafeTrieRawHashMapBase()
Destructor, which asserts if there's anything to do.
LLVM_ABI void destroyImpl(function_ref< void(void *ValueMem)> Destructor)
static constexpr size_t DefaultContentAllocSize
friend class TrieRawHashMapTestHelper
static constexpr size_t DefaultContentAllocAlign
static constexpr size_t DefaultContentOffset
static constexpr size_t DefaultNumSubtrieBits
ThreadSafeTrieRawHashMapBase()=delete
LLVM_ABI PointerBase find(ArrayRef< uint8_t > Hash) const
Find the stored content with hash.
LLVM_DUMP_METHOD void dump() const
LLVM_ABI PointerBase getRoot() const
LLVM_ABI PointerBase insert(PointerBase Hint, ArrayRef< uint8_t > Hash, function_ref< const uint8_t *(void *Mem, ArrayRef< uint8_t > Hash)> Constructor)
Insert and return the stored content.
LLVM_ABI unsigned getStartBit(PointerBase P) const
LLVM_ABI void print(raw_ostream &OS) const
ThreadSafeTrieRawHashMapBase & operator=(ThreadSafeTrieRawHashMapBase &&RHS)=delete
LLVM_ABI std::string getTriePrefixAsString(PointerBase P) const
static constexpr size_t TrieContentBaseSize
static constexpr size_t DefaultNumRootBits
ThreadSafeTrieRawHashMapBase(const ThreadSafeTrieRawHashMapBase &)=delete
friend class ThreadSafeTrieRawHashMap
value_type & operator()(T &&RHS)
value_type & emplace(ArgsT &&...Args)
value_type & operator()(const T &RHS)
LazyValueConstructor(LazyValueConstructor &&RHS)
friend class ThreadSafeTrieRawHashMap
const_pointer(const pointer &P)
friend class ThreadSafeTrieRawHashMap
friend class const_pointer
ThreadSafeTrieRawHashMap & operator=(const ThreadSafeTrieRawHashMap &)=delete
pointer insertLazy(ArrayRef< uint8_t > Hash, function_ref< void(LazyValueConstructor)> OnConstruct)
ThreadSafeTrieRawHashMap & operator=(ThreadSafeTrieRawHashMap &&)=delete
pointer find(ArrayRef< uint8_t > Hash)
std::array< uint8_t, NumHashBytes > HashT
pointer insertLazy(const_pointer Hint, ArrayRef< uint8_t > Hash, function_ref< void(LazyValueConstructor)> OnConstruct)
Insert with a hint.
const_pointer find(ArrayRef< uint8_t > Hash) const
pointer insert(const_pointer Hint, value_type &&HashedData)
pointer insert(const_pointer Hint, const value_type &HashedData)
ThreadSafeTrieRawHashMap(std::optional< size_t > NumRootBits=std::nullopt, std::optional< size_t > NumSubtrieBits=std::nullopt)
ThreadSafeTrieRawHashMap(const ThreadSafeTrieRawHashMap &)=delete
ThreadSafeTrieRawHashMap(ThreadSafeTrieRawHashMap &&)=default
~ThreadSafeTrieRawHashMap()
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
APInt operator*(APInt a, uint64_t RHS)
FunctionAddr VTableAddr uintptr_t uintptr_t Data
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
friend class LazyValueConstructor
value_type(const value_type &)=default
value_type(value_type &&)=default
value_type(ArrayRef< uint8_t > Hash, T &&Data)
value_type(ArrayRef< uint8_t > Hash, const T &Data)