[llvm] r226499 - IR: Extract out and reuse `storeImpl()`, NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jan 19 12:18:14 PST 2015
Author: dexonsmith
Date: Mon Jan 19 14:18:13 2015
New Revision: 226499
URL: http://llvm.org/viewvc/llvm-project?rev=226499&view=rev
Log:
IR: Extract out and reuse `storeImpl()`, NFC
Modified:
llvm/trunk/include/llvm/IR/Metadata.h
llvm/trunk/lib/IR/Metadata.cpp
Modified: llvm/trunk/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=226499&r1=226498&r2=226499&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.h (original)
+++ llvm/trunk/include/llvm/IR/Metadata.h Mon Jan 19 14:18:13 2015
@@ -820,6 +820,8 @@ protected:
~UniquableMDNode() {}
void storeDistinctInContext();
+ template <class T, class StoreT>
+ static T *storeImpl(T *N, StorageType Storage, StoreT &Store);
public:
static bool classof(const Metadata *MD) {
Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=226499&r1=226498&r2=226499&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Mon Jan 19 14:18:13 2015
@@ -611,6 +611,21 @@ static T *getUniqued(DenseSet<T *, InfoT
return I == Store.end() ? nullptr : *I;
}
+template <class T, class StoreT>
+T *UniquableMDNode::storeImpl(T *N, StorageType Storage, StoreT &Store) {
+ switch (Storage) {
+ case Uniqued:
+ Store.insert(N);
+ break;
+ case Distinct:
+ N->storeDistinctInContext();
+ break;
+ case Temporary:
+ llvm_unreachable("Unexpected temporary node");
+ }
+ return N;
+}
+
MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef<Metadata *> MDs,
StorageType Storage, bool ShouldCreate) {
unsigned Hash = 0;
@@ -625,20 +640,8 @@ MDTuple *MDTuple::getImpl(LLVMContext &C
assert(ShouldCreate && "Expected non-uniqued nodes to always be created");
}
- auto *N = new (MDs.size()) MDTuple(Context, Storage, Hash, MDs);
-
- switch (Storage) {
- case Uniqued:
- Context.pImpl->MDTuples.insert(N);
- break;
- case Distinct:
- N->storeDistinctInContext();
- break;
- case Temporary:
- llvm_unreachable("Unexpected temporary node");
- }
-
- return N;
+ return storeImpl(new (MDs.size()) MDTuple(Context, Storage, Hash, MDs),
+ Storage, Context.pImpl->MDTuples);
}
MDTuple *MDTuple::uniquifyImpl() {
@@ -702,20 +705,9 @@ MDLocation *MDLocation::getImpl(LLVMCont
Ops.push_back(Scope);
if (InlinedAt)
Ops.push_back(InlinedAt);
- auto *N = new (Ops.size()) MDLocation(Context, Storage, Line, Column, Ops);
-
- switch (Storage) {
- case Uniqued:
- Context.pImpl->MDLocations.insert(N);
- break;
- case Distinct:
- N->storeDistinctInContext();
- break;
- case Temporary:
- llvm_unreachable("Unexpected temporary node");
- }
-
- return N;
+ return storeImpl(new (Ops.size())
+ MDLocation(Context, Storage, Line, Column, Ops),
+ Storage, Context.pImpl->MDLocations);
}
MDLocation *MDLocation::uniquifyImpl() {
More information about the llvm-commits
mailing list