diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-04-11 14:06:54 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-04-11 14:06:54 +0000 |
commit | 611afc0620aed7827b5fdf9072a1827952b684b6 (patch) | |
tree | 960bae4c0746e76916e5b0e3cdd1faf082ca59ed /include | |
parent | f7c3e5f05199e1202c86198e0827cac19c0f48b5 (diff) | |
download | external_llvm-611afc0620aed7827b5fdf9072a1827952b684b6.zip external_llvm-611afc0620aed7827b5fdf9072a1827952b684b6.tar.gz external_llvm-611afc0620aed7827b5fdf9072a1827952b684b6.tar.bz2 |
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
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Metadata.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h index 0d43852..7f232a3 100644 --- a/include/llvm/Metadata.h +++ b/include/llvm/Metadata.h @@ -75,6 +75,10 @@ class MDNode : public Value, public FoldingSetNode { void operator=(const MDNode &); // DO NOT IMPLEMENT friend class MDNodeOperand; friend class LLVMContextImpl; + friend struct FoldingSetTrait<MDNode>; + + /// NumOperands - If the MDNode is uniqued cache the hash to speed up lookup. + unsigned Hash; /// NumOperands - This many 'MDNodeOperand' items are co-allocated onto the /// end of this MDNode. |