IR: Detect whether to call recalculateHash() via SFINAE, NFC

Rather than relying on updating switch statements correctly, detect
whether `setHash()` exists in the subclass.  If so, call
`recalculateHash()` and `setHash(0)` appropriately.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226531 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-20 00:57:33 +00:00
parent 0a9f921686
commit c10ef2df5c
2 changed files with 47 additions and 18 deletions

View File

@@ -825,6 +825,20 @@ private:
MDNode *uniquify();
void eraseFromStore();
template <class NodeTy> struct HasCachedHash;
template <class NodeTy>
static void dispatchRecalculateHash(NodeTy *N, std::true_type) {
N->recalculateHash();
}
template <class NodeTy>
static void dispatchRecalculateHash(NodeTy *N, std::false_type) {}
template <class NodeTy>
static void dispatchResetHash(NodeTy *N, std::true_type) {
N->setHash(0);
}
template <class NodeTy>
static void dispatchResetHash(NodeTy *N, std::false_type) {}
public:
typedef const MDOperand *op_iterator;
typedef iterator_range<op_iterator> op_range;