diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 23:17:09 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-19 23:17:09 +0000 |
| commit | 8647529250d01dc24b57329ecff6bdd4f7ad4cfb (patch) | |
| tree | b147dfce66ac7ba5a366c383a71dd199ab442b98 | |
| parent | a1ae4f6b30205cf49f2109bac0b6c787d8a8767b (diff) | |
| download | bcm5719-llvm-8647529250d01dc24b57329ecff6bdd4f7ad4cfb.tar.gz bcm5719-llvm-8647529250d01dc24b57329ecff6bdd4f7ad4cfb.zip | |
IR: Move replaceWithUniqued(), etc., to source file, NFC
llvm-svn: 226522
| -rw-r--r-- | llvm/include/llvm/IR/Metadata.h | 34 | ||||
| -rw-r--r-- | llvm/lib/IR/Metadata.cpp | 19 |
2 files changed, 29 insertions, 24 deletions
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index 7a5474efa49..e2bfcadc5cf 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -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 diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index fb70149330b..3613871207a 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/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)); } |

