diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 22:53:18 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 22:53:18 +0000 |
commit | 93e983e70796b047d4a798d23b536ba7ef111565 (patch) | |
tree | 9fc593e5628f9fce6a0de4a0d75b76343314a03c /llvm/lib/IR/LLVMContextImpl.cpp | |
parent | f9d1bc99192da5ace50643bb630ef014bc12cd25 (diff) | |
download | llvm-93e983e70796b047d4a798d23b536ba7ef111565.zip llvm-93e983e70796b047d4a798d23b536ba7ef111565.tar.gz llvm-93e983e70796b047d4a798d23b536ba7ef111565.tar.bz2 |
IR: Extract MDNodeOpsKey, NFC
Make the MDTuple operand hashing logic reusable.
llvm-svn: 226519
Diffstat (limited to 'llvm/lib/IR/LLVMContextImpl.cpp')
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index 01a786d..2fa6780 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -163,6 +163,40 @@ LLVMContextImpl::~LLVMContextImpl() { MDStringCache.clear(); } +namespace llvm { +/// \brief Make MDOperand transparent for hashing. +/// +/// This overload of an implementation detail of the hashing library makes +/// MDOperand hash to the same value as a \a Metadata pointer. +/// +/// Note that overloading \a hash_value() as follows: +/// +/// \code +/// size_t hash_value(const MDOperand &X) { return hash_value(X.get()); } +/// \endcode +/// +/// does not cause MDOperand to be transparent. In particular, a bare pointer +/// doesn't get hashed before it's combined, whereas \a MDOperand would. +static const Metadata *get_hashable_data(const MDOperand &X) { return X.get(); } +} + +unsigned MDNodeOpsKey::calculateHash(MDNode *N) { + unsigned Hash = hash_combine_range(N->op_begin(), N->op_end()); +#ifndef NDEBUG + { + SmallVector<Metadata *, 8> MDs(N->op_begin(), N->op_end()); + unsigned RawHash = calculateHash(MDs); + assert(Hash == RawHash && + "Expected hash of MDOperand to equal hash of Metadata*"); + } +#endif + return Hash; +} + +unsigned MDNodeOpsKey::calculateHash(ArrayRef<Metadata *> Ops) { + return hash_combine_range(Ops.begin(), Ops.end()); +} + // ConstantsContext anchors void UnaryConstantExpr::anchor() { } |