diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 20:18:13 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 20:18:13 +0000 |
commit | 5b8c4401003f6eb597d0dc42f6e38e41f83306c7 (patch) | |
tree | 50b7a4a4e79f0ac8075f73474049381febfb549e /llvm/lib/IR/Metadata.cpp | |
parent | b57f9e9735bf95f151a37635b57dd41086b5fcee (diff) | |
download | bcm5719-llvm-5b8c4401003f6eb597d0dc42f6e38e41f83306c7.tar.gz bcm5719-llvm-5b8c4401003f6eb597d0dc42f6e38e41f83306c7.zip |
IR: Extract out and reuse `storeImpl()`, NFC
llvm-svn: 226499
Diffstat (limited to 'llvm/lib/IR/Metadata.cpp')
-rw-r--r-- | llvm/lib/IR/Metadata.cpp | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 6513c9a23d2..8d83e1652cd 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -611,6 +611,21 @@ static T *getUniqued(DenseSet<T *, InfoT> &Store, 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 &Context, ArrayRef<Metadata *> MDs, 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(LLVMContext &Context, unsigned Line, 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() { |