mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
IR: Allow temporary nodes to become uniqued or distinct
Add `MDNode::replaceWithUniqued()` and `MDNode::replaceWithDistinct()`, which mutate temporary nodes to become uniqued or distinct. On uniquing collisions, the unique version is returned and the node is deleted. This takes advantage of temporary nodes being folded back in, and should let me clean up some awkward logic in `MapMetadata()`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -438,6 +438,85 @@ TEST_F(MDNodeTest, replaceResolvedOperand) {
|
||||
Temp->replaceAllUsesWith(nullptr);
|
||||
}
|
||||
|
||||
TEST_F(MDNodeTest, replaceWithUniqued) {
|
||||
auto *Empty = MDTuple::get(Context, None);
|
||||
MDTuple *FirstUniqued;
|
||||
{
|
||||
Metadata *Ops[] = {Empty};
|
||||
auto Temp = MDTuple::getTemporary(Context, Ops);
|
||||
EXPECT_TRUE(Temp->isTemporary());
|
||||
|
||||
// Don't expect a collision.
|
||||
auto *Current = Temp.get();
|
||||
FirstUniqued = MDNode::replaceWithUniqued(std::move(Temp));
|
||||
EXPECT_TRUE(FirstUniqued->isUniqued());
|
||||
EXPECT_TRUE(FirstUniqued->isResolved());
|
||||
EXPECT_EQ(Current, FirstUniqued);
|
||||
}
|
||||
{
|
||||
Metadata *Ops[] = {Empty};
|
||||
auto Temp = MDTuple::getTemporary(Context, Ops);
|
||||
EXPECT_TRUE(Temp->isTemporary());
|
||||
|
||||
// Should collide with Uniqued above this time.
|
||||
auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp));
|
||||
EXPECT_TRUE(Uniqued->isUniqued());
|
||||
EXPECT_TRUE(Uniqued->isResolved());
|
||||
EXPECT_EQ(FirstUniqued, Uniqued);
|
||||
}
|
||||
{
|
||||
auto Unresolved = MDTuple::getTemporary(Context, None);
|
||||
Metadata *Ops[] = {Unresolved.get()};
|
||||
auto Temp = MDTuple::getTemporary(Context, Ops);
|
||||
EXPECT_TRUE(Temp->isTemporary());
|
||||
|
||||
// Shouldn't be resolved.
|
||||
auto *Uniqued = MDNode::replaceWithUniqued(std::move(Temp));
|
||||
EXPECT_TRUE(Uniqued->isUniqued());
|
||||
EXPECT_FALSE(Uniqued->isResolved());
|
||||
|
||||
// Should be a different node.
|
||||
EXPECT_NE(FirstUniqued, Uniqued);
|
||||
|
||||
// Should resolve when we update its node (note: be careful to avoid a
|
||||
// collision with any other nodes above).
|
||||
Uniqued->replaceOperandWith(0, nullptr);
|
||||
EXPECT_TRUE(Uniqued->isResolved());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MDNodeTest, replaceWithDistinct) {
|
||||
{
|
||||
auto *Empty = MDTuple::get(Context, None);
|
||||
Metadata *Ops[] = {Empty};
|
||||
auto Temp = MDTuple::getTemporary(Context, Ops);
|
||||
EXPECT_TRUE(Temp->isTemporary());
|
||||
|
||||
// Don't expect a collision.
|
||||
auto *Current = Temp.get();
|
||||
auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp));
|
||||
EXPECT_TRUE(Distinct->isDistinct());
|
||||
EXPECT_TRUE(Distinct->isResolved());
|
||||
EXPECT_EQ(Current, Distinct);
|
||||
}
|
||||
{
|
||||
auto Unresolved = MDTuple::getTemporary(Context, None);
|
||||
Metadata *Ops[] = {Unresolved.get()};
|
||||
auto Temp = MDTuple::getTemporary(Context, Ops);
|
||||
EXPECT_TRUE(Temp->isTemporary());
|
||||
|
||||
// Don't expect a collision.
|
||||
auto *Current = Temp.get();
|
||||
auto *Distinct = MDNode::replaceWithDistinct(std::move(Temp));
|
||||
EXPECT_TRUE(Distinct->isDistinct());
|
||||
EXPECT_TRUE(Distinct->isResolved());
|
||||
EXPECT_EQ(Current, Distinct);
|
||||
|
||||
// Cleanup; required for teardown.
|
||||
Unresolved->replaceAllUsesWith(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
typedef MetadataTest MDLocationTest;
|
||||
|
||||
TEST_F(MDLocationTest, Overflow) {
|
||||
|
Reference in New Issue
Block a user