diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-07 21:35:38 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-07 21:35:38 +0000 |
commit | 136ea3f97b64f82666cb6c8803321e7160af16c7 (patch) | |
tree | 21ca2f2877dd309a415e233bc34dfc764a4b9a99 | |
parent | 9d01a5b5e4432ef56b3cfdd3ea56a140ee9326ab (diff) | |
download | bcm5719-llvm-136ea3f97b64f82666cb6c8803321e7160af16c7.tar.gz bcm5719-llvm-136ea3f97b64f82666cb6c8803321e7160af16c7.zip |
IR: Add MDNode::isDistinct()
Add API to indicate whether an `MDNode` is distinct. A distinct node is
not stored in the MDNode uniquing tables, and will never be returned by
`MDNode::get()`.
Although distinct nodes are only currently created by uniquing
collisions (when operands change), PR22111 will allow these nodes to be
explicitly created.
llvm-svn: 225401
-rw-r--r-- | llvm/include/llvm/IR/Metadata.h | 6 | ||||
-rw-r--r-- | llvm/unittests/IR/MetadataTest.cpp | 27 |
2 files changed, 33 insertions, 0 deletions
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h index a010341305c..4ae29132100 100644 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -642,6 +642,12 @@ 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 IsDistinctInContext; } + protected: /// \brief Set an operand. /// diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp index ef071b38a7b..9c4403c4ce0 100644 --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -222,6 +222,33 @@ TEST_F(MDNodeTest, NullOperand) { EXPECT_EQ(N, NullOp); } +TEST_F(MDNodeTest, DistinctOnUniquingCollision) { + // !{} + MDNode *Empty = MDNode::get(Context, None); + ASSERT_TRUE(Empty->isResolved()); + EXPECT_FALSE(Empty->isDistinct()); + + // !{!{}} + Metadata *Wrapped1Ops[] = {Empty}; + MDNode *Wrapped1 = MDNode::get(Context, Wrapped1Ops); + ASSERT_EQ(Empty, Wrapped1->getOperand(0)); + ASSERT_TRUE(Wrapped1->isResolved()); + EXPECT_FALSE(Wrapped1->isDistinct()); + + // !{!{!{}}} + Metadata *Wrapped2Ops[] = {Wrapped1}; + MDNode *Wrapped2 = MDNode::get(Context, Wrapped2Ops); + ASSERT_EQ(Wrapped1, Wrapped2->getOperand(0)); + ASSERT_TRUE(Wrapped2->isResolved()); + EXPECT_FALSE(Wrapped2->isDistinct()); + + // !{!{!{}}} => !{!{}} + Wrapped2->replaceOperandWith(0, Empty); + ASSERT_EQ(Empty, Wrapped2->getOperand(0)); + EXPECT_TRUE(Wrapped2->isDistinct()); + EXPECT_FALSE(Wrapped1->isDistinct()); +} + typedef MetadataTest MetadataAsValueTest; TEST_F(MetadataAsValueTest, MDNode) { |