Change ConstantAggrUniqueMap to use Chandler's new hashing

implementation. Patch by Meador Inge

llvm-svn: 152116
This commit is contained in:
Jay Foad 2012-03-06 10:43:52 +00:00
parent 4fa13ccbec
commit cc5fd3e25d
1 changed files with 9 additions and 36 deletions

View File

@ -16,6 +16,7 @@
#define LLVM_CONSTANTSCONTEXT_H #define LLVM_CONSTANTSCONTEXT_H
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/InlineAsm.h" #include "llvm/InlineAsm.h"
#include "llvm/Instructions.h" #include "llvm/Instructions.h"
#include "llvm/Operator.h" #include "llvm/Operator.h"
@ -656,48 +657,20 @@ private:
return ConstantClassInfo::getTombstoneKey(); return ConstantClassInfo::getTombstoneKey();
} }
static unsigned getHashValue(const ConstantClass *CP) { static unsigned getHashValue(const ConstantClass *CP) {
// This is adapted from SuperFastHash by Paul Hsieh. hash_code code = hash_value(CP->getType());
unsigned Hash = TypeClassInfo::getHashValue(CP->getType()); for (unsigned I = 0, E = CP->getNumOperands(); I < E; ++I)
for (unsigned I = 0, E = CP->getNumOperands(); I < E; ++I) { code = hash_combine(code, hash_value(CP->getOperand(I)));
unsigned Data = ConstantInfo::getHashValue(CP->getOperand(I)); return code;
Hash += Data & 0xFFFF;
unsigned Tmp = ((Data >> 16) << 11) ^ Hash;
Hash = (Hash << 16) ^ Tmp;
Hash += Hash >> 11;
}
// Force "avalanching" of final 127 bits.
Hash ^= Hash << 3;
Hash += Hash >> 5;
Hash ^= Hash << 4;
Hash += Hash >> 17;
Hash ^= Hash << 25;
Hash += Hash >> 6;
return Hash;
} }
static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) { static bool isEqual(const ConstantClass *LHS, const ConstantClass *RHS) {
return LHS == RHS; return LHS == RHS;
} }
static unsigned getHashValue(const LookupKey &Val) { static unsigned getHashValue(const LookupKey &Val) {
// This is adapted from SuperFastHash by Paul Hsieh. hash_code code = hash_value(Val.first);
unsigned Hash = TypeClassInfo::getHashValue(Val.first);
for (Operands::const_iterator for (Operands::const_iterator
I = Val.second.begin(), E = Val.second.end(); I != E; ++I) { I = Val.second.begin(), E = Val.second.end(); I != E; ++I)
unsigned Data = ConstantInfo::getHashValue(*I); code = hash_combine(code, hash_value(*I));
Hash += Data & 0xFFFF; return code;
unsigned Tmp = ((Data >> 16) << 11) ^ Hash;
Hash = (Hash << 16) ^ Tmp;
Hash += Hash >> 11;
}
// Force "avalanching" of final 127 bits.
Hash ^= Hash << 3;
Hash += Hash >> 5;
Hash ^= Hash << 4;
Hash += Hash >> 17;
Hash ^= Hash << 25;
Hash += Hash >> 6;
return Hash;
} }
static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) { static bool isEqual(const LookupKey &LHS, const ConstantClass *RHS) {
if (RHS == getEmptyKey() || RHS == getTombstoneKey()) if (RHS == getEmptyKey() || RHS == getTombstoneKey())