llvm.org GIT mirror llvm / 1d72e18
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 Duncan P. N. Exon Smith 5 years ago
4 changed file(s) with 32 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
645645 /// \brief Check if node is fully resolved.
646646 bool isResolved() const;
647647
648 /// \brief Check if node is distinct.
649 ///
650 /// Distinct nodes are not uniqued, and will not be returned by \a
651 /// MDNode::get().
652 bool isDistinct() const {
653 return isStoredDistinctInContext() || isa(this);
654 }
648 bool isUniqued() const { return Storage == Uniqued; }
649 bool isDistinct() const { return Storage == Distinct; }
650 bool isTemporary() const { return Storage == Temporary; }
655651
656652 protected:
657653 /// \brief Set an operand.
749749 if (getOperand(I) == New)
750750 return;
751751
752 if (isDistinct()) {
752 if (!isUniqued()) {
753753 setOperand(I, New);
754754 return;
755755 }
281281 ValueToValueMapTy &VM, RemapFlags Flags,
282282 ValueMapTypeRemapper *TypeMapper,
283283 ValueMaterializer *Materializer) {
284 assert(!Node->isDistinct() && "Expected uniqued node");
284 assert(Node->isUniqued() && "Expected uniqued node");
285285
286286 // Create a dummy node in case we have a metadata cycle.
287287 MDNodeFwdDecl *Dummy = MDNode::getTemporary(Node->getContext(), None);
273273 ASSERT_EQ(Empty, MDNode::get(Context, None));
274274 }
275275
276 TEST_F(MDNodeTest, TempIsDistinct) {
277 MDNode *T = MDNode::getTemporary(Context, None);
278 EXPECT_TRUE(T->isDistinct());
276 TEST_F(MDNodeTest, isUniqued) {
277 MDNode *U = MDTuple::get(Context, None);
278 MDNode *D = MDTuple::getDistinct(Context, None);
279 MDNode *T = MDTuple::getTemporary(Context, None);
280 EXPECT_TRUE(U->isUniqued());
281 EXPECT_FALSE(D->isUniqued());
282 EXPECT_FALSE(T->isUniqued());
283 MDNode::deleteTemporary(T);
284 }
285
286 TEST_F(MDNodeTest, isDistinct) {
287 MDNode *U = MDTuple::get(Context, None);
288 MDNode *D = MDTuple::getDistinct(Context, None);
289 MDNode *T = MDTuple::getTemporary(Context, None);
290 EXPECT_FALSE(U->isDistinct());
291 EXPECT_TRUE(D->isDistinct());
292 EXPECT_FALSE(T->isDistinct());
293 MDNode::deleteTemporary(T);
294 }
295
296 TEST_F(MDNodeTest, isTemporary) {
297 MDNode *U = MDTuple::get(Context, None);
298 MDNode *D = MDTuple::getDistinct(Context, None);
299 MDNode *T = MDTuple::getTemporary(Context, None);
300 EXPECT_FALSE(U->isTemporary());
301 EXPECT_FALSE(D->isTemporary());
302 EXPECT_TRUE(T->isTemporary());
279303 MDNode::deleteTemporary(T);
280304 }
281305