summaryrefslogtreecommitdiff
path: root/compiler/optimizing
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2024-08-26 12:07:52 +0000
committer VladimĂ­r Marko <vmarko@google.com> 2024-08-27 15:22:50 +0000
commit94dab79b1cb768088c254349cdf8a14419e69ed6 (patch)
tree08435eb4305c42ac16dc39579f0d2ebb07d449d1 /compiler/optimizing
parent581f40f6612a2a2d31e9f91ffe50b7c362490af2 (diff)
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
Diffstat (limited to 'compiler/optimizing')
-rw-r--r--compiler/optimizing/instruction_simplifier_test.cc10
-rw-r--r--compiler/optimizing/load_store_analysis_test.cc4
-rw-r--r--compiler/optimizing/load_store_elimination_test.cc220
-rw-r--r--compiler/optimizing/nodes_test.cc23
-rw-r--r--compiler/optimizing/optimizing_unit_test.h30
-rw-r--r--compiler/optimizing/select_generator_test.cc4
-rw-r--r--compiler/optimizing/ssa_liveness_analysis_test.cc43
-rw-r--r--compiler/optimizing/superblock_cloner_test.cc15
8 files changed, 109 insertions, 240 deletions
diff --git a/compiler/optimizing/instruction_simplifier_test.cc b/compiler/optimizing/instruction_simplifier_test.cc
index e140c4d058..a2e3882c19 100644
--- a/compiler/optimizing/instruction_simplifier_test.cc
+++ b/compiler/optimizing/instruction_simplifier_test.cc
@@ -173,11 +173,6 @@ TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassInstanceOfOther) {
}
if_block->AddInstruction(instance_of);
HIf* if_inst = MakeIf(if_block, 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* read_bottom =
MakeIFieldGet(breturn, new_inst, DataType::Type::kInt32, MemberOffset(32));
@@ -222,11 +217,6 @@ TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassCheckCastOther) {
}
main->AddInstruction(check_cast);
MakeReturn(main, 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());
PerformSimplification();
diff --git a/compiler/optimizing/load_store_analysis_test.cc b/compiler/optimizing/load_store_analysis_test.cc
index b53e224ab5..b6a7cd9c76 100644
--- a/compiler/optimizing/load_store_analysis_test.cc
+++ b/compiler/optimizing/load_store_analysis_test.cc
@@ -642,9 +642,6 @@ TEST_F(LoadStoreAnalysisTest, PartialPhiPropagation1) {
HInstruction* new_inst = MakeNewInstance(start, cls);
HInstruction* store = MakeIFieldSet(start, new_inst, c12, MemberOffset(32));
MakeIf(start, param1);
- ArenaVector<HInstruction*> current_locals({}, GetAllocator()->Adapter(kArenaAllocInstruction));
- ManuallyBuildEnvFor(cls, &current_locals);
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
MakeIf(left, param2);
@@ -652,7 +649,6 @@ TEST_F(LoadStoreAnalysisTest, PartialPhiPropagation1) {
HInstruction* call_left = MakeInvokeStatic(left_merge, DataType::Type::kVoid, {left_phi});
MakeGoto(left_merge);
left_phi->SetCanBeNull(true);
- call_left->CopyEnvironmentFrom(cls->GetEnvironment());
HPhi* return_phi = MakePhi(breturn, {left_phi, obj_param});
HInstruction* read_exit =
diff --git a/compiler/optimizing/load_store_elimination_test.cc b/compiler/optimizing/load_store_elimination_test.cc
index 416e5843ef..569760e99e 100644
--- a/compiler/optimizing/load_store_elimination_test.cc
+++ b/compiler/optimizing/load_store_elimination_test.cc
@@ -116,21 +116,14 @@ class LoadStoreEliminationTestBase : public SuperTest, public OptimizingUnitTest
CreateEntryBlockInstructions();
- std::tie(phi_, std::ignore) = MakeLinearLoopVar(loop_, loop_, /*initial=*/ 0, /*increment=*/ 1);
-
// loop block:
// suspend_check
// phi++;
// if (phi >= 128)
- suspend_check_ = MakeSuspendCheck(loop_);
+ suspend_check_ = MakeSuspendCheck(loop_, /*env=*/ {array_, i_, j_});
+ std::tie(phi_, std::ignore) = MakeLinearLoopVar(loop_, loop_, /*initial=*/ 0, /*increment=*/ 1);
HInstruction* cmp = MakeCondition(loop_, kCondGE, phi_, c128);
MakeIf(loop_, cmp);
-
- CreateEnvForSuspendCheck();
- }
-
- void CreateEnvForSuspendCheck() {
- ManuallyBuildEnvFor(suspend_check_, {array_, i_, j_});
}
// Create the diamond-shaped CFG:
@@ -203,38 +196,6 @@ class LoadStoreEliminationTestBase : public SuperTest, public OptimizingUnitTest
return vstore;
}
- // Add a HArrayGet instruction to the end of the provided basic block.
- //
- // Return: the created HArrayGet instruction.
- HInstruction* AddArrayGet(HBasicBlock* block, HInstruction* array, HInstruction* index) {
- DCHECK(block != nullptr);
- DCHECK(array != nullptr);
- DCHECK(index != nullptr);
- HInstruction* get = new (GetAllocator()) HArrayGet(array, index, DataType::Type::kInt32, 0);
- block->InsertInstructionBefore(get, block->GetLastInstruction());
- return get;
- }
-
- // Add a HArraySet instruction to the end of the provided basic block.
- // If no data is specified, generate HArraySet: array[index] = 1.
- //
- // Return: the created HArraySet instruction.
- HInstruction* AddArraySet(HBasicBlock* block,
- HInstruction* array,
- HInstruction* index,
- HInstruction* data = nullptr) {
- DCHECK(block != nullptr);
- DCHECK(array != nullptr);
- DCHECK(index != nullptr);
- if (data == nullptr) {
- data = graph_->GetIntConstant(1);
- }
- HInstruction* store =
- new (GetAllocator()) HArraySet(array, index, data, DataType::Type::kInt32, 0);
- block->InsertInstructionBefore(store, block->GetLastInstruction());
- return store;
- }
-
void InitGraphAndParameters() {
return_block_ = InitEntryMainExitGraphWithReturnVoid();
array_ = MakeParam(DataType::Type::kInt32);
@@ -281,12 +242,12 @@ TEST_F(LoadStoreEliminationTest, ArrayGetSetElimination) {
// array[1] = 1; <--- Remove, since it stores same value.
// array[i] = 3; <--- MAY alias.
// array[1] = 1; <--- Cannot remove, even if it stores the same value.
- AddArraySet(entry_block_, array_, c1, c1);
- HInstruction* load1 = AddArrayGet(entry_block_, array_, c1);
- HInstruction* load2 = AddArrayGet(entry_block_, array_, c2);
- HInstruction* store1 = AddArraySet(entry_block_, array_, c1, c1);
- AddArraySet(entry_block_, array_, i_, c3);
- HInstruction* store2 = AddArraySet(entry_block_, array_, c1, c1);
+ MakeArraySet(entry_block_, array_, c1, c1);
+ HInstruction* load1 = MakeArrayGet(entry_block_, array_, c1, DataType::Type::kInt32);
+ HInstruction* load2 = MakeArrayGet(entry_block_, array_, c2, DataType::Type::kInt32);
+ HInstruction* store1 = MakeArraySet(entry_block_, array_, c1, c1);
+ MakeArraySet(entry_block_, array_, i_, c3);
+ HInstruction* store2 = MakeArraySet(entry_block_, array_, c1, c1);
PerformLSE();
@@ -307,10 +268,10 @@ TEST_F(LoadStoreEliminationTest, SameHeapValue1) {
// array[2] = 1;
// array[1] = 1; <--- Can remove.
// array[1] = 2; <--- Can NOT remove.
- AddArraySet(entry_block_, array_, c1, c1);
- AddArraySet(entry_block_, array_, c2, c1);
- HInstruction* store1 = AddArraySet(entry_block_, array_, c1, c1);
- HInstruction* store2 = AddArraySet(entry_block_, array_, c1, c2);
+ MakeArraySet(entry_block_, array_, c1, c1);
+ MakeArraySet(entry_block_, array_, c2, c1);
+ HInstruction* store1 = MakeArraySet(entry_block_, array_, c1, c1);
+ HInstruction* store2 = MakeArraySet(entry_block_, array_, c1, c2);
PerformLSE();
@@ -364,10 +325,10 @@ TEST_F(LoadStoreEliminationTest, OverlappingLoadStore) {
// .. = a[i]; <-- Remove.
// a[i,i+1,i+2,i+3] = data; <-- PARTIAL OVERLAP !
// .. = a[i]; <-- Cannot remove.
- AddArraySet(entry_block_, array_, i_, c1);
- HInstruction* load1 = AddArrayGet(entry_block_, array_, i_);
+ MakeArraySet(entry_block_, array_, i_, c1);
+ HInstruction* load1 = MakeArrayGet(entry_block_, array_, i_, DataType::Type::kInt32);
AddVecStore(entry_block_, array_, i_);
- HInstruction* load2 = AddArrayGet(entry_block_, array_, i_);
+ HInstruction* load2 = MakeArrayGet(entry_block_, array_, i_, DataType::Type::kInt32);
// Test LSE handling vector load/store partial overlap.
// a[i,i+1,i+2,i+3] = data;
@@ -390,7 +351,7 @@ TEST_F(LoadStoreEliminationTest, OverlappingLoadStore) {
// a[i+1] = 1; <-- PARTIAL OVERLAP !
// .. = a[i,i+1,i+2,i+3];
AddVecStore(entry_block_, array_, i_);
- AddArraySet(entry_block_, array_, i_, c1);
+ MakeArraySet(entry_block_, array_, i_, c1);
HInstruction* vload5 = AddVecLoad(entry_block_, array_, i_);
// TODO: enable LSE for graphs with predicated SIMD.
@@ -419,14 +380,14 @@ TEST_F(LoadStoreEliminationTest, StoreAfterLoopWithoutSideEffects) {
HInstruction* c1 = graph_->GetIntConstant(1);
// a[j] = 1
- AddArraySet(pre_header_, array_, j_, c1);
+ MakeArraySet(pre_header_, array_, j_, c1);
// LOOP BODY:
// .. = a[i,i+1,i+2,i+3];
AddVecLoad(loop_, array_, phi_);
// a[j] = 1;
- HInstruction* array_set = AddArraySet(return_block_, array_, j_, c1);
+ HInstruction* array_set = MakeArraySet(return_block_, array_, j_, c1);
// TODO: enable LSE for graphs with predicated SIMD.
graph_->SetHasTraditionalSIMD(true);
@@ -455,7 +416,7 @@ TEST_F(LoadStoreEliminationTest, StoreAfterSIMDLoopWithSideEffects) {
array_b->CopyEnvironmentFrom(suspend_check_->GetEnvironment());
// a[j] = 0;
- AddArraySet(pre_header_, array_, j_, c0);
+ MakeArraySet(pre_header_, array_, j_, c0);
// LOOP BODY:
// a[phi,phi+1,phi+2,phi+3] = [1,1,1,1];
@@ -465,7 +426,7 @@ TEST_F(LoadStoreEliminationTest, StoreAfterSIMDLoopWithSideEffects) {
AddVecStore(loop_, array_b, phi_, vload);
// a[j] = 0;
- HInstruction* a_set = AddArraySet(return_block_, array_, j_, c0);
+ HInstruction* a_set = MakeArraySet(return_block_, array_, j_, c0);
// TODO: enable LSE for graphs with predicated SIMD.
graph_->SetHasTraditionalSIMD(true);
@@ -495,7 +456,7 @@ TEST_F(LoadStoreEliminationTest, LoadAfterSIMDLoopWithSideEffects) {
array_b->CopyEnvironmentFrom(suspend_check_->GetEnvironment());
// a[j] = 0;
- AddArraySet(pre_header_, array_, j_, c0);
+ MakeArraySet(pre_header_, array_, j_, c0);
// LOOP BODY:
// a[phi,phi+1,phi+2,phi+3] = [1,1,1,1];
@@ -505,7 +466,7 @@ TEST_F(LoadStoreEliminationTest, LoadAfterSIMDLoopWithSideEffects) {
AddVecStore(loop_, array_b, phi_, vload);
// x = a[j];
- HInstruction* load = AddArrayGet(return_block_, array_, j_);
+ HInstruction* load = MakeArrayGet(return_block_, array_, j_, DataType::Type::kInt32);
// TODO: enable LSE for graphs with predicated SIMD.
graph_->SetHasTraditionalSIMD(true);
@@ -571,17 +532,19 @@ TEST_F(LoadStoreEliminationTest, MergePredecessorVecStores) {
TEST_F(LoadStoreEliminationTest, MergePredecessorStores) {
auto [upper, left, right, down] = CreateDiamondShapedCFG();
- // upper: a[i,... i + 3] = [1,...1]
- AddArraySet(upper, array_, i_);
+ HInstruction* c1 = graph_->GetIntConstant(1);
- // left: a[i,... i + 3] = [1,...1]
- HInstruction* store1 = AddArraySet(left, array_, i_);
+ // upper: a[i] = 1
+ MakeArraySet(upper, array_, i_, c1);
- // right: a[i+1, ... i + 4] = [1, ... 1]
- HInstruction* store2 = AddArraySet(right, array_, i_add1_);
+ // left: a[i] = 1
+ HInstruction* store1 = MakeArraySet(left, array_, i_, c1);
- // down: a[i,... i + 3] = [1,...1]
- HInstruction* store3 = AddArraySet(down, array_, i_);
+ // right: a[i+1] = 1
+ HInstruction* store2 = MakeArraySet(right, array_, i_add1_, c1);
+
+ // down: a[i] = 1
+ HInstruction* store3 = MakeArraySet(down, array_, i_, c1);
PerformLSE();
@@ -655,16 +618,16 @@ TEST_F(LoadStoreEliminationTest, StoreAfterLoopWithSideEffects) {
// loop:
// b[i] = array[i]
// array[0] = 2
- HInstruction* store1 = AddArraySet(entry_block_, array_, c0, c2);
+ HInstruction* store1 = MakeArraySet(entry_block_, array_, c0, c2);
HInstruction* array_b = new (GetAllocator()) HNewArray(c0, c128, 0, 0);
pre_header_->InsertInstructionBefore(array_b, pre_header_->GetLastInstruction());
array_b->CopyEnvironmentFrom(suspend_check_->GetEnvironment());
- HInstruction* load = AddArrayGet(loop_, array_, phi_);
- HInstruction* store2 = AddArraySet(loop_, array_b, phi_, load);
+ HInstruction* load = MakeArrayGet(loop_, array_, phi_, DataType::Type::kInt32);
+ HInstruction* store2 = MakeArraySet(loop_, array_b, phi_, load);
- HInstruction* store3 = AddArraySet(return_block_, array_, c0, c2);
+ HInstruction* store3 = MakeArraySet(return_block_, array_, c0, c2);
PerformLSE();
@@ -688,12 +651,12 @@ TEST_F(LoadStoreEliminationTest, StoreAfterLoopWithSideEffects2) {
// loop:
// array2[i] = array[i]
// array[0] = 2
- HInstruction* store1 = AddArraySet(pre_header_, array_, c0, c2);
+ HInstruction* store1 = MakeArraySet(pre_header_, array_, c0, c2);
- HInstruction* load = AddArrayGet(loop_, array_, phi_);
- HInstruction* store2 = AddArraySet(loop_, array2, phi_, load);
+ HInstruction* load = MakeArrayGet(loop_, array_, phi_, DataType::Type::kInt32);
+ HInstruction* store2 = MakeArraySet(loop_, array2, phi_, load);
- HInstruction* store3 = AddArraySet(return_block_, array_, c0, c2);
+ HInstruction* store3 = MakeArraySet(return_block_, array_, c0, c2);
PerformLSE();
@@ -768,8 +731,8 @@ TEST_F(LoadStoreEliminationTest, LoadDefaultValueInLoopWithoutWriteSideEffects)
// LOOP BODY:
// v = a[i]
// array[0] = v
- HInstruction* load = AddArrayGet(loop_, array_a, phi_);
- HInstruction* store = AddArraySet(return_block_, array_, c0, load);
+ HInstruction* load = MakeArrayGet(loop_, array_a, phi_, DataType::Type::kInt32);
+ HInstruction* store = MakeArraySet(return_block_, array_, c0, load);
PerformLSE();
@@ -791,8 +754,8 @@ TEST_F(LoadStoreEliminationTest, LoadDefaultValue) {
// v = a[0]
// array[0] = v
- HInstruction* load = AddArrayGet(pre_header_, array_a, c0);
- HInstruction* store = AddArraySet(return_block_, array_, c0, load);
+ HInstruction* load = MakeArrayGet(pre_header_, array_a, c0, DataType::Type::kInt32);
+ HInstruction* store = MakeArraySet(return_block_, array_, c0, load);
PerformLSE();
@@ -819,9 +782,9 @@ TEST_F(LoadStoreEliminationTest, VLoadAndLoadDefaultValueInLoopWithoutWriteSideE
// array[0,... 3] = v
// array[0] = v1
HInstruction* vload = AddVecLoad(loop_, array_a, phi_);
- HInstruction* load = AddArrayGet(loop_, array_a, phi_);
+ HInstruction* load = MakeArrayGet(loop_, array_a, phi_, DataType::Type::kInt32);
HInstruction* vstore = AddVecStore(return_block_, array_, c0, vload);
- HInstruction* store = AddArraySet(return_block_, array_, c0, load);
+ HInstruction* store = MakeArraySet(return_block_, array_, c0, load);
// TODO: enable LSE for graphs with predicated SIMD.
graph_->SetHasTraditionalSIMD(true);
@@ -851,9 +814,9 @@ TEST_F(LoadStoreEliminationTest, VLoadAndLoadDefaultValue) {
// array[0,... 3] = v
// array[0] = v1
HInstruction* vload = AddVecLoad(pre_header_, array_a, c0);
- HInstruction* load = AddArrayGet(pre_header_, array_a, c0);
+ HInstruction* load = MakeArrayGet(pre_header_, array_a, c0, DataType::Type::kInt32);
HInstruction* vstore = AddVecStore(return_block_, array_, c0, vload);
- HInstruction* store = AddArraySet(return_block_, array_, c0, load);
+ HInstruction* store = MakeArraySet(return_block_, array_, c0, load);
// TODO: enable LSE for graphs with predicated SIMD.
graph_->SetHasTraditionalSIMD(true);
@@ -940,7 +903,6 @@ TEST_F(LoadStoreEliminationTest, DefaultShadowClass) {
HBasicBlock* main = InitEntryMainExitGraph();
HInstruction* suspend_check = MakeSuspendCheck(entry_block_);
- ManuallyBuildEnvFor(suspend_check, {});
HInstruction* cls = MakeLoadClass(main);
HInstruction* new_inst = MakeNewInstance(main, cls);
@@ -951,8 +913,6 @@ TEST_F(LoadStoreEliminationTest, DefaultShadowClass) {
HInstruction* get_field =
MakeIFieldGet(main, new_inst, DataType::Type::kReference, mirror::Object::ClassOffset());
HReturn* return_val = MakeReturn(main, get_field);
- cls->CopyEnvironmentFrom(suspend_check->GetEnvironment());
- new_inst->CopyEnvironmentFrom(suspend_check->GetEnvironment());
PerformLSE();
@@ -975,7 +935,6 @@ TEST_F(LoadStoreEliminationTest, DefaultShadowMonitor) {
HBasicBlock* main = InitEntryMainExitGraph();
HInstruction* suspend_check = MakeSuspendCheck(entry_block_);
- ManuallyBuildEnvFor(suspend_check, {});
HInstruction* cls = MakeLoadClass(main);
HInstruction* new_inst = MakeNewInstance(main, cls);
@@ -986,8 +945,6 @@ TEST_F(LoadStoreEliminationTest, DefaultShadowMonitor) {
HInstruction* get_field =
MakeIFieldGet(main, new_inst, DataType::Type::kInt32, mirror::Object::MonitorOffset());
HReturn* return_val = MakeReturn(main, get_field);
- cls->CopyEnvironmentFrom(suspend_check->GetEnvironment());
- new_inst->CopyEnvironmentFrom(suspend_check->GetEnvironment());
PerformLSE();
@@ -1022,30 +979,26 @@ TEST_F(LoadStoreEliminationTest, ArrayLoopOverlap) {
// preheader
HInstruction* alloc_w = MakeNewArray(preheader, zero_const, eighty_const);
- ManuallyBuildEnvFor(alloc_w, {});
// loop-start
auto [i_phi, i_add] = MakeLinearLoopVar(loop, body, one_const, one_const);
HPhi* t_phi = MakePhi(loop, {zero_const, /* placeholder */ zero_const});
- HInstruction* suspend = MakeSuspendCheck(loop);
+ std::initializer_list<HInstruction*> common_env{alloc_w, i_phi, t_phi};
+ HInstruction* suspend = MakeSuspendCheck(loop, common_env);
HInstruction* i_cmp_top = MakeCondition(loop, kCondGE, i_phi, eighty_const);
HIf* loop_if = MakeIf(loop, i_cmp_top);
CHECK(loop_if->IfTrueSuccessor() == ret);
- // environment
- ManuallyBuildEnvFor(suspend, { alloc_w, i_phi, t_phi });
-
// BODY
HInstruction* last_i = MakeBinOp<HSub>(body, DataType::Type::kInt32, i_phi, one_const);
HInstruction* last_get = MakeArrayGet(body, alloc_w, last_i, DataType::Type::kInt32);
- HInvoke* body_value = MakeInvokeStatic(body, DataType::Type::kInt32, { last_get, one_const });
+ HInvoke* body_value =
+ MakeInvokeStatic(body, DataType::Type::kInt32, { last_get, one_const }, common_env);
HInstruction* body_set = MakeArraySet(body, alloc_w, i_phi, body_value, DataType::Type::kInt32);
HInstruction* body_get = MakeArrayGet(body, alloc_w, i_phi, DataType::Type::kInt32);
- HInvoke* t_next = MakeInvokeStatic(body, DataType::Type::kInt32, { body_get, t_phi });
- body_value->CopyEnvironmentFrom(suspend->GetEnvironment());
+ HInvoke* t_next = MakeInvokeStatic(body, DataType::Type::kInt32, { body_get, t_phi }, common_env);
t_phi->ReplaceInput(t_next, 1u); // Update back-edge input.
- t_next->CopyEnvironmentFrom(suspend->GetEnvironment());
// ret
MakeReturn(ret, t_phi);
@@ -1095,41 +1048,33 @@ TEST_F(LoadStoreEliminationTest, ArrayLoopOverlap2) {
// preheader
HInstruction* alloc_w = MakeNewArray(preheader, zero_const, eighty_const);
- // environment
- ManuallyBuildEnvFor(alloc_w, {});
// loop-start
auto [i_phi, i_add] = MakeLinearLoopVar(loop, body, one_const, one_const);
HPhi* t_phi = MakePhi(loop, {zero_const, /* placeholder */ zero_const});
- HInstruction* suspend = MakeSuspendCheck(loop);
+ std::initializer_list<HInstruction*> common_env{alloc_w, i_phi, t_phi};
+ HInstruction* suspend = MakeSuspendCheck(loop, common_env);
HInstruction* i_cmp_top = MakeCondition(loop, kCondGE, i_phi, eighty_const);
HIf* loop_if = MakeIf(loop, i_cmp_top);
CHECK(loop_if->IfTrueSuccessor() == ret);
- // environment
- ManuallyBuildEnvFor(suspend, { alloc_w, i_phi, t_phi });
-
// BODY
HInstruction* last_i = MakeBinOp<HSub>(body, DataType::Type::kInt32, i_phi, one_const);
auto make_instructions = [&](HInstruction* last_t_value) {
HInstruction* last_get = MakeArrayGet(body, alloc_w, last_i, DataType::Type::kInt32);
- HInvoke* body_value = MakeInvokeStatic(body, DataType::Type::kInt32, { last_get, one_const });
+ HInvoke* body_value =
+ MakeInvokeStatic(body, DataType::Type::kInt32, { last_get, one_const }, common_env);
HInstruction* body_set = MakeArraySet(body, alloc_w, i_phi, body_value, DataType::Type::kInt32);
HInstruction* body_get = MakeArrayGet(body, alloc_w, i_phi, DataType::Type::kInt32);
- HInvoke* t_next = MakeInvokeStatic(body, DataType::Type::kInt32, { body_get, last_t_value });
+ HInvoke* t_next =
+ MakeInvokeStatic(body, DataType::Type::kInt32, { body_get, last_t_value }, common_env);
return std::make_tuple(last_get, body_value, body_set, body_get, t_next);
};
auto [last_get_1, body_value_1, body_set_1, body_get_1, t_next_1] = make_instructions(t_phi);
auto [last_get_2, body_value_2, body_set_2, body_get_2, t_next_2] = make_instructions(t_next_1);
auto [last_get_3, body_value_3, body_set_3, body_get_3, t_next_3] = make_instructions(t_next_2);
- body_value_1->CopyEnvironmentFrom(suspend->GetEnvironment());
- body_value_2->CopyEnvironmentFrom(suspend->GetEnvironment());
- body_value_3->CopyEnvironmentFrom(suspend->GetEnvironment());
t_phi->ReplaceInput(t_next_3, 1u); // Update back-edge input.
- t_next_1->CopyEnvironmentFrom(suspend->GetEnvironment());
- t_next_2->CopyEnvironmentFrom(suspend->GetEnvironment());
- t_next_3->CopyEnvironmentFrom(suspend->GetEnvironment());
// ret
MakeReturn(ret, t_phi);
@@ -1175,23 +1120,22 @@ TEST_F(LoadStoreEliminationTest, ArrayNonLoopPhi) {
// start
HInstruction* alloc_w = MakeNewArray(start, zero_const, two_const);
- ManuallyBuildEnvFor(alloc_w, {});
// left
- HInvoke* left_value = MakeInvokeStatic(left, DataType::Type::kInt32, { zero_const });
+ HInvoke* left_value =
+ MakeInvokeStatic(left, DataType::Type::kInt32, { zero_const }, /*env=*/ { alloc_w });
HInstruction* left_set_1 =
MakeArraySet(left, alloc_w, zero_const, left_value, DataType::Type::kInt32);
HInstruction* left_set_2 =
MakeArraySet(left, alloc_w, one_const, zero_const, DataType::Type::kInt32);
- ManuallyBuildEnvFor(left_value, { alloc_w });
// right
- HInvoke* right_value = MakeInvokeStatic(right, DataType::Type::kInt32, { one_const });
+ HInvoke* right_value =
+ MakeInvokeStatic(right, DataType::Type::kInt32, { one_const }, /*env=*/ { alloc_w });
HInstruction* right_set_1 =
MakeArraySet(right, alloc_w, zero_const, right_value, DataType::Type::kInt32);
HInstruction* right_set_2 =
MakeArraySet(right, alloc_w, one_const, zero_const, DataType::Type::kInt32);
- ManuallyBuildEnvFor(right_value, { alloc_w });
// ret
HInstruction* read_1 = MakeArrayGet(ret, alloc_w, zero_const, DataType::Type::kInt32);
@@ -1228,7 +1172,6 @@ TEST_F(LoadStoreEliminationTest, ArrayMergeDefault) {
// start
HInstruction* alloc_w = MakeNewArray(start, zero_const, two_const);
ArenaVector<HInstruction*> alloc_locals({}, GetAllocator()->Adapter(kArenaAllocInstruction));
- ManuallyBuildEnvFor(alloc_w, {});
// left
HInstruction* left_set_1 =
@@ -1278,8 +1221,6 @@ TEST_F(LoadStoreEliminationTest, ArrayLoopAliasing1) {
// preheader
HInstruction* cls = MakeLoadClass(preheader);
HInstruction* array = MakeNewArray(preheader, cls, n);
- ManuallyBuildEnvFor(cls, {});
- ManuallyBuildEnvFor(array, {});
// loop
auto [i_phi, i_add] = MakeLinearLoopVar(loop, body, c0, c1);
@@ -1287,7 +1228,6 @@ TEST_F(LoadStoreEliminationTest, ArrayLoopAliasing1) {
HInstruction* loop_cond = MakeCondition(loop, kCondLT, i_phi, n);
HIf* loop_if = MakeIf(loop, loop_cond);
CHECK(loop_if->IfTrueSuccessor() == body);
- ManuallyBuildEnvFor(loop_suspend_check, {});
// body
HInstruction* body_set = MakeArraySet(body, array, i_phi, i_phi, DataType::Type::kInt32);
@@ -1326,8 +1266,6 @@ TEST_F(LoadStoreEliminationTest, ArrayLoopAliasing2) {
// preheader
HInstruction* cls = MakeLoadClass(preheader);
HInstruction* array = MakeNewArray(preheader, cls, n);
- ManuallyBuildEnvFor(cls, {});
- ManuallyBuildEnvFor(array, {});
// loop
auto [i_phi, i_add] = MakeLinearLoopVar(loop, body, c0, c1);
@@ -1335,7 +1273,6 @@ TEST_F(LoadStoreEliminationTest, ArrayLoopAliasing2) {
HInstruction* loop_cond = MakeCondition(loop, kCondLT, i_phi, n);
HIf* loop_if = MakeIf(loop, loop_cond);
CHECK(loop_if->IfTrueSuccessor() == body);
- ManuallyBuildEnvFor(loop_suspend_check, {});
// body
HInstruction* body_set = MakeArraySet(body, array, i_phi, i_phi, DataType::Type::kInt32);
@@ -1435,8 +1372,6 @@ TEST_F(LoadStoreEliminationTest, PartialUnknownMerge) {
HInstruction* cls = MakeLoadClass(entry);
HInstruction* new_inst = MakeNewInstance(entry, cls);
MakeGoto(entry);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* switch_inst = new (GetAllocator()) HPackedSwitch(0, 2, switch_val);
bswitch->AddInstruction(switch_inst);
@@ -1444,12 +1379,10 @@ TEST_F(LoadStoreEliminationTest, PartialUnknownMerge) {
HInstruction* write_c1 = MakeIFieldSet(case1, new_inst, c1, MemberOffset(32));
HInstruction* call_c1 = MakeInvokeStatic(case1, DataType::Type::kVoid, { new_inst });
MakeGoto(case1);
- call_c1->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_c2 = MakeIFieldSet(case2, new_inst, c2, MemberOffset(32));
HInstruction* call_c2 = MakeInvokeStatic(case2, DataType::Type::kVoid, { new_inst });
MakeGoto(case2);
- call_c2->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_c3 = MakeIFieldSet(case3, new_inst, c3, MemberOffset(32));
MakeGoto(case3);
@@ -1459,12 +1392,9 @@ TEST_F(LoadStoreEliminationTest, PartialUnknownMerge) {
HInstruction* suspend_check_header = MakeSuspendCheck(loop_header);
HInstruction* call_loop_header = MakeInvokeStatic(loop_header, DataType::Type::kBool, {});
MakeIf(loop_header, call_loop_header);
- call_loop_header->CopyEnvironmentFrom(cls->GetEnvironment());
- suspend_check_header->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* call_loop_body = MakeInvokeStatic(loop_body, DataType::Type::kBool, {});
MakeIf(loop_body, call_loop_body);
- call_loop_body->CopyEnvironmentFrom(cls->GetEnvironment());
MakeGoto(loop_if_left);
@@ -1516,12 +1446,9 @@ TEST_F(LoadStoreEliminationTest, PartialLoadPreserved) {
HInstruction* cls = MakeLoadClass(start);
HInstruction* new_inst = MakeNewInstance(start, cls);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_left = MakeIFieldSet(left, new_inst, c1, MemberOffset(32));
HInstruction* call_left = MakeInvokeStatic(left, DataType::Type::kVoid, { new_inst });
- call_left->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_right = MakeIFieldSet(right, new_inst, c2, MemberOffset(32));
@@ -1570,12 +1497,9 @@ TEST_F(LoadStoreEliminationTest, PartialLoadPreserved2) {
HInstruction* cls = MakeLoadClass(start);
HInstruction* new_inst = MakeNewInstance(start, cls);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_left = MakeIFieldSet(left, new_inst, c1, MemberOffset(32));
HInstruction* call_left = MakeInvokeStatic(left, DataType::Type::kVoid, { new_inst });
- call_left->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_right_first = MakeIFieldSet(right_first, new_inst, c2, MemberOffset(32));
@@ -1649,8 +1573,6 @@ TEST_F(LoadStoreEliminationTest, PartialLoadPreserved3) {
HInstruction* cls = MakeLoadClass(entry);
HInstruction* new_inst = MakeNewInstance(entry, cls);
MakeGoto(entry);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
MakeIf(entry_post, bool_value);
@@ -1660,8 +1582,6 @@ TEST_F(LoadStoreEliminationTest, PartialLoadPreserved3) {
HInstruction* suspend_left_loop = MakeSuspendCheck(left_loop);
HInstruction* call_left_loop = MakeInvokeStatic(left_loop, DataType::Type::kBool, {new_inst});
MakeIf(left_loop, call_left_loop);
- suspend_left_loop->CopyEnvironmentFrom(cls->GetEnvironment());
- call_left_loop->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_left_loop = MakeIFieldSet(left_loop_post, new_inst, c3, MemberOffset(32));
MakeGoto(left_loop_post);
@@ -1741,8 +1661,6 @@ TEST_F(LoadStoreEliminationTest, DISABLED_PartialLoadPreserved4) {
HInstruction* cls = MakeLoadClass(entry);
HInstruction* new_inst = MakeNewInstance(entry, cls);
MakeGoto(entry);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
MakeIf(entry_post, bool_value);
@@ -1753,13 +1671,10 @@ TEST_F(LoadStoreEliminationTest, DISABLED_PartialLoadPreserved4) {
HInstruction* call_left_loop = MakeInvokeStatic(left_loop, DataType::Type::kBool, {});
HInstruction* write_left_loop = MakeIFieldSet(left_loop, new_inst, c3, MemberOffset(32));
MakeIf(left_loop, call_left_loop);
- suspend_left_loop->CopyEnvironmentFrom(cls->GetEnvironment());
- call_left_loop->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_right = MakeIFieldSet(right, new_inst, c2, MemberOffset(32));
HInstruction* call_right = MakeInvokeStatic(right, DataType::Type::kBool, {new_inst});
MakeGoto(right);
- call_right->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* read_return =
MakeIFieldGet(return_block, new_inst, DataType::Type::kInt32, MemberOffset(32));
@@ -1810,18 +1725,13 @@ TEST_F(LoadStoreEliminationTest, PartialLoadPreserved5) {
// start
HInstruction* cls = MakeLoadClass(start);
HInstruction* new_inst = MakeNewInstance(start, cls);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* call_left = MakeInvokeStatic(left, DataType::Type::kVoid, { new_inst });
HInstruction* write_left = MakeIFieldSet(left, new_inst, c1, MemberOffset(32));
HInstruction* call2_left = MakeInvokeStatic(left, DataType::Type::kVoid, {});
- call_left->CopyEnvironmentFrom(cls->GetEnvironment());
- call2_left->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_right = MakeIFieldSet(right, new_inst, c2, MemberOffset(32));
HInstruction* call_right = MakeInvokeStatic(right, DataType::Type::kVoid, {});
- call_right->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* read_bottom =
MakeIFieldGet(breturn, new_inst, DataType::Type::kInt32, MemberOffset(32));
@@ -1881,14 +1791,10 @@ TEST_F(LoadStoreEliminationTest, DISABLED_PartialLoadPreserved6) {
HInstruction* write_entry = MakeIFieldSet(entry, new_inst, c3, MemberOffset(32));
HInstruction* call_entry = MakeInvokeStatic(entry, DataType::Type::kVoid, {});
MakeIf(entry, bool_value);
- ManuallyBuildEnvFor(cls, {});
- new_inst->CopyEnvironmentFrom(cls->GetEnvironment());
- call_entry->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* call_left = MakeInvokeStatic(left, DataType::Type::kVoid, { new_inst });
HInstruction* write_left = MakeIFieldSet(left, new_inst, c1, MemberOffset(32));
MakeGoto(left);
- call_left->CopyEnvironmentFrom(cls->GetEnvironment());
HInstruction* write_right = MakeIFieldSet(right, new_inst, c2, MemberOffset(32));
MakeGoto(right);
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<HInstruction* const>(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<HInstruction* const>(array));
+ parent1->CopyFrom(ArrayRef<HInstruction* const>(&parameter1, 1u));
ASSERT_EQ(parameter1->GetEnvUses().SizeSlow(), 2u);
HEnvironment* parent2 = new (GetAllocator()) HEnvironment(
GetAllocator(), 1, graph->GetArtMethod(), 0, nullptr);
- parent2->CopyFrom(ArrayRef<HInstruction* const>(array));
+ parent2->CopyFrom(ArrayRef<HInstruction* const>(&parameter1, 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);
}
diff --git a/compiler/optimizing/optimizing_unit_test.h b/compiler/optimizing/optimizing_unit_test.h
index c30292c1f0..f4f62e67ed 100644
--- a/compiler/optimizing/optimizing_unit_test.h
+++ b/compiler/optimizing/optimizing_unit_test.h
@@ -472,6 +472,7 @@ class OptimizingUnitTestHelper {
HLoadClass* MakeLoadClass(HBasicBlock* block,
std::optional<dex::TypeIndex> ti = std::nullopt,
std::optional<Handle<mirror::Class>> klass = std::nullopt,
+ std::initializer_list<HInstruction*> env = {},
uint32_t dex_pc = kNoDexPc) {
HLoadClass* load_class = new (GetAllocator()) HLoadClass(
graph_->GetCurrentMethod(),
@@ -482,10 +483,14 @@ class OptimizingUnitTestHelper {
dex_pc,
/* needs_access_check= */ false);
AddOrInsertInstruction(block, load_class);
+ ManuallyBuildEnvFor(load_class, env);
return load_class;
}
- HNewInstance* MakeNewInstance(HBasicBlock* block, HInstruction* cls, uint32_t dex_pc = kNoDexPc) {
+ HNewInstance* MakeNewInstance(HBasicBlock* block,
+ HInstruction* cls,
+ std::initializer_list<HInstruction*> env = {},
+ uint32_t dex_pc = kNoDexPc) {
EXPECT_TRUE(cls->IsLoadClass() || cls->IsClinitCheck()) << *cls;
HLoadClass* load =
cls->IsLoadClass() ? cls->AsLoadClass() : cls->AsClinitCheck()->GetLoadClass();
@@ -497,6 +502,7 @@ class OptimizingUnitTestHelper {
/* finalizable= */ false,
QuickEntrypointEnum::kQuickAllocObjectInitialized);
AddOrInsertInstruction(block, new_instance);
+ ManuallyBuildEnvFor(new_instance, env);
return new_instance;
}
@@ -553,10 +559,12 @@ class OptimizingUnitTestHelper {
HInstruction* cls,
HInstruction* length,
size_t component_size_shift = DataType::SizeShift(DataType::Type::kInt32),
+ std::initializer_list<HInstruction*> env = {},
uint32_t dex_pc = kNoDexPc) {
HNewArray* new_array =
new (GetAllocator()) HNewArray(cls, length, dex_pc, component_size_shift);
AddOrInsertInstruction(block, new_array);
+ ManuallyBuildEnvFor(new_array, env);
return new_array;
}
@@ -564,6 +572,15 @@ class OptimizingUnitTestHelper {
HInstruction* array,
HInstruction* index,
HInstruction* value,
+ uint32_t dex_pc = kNoDexPc) {
+ CHECK(value != nullptr);
+ return MakeArraySet(block, array, index, value, value->GetType(), dex_pc);
+ }
+
+ HArraySet* MakeArraySet(HBasicBlock* block,
+ HInstruction* array,
+ HInstruction* index,
+ HInstruction* value,
DataType::Type type,
uint32_t dex_pc = kNoDexPc) {
HArraySet* array_set = new (GetAllocator()) HArraySet(array, index, value, type, dex_pc);
@@ -591,18 +608,22 @@ class OptimizingUnitTestHelper {
HNullCheck* MakeNullCheck(HBasicBlock* block,
HInstruction* value,
+ std::initializer_list<HInstruction*> env = {},
uint32_t dex_pc = kNoDexPc) {
HNullCheck* null_check = new (GetAllocator()) HNullCheck(value, dex_pc);
AddOrInsertInstruction(block, null_check);
+ ManuallyBuildEnvFor(null_check, env);
return null_check;
}
HBoundsCheck* MakeBoundsCheck(HBasicBlock* block,
HInstruction* index,
HInstruction* length,
+ std::initializer_list<HInstruction*> env = {},
uint32_t dex_pc = kNoDexPc) {
HBoundsCheck* bounds_check = new (GetAllocator()) HBoundsCheck(index, length, dex_pc);
AddOrInsertInstruction(block, bounds_check);
+ ManuallyBuildEnvFor(bounds_check, env);
return bounds_check;
}
@@ -623,6 +644,7 @@ class OptimizingUnitTestHelper {
HInvokeStaticOrDirect* MakeInvokeStatic(HBasicBlock* block,
DataType::Type return_type,
const std::vector<HInstruction*>& args,
+ std::initializer_list<HInstruction*> env = {},
uint32_t dex_pc = kNoDexPc) {
MethodReference method_reference{/* file= */ &graph_->GetDexFile(), /* index= */ method_idx_++};
HInvokeStaticOrDirect* invoke = new (GetAllocator())
@@ -641,6 +663,7 @@ class OptimizingUnitTestHelper {
invoke->SetRawInputAt(idx, ins);
}
AddOrInsertInstruction(block, invoke);
+ ManuallyBuildEnvFor(invoke, env);
return invoke;
}
@@ -676,9 +699,12 @@ class OptimizingUnitTestHelper {
return select;
}
- HSuspendCheck* MakeSuspendCheck(HBasicBlock* block, uint32_t dex_pc = kNoDexPc) {
+ HSuspendCheck* MakeSuspendCheck(HBasicBlock* block,
+ std::initializer_list<HInstruction*> env = {},
+ uint32_t dex_pc = kNoDexPc) {
HSuspendCheck* suspend_check = new (GetAllocator()) HSuspendCheck(dex_pc);
AddOrInsertInstruction(block, suspend_check);
+ ManuallyBuildEnvFor(suspend_check, env);
return suspend_check;
}
diff --git a/compiler/optimizing/select_generator_test.cc b/compiler/optimizing/select_generator_test.cc
index 2e91c884eb..9cd6604d34 100644
--- a/compiler/optimizing/select_generator_test.cc
+++ b/compiler/optimizing/select_generator_test.cc
@@ -55,9 +55,7 @@ TEST_F(SelectGeneratorTest, testZeroCheck) {
HDivZeroCheck* instr = new (GetAllocator()) HDivZeroCheck(param, 0);
HPhi* phi = ConstructBasicGraphForSelect(return_block, instr);
- ArenaVector<HInstruction*> current_locals({param, graph_->GetIntConstant(1)},
- GetAllocator()->Adapter(kArenaAllocInstruction));
- ManuallyBuildEnvFor(instr, &current_locals);
+ ManuallyBuildEnvFor(instr, {param, graph_->GetIntConstant(1)});
EXPECT_FALSE(CheckGraphAndTrySelectGenerator());
EXPECT_FALSE(phi->GetBlock() == nullptr);
diff --git a/compiler/optimizing/ssa_liveness_analysis_test.cc b/compiler/optimizing/ssa_liveness_analysis_test.cc
index a0b03ce0e2..d896aa88f4 100644
--- a/compiler/optimizing/ssa_liveness_analysis_test.cc
+++ b/compiler/optimizing/ssa_liveness_analysis_test.cc
@@ -80,26 +80,12 @@ TEST_F(SsaLivenessAnalysisTest, TestAput) {
HInstruction* value = MakeParam(DataType::Type::kInt32);
HInstruction* extra_arg1 = MakeParam(DataType::Type::kInt32);
HInstruction* extra_arg2 = MakeParam(DataType::Type::kReference);
- HInstruction* const args[] = { array, index, value, extra_arg1, extra_arg2 };
+ std::initializer_list<HInstruction*> args{array, index, value, extra_arg1, extra_arg2};
HBasicBlock* block = CreateSuccessor(entry_);
- HInstruction* null_check = MakeNullCheck(block, array);
- HEnvironment* null_check_env = new (GetAllocator()) HEnvironment(GetAllocator(),
- /* number_of_vregs= */ 5,
- /* method= */ nullptr,
- /* dex_pc= */ 0u,
- null_check);
- null_check_env->CopyFrom(ArrayRef<HInstruction* const>(args));
- null_check->SetRawEnvironment(null_check_env);
+ HInstruction* null_check = MakeNullCheck(block, array, /*env=*/ args);
HInstruction* length = MakeArrayLength(block, array);
- HInstruction* bounds_check = MakeBoundsCheck(block, index, length);
- HEnvironment* bounds_check_env = new (GetAllocator()) HEnvironment(GetAllocator(),
- /* number_of_vregs= */ 5,
- /* method= */ nullptr,
- /* dex_pc= */ 0u,
- bounds_check);
- bounds_check_env->CopyFrom(ArrayRef<HInstruction* const>(args));
- bounds_check->SetRawEnvironment(bounds_check_env);
+ HInstruction* bounds_check = MakeBoundsCheck(block, index, length, /*env=*/ args);
MakeArraySet(block, array, index, value, DataType::Type::kInt32);
graph_->BuildDominatorTree();
@@ -120,7 +106,7 @@ TEST_F(SsaLivenessAnalysisTest, TestAput) {
// Environment uses keep the reference argument alive.
"ranges: { [10,19) }, uses: { }, { 15 19 } is_fixed: 0, is_split: 0 is_low: 0 is_high: 0",
};
- static_assert(arraysize(expected) == arraysize(args), "Array size check.");
+ CHECK_EQ(arraysize(expected), args.size());
size_t arg_index = 0u;
for (HInstruction* arg : args) {
std::ostringstream arg_dump;
@@ -136,30 +122,17 @@ TEST_F(SsaLivenessAnalysisTest, TestDeoptimize) {
HInstruction* value = MakeParam(DataType::Type::kInt32);
HInstruction* extra_arg1 = MakeParam(DataType::Type::kInt32);
HInstruction* extra_arg2 = MakeParam(DataType::Type::kReference);
- HInstruction* const args[] = { array, index, value, extra_arg1, extra_arg2 };
+ std::initializer_list<HInstruction*> args{array, index, value, extra_arg1, extra_arg2};
HBasicBlock* block = CreateSuccessor(entry_);
- HInstruction* null_check = MakeNullCheck(block, array);
- HEnvironment* null_check_env = new (GetAllocator()) HEnvironment(GetAllocator(),
- /* number_of_vregs= */ 5,
- /* method= */ nullptr,
- /* dex_pc= */ 0u,
- null_check);
- null_check_env->CopyFrom(ArrayRef<HInstruction* const>(args));
- null_check->SetRawEnvironment(null_check_env);
+ HInstruction* null_check = MakeNullCheck(block, array, /*env=*/ args);
HInstruction* length = MakeArrayLength(block, array);
// Use HAboveOrEqual+HDeoptimize as the bounds check.
HInstruction* ae = MakeCondition(block, kCondAE, index, length);
HInstruction* deoptimize = new(GetAllocator()) HDeoptimize(
GetAllocator(), ae, DeoptimizationKind::kBlockBCE, /* dex_pc= */ 0u);
block->AddInstruction(deoptimize);
- HEnvironment* deoptimize_env = new (GetAllocator()) HEnvironment(GetAllocator(),
- /* number_of_vregs= */ 5,
- /* method= */ nullptr,
- /* dex_pc= */ 0u,
- deoptimize);
- deoptimize_env->CopyFrom(ArrayRef<HInstruction* const>(args));
- deoptimize->SetRawEnvironment(deoptimize_env);
+ ManuallyBuildEnvFor(deoptimize, /*env=*/ args);
MakeArraySet(block, array, index, value, DataType::Type::kInt32);
graph_->BuildDominatorTree();
@@ -179,7 +152,7 @@ TEST_F(SsaLivenessAnalysisTest, TestDeoptimize) {
// Environment uses keep the reference argument alive.
"ranges: { [10,21) }, uses: { }, { 15 21 } is_fixed: 0, is_split: 0 is_low: 0 is_high: 0",
};
- static_assert(arraysize(expected) == arraysize(args), "Array size check.");
+ CHECK_EQ(arraysize(expected), args.size());
size_t arg_index = 0u;
for (HInstruction* arg : args) {
std::ostringstream arg_dump;
diff --git a/compiler/optimizing/superblock_cloner_test.cc b/compiler/optimizing/superblock_cloner_test.cc
index 4a61e45021..5190dae033 100644
--- a/compiler/optimizing/superblock_cloner_test.cc
+++ b/compiler/optimizing/superblock_cloner_test.cc
@@ -49,14 +49,15 @@ class SuperblockClonerTest : public OptimizingUnitTest {
// Header block.
auto [phi, induction_inc] = MakeLinearLoopVar(loop_header, loop_body, const_0, const_1);
- HInstruction* suspend_check = MakeSuspendCheck(loop_header);
+ std::initializer_list<HInstruction*> common_env{phi, const_128, param_};
+ HInstruction* suspend_check = MakeSuspendCheck(loop_header, common_env);
HInstruction* loop_check = MakeCondition(loop_header, kCondGE, phi, const_128);
MakeIf(loop_header, loop_check);
// Loop body block.
- HInstruction* null_check = MakeNullCheck(loop_body, param_, dex_pc);
+ HInstruction* null_check = MakeNullCheck(loop_body, param_, common_env, dex_pc);
HInstruction* array_length = MakeArrayLength(loop_body, null_check, dex_pc);
- HInstruction* bounds_check = MakeBoundsCheck(loop_body, phi, array_length, dex_pc);
+ HInstruction* bounds_check = MakeBoundsCheck(loop_body, phi, array_length, common_env, dex_pc);
HInstruction* array_get =
MakeArrayGet(loop_body, null_check, bounds_check, DataType::Type::kInt32, dex_pc);
HInstruction* add = MakeBinOp<HAdd>(loop_body, DataType::Type::kInt32, array_get, const_1);
@@ -64,14 +65,6 @@ class SuperblockClonerTest : public OptimizingUnitTest {
MakeArraySet(loop_body, null_check, bounds_check, add, DataType::Type::kInt32, dex_pc);
graph_->SetHasBoundsChecks(true);
-
- // Adjust HEnvironment for each instruction which require that.
- ArenaVector<HInstruction*> current_locals({phi, const_128, param_},
- GetAllocator()->Adapter(kArenaAllocInstruction));
-
- HEnvironment* env = ManuallyBuildEnvFor(suspend_check, &current_locals);
- null_check->CopyEnvironmentFrom(env);
- bounds_check->CopyEnvironmentFrom(env);
}
HParameterValue* param_ = nullptr;