From: Duncan P. N. Exon Smith Date: Mon, 19 Jan 2015 23:17:09 +0000 (+0000) Subject: IR: Move replaceWithUniqued(), etc., to source file, NFC X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c062fbe4ca6016bf74274003340cb78a56bc4b8c;p=oota-llvm.git IR: Move replaceWithUniqued(), etc., to source file, NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226522 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/Metadata.h b/include/llvm/IR/Metadata.h index 7a5474efa49..e2bfcadc5cf 100644 --- a/include/llvm/IR/Metadata.h +++ b/include/llvm/IR/Metadata.h @@ -774,7 +774,9 @@ public: /// it. Takes ownership of the temporary node. template static typename std::enable_if::value, T *>::type - replaceWithUniqued(std::unique_ptr N); + replaceWithUniqued(std::unique_ptr N) { + return cast(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 static typename std::enable_if::value, T *>::type - replaceWithDistinct(std::unique_ptr N); + replaceWithDistinct(std::unique_ptr N) { + return cast(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 -typename std::enable_if::value, NodeTy *>::type -MDNode::replaceWithUniqued(std::unique_ptr 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(UniquedNode); -} - -template -typename std::enable_if::value, NodeTy *>::type -MDNode::replaceWithDistinct(std::unique_ptr Node) { - Node->makeDistinct(); - return Node.release(); -} - /// \brief Tuple of metadata. /// /// This is the simple \a MDNode arbitrary tuple. Nodes are uniqued by diff --git a/lib/IR/Metadata.cpp b/lib/IR/Metadata.cpp index fb70149330b..3613871207a 100644 --- a/lib/IR/Metadata.cpp +++ b/lib/IR/Metadata.cpp @@ -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)); }