IR: Extract out and reuse `storeImpl()`, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 19 Jan 2015 20:18:13 +0000 (20:18 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 19 Jan 2015 20:18:13 +0000 (20:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226499 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Metadata.h
lib/IR/Metadata.cpp

index 8cbd1df9dcbf73e6b087497881122473e5f57d68..bbbb328890f8c927fb8d60238e332ff286bd2313 100644 (file)
@@ -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) {
index 6513c9a23d25ac50e814ea1957e7beacce90569d..8d83e1652cd7de40a2cd11cb512c280220fe9d25 100644 (file)
@@ -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() {