From 1c588db19ba21b4a8c0351bb07dfe7338d868911 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 19 Jan 2015 20:16:50 +0000 Subject: [PATCH] IR: Extract out getUniqued(), NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226498 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Metadata.cpp | 52 +++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index cfa53ef6f33..6513c9a23d2 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -604,19 +604,23 @@ void UniquableMDNode::eraseFromStore() { } } +template +static T *getUniqued(DenseSet &Store, + const typename InfoT::KeyTy &Key) { + auto I = Store.find_as(Key); + return I == Store.end() ? nullptr : *I; +} + MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef MDs, StorageType Storage, bool ShouldCreate) { unsigned Hash = 0; if (Storage == Uniqued) { MDTupleInfo::KeyTy Key(MDs); - Hash = Key.Hash; - - auto &Store = Context.pImpl->MDTuples; - auto I = Store.find_as(Key); - if (I != Store.end()) - return *I; + if (auto *N = getUniqued(Context.pImpl->MDTuples, Key)) + return N; if (!ShouldCreate) return nullptr; + Hash = Key.Hash; } else { assert(ShouldCreate && "Expected non-uniqued nodes to always be created"); } @@ -639,15 +643,12 @@ MDTuple *MDTuple::getImpl(LLVMContext &Context, ArrayRef MDs, MDTuple *MDTuple::uniquifyImpl() { recalculateHash(); - MDTupleInfo::KeyTy Key(this); - auto &Store = getContext().pImpl->MDTuples; - auto I = Store.find_as(Key); - if (I == Store.end()) { - Store.insert(this); - return this; - } - return *I; + if (MDTuple *N = getUniqued(Store, this)) + return N; + + Store.insert(this); + return this; } void MDTuple::eraseFromStoreImpl() { getContext().pImpl->MDTuples.erase(this); } @@ -687,12 +688,10 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line, adjustColumn(Column); if (Storage == Uniqued) { - MDLocationInfo::KeyTy Key(Line, Column, Scope, InlinedAt); - - auto &Store = Context.pImpl->MDLocations; - auto I = Store.find_as(Key); - if (I != Store.end()) - return *I; + if (auto *N = getUniqued( + Context.pImpl->MDLocations, + MDLocationInfo::KeyTy(Line, Column, Scope, InlinedAt))) + return N; if (!ShouldCreate) return nullptr; } else { @@ -720,15 +719,12 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line, } MDLocation *MDLocation::uniquifyImpl() { - MDLocationInfo::KeyTy Key(this); - auto &Store = getContext().pImpl->MDLocations; - auto I = Store.find_as(Key); - if (I == Store.end()) { - Store.insert(this); - return this; - } - return *I; + if (MDLocation *N = getUniqued(Store, this)) + return N; + + Store.insert(this); + return this; } void MDLocation::eraseFromStoreImpl() { -- 2.34.1