[llvm] r234695 - DebugInfo: Introduce DIBuilder::replaceTemporary()

Duncan P. N. Exon Smith dexonsmith at apple.com
Sat Apr 11 12:04:09 PDT 2015


Author: dexonsmith
Date: Sat Apr 11 14:04:09 2015
New Revision: 234695

URL: http://llvm.org/viewvc/llvm-project?rev=234695&view=rev
Log:
DebugInfo: Introduce DIBuilder::replaceTemporary()

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.

Modified:
    llvm/trunk/include/llvm/IR/DIBuilder.h

Modified: llvm/trunk/include/llvm/IR/DIBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DIBuilder.h?rev=234695&r1=234694&r2=234695&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DIBuilder.h (original)
+++ llvm/trunk/include/llvm/IR/DIBuilder.h Sat Apr 11 14:04:09 2015
@@ -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
 





More information about the llvm-commits mailing list