summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Metadata.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 22:52:07 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-01-19 22:52:07 +0000
commitf9d1bc99192da5ace50643bb630ef014bc12cd25 (patch)
tree8f3099452d791d6d629a31d948fdf95f76bb817b /llvm/lib/IR/Metadata.cpp
parent6cf10d27864292722af5886fa1d479cec33ec9c5 (diff)
downloadbcm5719-llvm-f9d1bc99192da5ace50643bb630ef014bc12cd25.tar.gz
bcm5719-llvm-f9d1bc99192da5ace50643bb630ef014bc12cd25.zip
IR: Simplify uniquifyImpl(), NFC
llvm-svn: 226518
Diffstat (limited to 'llvm/lib/IR/Metadata.cpp')
-rw-r--r--llvm/lib/IR/Metadata.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 5f327fad06a..e9265eb96ad 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -614,13 +614,39 @@ void UniquableMDNode::deleteAsSubclass() {
}
}
+template <class T, class InfoT>
+static T *getUniqued(DenseSet<T *, InfoT> &Store,
+ const typename InfoT::KeyTy &Key) {
+ auto I = Store.find_as(Key);
+ return I == Store.end() ? nullptr : *I;
+}
+
+template <class T, class InfoT>
+static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {
+ if (T *U = getUniqued(Store, N))
+ return U;
+
+ Store.insert(N);
+ return N;
+}
+
UniquableMDNode *UniquableMDNode::uniquify() {
+ // Recalculate hash, if necessary.
+ switch (getMetadataID()) {
+ default:
+ break;
+ case MDTupleKind:
+ cast<MDTuple>(this)->recalculateHash();
+ break;
+ }
+
+ // Try to insert into uniquing store.
switch (getMetadataID()) {
default:
llvm_unreachable("Invalid subclass of UniquableMDNode");
#define HANDLE_UNIQUABLE_LEAF(CLASS) \
case CLASS##Kind: \
- return cast<CLASS>(this)->uniquifyImpl();
+ return uniquifyImpl(cast<CLASS>(this), getContext().pImpl->CLASS##s);
#include "llvm/IR/Metadata.def"
}
}
@@ -637,13 +663,6 @@ void UniquableMDNode::eraseFromStore() {
}
}
-template <class T, class InfoT>
-static T *getUniqued(DenseSet<T *, InfoT> &Store,
- const typename InfoT::KeyTy &Key) {
- auto I = Store.find_as(Key);
- return I == Store.end() ? nullptr : *I;
-}
-
template <class T, class StoreT>
T *UniquableMDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
switch (Storage) {
@@ -677,16 +696,6 @@ MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
Storage, Context.pImpl->MDTuples);
}
-MDTuple *MDTuple::uniquifyImpl() {
- recalculateHash();
- auto &Store = getContext().pImpl->MDTuples;
- if (MDTuple *N = getUniqued(Store, this))
- return N;
-
- Store.insert(this);
- return this;
-}
-
MDLocation::MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> MDs)
: UniquableMDNode(C, MDLocationKind, Storage, MDs) {
@@ -741,15 +750,6 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
Storage, Context.pImpl->MDLocations);
}
-MDLocation *MDLocation::uniquifyImpl() {
- auto &Store = getContext().pImpl->MDLocations;
- if (MDLocation *N = getUniqued(Store, this))
- return N;
-
- Store.insert(this);
- return this;
-}
-
void MDNode::deleteTemporary(MDNode *N) {
assert(N->isTemporary() && "Expected temporary node");
cast<UniquableMDNode>(N)->deleteAsSubclass();
OpenPOWER on IntegriCloud