IR: Move replaceWithUniqued(), etc., to source file, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 19 Jan 2015 23:17:09 +0000 (23:17 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 19 Jan 2015 23:17:09 +0000 (23:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226522 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7a5474efa495e262b348c545e3ce7e8def11b04c..e2bfcadc5cf5c2f063b601d41ab2aac0f1fff642 100644 (file)
@@ -774,7 +774,9 @@ public:
   /// it.  Takes ownership of the temporary node.
   template <class T>
   static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
-  replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N);
+  replaceWithUniqued(std::unique_ptr<T, TempMDNodeDeleter> N) {
+    return cast<T>(N.release()->replaceWithUniquedImpl());
+  }
 
   /// \brief Replace a temporary node with a distinct one.
   ///
@@ -782,7 +784,13 @@ public:
   /// it.  Takes ownership of the temporary node.
   template <class T>
   static typename std::enable_if<std::is_base_of<MDNode, T>::value, T *>::type
-  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N);
+  replaceWithDistinct(std::unique_ptr<T, TempMDNodeDeleter> N) {
+    return cast<T>(N.release()->replaceWithDistinctImpl());
+  }
+
+private:
+  MDNode *replaceWithUniquedImpl();
+  MDNode *replaceWithDistinctImpl();
 
 protected:
   /// \brief Set an operand.
@@ -856,28 +864,6 @@ public:
   static MDNode *getMostGenericRange(MDNode *A, MDNode *B);
 };
 
-template <class NodeTy>
-typename std::enable_if<std::is_base_of<MDNode, NodeTy>::value, NodeTy *>::type
-MDNode::replaceWithUniqued(std::unique_ptr<NodeTy, TempMDNodeDeleter> Node) {
-  // Try to uniquify in place.
-  MDNode *UniquedNode = Node->uniquify();
-  if (UniquedNode == Node.get()) {
-    Node->makeUniqued();
-    return Node.release();
-  }
-
-  // Collision, so RAUW instead.
-  Node->replaceAllUsesWith(UniquedNode);
-  return cast<NodeTy>(UniquedNode);
-}
-
-template <class NodeTy>
-typename std::enable_if<std::is_base_of<MDNode, NodeTy>::value, NodeTy *>::type
-MDNode::replaceWithDistinct(std::unique_ptr<NodeTy, TempMDNodeDeleter> Node) {
-  Node->makeDistinct();
-  return Node.release();
-}
-
 /// \brief Tuple of metadata.
 ///
 /// This is the simple \a MDNode arbitrary tuple.  Nodes are uniqued by
index fb70149330b5c481af762b3ac060e86aab4a5ea0..3613871207a4e9aada4b12d52ac7cee29a9377db 100644 (file)
@@ -509,6 +509,25 @@ void MDNode::resolveCycles() {
   }
 }
 
+MDNode *MDNode::replaceWithUniquedImpl() {
+  // Try to uniquify in place.
+  MDNode *UniquedNode = uniquify();
+  if (UniquedNode == this) {
+    makeUniqued();
+    return this;
+  }
+
+  // Collision, so RAUW instead.
+  replaceAllUsesWith(UniquedNode);
+  deleteAsSubclass();
+  return UniquedNode;
+}
+
+MDNode *MDNode::replaceWithDistinctImpl() {
+  makeDistinct();
+  return this;
+}
+
 void MDTuple::recalculateHash() {
   setHash(MDTupleInfo::KeyTy::calculateHash(this));
 }