9#ifndef LLVM_ADT_TRIERAWHASHMAP_H
10#define LLVM_ADT_TRIERAWHASHMAP_H
73 template <
class T>
struct AllocValueType {
75 std::aligned_union_t<
sizeof(
T),
T>
Content;
90 static void *
operator new(
size_t Size) { return ::operator
new(
Size); }
91 void operator delete(
void *
Ptr) { ::operator
delete(
Ptr); }
103 void *
get()
const {
return I == -2u ? P :
nullptr; }
113 bool isHint()
const {
return I != -1u && I != -2u; }
121 PointerBase
find(ArrayRef<uint8_t> Hash)
const;
125 insert(PointerBase Hint, ArrayRef<uint8_t> Hash,
126 function_ref<
const uint8_t *(
void *Mem, ArrayRef<uint8_t> Hash)>
132 size_t ContentAllocSize,
size_t ContentAllocAlign,
size_t ContentOffset,
133 std::optional<size_t> NumRootBits = std::nullopt,
134 std::optional<size_t> NumSubtrieBits = std::nullopt);
167 const unsigned short ContentAllocSize;
168 const unsigned short ContentAllocAlign;
169 const unsigned short ContentOffset;
170 unsigned short NumRootBits;
171 unsigned short NumSubtrieBits;
175 std::atomic<ImplType *> ImplPtr;
181template <
class T,
size_t NumHashBytes>
184 using HashT = std::array<uint8_t, NumHashBytes>;
202 struct EmplaceTag {};
203 template <
class... ArgsT>
214 using ThreadSafeTrieRawHashMapBase::operator
delete;
221 template <
class ValueT>
class PointerImpl :
PointerBase {
225 return reinterpret_cast<ValueT *
>(PointerBase::get());
233 ValueT *operator->()
const {
237 explicit operator bool()
const {
return get(); }
239 PointerImpl() =
default;
248 class pointer :
public PointerImpl<value_type> {
273 assert(Mem &&
"Constructor already called, or moved away");
277 assert(Mem &&
"Constructor already called, or moved away");
281 assert(Mem &&
"Constructor already called, or moved away");
282 return assign(::new (Mem)
283 value_type(Hash,
typename value_type::EmplaceTag{},
284 std::forward<ArgsT>(Args)...));
288 : Mem(
RHS.Mem), Result(
RHS.Result), Hash(
RHS.Hash) {
302 : Mem(Mem), Result(Result), Hash(Hash) {
304 assert(Mem &&
"Invalid memory for construction");
320 return Result->Hash.data();
331 C(std::move(HashedData.Data));
341 assert(Hash.
size() == std::tuple_size<HashT>::value);
346 assert(Hash.
size() == std::tuple_size<HashT>::value);
351 std::optional<size_t> NumSubtrieBits = std::nullopt)
355 NumRootBits, NumSubtrieBits) {}
358 if constexpr (std::is_trivially_destructible<value_type>::value)
#define offsetof(TYPE, MEMBER)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
TrieRawHashMap - is a lock-free thread-safe trie that is can be used to store/index data based on a h...
PointerBase getNextTrie(PointerBase P) const
unsigned getNumTries() const
unsigned getNumBits(PointerBase P) const
ThreadSafeTrieRawHashMapBase & operator=(const ThreadSafeTrieRawHashMapBase &)=delete
unsigned getNumSlotUsed(PointerBase P) const
~ThreadSafeTrieRawHashMapBase()
Destructor, which asserts if there's anything to do.
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
PointerBase find(ArrayRef< uint8_t > Hash) const
Find the stored content with hash.
LLVM_DUMP_METHOD void dump() const
PointerBase getRoot() const
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.
unsigned getStartBit(PointerBase P) const
void print(raw_ostream &OS) const
ThreadSafeTrieRawHashMapBase & operator=(ThreadSafeTrieRawHashMapBase &&RHS)=delete
std::string getTriePrefixAsString(PointerBase P) const
static constexpr size_t TrieContentBaseSize
static constexpr size_t DefaultNumRootBits
ThreadSafeTrieRawHashMapBase(const ThreadSafeTrieRawHashMapBase &)=delete
value_type & operator()(T &&RHS)
value_type & emplace(ArgsT &&...Args)
value_type & operator()(const T &RHS)
LazyValueConstructor(LazyValueConstructor &&RHS)
const_pointer(const pointer &P)
Lock-free thread-safe hash-mapped trie.
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)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
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.
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)