Cache the hash value of the operands in the MDNode.
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 11 Apr 2012 14:06:54 +0000 (14:06 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 11 Apr 2012 14:06:54 +0000 (14:06 +0000)
commit611afc0620aed7827b5fdf9072a1827952b684b6
tree960bae4c0746e76916e5b0e3cdd1faf082ca59ed
parentf7c3e5f05199e1202c86198e0827cac19c0f48b5
Cache the hash value of the operands in the MDNode.

FoldingSet is implemented as a chained hash table. When there is a hash
collision during insertion, which is common as we fill the table until a
load factor of 2.0 is hit, we walk the chained elements, comparing every
operand with the new element's operands. This can be very expensive if the
MDNode has many operands.

We sacrifice a word of space in MDNode to cache the full hash value, reducing
compares on collision to a minimum. MDNode grows from 28 to 32 bytes + operands
on x86. On x86_64 the new bits fit nicely into existing padding, not growing
the struct at all.

The actual speedup depends a lot on the test case and is typically between
1% and 2% for C++ code with clang -c -O0 -g.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154497 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Metadata.h
lib/VMCore/LLVMContextImpl.h
lib/VMCore/Metadata.cpp