From 9fc44c39b43b86b37e70b6c14c044d32b6ee9a20 Mon Sep 17 00:00:00 2001 From: yangliping Date: Thu, 11 Sep 2025 16:10:54 +0800 Subject: [PATCH] [features]: optimize aot cmc Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICXJUF?from=project-issue Signed-off-by: yangliping --- ecmascript/compiler/call_stub_builder.cpp | 30 +++++++++++------------ ecmascript/compiler/call_stub_builder.h | 4 +-- ecmascript/compiler/common_stubs.cpp | 16 ++++++------ ecmascript/compiler/slowpath_lowering.cpp | 13 ++++++---- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/ecmascript/compiler/call_stub_builder.cpp b/ecmascript/compiler/call_stub_builder.cpp index c5eb94c023..7a6f5d0adf 100644 --- a/ecmascript/compiler/call_stub_builder.cpp +++ b/ecmascript/compiler/call_stub_builder.cpp @@ -278,8 +278,8 @@ void CallCoStubBuilder::LowerFastSuperCall(GateRef glue, CircuitBuilder &builder } void CallCoStubBuilder::LowerFastCall(GateRef gate, GateRef glue, CircuitBuilder &builder, GateRef func, GateRef argc, - const std::vector &args, const std::vector &argsFastCall, - Variable *result, Label *exit, bool isNew) + const std::vector &args, const std::vector &argsFastCall, + Variable *result, Label *exit, bool isNew, bool useCmc) { auto env = builder.GetCurrentEnvironment(); Label isHeapObject(&builder); @@ -298,16 +298,17 @@ void CallCoStubBuilder::LowerFastCall(GateRef gate, GateRef glue, CircuitBuilder auto &builder_ = builder; Label readBarrier(&builder); Label skipReadBarrier(&builder); - BRANCH_CIR( - builder.LoadWithoutBarrier( - VariableType::BOOL(), glue, - builder.IntPtr(JSThread::GlueData::GetIsEnableCMCGCOffset(env->Is32Bit()))), - &readBarrier, &skipReadBarrier); - builder.Bind(&readBarrier); - builder_.CallNGCRuntime(glue, RTSTUB_ID(CopyCallTarget), - Gate::InvalidGateRef, {glue, func}, glue); - builder.Jump(&skipReadBarrier); - builder.Bind(&skipReadBarrier); + if (useCmc) { + BRANCH_CIR( + builder.LoadWithoutBarrier(VariableType::BOOL(), glue, + builder.IntPtr(JSThread::GlueData::GetIsEnableCMCGCOffset(env->Is32Bit()))), + &readBarrier, &skipReadBarrier); + builder.Bind(&readBarrier); + builder_.CallNGCRuntime(glue, RTSTUB_ID(CopyCallTarget), Gate::InvalidGateRef, {glue, func}, glue); + builder.Jump(&skipReadBarrier); + builder.Bind(&skipReadBarrier); + } + BRANCH_CIR(builder.TaggedIsHeapObject(func), &isHeapObject, &slowPath); builder.Bind(&isHeapObject); { @@ -400,7 +401,7 @@ void CallCoStubBuilder::LowerFastCall(GateRef gate, GateRef glue, CircuitBuilder } } -GateRef CallCoStubBuilder::CallStubDispatch() +GateRef CallCoStubBuilder::CallStubDispatch(bool useCmc) { std::vector args = {}; std::vector argsFastCall = {}; @@ -413,8 +414,7 @@ GateRef CallCoStubBuilder::CallStubDispatch() env->SubCfgEntry(&entry); DEFVARIABLE(result, VariableType::JS_ANY(), builder.Undefined()); - LowerFastCall(hirGate_, glue_, builder, func_, actualArgc_, args, argsFastCall, - &result, &exit, false); + LowerFastCall(hirGate_, glue_, builder, func_, actualArgc_, args, argsFastCall, &result, &exit, false, useCmc); Bind(&exit); auto ret = *result; env->SubCfgExit(); diff --git a/ecmascript/compiler/call_stub_builder.h b/ecmascript/compiler/call_stub_builder.h index 9988d6fd25..b99e48736b 100644 --- a/ecmascript/compiler/call_stub_builder.h +++ b/ecmascript/compiler/call_stub_builder.h @@ -120,11 +120,11 @@ public: NO_COPY_SEMANTIC(CallCoStubBuilder); void GenerateCircuit() override {} void PrepareArgs(std::vector &args, std::vector &argsFastCall); - GateRef CallStubDispatch(); + GateRef CallStubDispatch(bool useCmc); std::tuple GetOpInfo(); static void LowerFastCall(GateRef gate, GateRef glue, CircuitBuilder &builder, GateRef func, GateRef argc, const std::vector &args, const std::vector &fastCallArgs, - Variable *result, Label *exit, bool isNew); + Variable *result, Label *exit, bool isNew, bool useCmc); static void FastCallSelector(CircuitBuilder &builder, GateRef glue, GateRef func, GateRef argc, Variable *result, Label *exit); static void LowerFastSuperCall(GateRef glue, CircuitBuilder &builder, const std::vector &args, diff --git a/ecmascript/compiler/common_stubs.cpp b/ecmascript/compiler/common_stubs.cpp index 4fa0e7de63..5297b5940b 100644 --- a/ecmascript/compiler/common_stubs.cpp +++ b/ecmascript/compiler/common_stubs.cpp @@ -122,49 +122,49 @@ JIT_DEFINEFUNC_STUB_GENERATOR(BaseConstructor, FunctionKind::BASE_CONSTRUCTOR) void CallArg0StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLARG0_IMM8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallArg1StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLARG1_IMM8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallArg2StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLARGS2_IMM8_V8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallArg3StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLARGS3_IMM8_V8_V8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallThis0StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLTHIS0_IMM8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallThis1StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLTHIS1_IMM8_V8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallThis2StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLTHIS2_IMM8_V8_V8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void CallThis3StubStubBuilder::GenerateCircuit() { CallCoStubBuilder callBuilder(this, EcmaOpcode::CALLTHIS3_IMM8_V8_V8_V8_V8); - Return(callBuilder.CallStubDispatch()); + Return(callBuilder.CallStubDispatch(!GetCallSignature()->IsStwCopyStub())); } void NewFloat32ArrayWithNoArgsStubBuilder::GenerateCircuit() diff --git a/ecmascript/compiler/slowpath_lowering.cpp b/ecmascript/compiler/slowpath_lowering.cpp index 00003d3b0a..342b0526d5 100644 --- a/ecmascript/compiler/slowpath_lowering.cpp +++ b/ecmascript/compiler/slowpath_lowering.cpp @@ -147,7 +147,8 @@ void SlowPathLowering::LowerToJSCall(GateRef hirGate, const std::vector DEFVALUE(res, (&builder_), VariableType::JS_ANY(), builder_.Undefined()); GateRef func = args[static_cast(CommonArgIdx::FUNC)]; GateRef argc = args[static_cast(CommonArgIdx::ACTUAL_ARGC)]; - CallCoStubBuilder::LowerFastCall(hirGate, glue_, builder_, func, argc, args, argsFastCall, &res, &exit, false); + CallCoStubBuilder::LowerFastCall(hirGate, glue_, builder_, func, argc, args, argsFastCall, &res, &exit, false, + g_isEnableCMCGC); builder_.Bind(&exit); GateRef stateInGate = builder_.GetState(); GateRef depend = builder_.GetDepend(); @@ -2144,7 +2145,7 @@ void SlowPathLowering::GenerateSuperCallForwardAllArgsWithoutArgv(const std::vec SelectFastNew(selectCall, gate, super, callArgs, argsFastCall, &result, &afterCallSuper); } else { CallCoStubBuilder::LowerFastCall(gate, glue_, builder_, super, actualArgc, callArgs, argsFastCall, &result, - &afterCallSuper, true); + &afterCallSuper, true, g_isEnableCMCGC); } builder_.Bind(&afterCallSuper); result = builder_.CallStub(glue_, gate, CommonStubCSigns::ConstructorCheck, { glue_, super, *result, thisObj }); @@ -2200,7 +2201,7 @@ void SlowPathLowering::LowerNewObjRange(GateRef gate) SelectFastNew(selectCall, gate, ctor, args, argsFastCall, &result, &exit); } else { CallCoStubBuilder::LowerFastCall(gate, glue_, builder_, ctor, actualArgc, args, argsFastCall, &result, - &exit, true); + &exit, true, g_isEnableCMCGC); } builder_.Bind(&exit); result = builder_.CallStub(glue_, gate, CommonStubCSigns::ConstructorCheck, {glue_, ctor, *result, thisObj}); @@ -3509,7 +3510,8 @@ void SlowPathLowering::LowerConstruct(GateRef gate) auto selectCall = builder_.CallStub(glue_, gate, CommonStubCSigns::FastCallSelector, {glue_, ctor, argc}); SelectFastNew(selectCall, gate, ctor, args, argsFastCall, &res, &exit); } else { - CallCoStubBuilder::LowerFastCall(gate, glue_, builder_, ctor, argc, args, argsFastCall, &res, &exit, true); + CallCoStubBuilder::LowerFastCall(gate, glue_, builder_, ctor, argc, args, argsFastCall, &res, &exit, true, + g_isEnableCMCGC); } builder_.Bind(&exit); GateRef thisObj = acc_.GetValueIn(gate, static_cast(CommonArgIdx::THIS_OBJECT)); @@ -3539,7 +3541,8 @@ void SlowPathLowering::LowerCallInternal(GateRef gate) GateRef argc = acc_.GetValueIn(gate, static_cast(CommonArgIdx::ACTUAL_ARGC)); Label exit(&builder_); DEFVALUE(res, (&builder_), VariableType::JS_ANY(), builder_.Undefined()); - CallCoStubBuilder::LowerFastCall(gate, glue_, builder_, func, argc, args, argsFastCall, &res, &exit, false); + CallCoStubBuilder::LowerFastCall(gate, glue_, builder_, func, argc, args, argsFastCall, &res, &exit, false, + g_isEnableCMCGC); builder_.Bind(&exit); acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), *res); } -- Gitee