From de03a8b38d88d278e39e6218ab2f0f7de6a3c161 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Mon, 19 Jan 2015 18:45:35 +0000 Subject: [PATCH] IR: Add isUniqued() and isTemporary() Change `MDNode::isDistinct()` to only apply to 'distinct' nodes (not temporaries), and introduce `MDNode::isUniqued()` and `MDNode::isTemporary()` for the other two possibilities. llvm-svn: 226482 --- llvm/include/llvm/IR/Metadata.h | 10 +++------- llvm/lib/IR/Metadata.cpp | 2 +- llvm/lib/Transforms/Utils/ValueMapper.cpp | 2 +- llvm/unittests/IR/MetadataTest.cpp | 30 +++++++++++++++++++++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index 1238bd0..2b10022 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -646,13 +646,9 @@ public: /// \brief Check if node is fully resolved. bool isResolved() const; - /// \brief Check if node is distinct. - /// - /// Distinct nodes are not uniqued, and will not be returned by \a - /// MDNode::get(). - bool isDistinct() const { - return isStoredDistinctInContext() || isa(this); - } + bool isUniqued() const { return Storage == Uniqued; } + bool isDistinct() const { return Storage == Distinct; } + bool isTemporary() const { return Storage == Temporary; } protected: /// \brief Set an operand. diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp index 714b17e..93778c2 100644 --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -750,7 +750,7 @@ void MDNode::replaceOperandWith(unsigned I, Metadata *New) { if (getOperand(I) == New) return; - if (isDistinct()) { + if (!isUniqued()) { setOperand(I, New); return; } diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 477fba42..5d89858 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -282,7 +282,7 @@ static Metadata *mapUniquedNode(const UniquableMDNode *Node, ValueToValueMapTy &VM, RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, ValueMaterializer *Materializer) { - assert(!Node->isDistinct() && "Expected uniqued node"); + assert(Node->isUniqued() && "Expected uniqued node"); // Create a dummy node in case we have a metadata cycle. MDNodeFwdDecl *Dummy = MDNode::getTemporary(Node->getContext(), None); diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index 83fd0c1..930bebf 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -274,9 +274,33 @@ TEST_F(MDNodeTest, getDistinct) { ASSERT_EQ(Empty, MDNode::get(Context, None)); } -TEST_F(MDNodeTest, TempIsDistinct) { - MDNode *T = MDNode::getTemporary(Context, None); - EXPECT_TRUE(T->isDistinct()); +TEST_F(MDNodeTest, isUniqued) { + MDNode *U = MDTuple::get(Context, None); + MDNode *D = MDTuple::getDistinct(Context, None); + MDNode *T = MDTuple::getTemporary(Context, None); + EXPECT_TRUE(U->isUniqued()); + EXPECT_FALSE(D->isUniqued()); + EXPECT_FALSE(T->isUniqued()); + MDNode::deleteTemporary(T); +} + +TEST_F(MDNodeTest, isDistinct) { + MDNode *U = MDTuple::get(Context, None); + MDNode *D = MDTuple::getDistinct(Context, None); + MDNode *T = MDTuple::getTemporary(Context, None); + EXPECT_FALSE(U->isDistinct()); + EXPECT_TRUE(D->isDistinct()); + EXPECT_FALSE(T->isDistinct()); + MDNode::deleteTemporary(T); +} + +TEST_F(MDNodeTest, isTemporary) { + MDNode *U = MDTuple::get(Context, None); + MDNode *D = MDTuple::getDistinct(Context, None); + MDNode *T = MDTuple::getTemporary(Context, None); + EXPECT_FALSE(U->isTemporary()); + EXPECT_FALSE(D->isTemporary()); + EXPECT_TRUE(T->isTemporary()); MDNode::deleteTemporary(T); } -- 2.7.4