[llvm-commits] [llvm] r152116 - /llvm/trunk/lib/VMCore/ConstantsContext.h
Chandler Carruth
chandlerc at google.com
Tue Mar 6 19:27:21 PST 2012
On Tue, Mar 6, 2012 at 3:02 AM, Jay Foad <jay.foad at gmail.com> wrote:
> >> --- llvm/trunk/lib/VMCore/ConstantsContext.h (original)
> >> +++ llvm/trunk/lib/VMCore/ConstantsContext.h Tue Mar 6 04:43:52 2012
> >> @@ -16,6 +16,7 @@
> >> #define LLVM_CONSTANTSCONTEXT_H
> >>
> >> #include "llvm/ADT/DenseMap.h"
> >> +#include "llvm/ADT/Hashing.h"
> >> #include "llvm/InlineAsm.h"
> >> #include "llvm/Instructions.h"
> >> #include "llvm/Operator.h"
> >> @@ -656,48 +657,20 @@
> >> return ConstantClassInfo::getTombstoneKey();
> >> }
> >> static unsigned getHashValue(const ConstantClass *CP) {
> >> - // This is adapted from SuperFastHash by Paul Hsieh.
> >> - unsigned Hash = TypeClassInfo::getHashValue(CP->getType());
> >> - for (unsigned I = 0, E = CP->getNumOperands(); I< E; ++I) {
> >> - unsigned Data = ConstantInfo::getHashValue(CP->getOperand(I));
> >> - 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;
> >> + hash_code code = hash_value(CP->getType());
> >> + for (unsigned I = 0, E = CP->getNumOperands(); I< E; ++I)
> >> + code = hash_combine(code, hash_value(CP->getOperand(I)));
> >
> > maybe this could/should be done with hash_combine_range?
>
> As Meador explained when he posted the patch :-) the operands array is
> an array of Uses, but we don't want to hash the whole of each Use,
> just the Value* pointer.
>
I think you underestimate how slow it is to hash things using incremental
calls to hash_combine. The reason for the other interface is that it is
*much* faster.
Also, in the second case, we already had an array of pointers that we could
chew through with hash_combine_range. We can make both interfaces look the
same with a SmallVector buffer. I've switched the code in r152200.
It most cases it is cheaper to build a buffer, and hash it once, than to
call hash_combine incrementally.
FYI, feel free to ping me on any hashing reviews if there are questions
about how best to use the interface.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120306/524ea0dd/attachment.html>
More information about the llvm-commits
mailing list