summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 668bd8c)
raw | patch | inline | side by side (parent: 668bd8c)
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | |
Mon, 19 Jan 2015 22:52:07 +0000 (22:52 +0000) | ||
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | |
Mon, 19 Jan 2015 22:52:07 +0000 (22:52 +0000) |
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226518 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/Metadata.h | patch | blob | history | |
lib/IR/Metadata.cpp | patch | blob | history |
index 8ce2726899645ffbf268c401f32c48605d12a8f5..449403f2a5e7b9f9ccdb027e0647d4d53b26e890 100644 (file)
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDTupleKind;
}
-
-private:
- MDTuple *uniquifyImpl();
};
MDTuple *MDNode::get(LLVMContext &Context, ArrayRef<Metadata *> MDs) {
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDLocationKind;
}
-
-private:
- MDLocation *uniquifyImpl();
};
//===----------------------------------------------------------------------===//
diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp
index 5f327fad06a02b9612fc1afae2850ccd7e581f1a..e9265eb96ad44081ab7dca949af4dd59b9c738d8 100644 (file)
--- a/lib/IR/Metadata.cpp
+++ b/lib/IR/Metadata.cpp
}
}
+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"
}
}
}
}
-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) {
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) {
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();