forked from OSchip/llvm-project
Update getHashValue for ptr values stored in a DenseMap/Set to use getHasValue of KeyTy.
Ensures both hash values returned are the same. Tested by triggering resize of map/set and verifying failure before change. PiperOrigin-RevId: 223651443
This commit is contained in:
parent
45e3139bc8
commit
3277f94bf4
|
@ -49,9 +49,12 @@ namespace {
|
|||
struct FunctionTypeKeyInfo : DenseMapInfo<FunctionTypeStorage *> {
|
||||
// Functions are uniqued based on their inputs and results.
|
||||
using KeyTy = std::pair<ArrayRef<Type>, ArrayRef<Type>>;
|
||||
using DenseMapInfo<FunctionTypeStorage *>::getHashValue;
|
||||
using DenseMapInfo<FunctionTypeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(FunctionTypeStorage *key) {
|
||||
return getHashValue(KeyTy(key->getInputs(), key->getResults()));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(
|
||||
hash_combine_range(key.first.begin(), key.first.end()),
|
||||
|
@ -114,9 +117,12 @@ struct IntegerSetKeyInfo : DenseMapInfo<IntegerSet> {
|
|||
struct VectorTypeKeyInfo : DenseMapInfo<VectorTypeStorage *> {
|
||||
// Vectors are uniqued based on their element type and shape.
|
||||
using KeyTy = std::pair<Type, ArrayRef<int>>;
|
||||
using DenseMapInfo<VectorTypeStorage *>::getHashValue;
|
||||
using DenseMapInfo<VectorTypeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(VectorTypeStorage *key) {
|
||||
return getHashValue(KeyTy(key->elementType, key->getShape()));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(
|
||||
DenseMapInfo<Type>::getHashValue(key.first),
|
||||
|
@ -156,9 +162,13 @@ struct MemRefTypeKeyInfo : DenseMapInfo<MemRefTypeStorage *> {
|
|||
// MemRefs are uniqued based on their element type, shape, affine map
|
||||
// composition, and memory space.
|
||||
using KeyTy = std::tuple<Type, ArrayRef<int>, ArrayRef<AffineMap>, unsigned>;
|
||||
using DenseMapInfo<MemRefTypeStorage *>::getHashValue;
|
||||
using DenseMapInfo<MemRefTypeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(MemRefTypeStorage *key) {
|
||||
return getHashValue(KeyTy(key->elementType, key->getShape(),
|
||||
key->getAffineMaps(), key->memorySpace));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(
|
||||
DenseMapInfo<Type>::getHashValue(std::get<0>(key)),
|
||||
|
@ -178,9 +188,12 @@ struct MemRefTypeKeyInfo : DenseMapInfo<MemRefTypeStorage *> {
|
|||
struct FloatAttrKeyInfo : DenseMapInfo<FloatAttributeStorage *> {
|
||||
// Float attributes are uniqued based on wrapped APFloat.
|
||||
using KeyTy = std::pair<Type, APFloat>;
|
||||
using DenseMapInfo<FloatAttributeStorage *>::getHashValue;
|
||||
using DenseMapInfo<FloatAttributeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(FloatAttributeStorage *key) {
|
||||
return getHashValue(KeyTy(key->type, key->getValue()));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(key.first, llvm::hash_value(key.second));
|
||||
}
|
||||
|
@ -195,9 +208,12 @@ struct FloatAttrKeyInfo : DenseMapInfo<FloatAttributeStorage *> {
|
|||
struct IntegerAttrKeyInfo : DenseMapInfo<IntegerAttributeStorage *> {
|
||||
// Integer attributes are uniqued based on wrapped APInt.
|
||||
using KeyTy = std::pair<Type, APInt>;
|
||||
using DenseMapInfo<IntegerAttributeStorage *>::getHashValue;
|
||||
using DenseMapInfo<IntegerAttributeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(IntegerAttributeStorage *key) {
|
||||
return getHashValue(KeyTy(key->type, key->getValue()));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(key.first, llvm::hash_value(key.second));
|
||||
}
|
||||
|
@ -214,9 +230,12 @@ struct IntegerAttrKeyInfo : DenseMapInfo<IntegerAttributeStorage *> {
|
|||
struct ArrayAttrKeyInfo : DenseMapInfo<ArrayAttributeStorage *> {
|
||||
// Array attributes are uniqued based on their elements.
|
||||
using KeyTy = ArrayRef<Attribute>;
|
||||
using DenseMapInfo<ArrayAttributeStorage *>::getHashValue;
|
||||
using DenseMapInfo<ArrayAttributeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(ArrayAttributeStorage *key) {
|
||||
return getHashValue(KeyTy(key->value));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine_range(key.begin(), key.end());
|
||||
}
|
||||
|
@ -231,9 +250,12 @@ struct ArrayAttrKeyInfo : DenseMapInfo<ArrayAttributeStorage *> {
|
|||
struct AttributeListKeyInfo : DenseMapInfo<AttributeListStorage *> {
|
||||
// Array attributes are uniqued based on their elements.
|
||||
using KeyTy = ArrayRef<NamedAttribute>;
|
||||
using DenseMapInfo<AttributeListStorage *>::getHashValue;
|
||||
using DenseMapInfo<AttributeListStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(AttributeListStorage *key) {
|
||||
return getHashValue(KeyTy(key->getElements()));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine_range(key.begin(), key.end());
|
||||
}
|
||||
|
@ -247,9 +269,12 @@ struct AttributeListKeyInfo : DenseMapInfo<AttributeListStorage *> {
|
|||
|
||||
struct DenseElementsAttrInfo : DenseMapInfo<DenseElementsAttributeStorage *> {
|
||||
using KeyTy = std::pair<VectorOrTensorType, ArrayRef<char>>;
|
||||
using DenseMapInfo<DenseElementsAttributeStorage *>::getHashValue;
|
||||
using DenseMapInfo<DenseElementsAttributeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(DenseElementsAttributeStorage *key) {
|
||||
return getHashValue(KeyTy(key->type, key->data));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(
|
||||
key.first, hash_combine_range(key.second.begin(), key.second.end()));
|
||||
|
@ -265,9 +290,12 @@ struct DenseElementsAttrInfo : DenseMapInfo<DenseElementsAttributeStorage *> {
|
|||
|
||||
struct OpaqueElementsAttrInfo : DenseMapInfo<OpaqueElementsAttributeStorage *> {
|
||||
using KeyTy = std::pair<VectorOrTensorType, StringRef>;
|
||||
using DenseMapInfo<OpaqueElementsAttributeStorage *>::getHashValue;
|
||||
using DenseMapInfo<OpaqueElementsAttributeStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(OpaqueElementsAttributeStorage *key) {
|
||||
return getHashValue(KeyTy(key->type, key->bytes));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(
|
||||
key.first, hash_combine_range(key.second.begin(), key.second.end()));
|
||||
|
@ -285,9 +313,12 @@ struct FusedLocKeyInfo : DenseMapInfo<FusedLocationStorage *> {
|
|||
// Fused locations are uniqued based on their held locations and an optional
|
||||
// metadata attribute.
|
||||
using KeyTy = std::pair<ArrayRef<Location>, Attribute>;
|
||||
using DenseMapInfo<FusedLocationStorage *>::getHashValue;
|
||||
using DenseMapInfo<FusedLocationStorage *>::isEqual;
|
||||
|
||||
static unsigned getHashValue(FusedLocationStorage *key) {
|
||||
return getHashValue(KeyTy(key->getLocations(), key->metadata));
|
||||
}
|
||||
|
||||
static unsigned getHashValue(KeyTy key) {
|
||||
return hash_combine(hash_combine_range(key.first.begin(), key.first.end()),
|
||||
key.second);
|
||||
|
|
Loading…
Reference in New Issue