From 50923aa33f09b2530cfe492a53f70296f9ce9107 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Mon, 17 Jun 2024 11:32:35 +0800 Subject: [PATCH] [Serialization] Use specialized decl hash function for GlobalDeclID See the comment: https://github.com/llvm/llvm-project/pull/92083#issuecomment-2168121729 After the patch, https://github.com/llvm/llvm-project/pull/92083, the lower 32 bits of DeclID can be the same commonly. This may produce many collisions. It will be best to change the default hash implementation for uint64_t. But sent this one as a quick workaround. --- clang/include/clang/AST/DeclID.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h index 32d2ed41a374a0..4ad7afb463b18f 100644 --- a/clang/include/clang/AST/DeclID.h +++ b/clang/include/clang/AST/DeclID.h @@ -230,7 +230,11 @@ template <> struct DenseMapInfo { } static unsigned getHashValue(const GlobalDeclID &Key) { - return DenseMapInfo::getHashValue(Key.get()); + // Our default hash algorithm for 64 bits integer may not be very good. + // In GlobalDeclID's case, it is pretty common that the lower 32 bits can + // be same. + return DenseMapInfo::getHashValue(Key.getModuleFileIndex()) ^ + DenseMapInfo::getHashValue(Key.getLocalDeclIndex()); } static bool isEqual(const GlobalDeclID &L, const GlobalDeclID &R) {