LLVM 20.0.0git
StringPool.h
Go to the documentation of this file.
1//===- StringPool.h ---------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DWARFLINKER_STRINGPOOL_H
10#define LLVM_DWARFLINKER_STRINGPOOL_H
11
16#include <string_view>
17
18namespace llvm {
19namespace dwarf_linker {
20
21/// StringEntry keeps data of the string: the length, external offset
22/// and a string body which is placed right after StringEntry.
24
26public:
27 /// \returns Hash value for the specified \p Key.
28 static inline uint64_t getHashValue(const StringRef &Key) {
29 return xxh3_64bits(Key);
30 }
31
32 /// \returns true if both \p LHS and \p RHS are equal.
33 static inline bool isEqual(const StringRef &LHS, const StringRef &RHS) {
34 return LHS == RHS;
35 }
36
37 /// \returns key for the specified \p KeyData.
38 static inline StringRef getKey(const StringEntry &KeyData) {
39 return KeyData.getKey();
40 }
41
42 /// \returns newly created object of KeyDataTy type.
43 static inline StringEntry *
44 create(const StringRef &Key,
46 return StringEntry::create(Key, Allocator);
47 }
48};
49
51 : public ConcurrentHashTableByPtr<StringRef, StringEntry,
52 llvm::parallel::PerThreadBumpPtrAllocator,
53 StringPoolEntryInfo> {
54public:
57 llvm::parallel::PerThreadBumpPtrAllocator,
58 StringPoolEntryInfo>(Allocator) {}
59
60 StringPool(size_t InitialSize)
62 llvm::parallel::PerThreadBumpPtrAllocator,
63 StringPoolEntryInfo>(Allocator, InitialSize) {}
64
66 return Allocator;
67 }
68
69 void clear() { Allocator.Reset(); }
70
71private:
73};
74
75} // namespace dwarf_linker
76} // end namespace llvm
77
78#endif // LLVM_DWARFLINKER_STRINGPOOL_H
This file defines the BumpPtrAllocator interface.
Basic Register Allocator
Value * RHS
Value * LHS
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
static StringMapEntry * create(StringRef key, AllocatorTy &allocator, InitTy &&...initVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
StringRef getKey() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
static uint64_t getHashValue(const StringRef &Key)
Definition: StringPool.h:28
static StringEntry * create(const StringRef &Key, llvm::parallel::PerThreadBumpPtrAllocator &Allocator)
Definition: StringPool.h:44
static bool isEqual(const StringRef &LHS, const StringRef &RHS)
Definition: StringPool.h:33
static StringRef getKey(const StringEntry &KeyData)
Definition: StringPool.h:38
llvm::parallel::PerThreadBumpPtrAllocator & getAllocatorRef()
Definition: StringPool.h:65
StringPool(size_t InitialSize)
Definition: StringPool.h:60
PerThreadAllocator< BumpPtrAllocator > PerThreadBumpPtrAllocator
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Definition: xxhash.cpp:553