IR: Remove MDNodeFwdDecl
Remove `MDNodeFwdDecl` (as promised in r226481). Aside from API
changes, there's no real functionality change here.
`MDNode::getTemporary()` now forwards to `MDTuple::getTemporary()`,
which returns a tuple with `isTemporary()` equal to true.
The main point is that we can now add temporaries of other `MDNode`
subclasses, needed for PR22235 (I introduced `MDNodeFwdDecl` in the
first place because I didn't recognize this need, and thought they were
only needed to handle forward references).
A few things left out of (or highlighted by) this commit:
- I've had to remove the (few) uses of `std::unique_ptr<>` to deal
with temporaries, since the destructor is no longer public.
`getTemporary()` should probably return the equivalent of
`std::unique_ptr<T, MDNode::deleteTemporary>`.
- `MDLocation::getTemporary()` doesn't exist yet (worse, it actually
does exist, but does the wrong thing: `MDNode::getTemporary()` is
inherited and returns an `MDTuple`).
- `MDNode` now only has one subclass, `UniquableMDNode`, and the
distinction between them is actually somewhat confusing.
I'll fix those up next.
llvm-svn: 226501
diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 2de1f06..9515f0d 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -167,10 +167,6 @@
delete I;
}
-TEST_F(MDNodeTest, DeleteMDNodeFwdDecl) {
- delete MDNode::getTemporary(Context, None);
-}
-
TEST_F(MDNodeTest, SelfReference) {
// !0 = !{!0}
// !1 = !{!0}
@@ -343,7 +339,7 @@
TEST_F(MDNodeTest, getDistinctWithUnresolvedOperands) {
// temporary !{}
- MDNodeFwdDecl *Temp = MDNode::getTemporary(Context, None);
+ MDTuple *Temp = MDTuple::getTemporary(Context, None);
ASSERT_FALSE(Temp->isResolved());
// distinct !{temporary !{}}
@@ -364,18 +360,19 @@
MDNode *N0 = MDNode::get(Context, None);
// !1 = !{!3, null}
- std::unique_ptr<MDNodeFwdDecl> Temp3(MDNode::getTemporary(Context, None));
- Metadata *Ops1[] = {Temp3.get(), nullptr};
+ MDTuple *Temp3 = MDTuple::getTemporary(Context, None);
+ Metadata *Ops1[] = {Temp3, nullptr};
MDNode *N1 = MDNode::get(Context, Ops1);
// !2 = !{!3, !0}
- Metadata *Ops2[] = {Temp3.get(), N0};
+ Metadata *Ops2[] = {Temp3, N0};
MDNode *N2 = MDNode::get(Context, Ops2);
// !3 = !{!2}
Metadata *Ops3[] = {N2};
MDNode *N3 = MDNode::get(Context, Ops3);
Temp3->replaceAllUsesWith(N3);
+ MDNode::deleteTemporary(Temp3);
// !4 = !{!1}
Metadata *Ops4[] = {N1};
@@ -428,8 +425,8 @@
// a global value that gets RAUW'ed.
//
// Use a temporary node to keep N from being resolved.
- std::unique_ptr<MDNodeFwdDecl> Temp(MDNodeFwdDecl::get(Context, None));
- Metadata *Ops[] = {nullptr, Temp.get()};
+ MDTuple *Temp = MDTuple::getTemporary(Context, None);
+ Metadata *Ops[] = {nullptr, Temp};
MDNode *Empty = MDTuple::get(Context, ArrayRef<Metadata *>());
MDNode *N = MDTuple::get(Context, Ops);
@@ -441,11 +438,12 @@
EXPECT_EQ(Empty, N->getOperand(0));
// Check code for adding another unresolved operand.
- N->replaceOperandWith(0, Temp.get());
- EXPECT_EQ(Temp.get(), N->getOperand(0));
+ N->replaceOperandWith(0, Temp);
+ EXPECT_EQ(Temp, N->getOperand(0));
// Remove the references to Temp; required for teardown.
Temp->replaceAllUsesWith(nullptr);
+ MDNode::deleteTemporary(Temp);
}
typedef MetadataTest MDLocationTest;
@@ -551,11 +549,11 @@
ConstantInt::get(getGlobalContext(), APInt(8, 0)));
// Create a temporary to prevent nodes from resolving.
- std::unique_ptr<MDNodeFwdDecl> Temp(MDNode::getTemporary(Context, None));
+ MDTuple *Temp = MDTuple::getTemporary(Context, None);
// When the first operand of N1 gets reset to nullptr, it'll collide with N2.
- Metadata *Ops1[] = {CI, CI, Temp.get()};
- Metadata *Ops2[] = {nullptr, CI, Temp.get()};
+ Metadata *Ops1[] = {CI, CI, Temp};
+ Metadata *Ops2[] = {nullptr, CI, Temp};
auto *N1 = MDTuple::get(Context, Ops1);
auto *N2 = MDTuple::get(Context, Ops2);
@@ -567,10 +565,11 @@
ValueAsMetadata::handleDeletion(CI->getValue());
EXPECT_EQ(nullptr, N2->getOperand(0));
EXPECT_EQ(nullptr, N2->getOperand(1));
- EXPECT_EQ(Temp.get(), N2->getOperand(2));
+ EXPECT_EQ(Temp, N2->getOperand(2));
// Clean up Temp for teardown.
Temp->replaceAllUsesWith(nullptr);
+ MDNode::deleteTemporary(Temp);
}
typedef MetadataTest TrackingMDRefTest;