Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:49

0001 //===- StringPool.h ---------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DWARFLINKER_STRINGPOOL_H
0010 #define LLVM_DWARFLINKER_STRINGPOOL_H
0011 
0012 #include "llvm/ADT/ConcurrentHashtable.h"
0013 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
0014 #include "llvm/Support/Allocator.h"
0015 #include "llvm/Support/PerThreadBumpPtrAllocator.h"
0016 #include <string_view>
0017 
0018 namespace llvm {
0019 namespace dwarf_linker {
0020 
0021 /// StringEntry keeps data of the string: the length, external offset
0022 /// and a string body which is placed right after StringEntry.
0023 using StringEntry = StringMapEntry<std::nullopt_t>;
0024 
0025 class StringPoolEntryInfo {
0026 public:
0027   /// \returns Hash value for the specified \p Key.
0028   static inline uint64_t getHashValue(const StringRef &Key) {
0029     return xxh3_64bits(Key);
0030   }
0031 
0032   /// \returns true if both \p LHS and \p RHS are equal.
0033   static inline bool isEqual(const StringRef &LHS, const StringRef &RHS) {
0034     return LHS == RHS;
0035   }
0036 
0037   /// \returns key for the specified \p KeyData.
0038   static inline StringRef getKey(const StringEntry &KeyData) {
0039     return KeyData.getKey();
0040   }
0041 
0042   /// \returns newly created object of KeyDataTy type.
0043   static inline StringEntry *
0044   create(const StringRef &Key,
0045          llvm::parallel::PerThreadBumpPtrAllocator &Allocator) {
0046     return StringEntry::create(Key, Allocator);
0047   }
0048 };
0049 
0050 class StringPool
0051     : public ConcurrentHashTableByPtr<StringRef, StringEntry,
0052                                       llvm::parallel::PerThreadBumpPtrAllocator,
0053                                       StringPoolEntryInfo> {
0054 public:
0055   StringPool()
0056       : ConcurrentHashTableByPtr<StringRef, StringEntry,
0057                                  llvm::parallel::PerThreadBumpPtrAllocator,
0058                                  StringPoolEntryInfo>(Allocator) {}
0059 
0060   StringPool(size_t InitialSize)
0061       : ConcurrentHashTableByPtr<StringRef, StringEntry,
0062                                  llvm::parallel::PerThreadBumpPtrAllocator,
0063                                  StringPoolEntryInfo>(Allocator, InitialSize) {}
0064 
0065   llvm::parallel::PerThreadBumpPtrAllocator &getAllocatorRef() {
0066     return Allocator;
0067   }
0068 
0069   void clear() { Allocator.Reset(); }
0070 
0071 private:
0072   llvm::parallel::PerThreadBumpPtrAllocator Allocator;
0073 };
0074 
0075 } // namespace dwarf_linker
0076 } // end namespace llvm
0077 
0078 #endif // LLVM_DWARFLINKER_STRINGPOOL_H