From: Justin Bogner Date: Fri, 18 Apr 2014 20:27:24 +0000 (+0000) Subject: Teach users of OnDiskHashTable to define hash_value and offset types X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f4a4206c265fa656dc93f22822ee6a63b55ac542;p=clang Teach users of OnDiskHashTable to define hash_value and offset types This paves the way to making OnDiskHashTable work with hashes that are not 32 bits wide and to making OnDiskHashTable work very large hash tables. The LLVM change to use these types is upcoming. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206640 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp index 0d4d1c4710..bf1c968da1 100644 --- a/lib/Frontend/CacheTokens.cpp +++ b/lib/Frontend/CacheTokens.cpp @@ -117,7 +117,10 @@ public: typedef PTHEntry data_type; typedef const PTHEntry& data_type_ref; - static unsigned ComputeHash(PTHEntryKeyVariant V) { + typedef unsigned hash_value_type; + typedef unsigned offset_type; + + static hash_value_type ComputeHash(PTHEntryKeyVariant V) { return llvm::HashString(V.getString()); } @@ -599,7 +602,10 @@ public: typedef uint32_t data_type; typedef data_type data_type_ref; - static unsigned ComputeHash(PTHIdKey* key) { + typedef unsigned hash_value_type; + typedef unsigned offset_type; + + static hash_value_type ComputeHash(PTHIdKey* key) { return llvm::HashString(key->II->getName()); } diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index f30e12157f..b888f2ed9b 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -318,8 +318,10 @@ public: class PTHFileLookupCommonTrait { public: typedef std::pair internal_key_type; + typedef unsigned hash_value_type; + typedef unsigned offset_type; - static unsigned ComputeHash(internal_key_type x) { + static hash_value_type ComputeHash(internal_key_type x) { return llvm::HashString(x.second); } @@ -363,13 +365,11 @@ public: class PTHStringLookupTrait { public: - typedef uint32_t - data_type; - - typedef const std::pair - external_key_type; - + typedef uint32_t data_type; + typedef const std::pair external_key_type; typedef external_key_type internal_key_type; + typedef uint32_t hash_value_type; + typedef unsigned offset_type; static bool EqualKey(const internal_key_type& a, const internal_key_type& b) { @@ -377,7 +377,7 @@ public: : false; } - static unsigned ComputeHash(const internal_key_type& a) { + static hash_value_type ComputeHash(const internal_key_type& a) { return llvm::HashString(StringRef(a.first, a.second)); } diff --git a/lib/Serialization/ASTReaderInternals.h b/lib/Serialization/ASTReaderInternals.h index 7f0201b916..fdcecca4aa 100644 --- a/lib/Serialization/ASTReaderInternals.h +++ b/lib/Serialization/ASTReaderInternals.h @@ -46,6 +46,8 @@ public: /// particular lookup t typedef llvm::support::ulittle32_t LE32DeclID; typedef std::pair data_type; + typedef unsigned hash_value_type; + typedef unsigned offset_type; /// \brief Special internal key for declaration names. /// The hash table creates keys for comparison; we do not create @@ -67,7 +69,7 @@ public: return a.Kind == b.Kind && a.Data == b.Data; } - unsigned ComputeHash(const DeclNameKey &Key) const; + hash_value_type ComputeHash(const DeclNameKey &Key) const; internal_key_type GetInternalKey(const external_key_type& Name) const; static std::pair @@ -92,13 +94,14 @@ class ASTIdentifierLookupTraitBase { public: typedef StringRef external_key_type; typedef StringRef internal_key_type; - + typedef unsigned hash_value_type; + typedef unsigned offset_type; static bool EqualKey(const internal_key_type& a, const internal_key_type& b) { return a == b; } - static unsigned ComputeHash(const internal_key_type& a); + static hash_value_type ComputeHash(const internal_key_type& a); static std::pair ReadKeyDataLength(const unsigned char*& d); @@ -160,6 +163,8 @@ public: typedef Selector external_key_type; typedef external_key_type internal_key_type; + typedef unsigned hash_value_type; + typedef unsigned offset_type; ASTSelectorLookupTrait(ASTReader &Reader, ModuleFile &F) : Reader(Reader), F(F) { } @@ -169,7 +174,7 @@ public: return a == b; } - static unsigned ComputeHash(Selector Sel); + static hash_value_type ComputeHash(Selector Sel); static const internal_key_type& GetInternalKey(const external_key_type& x) { return x; } @@ -211,12 +216,14 @@ public: typedef const internal_key_type &internal_key_ref; typedef HeaderFileInfo data_type; + typedef unsigned hash_value_type; + typedef unsigned offset_type; HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS, const char *FrameworkStrings) : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) { } - static unsigned ComputeHash(internal_key_ref ikey); + static hash_value_type ComputeHash(internal_key_ref ikey); static internal_key_type GetInternalKey(const FileEntry *FE); bool EqualKey(internal_key_ref a, internal_key_ref b); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index cb25fe6f88..d770f8df26 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1482,8 +1482,10 @@ namespace { typedef HeaderFileInfo data_type; typedef const data_type &data_type_ref; + typedef unsigned hash_value_type; + typedef unsigned offset_type; - static unsigned ComputeHash(key_type_ref key) { + static hash_value_type ComputeHash(key_type_ref key) { // The hash is based only on size/time of the file, so that the reader can // match even when symlinking or excess path elements ("foo/../", "../") // change the form of the name. However, complete path is still the key. @@ -1855,8 +1857,10 @@ public: typedef Data data_type; typedef const data_type &data_type_ref; + typedef unsigned hash_value_type; + typedef unsigned offset_type; - static unsigned ComputeHash(IdentID IdID) { + static hash_value_type ComputeHash(IdentID IdID) { return llvm::hash_value(IdID); } @@ -2738,9 +2742,12 @@ public: }; typedef const data_type& data_type_ref; + typedef unsigned hash_value_type; + typedef unsigned offset_type; + explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) { } - static unsigned ComputeHash(Selector Sel) { + static hash_value_type ComputeHash(Selector Sel) { return serialization::ComputeHash(Sel); } @@ -3090,11 +3097,14 @@ public: typedef IdentID data_type; typedef data_type data_type_ref; + typedef unsigned hash_value_type; + typedef unsigned offset_type; + ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, IdentifierResolver &IdResolver, bool IsModule) : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule) { } - static unsigned ComputeHash(const IdentifierInfo* II) { + static hash_value_type ComputeHash(const IdentifierInfo* II) { return llvm::HashString(II->getName()); } @@ -3349,9 +3359,12 @@ public: typedef DeclContext::lookup_result data_type; typedef const data_type& data_type_ref; + typedef unsigned hash_value_type; + typedef unsigned offset_type; + explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) { } - unsigned ComputeHash(DeclarationName Name) { + hash_value_type ComputeHash(DeclarationName Name) { llvm::FoldingSetNodeID ID; ID.AddInteger(Name.getNameKind()); diff --git a/lib/Serialization/GlobalModuleIndex.cpp b/lib/Serialization/GlobalModuleIndex.cpp index 1649476342..21a714999b 100644 --- a/lib/Serialization/GlobalModuleIndex.cpp +++ b/lib/Serialization/GlobalModuleIndex.cpp @@ -72,12 +72,14 @@ public: typedef StringRef external_key_type; typedef StringRef internal_key_type; typedef SmallVector data_type; + typedef unsigned hash_value_type; + typedef unsigned offset_type; static bool EqualKey(const internal_key_type& a, const internal_key_type& b) { return a == b; } - static unsigned ComputeHash(const internal_key_type& a) { + static hash_value_type ComputeHash(const internal_key_type& a) { return llvm::HashString(a); } @@ -645,8 +647,10 @@ public: typedef StringRef key_type_ref; typedef SmallVector data_type; typedef const SmallVector &data_type_ref; + typedef unsigned hash_value_type; + typedef unsigned offset_type; - static unsigned ComputeHash(key_type_ref Key) { + static hash_value_type ComputeHash(key_type_ref Key) { return llvm::HashString(Key); }