From 6205b21cf5e597e6ecfcc73d70dc5a830c28df02 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 12 Jan 2015 19:16:34 +0000 Subject: [PATCH] IR: Separate out recalculateHash(), NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225655 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Metadata.h | 1 + lib/IR/Metadata.cpp | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index d868c4bdc61..8033a17efd7 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -731,6 +731,7 @@ class GenericMDNode : public MDNode { ~GenericMDNode(); void setHash(unsigned Hash) { MDNodeSubclassData = Hash; } + void recalculateHash(); public: /// \brief Get the hash, if any. diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index f303b7d8a71..1ae9a96fe46 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -484,6 +484,18 @@ void GenericMDNode::resolveCycles() { } } +void GenericMDNode::recalculateHash() { + setHash(hash_combine_range(op_begin(), op_end())); +#ifndef NDEBUG + { + SmallVector MDs(op_begin(), op_end()); + unsigned RawHash = hash_combine_range(MDs.begin(), MDs.end()); + assert(getHash() == RawHash && + "Expected hash of MDOperand to equal hash of Metadata*"); + } +#endif +} + void MDNode::dropAllReferences() { for (unsigned I = 0, E = NumOperands; I != E; ++I) setOperand(I, nullptr); @@ -545,18 +557,8 @@ void GenericMDNode::handleChangedOperand(void *Ref, Metadata *New) { return; } - // Re-calculate the hash. - setHash(hash_combine_range(op_begin(), op_end())); -#ifndef NDEBUG - { - SmallVector MDs(op_begin(), op_end()); - unsigned RawHash = hash_combine_range(MDs.begin(), MDs.end()); - assert(getHash() == RawHash && - "Expected hash of MDOperand to equal hash of Metadata*"); - } -#endif - // Re-unique the node. + recalculateHash(); GenericMDNodeInfo::KeyTy Key(this); auto I = Store.find_as(Key); if (I == Store.end()) {