From 4018a7d772fc09c7955eb4c88eea788be5cc2143 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Tue, 6 Aug 2024 07:54:26 +0000 Subject: ART: Clean up HIR construction in gtests. Make `OptimizingUnitTestHelper::Make*()` functions add the the new instruction to the block. If the block already ends with a control flow instruction, the new instruction is inserted before the control flow instruction (some tests create the control flow before adding instruction). Add new helper functions for additional instruction types, rename and clean up existing helpers. Test: m test-art-host-gtest Change-Id: I0bb88bc4d2ff6ce98ddbec25990a1ae68f582042 --- compiler/optimizing/instruction_simplifier_test.cc | 55 +++++++++------------- 1 file changed, 22 insertions(+), 33 deletions(-) (limited to 'compiler/optimizing/instruction_simplifier_test.cc') diff --git a/compiler/optimizing/instruction_simplifier_test.cc b/compiler/optimizing/instruction_simplifier_test.cc index 9f47995cf5..3f49492938 100644 --- a/compiler/optimizing/instruction_simplifier_test.cc +++ b/compiler/optimizing/instruction_simplifier_test.cc @@ -103,18 +103,21 @@ class InstanceOfInstructionSimplifierTestGroup } } - std::pair GetLoadClasses(VariableSizedHandleScope* vshs) { + std::pair GetLoadClasses(HBasicBlock* block, + VariableSizedHandleScope* vshs) { InstanceOfKind kind = GetParam(); ScopedObjectAccess soa(Thread::Current()); // New inst always needs to have a valid rti since we dcheck that. - HLoadClass* new_inst = MakeClassLoad( - /* ti= */ std::nullopt, vshs->NewHandle(GetClassRoot())); + HLoadClass* new_inst = MakeLoadClass( + block, + /* ti= */ std::nullopt, + vshs->NewHandle(GetClassRoot())); new_inst->SetValidLoadedClassRTI(); if (kind == InstanceOfKind::kSelf) { return {new_inst, new_inst}; } if (kind == InstanceOfKind::kUnrelatedUnloaded) { - HLoadClass* target_class = MakeClassLoad(); + HLoadClass* target_class = MakeLoadClass(block); EXPECT_FALSE(target_class->GetLoadedClassRTI().IsValid()); return {new_inst, target_class}; } @@ -122,7 +125,8 @@ class InstanceOfInstructionSimplifierTestGroup // For simplicity we use class-roots as the types. The new-inst will always // be a ClassExt, unrelated-loaded will always be Throwable and super will // always be Object - HLoadClass* target_class = MakeClassLoad( + HLoadClass* target_class = MakeLoadClass( + block, /* ti= */ std::nullopt, vshs->NewHandle(kind == InstanceOfKind::kSupertype ? GetClassRoot() : @@ -165,8 +169,8 @@ TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassInstanceOfOther) { EnsurePredecessorOrder(breturn, {left, right}); HInstruction* test_res = graph_->GetIntConstant(GetConstantResult() ? 1 : 0); - auto [new_inst_klass, target_klass] = GetLoadClasses(&vshs); - HInstruction* new_inst = MakeNewInstance(new_inst_klass); + auto [new_inst_klass, target_klass] = GetLoadClasses(entry, &vshs); + HInstruction* new_inst = MakeNewInstance(entry, new_inst_klass); new_inst->SetReferenceTypeInfo( ReferenceTypeInfo::Create(new_inst_klass->GetClass(), /*is_exact=*/true)); HInstanceOf* instance_of = new (GetAllocator()) HInstanceOf(new_inst, @@ -180,32 +184,23 @@ TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassInstanceOfOther) { if (target_klass->GetLoadedClassRTI().IsValid()) { instance_of->SetValidTargetClassRTI(); } - HInstruction* if_inst = new (GetAllocator()) HIf(instance_of); - entry->AddInstruction(new_inst_klass); - if (new_inst_klass != target_klass) { - entry->AddInstruction(target_klass); - } - entry->AddInstruction(new_inst); entry->AddInstruction(instance_of); - entry->AddInstruction(if_inst); + HIf* if_inst = MakeIf(entry, instance_of); ManuallyBuildEnvFor(new_inst_klass, {}); if (new_inst_klass != target_klass) { target_klass->CopyEnvironmentFrom(new_inst_klass->GetEnvironment()); } new_inst->CopyEnvironmentFrom(new_inst_klass->GetEnvironment()); - HInstruction* goto_left = new (GetAllocator()) HGoto(); - left->AddInstruction(goto_left); + MakeGoto(left); - HInstruction* goto_right = new (GetAllocator()) HGoto(); - right->AddInstruction(goto_right); + MakeGoto(right); - HInstruction* read_bottom = MakeIFieldGet(new_inst, DataType::Type::kInt32, MemberOffset(32)); - HInstruction* return_exit = new (GetAllocator()) HReturn(read_bottom); - breturn->AddInstruction(read_bottom); - breturn->AddInstruction(return_exit); + HInstruction* read_bottom = + MakeIFieldGet(breturn, new_inst, DataType::Type::kInt32, MemberOffset(32)); + MakeReturn(breturn, read_bottom); - SetupExit(exit); + MakeExit(exit); PerformSimplification(blks); @@ -235,8 +230,8 @@ TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassCheckCastOther) { GET_BLOCK(exit); #undef GET_BLOCK - auto [new_inst_klass, target_klass] = GetLoadClasses(&vshs); - HInstruction* new_inst = MakeNewInstance(new_inst_klass); + auto [new_inst_klass, target_klass] = GetLoadClasses(entry, &vshs); + HInstruction* new_inst = MakeNewInstance(entry, new_inst_klass); new_inst->SetReferenceTypeInfo( ReferenceTypeInfo::Create(new_inst_klass->GetClass(), /*is_exact=*/true)); HCheckCast* check_cast = new (GetAllocator()) HCheckCast(new_inst, @@ -250,21 +245,15 @@ TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassCheckCastOther) { if (target_klass->GetLoadedClassRTI().IsValid()) { check_cast->SetValidTargetClassRTI(); } - HInstruction* entry_return = new (GetAllocator()) HReturn(new_inst); - entry->AddInstruction(new_inst_klass); - if (new_inst_klass != target_klass) { - entry->AddInstruction(target_klass); - } - entry->AddInstruction(new_inst); entry->AddInstruction(check_cast); - entry->AddInstruction(entry_return); + MakeReturn(entry, new_inst); ManuallyBuildEnvFor(new_inst_klass, {}); if (new_inst_klass != target_klass) { target_klass->CopyEnvironmentFrom(new_inst_klass->GetEnvironment()); } new_inst->CopyEnvironmentFrom(new_inst_klass->GetEnvironment()); - SetupExit(exit); + MakeExit(exit); PerformSimplification(blks); -- cgit v1.2.3-59-g8ed1b