[llvm-dev] DenseMapInfo::getHashValue() of two sometimes identical pointers
Jeroen Dobbelaere via llvm-dev
llvm-dev at lists.llvm.org
Thu Sep 9 23:54:37 PDT 2021
Hi all,
is there a recommended way to implement a 'DenseMapInfo<..>::getHashValue()'
for a class that contains multiple pointers of which some are potentially identical ?
The standard used xor (^) is canceling out the hash contribution of those identical pointers.
More concrete: I am adding a 'PtrProvenance' member to MemoryLocation. When I add
the member to the hash computation in the way it seems intended,
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Analysis/MemoryLocation.h#L340-L344
I would do:
static unsigned getHashValue(const MemoryLocation &Val) {
return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^
DenseMapInfo<const Value *>::getHashValue(Val.PtrProvenance) ^ // Handle new member
DenseMapInfo<LocationSize>::getHashValue(Val.Size) ^
DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags);
}
But, in the initial case, it is very likely that Val.Ptr == Val.PtrProvenance.
Is there a recommended (standard) way to fix this ?
Thanks,
Jeroen Dobbelaere
More information about the llvm-dev
mailing list