mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-19 10:53:55 +00:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225401 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
699e5d7bc9
commit
ee06e126b7
@ -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.
|
||||
///
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user