DebugInfo: Introduce DIBuilder::replaceTemporary()
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 11 Apr 2015 19:04:09 +0000 (19:04 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Sat, 11 Apr 2015 19:04:09 +0000 (19:04 +0000)
Add `DIBuilder::replaceTemporary()` as a replacement for
`DIDescriptor::replaceAllUsesWith()`.  I'll update clang to use the new
method, and then come back to delete the original.

This method dispatches to `replaceAllUsesWith()` or
`replaceWithUniqued()`, depending on whether the replacement is actually
a different node from the original.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234695 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/DIBuilder.h

index eb5cdd60427ad2807cfeda70b950f26b157b2a75..ac82947741cc584935d47d5865cae78059868f3d 100644 (file)
@@ -701,6 +701,23 @@ namespace llvm {
     /// resolve cycles.
     void replaceArrays(DICompositeType &T, DIArray Elements,
                        DIArray TParems = DIArray());
+
+    /// \brief Replace a temporary node.
+    ///
+    /// Call \a MDNode::replaceAllUsesWith() on \c N, replacing it with \c
+    /// Replacement.
+    ///
+    /// If \c Replacement is the same as \c N.get(), instead call \a
+    /// MDNode::replaceWithUniqued().  In this case, the uniqued node could
+    /// have a different address, so we return the final address.
+    template <class NodeTy>
+    NodeTy *replaceTemporary(TempMDNode &&N, NodeTy *Replacement) {
+      if (N.get() == Replacement)
+        return cast<NodeTy>(MDNode::replaceWithUniqued(std::move(N)));
+
+      N->replaceAllUsesWith(Replacement);
+      return Replacement;
+    }
   };
 } // end namespace llvm