Skip to content

Commit

Permalink
[Serialization] Use specialized decl hash function for GlobalDeclID
Browse files Browse the repository at this point in the history
See the comment:
llvm#92083 (comment)

After the patch, llvm#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.
  • Loading branch information
ChuanqiXu9 committed Jun 17, 2024
1 parent 15bb026 commit 50923aa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/include/clang/AST/DeclID.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ template <> struct DenseMapInfo<clang::GlobalDeclID> {
}

static unsigned getHashValue(const GlobalDeclID &Key) {
return DenseMapInfo<DeclID>::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<uint32_t>::getHashValue(Key.getModuleFileIndex()) ^
DenseMapInfo<uint32_t>::getHashValue(Key.getLocalDeclIndex());
}

static bool isEqual(const GlobalDeclID &L, const GlobalDeclID &R) {
Expand Down

0 comments on commit 50923aa

Please sign in to comment.