From b5e7a36393e7a8f210ae97a9c42c889d48aee926 Mon Sep 17 00:00:00 2001 From: li-tao116 Date: Tue, 27 Feb 2024 09:43:30 +0800 Subject: [PATCH 1/2] Enable optimizations for try-catch Signed-off-by: litao Change-Id: Ic70ef036baa4085c6a9141af27cba0277ebdc132 --- BUILD.gn | 2 +- bytecode_optimizer/codegen.cpp | 14 ++- bytecode_optimizer/optimize_bytecode.cpp | 2 +- .../tests/optimize_bytecode_test.cpp | 3 +- compiler/compiler.yaml | 6 + compiler/optimizer/ir/basicblock.cpp | 2 +- .../optimizations/move_constants.cpp | 2 +- compiler/tests/BUILD.gn | 7 +- compiler/tests/compiler_basicblock_test.cpp | 6 - compiler/tests/compiler_graph_test.cpp | 4 +- compiler/tests/compiler_regalloc_test.cpp | 2 +- compiler/tests/dump_test.cpp | 111 +++++++++--------- compiler/tests/liveness_analyzer_new_test.cpp | 80 ++++++------- 13 files changed, 128 insertions(+), 113 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index ecea3a7d46..166bfdac32 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -342,7 +342,7 @@ if (!ark_standalone_build) { group("runtime_core_host_unittest") { testonly = true deps = [ - "$ark_root/abc2program/tests:host_unittest", + # "$ark_root/abc2program/tests:host_unittest", "$ark_root/arkplatform/tests:host_unittest", "$ark_root/assembler/tests:host_unittest", "$ark_root/bytecode_optimizer/tests:host_unittest", diff --git a/bytecode_optimizer/codegen.cpp b/bytecode_optimizer/codegen.cpp index 0f8a19e264..72255d0efe 100644 --- a/bytecode_optimizer/codegen.cpp +++ b/bytecode_optimizer/codegen.cpp @@ -68,6 +68,10 @@ bool BytecodeGen::RunImpl() { Reserve(function_->ins.size()); int32_t insn_order = 0; + if (!GetGraph()->GetTryBeginBlocks().empty()) { + // Workaround for AOT and JIT + result_.emplace_back(pandasm::Create_NOP()); + } for (auto *bb : GetGraph()->GetBlocksLinearOrder()) { EmitLabel(BytecodeGen::LabelName(bb->GetId())); if (bb->IsTryEnd() || bb->IsCatchEnd()) { @@ -486,12 +490,20 @@ void BytecodeGen::VisitIntrinsic(GraphVisitor *visitor, Inst *inst_base) void BytecodeGen::VisitCatchPhi(GraphVisitor *visitor, Inst *inst) { + // The Acc register stores the exception object. + // Create an STA instruction if the exception is used later in virtual registers. if (inst->CastToCatchPhi()->IsAcc()) { + bool hasRealUsers = false; for (auto &user : inst->GetUsers()) { if (!user.GetInst()->IsSaveState()) { - UNREACHABLE(); + hasRealUsers = true; + break; } } + if (hasRealUsers) { + auto enc = static_cast(visitor); + DoSta(inst->GetDstReg(), enc->result_); + } } } diff --git a/bytecode_optimizer/optimize_bytecode.cpp b/bytecode_optimizer/optimize_bytecode.cpp index 311743b482..e01f46e6ad 100644 --- a/bytecode_optimizer/optimize_bytecode.cpp +++ b/bytecode_optimizer/optimize_bytecode.cpp @@ -217,7 +217,7 @@ static void SetCompilerOptions(bool is_dynamic) if (!compiler::options.WasSetCompilerMaxBytecodeSize()) { compiler::options.SetCompilerMaxBytecodeSize(MAX_BYTECODE_SIZE); } - if (is_dynamic) { + if (is_dynamic && !compiler::options.IsCompilerOptTryCatchFunc()) { panda::bytecodeopt::options.SetSkipMethodsWithEh(true); } } diff --git a/bytecode_optimizer/tests/optimize_bytecode_test.cpp b/bytecode_optimizer/tests/optimize_bytecode_test.cpp index 8cb75402e1..719eefa8a6 100644 --- a/bytecode_optimizer/tests/optimize_bytecode_test.cpp +++ b/bytecode_optimizer/tests/optimize_bytecode_test.cpp @@ -219,7 +219,6 @@ HWTEST_F(OptimizeBytecodeTest, optimize_bytecode_test_003, TestSize.Level1) { panda::pandasm::AsmEmitter::PandaFileToPandaAsmMaps panda_file_to_asm_maps {}; EXPECT_TRUE(panda::pandasm::AsmEmitter::Emit(abc_file_name, program, nullptr, &panda_file_to_asm_maps, false)); - // do not optimize function having catch blocks" - EXPECT_FALSE(panda::bytecodeopt::OptimizeBytecode(&program, &panda_file_to_asm_maps, abc_file_name, true)); + EXPECT_TRUE(panda::bytecodeopt::OptimizeBytecode(&program, &panda_file_to_asm_maps, abc_file_name, true)); } } // namespace panda::bytecodeopt \ No newline at end of file diff --git a/compiler/compiler.yaml b/compiler/compiler.yaml index be8886d681..c5c00cd9bf 100644 --- a/compiler/compiler.yaml +++ b/compiler/compiler.yaml @@ -193,6 +193,12 @@ options: description: Enable Branch Elimination Pass tags: [perf] +- name: compiler-opt-try-catch-func + type: bool + default: true + description: Enable optimizations for functions with try-catch blocks + tags: [perf] + - name: compiler-checks-elimination type: bool default: true diff --git a/compiler/optimizer/ir/basicblock.cpp b/compiler/optimizer/ir/basicblock.cpp index 55b7fc4bbd..d36672ef1d 100644 --- a/compiler/optimizer/ir/basicblock.cpp +++ b/compiler/optimizer/ir/basicblock.cpp @@ -40,7 +40,7 @@ bool BasicBlock::IsEndBlock() const } bool BasicBlock::IsPseudoControlFlowBlock() const { - return IsStartBlock() || IsEndBlock() || IsTryBegin() || IsTryEnd(); + return IsStartBlock() || IsEndBlock() || IsTryBegin() || IsTryEnd() || IsCatchBegin(); } bool BasicBlock::IsLoopHeader() const diff --git a/compiler/optimizer/optimizations/move_constants.cpp b/compiler/optimizer/optimizations/move_constants.cpp index c17400b029..520cf08c16 100644 --- a/compiler/optimizer/optimizations/move_constants.cpp +++ b/compiler/optimizer/optimizations/move_constants.cpp @@ -46,7 +46,7 @@ bool MoveConstants::RunImpl() bool IsBlockSuitable(const BasicBlock *bb) { - return (!bb->IsLoopValid() || bb->GetLoop()->IsRoot()) && !bb->IsTryBegin(); + return (!bb->IsLoopValid() || bb->GetLoop()->IsRoot()) && !bb->IsTryBegin() && !bb->IsCatchBegin(); } void MoveConstants::MoveFromStartBlock(Inst *inst) diff --git a/compiler/tests/BUILD.gn b/compiler/tests/BUILD.gn index b2708375e7..901a034e2f 100644 --- a/compiler/tests/BUILD.gn +++ b/compiler/tests/BUILD.gn @@ -38,7 +38,6 @@ test_js_path = "//arkcompiler/runtime_core/compiler/tests/js/" # graph interface unit tests graph_test_js_files = [ "cleanUpTest", - "nestedTryCatch", "regallocTest", "regallocTryTest", "simpleTryCatch", @@ -61,7 +60,10 @@ foreach(file, graph_test_js_files) { } } -graph_test_js_files_un_opt = [ "branchElimination" ] +graph_test_js_files_un_opt = [ + "branchElimination", + "nestedTryCatch", +] foreach(file, graph_test_js_files_un_opt) { es2abc_gen_abc("gen_${file}_abc") { @@ -86,6 +88,7 @@ host_unittest_action("GraphInterfaceTest") { "compiler_graph_test.cpp", "compiler_inst_test.cpp", "compiler_optimizations_test.cpp", + "compiler_regalloc_test.cpp", "dominators_tree_new_test.cpp", "dump_test.cpp", "graph_checker_test.cpp", diff --git a/compiler/tests/compiler_basicblock_test.cpp b/compiler/tests/compiler_basicblock_test.cpp index ab43832374..d70bb490a7 100644 --- a/compiler/tests/compiler_basicblock_test.cpp +++ b/compiler/tests/compiler_basicblock_test.cpp @@ -441,9 +441,6 @@ HWTEST_F(CompilerBasicBlockTest, compiler_basicblock_test_014, TestSize.Level1) EXPECT_NE(graph, nullptr); for (auto bb : graph->GetBlocksRPO()) { - if (bb == nullptr) { - continue; - } if (bb->IsTry() && bb->IsLoopValid()) { auto inst = bb->GetLastInst(); EXPECT_NE(bb->SplitBlockAfterInstruction(inst, false), nullptr); @@ -454,9 +451,6 @@ HWTEST_F(CompilerBasicBlockTest, compiler_basicblock_test_014, TestSize.Level1) } for (auto bb : graph->GetVectorBlocks()) { - if (bb == nullptr) { - continue; - } for (auto inst : bb->AllInsts()) { if (inst->IsPhi() || bb->IsStartBlock() || bb->IsEndBlock()) { continue; diff --git a/compiler/tests/compiler_graph_test.cpp b/compiler/tests/compiler_graph_test.cpp index c70933d063..c47f0c6061 100644 --- a/compiler/tests/compiler_graph_test.cpp +++ b/compiler/tests/compiler_graph_test.cpp @@ -248,8 +248,8 @@ HWTEST_F(CompilerGraphTest, graph_test_007, TestSize.Level1) EXPECT_NE(graph, nullptr); graph->DumpThrowableInsts(&out); std::string str = "Throwable Inst " - "22.void Intrinsic.trystglobalbyname v21, v23" - " bc: 0x0000001f\n" + "17.void Intrinsic.trystglobalbyname v16, v18" + " bc: 0x0000001a\n" "Catch handlers: BB 9\n"; EXPECT_EQ(out.str(), str); }); diff --git a/compiler/tests/compiler_regalloc_test.cpp b/compiler/tests/compiler_regalloc_test.cpp index 3ae1095cf6..b9c728e809 100644 --- a/compiler/tests/compiler_regalloc_test.cpp +++ b/compiler/tests/compiler_regalloc_test.cpp @@ -877,7 +877,7 @@ HWTEST_F(RegallocTest, regalloc_test_017, TestSize.Level1) param->SetReg(reg++); param->AppendRange({0, 10}); param->StartFrom(0); - EXPECT_EQ(param->GetRanges().size(), 1); + EXPECT_EQ(param->GetRanges().size(), 2); EXPECT_EQ(param->GetReg(), reg - 1); EXPECT_NE(param->SplitAt(1, graph->GetAllocator()), nullptr); param->SetLocation(Location::MakeConstant(0)); diff --git a/compiler/tests/dump_test.cpp b/compiler/tests/dump_test.cpp index 191fd4b4af..996170e1d7 100644 --- a/compiler/tests/dump_test.cpp +++ b/compiler/tests/dump_test.cpp @@ -105,7 +105,7 @@ HWTEST_F(DumpTest, dump_test_002, TestSize.Level1) EXPECT_EQ(data.str(), test_data); data.clear(); data.str(""); - test_data = "prop: end, bc: 0x0000002d\n"; + test_data = "prop: end, bc: 0x00000026\n"; BlockProps(graph->GetEndBlock(), &data); EXPECT_EQ(data.str(), test_data); Loop loop(graph->GetAllocator(), graph->GetEndBlock(), 1); @@ -117,17 +117,17 @@ HWTEST_F(DumpTest, dump_test_002, TestSize.Level1) loop3.SetAsRoot(); data.clear(); data.str(""); - test_data = "prop: end, head, loop 1, bc: 0x0000002d\n"; + test_data = "prop: end, head, loop 1, bc: 0x00000026\n"; BlockProps(graph->GetEndBlock(), &data); EXPECT_EQ(data.str(), test_data); data.clear(); data.str(""); - test_data = "prop: loop 0, try_begin (id 0), bc: 0x0000001a\n" - "prop: loop (irreducible) 2, try (id 0), bc: 0x0000001a\n" - "prop: try_end (id 0), bc: 0x00000023\n" - "prop: catch_begin, catch, bc: 0x00000025\n" - "prop: catch_begin, catch, bc: 0x00000025\n" - "prop: catch, bc: 0x00000025\n"; + test_data = "prop: loop 0, try_begin (id 0), bc: 0x00000015\n" + "prop: loop (irreducible) 2, try (id 0), bc: 0x00000015\n" + "prop: try_end (id 0), bc: 0x0000001e\n" + "prop: catch_begin, catch, bc: 0x00000020\n" + "prop: catch_begin, catch, bc: 0x00000020\n" + "prop: catch, bc: 0x00000020\n"; for (auto block : graph->GetBlocksRPO()) { if (block->IsTry()) { block->SetLoop(&loop1); @@ -151,7 +151,7 @@ HWTEST_F(DumpTest, dump_test_002, TestSize.Level1) } auto value1 = PcToString(graph->GetEndBlock()->GetGuestPc(), graph->GetLocalAllocator()); std::string str = value1.data(); - EXPECT_EQ(str, "bc: 0x0000002d"); + EXPECT_EQ(str, "bc: 0x00000026"); EXPECT_EQ(data.str(), test_data); }); EXPECT_TRUE(status); @@ -612,7 +612,8 @@ HWTEST_F(DumpTest, dump_test_014, TestSize.Level1) EXPECT_NE(graph, nullptr); std::stringstream data; - std::string test_data = " Intrinsic.definefunc Intrinsic.stglobalvar Intrinsic.definefunc" + std::string test_data = " Intrinsic.definefunc" + " Intrinsic.stglobalvar Intrinsic.definefunc" " Intrinsic.stglobalvar Intrinsic.trystglobalbyname Intrinsic.tryldglobalbyname" " Intrinsic.ldundefined Intrinsic.returnundefined "; for (auto bb : graph->GetBlocksRPO()) { @@ -751,59 +752,59 @@ HWTEST_F(DumpTest, dump_test_018, TestSize.Level1) std::string test_data = "Method: L_GLOBAL;::func_main_0\n\n" "BB 7\n" "prop: start, bc: 0x00000000\n" - " 10.any Parameter " + " 5.any Parameter " "arg 0 \n -> [u64]\n" - " 11.any Parameter " + " 6.any Parameter " "arg 1 \n -> [u64]\n" - " 12.any Parameter " + " 7.any Parameter " "arg 2 \n -> [u64]\n" - " 21.i32 Constant 0x1 -> " - "(v22) \n" + " 16.i32 Constant 0x1 -> " + "(v17) \n" "succs: [bb 0]\n\n" "BB 0 preds: [bb 7]\n" "prop: bc: 0x00000000\n" - " 13.any Intrinsic.definefunc ss14 -> (v15)" - " \n" - " 15.void Intrinsic.stglobalvar v13, ss16" - " \n" - " 17.any Intrinsic.definefunc ss18 -> (v19)" + " 8.any Intrinsic.definefunc ss9 -> (v10)" + " \n" + " 10.void Intrinsic.stglobalvar v8, ss11" + " \n" + " 12.any Intrinsic.definefunc ss13 -> (v14)" " \n" - " 19.void Intrinsic.stglobalvar v17, ss20" + " 14.void Intrinsic.stglobalvar v12, ss15" " \n" "succs: [bb 2]\n\n" "BB 2 preds: [bb 0]\n" - "prop: try_begin (id 0), bc: 0x0000001a\n" + "prop: try_begin (id 0), bc: 0x00000015\n" " 0. Try " " \n" "succs: [bb 4, bb 9]\n\n" "BB 4 preds: [bb 2]\n" - "prop: try (id 0), bc: 0x0000001a\n" - " 22.void Intrinsic.trystglobalbyname v21, ss23" + "prop: try (id 0), bc: 0x00000015\n" + " 17.void Intrinsic.trystglobalbyname v16, ss18" " \n" "succs: [bb 3]\n\n" "BB 3 preds: [bb 4]\n" - "prop: try_end (id 0), bc: 0x00000023\n" + "prop: try_end (id 0), bc: 0x0000001e\n" "succs: [bb 5, bb 9]\n\n" "BB 9 preds: [bb 2, bb 3]\n" - "prop: catch_begin, catch, bc: 0x00000025\n" + "prop: catch_begin, catch, bc: 0x00000020\n" "succs: [bb 6]\n\n" "BB 6 preds: [bb 9]\n" - "prop: catch, bc: 0x00000025\n" - " 24.any Intrinsic.tryldglobalbyname ss25 " + "prop: catch, bc: 0x00000020\n" + " 19.any Intrinsic.tryldglobalbyname ss20 " " \n" "succs: [bb 1]\n\n" "BB 5 preds: [bb 3]\n" - "prop: bc: 0x00000023\n" + "prop: bc: 0x0000001e\n" "succs: [bb 1]\n\n" "BB 1 preds: [bb 5, bb 6]\n" - "prop: bc: 0x0000002b\n" - " 33.any Intrinsic.ldundefined ss34" + "prop: bc: 0x00000024\n" + " 25.any Intrinsic.ldundefined ss26" " \n" - " 35.void Intrinsic.returnundefined ss36" + " 27.void Intrinsic.returnundefined ss28" " \n" "succs: [bb 8]\n\n" "BB 8 preds: [bb 1]\n" - "prop: end, bc: 0x0000002d\n\n"; + "prop: end, bc: 0x00000026\n\n"; graph->Dump(&out); EXPECT_TRUE(graph->HasEndBlock()); EXPECT_EQ(out.str(), test_data); @@ -831,59 +832,59 @@ HWTEST_F(DumpTest, dump_test_019, TestSize.Level1) std::stringstream out; std::string test_data = "BB 7\n" "prop: start, bc: 0x00000000\n" - " 10.any Parameter arg 0" + " 5.any Parameter arg 0" " \n -> [u64]\n" - " 11.any Parameter arg 1" + " 6.any Parameter arg 1" " \n -> [u64]\n" - " 12.any Parameter arg 2" + " 7.any Parameter arg 2" " \n -> [u64]\n" - " 21.i32 Constant 0x1 -> (v22)" + " 16.i32 Constant 0x1 -> (v17)" " \n" "succs: [bb 0]\n" "BB 0 preds: [bb 7]\n" "prop: bc: 0x00000000\n" - " 13.any Intrinsic.definefunc ss14 -> (v15)" - " \n" - " 15.void Intrinsic.stglobalvar v13, ss16" - " \n" - " 17.any Intrinsic.definefunc ss18 -> (v19)" + " 8.any Intrinsic.definefunc ss9 -> (v10)" + " \n" + " 10.void Intrinsic.stglobalvar v8, ss11" + " \n" + " 12.any Intrinsic.definefunc ss13 -> (v14)" " \n" - " 19.void Intrinsic.stglobalvar v17, ss20" + " 14.void Intrinsic.stglobalvar v12, ss15" " \n" "succs: [bb 2]\n" "BB 2 preds: [bb 0]\n" - "prop: try_begin (id 0), bc: 0x0000001a\n" + "prop: try_begin (id 0), bc: 0x00000015\n" " 0. Try " " \n" "succs: [bb 4, bb 9]\n" "BB 4 preds: [bb 2]\n" - "prop: try (id 0), bc: 0x0000001a\n" - " 22.void Intrinsic.trystglobalbyname v21, ss23" + "prop: try (id 0), bc: 0x00000015\n" + " 17.void Intrinsic.trystglobalbyname v16, ss18" " \n" "succs: [bb 3]\n" "BB 3 preds: [bb 4]\n" - "prop: try_end (id 0), bc: 0x00000023\n" + "prop: try_end (id 0), bc: 0x0000001e\n" "succs: [bb 5, bb 9]\n" "BB 9 preds: [bb 2, bb 3]\n" - "prop: catch_begin, catch, bc: 0x00000025\n" + "prop: catch_begin, catch, bc: 0x00000020\n" "succs: [bb 6]\n" "BB 6 preds: [bb 9]\n" - "prop: catch, bc: 0x00000025\n" - " 24.any Intrinsic.tryldglobalbyname ss25" + "prop: catch, bc: 0x00000020\n" + " 19.any Intrinsic.tryldglobalbyname ss20" " \n" "succs: [bb 1]\n" "BB 5 preds: [bb 3]\n" - "prop: bc: 0x00000023\n" + "prop: bc: 0x0000001e\n" "succs: [bb 1]\n" "BB 1 preds: [bb 5, bb 6]\n" - "prop: bc: 0x0000002b\n" - " 33.any Intrinsic.ldundefined ss34" + "prop: bc: 0x00000024\n" + " 25.any Intrinsic.ldundefined ss26" " \n" - " 35.void Intrinsic.returnundefined ss36" + " 27.void Intrinsic.returnundefined ss28" " \n" "succs: [bb 8]\n" "BB 8 preds: [bb 1]\n" - "prop: end, bc: 0x0000002d\n"; + "prop: end, bc: 0x00000026\n"; for (auto bb : graph->GetBlocksRPO()) { bb->Dump(&out); } diff --git a/compiler/tests/liveness_analyzer_new_test.cpp b/compiler/tests/liveness_analyzer_new_test.cpp index 20b7858447..334c6b24ce 100644 --- a/compiler/tests/liveness_analyzer_new_test.cpp +++ b/compiler/tests/liveness_analyzer_new_test.cpp @@ -98,27 +98,27 @@ HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_002, TestSize.Level1) std::stringstream out; liveness_analyzer->DumpLifeIntervals(out); std::string str = "BB 7\t[0:10)\n" - "v10\t[2:4)@ ; \n" - "v11\t[4:6)@ ; \n" - "v12\t[6:8)@ ; \n" - "v13\t[8:20)@ ; \n" + "v5\t[2:4)@ ; \n" + "v6\t[4:6)@ ; \n" + "v7\t[6:8)@ ; \n" + "v8\t[8:20)@ ; \n" "BB 0\t[10:12)\n" "BB 2\t[12:16)\n" "v0\t[14:16)@ ; \n" "BB 4\t[16:22)\n" - "v15\t[18:20)@ ; \n" - "v14\t[20:22)@ ; \n" + "v10\t[18:20)@ ; \n" + "v9\t[20:22)@ ; \n" "BB 3\t[22:24)\n" "BB 9\t[26:28)\n" "BB 6\t[28:34)\n" - "v17\t[30:32)@ ; \n" - "v16\t[32:34)@ ; \n" + "v12\t[30:32)@ ; \n" + "v11\t[32:34)@ ; \n" "BB 5\t[24:26)\n" "BB 1\t[34:44)\n" - "v26\t[36:38)@ ; \n" - "v25\t[38:40)@ ; \n" - "v28\t[40:42)@ ; \n" - "v27\t[42:44)@ ; \n" + "v18\t[36:38)@ ; \n" + "v17\t[38:40)@ ; \n" + "v20\t[40:42)@ ; \n" + "v19\t[42:44)@ ; \n" "BB 8\t[44:46)\n\n" "Registers intervals\n-\n\n" "Vector registers intervals\n" @@ -136,31 +136,31 @@ HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_002, TestSize.Level1) out.str(""); liveness_analyzer->DumpLifeIntervals(out); str = "BB 7\t[0:10)\n" - "v10\t[2:4)@ ; \n" - "v11\t[4:6)@ ; \n" - "v12\t[6:8)@ ; \n" - "v13\t[8:20)@ ; \n" + "v5\t[2:4)@ ; \n" + "v6\t[4:6)@ ; \n" + "v7\t[6:8)@ ; \n" + "v8\t[8:20)@ ; \n" "BB 0\t[10:12)\n" "BB 2\t[12:16)\n" "v0\t[14:16)@ ; \n" "BB 4\t[16:22)\n" - "v15\t[18:20)@ ; \n" - "v14\t[20:22)@ ; \n" + "v10\t[18:20)@ ; \n" + "v9\t[20:22)@ ; \n" "BB 3\t[22:24)\n" "BB 9\t[26:28)\n" "BB 6\t[28:34)\n" - "v17\t[30:32)@ ; \n" - "v16\t[32:34)@ ; \n" + "v12\t[30:32)@ ; \n" + "v11\t[32:34)@ ; \n" "BB 5\t[24:26)\n" "BB 1\t[34:44)\n" - "v26\t[36:38)@ ; \n" - "v25\t[38:40)@ ; \n" - "v28\t[40:42)@ ; \n" - "v27\t[42:44)@ ; \n" + "v18\t[36:38)@ ; \n" + "v17\t[38:40)@ ; \n" + "v20\t[40:42)@ ; \n" + "v19\t[42:44)@ ; \n" "BB 8\t[44:46)\n\n" "Registers intervals\n" - "r0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); [38:40); " - "[40:42); [42:44)\n\n" + "r0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); " + "[38:40); [40:42); [42:44)\n\n" "Vector registers intervals\n-\n\n" "Stack slots intervals\n-\n"; EXPECT_EQ(out.str(), str); @@ -174,33 +174,33 @@ HWTEST_F(LivenessAnalyzerTest, liveness_analyzer_test_002, TestSize.Level1) out.str(""); liveness_analyzer->DumpLifeIntervals(out); str = "BB 7\t[0:10)\n" - "v10\t[2:4)@ ; \n" - "v11\t[4:6)@ ; \n" - "v12\t[6:8)@ ; \n" - "v13\t[8:20)@ ; \n" + "v5\t[2:4)@ ; \n" + "v6\t[4:6)@ ; \n" + "v7\t[6:8)@ ; \n" + "v8\t[8:20)@ ; \n" "BB 0\t[10:12)\n" "BB 2\t[12:16)\n" "v0\t[14:16)@ ; \n" "BB 4\t[16:22)\n" - "v15\t[18:20)@ ; \n" - "v14\t[20:22)@ ; \n" + "v10\t[18:20)@ ; \n" + "v9\t[20:22)@ ; \n" "BB 3\t[22:24)\n" "BB 9\t[26:28)\n" "BB 6\t[28:34)\n" - "v17\t[30:32)@ ; \n" - "v16\t[32:34)@ ; \n" + "v12\t[30:32)@ ; \n" + "v11\t[32:34)@ ; \n" "BB 5\t[24:26)\n" "BB 1\t[34:44)\n" - "v26\t[36:38)@ ; \n" - "v25\t[38:40)@ ; \n" - "v28\t[40:42)@ ; \n" - "v27\t[42:44)@ ; \n" + "v18\t[36:38)@ ; \n" + "v17\t[38:40)@ ; \n" + "v20\t[40:42)@ ; \n" + "v19\t[42:44)@ ; \n" "BB 8\t[44:46)\n\n" "Registers intervals\n-\n\n" "Vector registers intervals\n-\n\n" "Stack slots intervals\n" - "s0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); " - "[36:38); [38:40); [40:42); [42:44)\n"; + "s0: [2:4); [4:6); [6:8); [8:20); [14:16); [18:20); [20:22); [30:32); [32:34); [36:38); " + "[38:40); [40:42); [42:44)\n"; EXPECT_EQ(out.str(), str); EXPECT_TRUE(location2.IsStack()); }); -- Gitee From 184aac718f8d5f8fd3c460c15718d9eae0627949 Mon Sep 17 00:00:00 2001 From: zhaoziming Date: Wed, 22 May 2024 22:06:16 +0800 Subject: [PATCH 2/2] Change the way to pass opt-try-catch-func option Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/I91AY1 Tests: frontend_tests & test262 & runtime_core_ut & runtime_ut & AOT daily test Signed-off-by: zhaoziming Change-Id: I1d932d14ee6f5f75405bf085d0ad5406bde839d4 --- BUILD.gn | 2 +- bytecode_optimizer/optimize_bytecode.cpp | 7 ++----- compiler/compiler.yaml | 6 ------ compiler/tests/compiler_regalloc_test.cpp | 2 +- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 166bfdac32..ecea3a7d46 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -342,7 +342,7 @@ if (!ark_standalone_build) { group("runtime_core_host_unittest") { testonly = true deps = [ - # "$ark_root/abc2program/tests:host_unittest", + "$ark_root/abc2program/tests:host_unittest", "$ark_root/arkplatform/tests:host_unittest", "$ark_root/assembler/tests:host_unittest", "$ark_root/bytecode_optimizer/tests:host_unittest", diff --git a/bytecode_optimizer/optimize_bytecode.cpp b/bytecode_optimizer/optimize_bytecode.cpp index e01f46e6ad..6eb2e0b87d 100644 --- a/bytecode_optimizer/optimize_bytecode.cpp +++ b/bytecode_optimizer/optimize_bytecode.cpp @@ -210,16 +210,13 @@ static bool SkipFunction(const pandasm::Function &function, const std::string &f return false; } -static void SetCompilerOptions(bool is_dynamic) +static void SetCompilerOptions() { compiler::options.SetCompilerUseSafepoint(false); compiler::options.SetCompilerSupportInitObjectInst(true); if (!compiler::options.WasSetCompilerMaxBytecodeSize()) { compiler::options.SetCompilerMaxBytecodeSize(MAX_BYTECODE_SIZE); } - if (is_dynamic && !compiler::options.IsCompilerOptTryCatchFunc()) { - panda::bytecodeopt::options.SetSkipMethodsWithEh(true); - } } static bool StringStartsWith(const std::string &str, const std::string &prefix) @@ -427,7 +424,7 @@ bool OptimizeFunction(pandasm::Program *prog, const pandasm::AsmEmitter::PandaFi ArenaAllocator allocator {SpaceType::SPACE_TYPE_COMPILER}; ArenaAllocator local_allocator {SpaceType::SPACE_TYPE_COMPILER, nullptr, true}; - SetCompilerOptions(is_dynamic); + SetCompilerOptions(); auto ir_interface = BytecodeOptIrInterface(maps, prog); diff --git a/compiler/compiler.yaml b/compiler/compiler.yaml index c5c00cd9bf..be8886d681 100644 --- a/compiler/compiler.yaml +++ b/compiler/compiler.yaml @@ -193,12 +193,6 @@ options: description: Enable Branch Elimination Pass tags: [perf] -- name: compiler-opt-try-catch-func - type: bool - default: true - description: Enable optimizations for functions with try-catch blocks - tags: [perf] - - name: compiler-checks-elimination type: bool default: true diff --git a/compiler/tests/compiler_regalloc_test.cpp b/compiler/tests/compiler_regalloc_test.cpp index b9c728e809..bf3c776c8a 100644 --- a/compiler/tests/compiler_regalloc_test.cpp +++ b/compiler/tests/compiler_regalloc_test.cpp @@ -1052,7 +1052,7 @@ HWTEST_F(RegallocTest, regalloc_test_020, TestSize.Level1) HWTEST_F(RegallocTest, regalloc_test_021, TestSize.Level1) { std::string pfile_name = GRAPH_TEST_ABC_DIR "regallocTest.abc"; - const char *test_method_name = "func4"; + const char *test_method_name = "#*#func4"; bool status = false; auto pfile = panda_file::OpenPandaFile(pfile_name); for (uint32_t id : pfile->GetClasses()) { -- Gitee