[llvm] r226522 - IR: Move replaceWithUniqued(), etc., to source file, NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Mon Jan 19 15:17:09 PST 2015
Author: dexonsmith
Date: Mon Jan 19 17:17:09 2015
New Revision: 226522
URL: http://llvm.org/viewvc/llvm-project?rev=226522&view=rev
Log:
IR: Move replaceWithUniqued(), etc., to source file, NFC
Modified:
llvm/trunk/include/llvm/IR/Metadata.h
llvm/trunk/lib/IR/Metadata.cpp
Modified: llvm/trunk/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=226522&r1=226521&r2=226522&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.h (original)
+++ llvm/trunk/include/llvm/IR/Metadata.h Mon Jan 19 17:17:09 2015
@@ -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
Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=226522&r1=226521&r2=226522&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Mon Jan 19 17:17:09 2015
@@ -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));
}
More information about the llvm-commits
mailing list