From 94dab79b1cb768088c254349cdf8a14419e69ed6 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Mon, 26 Aug 2024 12:07:52 +0000 Subject: ART: Clean up environment construction in gtests. Create required instruction environments in helper functions that create instructions. Test: m test-art-host-gtest Change-Id: Iacdd3c3717d95bc3e7fc3c1b676bc8eb70f2e6bc --- compiler/optimizing/nodes_test.cc | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'compiler/optimizing/nodes_test.cc') diff --git a/compiler/optimizing/nodes_test.cc b/compiler/optimizing/nodes_test.cc index 01e12a061f..1a1d9ac7da 100644 --- a/compiler/optimizing/nodes_test.cc +++ b/compiler/optimizing/nodes_test.cc @@ -147,13 +147,7 @@ TEST_F(NodeTest, RemoveInstruction) { HInstruction* parameter = MakeParam(DataType::Type::kReference); - HInstruction* null_check = MakeNullCheck(main, parameter); - - HEnvironment* environment = new (GetAllocator()) HEnvironment( - GetAllocator(), 1, graph_->GetArtMethod(), 0, null_check); - null_check->SetRawEnvironment(environment); - environment->SetRawEnvAt(0, parameter); - parameter->AddEnvUseAt(null_check->GetEnvironment(), 0); + HInstruction* null_check = MakeNullCheck(main, parameter, /*env=*/ {parameter}); ASSERT_TRUE(parameter->HasEnvironmentUses()); ASSERT_TRUE(parameter->HasUses()); @@ -209,38 +203,31 @@ TEST_F(NodeTest, ParentEnvironment) { graph->AddBlock(entry); graph->SetEntryBlock(entry); HInstruction* parameter1 = MakeParam(DataType::Type::kReference); - HInstruction* with_environment = MakeNullCheck(entry, parameter1); + HInstruction* with_environment = MakeNullCheck(entry, parameter1, /*env=*/ {parameter1}); MakeExit(entry); ASSERT_TRUE(parameter1->HasUses()); ASSERT_TRUE(parameter1->GetUses().HasExactlyOneElement()); - HEnvironment* environment = new (GetAllocator()) HEnvironment( - GetAllocator(), 1, graph->GetArtMethod(), 0, with_environment); - HInstruction* const array[] = { parameter1 }; - - environment->CopyFrom(ArrayRef(array)); - with_environment->SetRawEnvironment(environment); - ASSERT_TRUE(parameter1->HasEnvironmentUses()); ASSERT_TRUE(parameter1->GetEnvUses().HasExactlyOneElement()); HEnvironment* parent1 = new (GetAllocator()) HEnvironment( GetAllocator(), 1, graph->GetArtMethod(), 0, nullptr); - parent1->CopyFrom(ArrayRef(array)); + parent1->CopyFrom(ArrayRef(¶meter1, 1u)); ASSERT_EQ(parameter1->GetEnvUses().SizeSlow(), 2u); HEnvironment* parent2 = new (GetAllocator()) HEnvironment( GetAllocator(), 1, graph->GetArtMethod(), 0, nullptr); - parent2->CopyFrom(ArrayRef(array)); + parent2->CopyFrom(ArrayRef(¶meter1, 1u)); parent1->SetAndCopyParentChain(GetAllocator(), parent2); // One use for parent2, and one other use for the new parent of parent1. ASSERT_EQ(parameter1->GetEnvUses().SizeSlow(), 4u); // We have copied the parent chain. So we now have two more uses. - environment->SetAndCopyParentChain(GetAllocator(), parent1); + with_environment->GetEnvironment()->SetAndCopyParentChain(GetAllocator(), parent1); ASSERT_EQ(parameter1->GetEnvUses().SizeSlow(), 6u); } -- cgit v1.2.3-59-g8ed1b