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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226482 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith
2015-01-19 18:45:35 +00:00
parent 5f50874b3d
commit 1d72e18caa
4 changed files with 32 additions and 12 deletions

View File

@ -646,13 +646,9 @@ public:
/// \brief Check if node is fully resolved. /// \brief Check if node is fully resolved.
bool isResolved() const; bool isResolved() const;
/// \brief Check if node is distinct. bool isUniqued() const { return Storage == Uniqued; }
/// bool isDistinct() const { return Storage == Distinct; }
/// Distinct nodes are not uniqued, and will not be returned by \a bool isTemporary() const { return Storage == Temporary; }
/// MDNode::get().
bool isDistinct() const {
return isStoredDistinctInContext() || isa<MDNodeFwdDecl>(this);
}
protected: protected:
/// \brief Set an operand. /// \brief Set an operand.

View File

@ -750,7 +750,7 @@ void MDNode::replaceOperandWith(unsigned I, Metadata *New) {
if (getOperand(I) == New) if (getOperand(I) == New)
return; return;
if (isDistinct()) { if (!isUniqued()) {
setOperand(I, New); setOperand(I, New);
return; return;
} }

View File

@ -282,7 +282,7 @@ static Metadata *mapUniquedNode(const UniquableMDNode *Node,
ValueToValueMapTy &VM, RemapFlags Flags, ValueToValueMapTy &VM, RemapFlags Flags,
ValueMapTypeRemapper *TypeMapper, ValueMapTypeRemapper *TypeMapper,
ValueMaterializer *Materializer) { 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. // Create a dummy node in case we have a metadata cycle.
MDNodeFwdDecl *Dummy = MDNode::getTemporary(Node->getContext(), None); MDNodeFwdDecl *Dummy = MDNode::getTemporary(Node->getContext(), None);

View File

@ -274,9 +274,33 @@ TEST_F(MDNodeTest, getDistinct) {
ASSERT_EQ(Empty, MDNode::get(Context, None)); ASSERT_EQ(Empty, MDNode::get(Context, None));
} }
TEST_F(MDNodeTest, TempIsDistinct) { TEST_F(MDNodeTest, isUniqued) {
MDNode *T = MDNode::getTemporary(Context, None); MDNode *U = MDTuple::get(Context, None);
EXPECT_TRUE(T->isDistinct()); 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); MDNode::deleteTemporary(T);
} }