From b12c654096f95a2e501161ebec6a91155d884da4 Mon Sep 17 00:00:00 2001 From: zhangyukun Date: Thu, 13 Jan 2022 16:03:18 +0800 Subject: [PATCH] Impl opcode of module Signed-off-by: zhangyukun Change-Id: Ie313b842151eae2a090be90ab9ed5124404f8b6a --- ecmascript/compiler/fast_stub_define.h | 5 +- ecmascript/compiler/interpreter_stub.cpp | 68 +++++++++++++++++++ ecmascript/compiler/interpreter_stub_define.h | 5 +- ecmascript/compiler/stub_descriptor.cpp | 44 ++++++++++++ .../interpreter/interpreter_assembly.cpp | 20 ------ ecmascript/js_thread.cpp | 7 ++ ecmascript/runtime_trampolines.cpp | 18 +++++ ecmascript/runtime_trampolines.h | 3 + 8 files changed, 148 insertions(+), 22 deletions(-) diff --git a/ecmascript/compiler/fast_stub_define.h b/ecmascript/compiler/fast_stub_define.h index 0357baf025..028e0aaadc 100644 --- a/ecmascript/compiler/fast_stub_define.h +++ b/ecmascript/compiler/fast_stub_define.h @@ -64,7 +64,10 @@ namespace panda::ecmascript::kungfu { V(ResolveClass, 6) \ V(CloneClassFromTemplate, 5) \ V(SetClassConstructorLength, 3) \ - V(UpdateHotnessCounter, 2) + V(UpdateHotnessCounter, 2) \ + V(ImportModule, 2) \ + V(StModuleVar, 3) \ + V(LdModvarByName, 3) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define FAST_RUNTIME_STUB_LIST(V) \ diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index f53c803585..f5b144c6c0 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -1299,4 +1299,72 @@ void HandleMovDynV16V16Stub::GenerateCircuit(const CompilationConfig *cfg) Dispatch(glue, pc, sp, constpool, profileTypeInfo, acc, hotnessCounter, GetArchRelateConstant(BytecodeInstruction::Size(BytecodeInstruction::Format::V16_V16))); } + +void HandleImportModulePrefId32Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + // auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is sp */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is constpool */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is profileTypeInfo */ + DEFVARIABLE(acc, MachineType::TAGGED, TaggedArgument(5)); /* 5: 6th parameter is value */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is hotnessCounter */ + + GateRef stringId = ReadInst32_1(pc); + GateRef prop = GetObjectFromConstPool(constpool, stringId); + StubDescriptor *importModule = GET_STUBDESCRIPTOR(ImportModule); + GateRef moduleRef = CallRuntime(importModule, glue, GetWord64Constant(FAST_STUB_ID(ImportModule)), { glue, prop }); + acc = moduleRef; + Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, + GetArchRelateConstant(BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_ID32))); +} + +void HandleStModuleVarPrefId32Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + // auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is sp */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is constpool */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is profileTypeInfo */ + GateRef acc = TaggedArgument(5); /* 5: 6th parameter is acc */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is hotnessCounter */ + + GateRef stringId = ReadInst32_1(pc); + GateRef prop = GetObjectFromConstPool(constpool, stringId); + GateRef value = acc; + + StubDescriptor *stModuleVar = GET_STUBDESCRIPTOR(StModuleVar); + CallRuntime(stModuleVar, glue, GetWord64Constant(FAST_STUB_ID(StModuleVar)), { glue, prop, value }); + Dispatch(glue, pc, sp, constpool, profileTypeInfo, acc, hotnessCounter, + GetArchRelateConstant(BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_ID32))); +} + +void HandleLdModVarByNamePrefId32V8Stub::GenerateCircuit(const CompilationConfig *cfg) +{ + Stub::GenerateCircuit(cfg); + // auto env = GetEnvironment(); + GateRef glue = PtrArgument(0); + GateRef pc = PtrArgument(1); + GateRef sp = PtrArgument(2); /* 2 : 3rd parameter is sp */ + GateRef constpool = TaggedPointerArgument(3); /* 3 : 4th parameter is constpool */ + GateRef profileTypeInfo = TaggedPointerArgument(4); /* 4 : 5th parameter is profileTypeInfo */ + DEFVARIABLE(acc, MachineType::TAGGED, TaggedArgument(5)); /* 5: 6th parameter is value */ + GateRef hotnessCounter = Int32Argument(6); /* 6 : 7th parameter is hotnessCounter */ + + GateRef stringId = ReadInst32_1(pc); + GateRef v0 = ReadInst8_5(pc); + GateRef itemName = GetObjectFromConstPool(constpool, stringId); + GateRef moduleObj = GetVregValue(sp, ZExtInt8ToPtr(v0)); + + StubDescriptor *ldModvarByName = GET_STUBDESCRIPTOR(LdModvarByName); + GateRef moduleVar = CallRuntime(ldModvarByName, glue, GetWord64Constant(FAST_STUB_ID(LdModvarByName)), + { glue, moduleObj, itemName }); + acc = moduleVar; + Dispatch(glue, pc, sp, constpool, profileTypeInfo, *acc, hotnessCounter, + GetArchRelateConstant(BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_ID32_V8))); +} } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/interpreter_stub_define.h b/ecmascript/compiler/interpreter_stub_define.h index c5d7e599ae..22ca4ea60f 100644 --- a/ecmascript/compiler/interpreter_stub_define.h +++ b/ecmascript/compiler/interpreter_stub_define.h @@ -45,7 +45,10 @@ namespace panda::ecmascript::kungfu { V(HandleLdFunctionPref, 7) \ V(HandleMovV4V4, 7) \ V(HandleMovDynV8V8, 7) \ - V(HandleMovDynV16V16, 7) + V(HandleMovDynV16V16, 7) \ + V(HandleImportModulePrefId32, 7) \ + V(HandleStModuleVarPrefId32, 7) \ + V(HandleLdModVarByNamePrefId32V8, 7) enum InterpreterStubId { #define DEF_STUB(name, counter) name##Id, diff --git a/ecmascript/compiler/stub_descriptor.cpp b/ecmascript/compiler/stub_descriptor.cpp index 5e9108360f..6b4bf96ffa 100644 --- a/ecmascript/compiler/stub_descriptor.cpp +++ b/ecmascript/compiler/stub_descriptor.cpp @@ -940,6 +940,50 @@ CALL_STUB_INIT_DESCRIPTOR(UpdateHotnessCounter) descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); } +CALL_STUB_INIT_DESCRIPTOR(ImportModule) +{ + // 2 : 2 input parameters + StubDescriptor importModule("ImportModule", 0, 2, + ArgumentsOrder::DEFAULT_ORDER, MachineType::TAGGED); + *descriptor = importModule; + std::array params = { // 2 : 2 input parameters + MachineType::NATIVE_POINTER, + MachineType::TAGGED, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + +CALL_STUB_INIT_DESCRIPTOR(StModuleVar) +{ + // 3 : 3 input parameters + StubDescriptor stModuleVar("StModuleVar", 0, 3, + ArgumentsOrder::DEFAULT_ORDER, MachineType::NONE); + *descriptor = stModuleVar; + std::array params = { // 3 : 3 input parameters + MachineType::NATIVE_POINTER, + MachineType::TAGGED, + MachineType::TAGGED, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + +CALL_STUB_INIT_DESCRIPTOR(LdModvarByName) +{ + // 3 : 3 input parameters + StubDescriptor ldModvarByName("LdModvarByName", 0, 3, + ArgumentsOrder::DEFAULT_ORDER, MachineType::TAGGED); + *descriptor = ldModvarByName; + std::array params = { // 3 : 3 input parameters + MachineType::NATIVE_POINTER, + MachineType::TAGGED, + MachineType::TAGGED, + }; + descriptor->SetParameters(params.data()); + descriptor->SetStubKind(StubDescriptor::CallStubKind::RUNTIME_STUB); +} + #ifndef NDEBUG CALL_STUB_INIT_DESCRIPTOR(FastMulGCTest) { diff --git a/ecmascript/interpreter/interpreter_assembly.cpp b/ecmascript/interpreter/interpreter_assembly.cpp index b42f2cca2d..8c449a6dea 100644 --- a/ecmascript/interpreter/interpreter_assembly.cpp +++ b/ecmascript/interpreter/interpreter_assembly.cpp @@ -1253,19 +1253,7 @@ void InterpreterAssembly::HandleMul2DynPrefV8( << " v" << v0; JSTaggedValue left = GET_VREG_VALUE(v0); JSTaggedValue right = acc; -#ifdef ECMASCRIPT_ENABLE_STUB_AOT - JSTaggedValue value = JSTaggedValue::Hole(); - if (left.IsInt() && right.IsInt()) { - auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(FastMul)); - typedef JSTaggedType (*PFFastMul)(JSTaggedValue, JSTaggedValue); - auto fastMulPtr = reinterpret_cast(stubAddr); - value = JSTaggedValue(fastMulPtr(left, right)); - } else { - value = FastRuntimeStub::FastMul(left, right); - } -#else JSTaggedValue value = FastRuntimeStub::FastMul(left, right); -#endif if (!value.IsHole()) { SET_ACC(value); } else { @@ -2273,14 +2261,7 @@ void InterpreterAssembly::HandleStOwnByNamePrefId32V8( JSTaggedValue value = GET_ACC(); // fast path SAVE_ACC(); -#ifdef ECMASCRIPT_ENABLE_STUB_AOT - auto stubAddr = thread->GetFastStubEntry(FAST_STUB_ID(SetPropertyByName)); - typedef JSTaggedValue (*PFSetPropertyByName)(JSThread *, JSTaggedValue, JSTaggedValue, JSTaggedValue, bool); - auto setPropertyByNamePtr = reinterpret_cast(stubAddr); - JSTaggedValue res = setPropertyByNamePtr(thread, receiver, propKey, value, true); -#else JSTaggedValue res = FastRuntimeStub::SetPropertyByName(thread, receiver, propKey, value); -#endif if (!res.IsHole()) { INTERPRETER_RETURN_IF_ABRUPT(res); RESTORE_ACC(); @@ -2288,7 +2269,6 @@ void InterpreterAssembly::HandleStOwnByNamePrefId32V8( } RESTORE_ACC(); } - SAVE_ACC(); receiver = GET_VREG_VALUE(v0); // Maybe moved by GC auto propKey = ConstantPool::Cast(constpool.GetTaggedObject())->GetObjectFromCache(stringId); // Maybe moved by GC diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index 878ad0638b..b6806299be 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -291,6 +291,13 @@ void JSThread::LoadStubModule(const char *moduleFile) stubModule.GetStubEntry(kungfu::StubId::STUB_HandleMovDynV8V8); bytecodeHandlers_[EcmaOpcode::MOV_DYN_V16_V16] = stubModule.GetStubEntry(kungfu::StubId::STUB_HandleMovDynV16V16); + bytecodeHandlers_[EcmaOpcode::IMPORTMODULE_PREF_ID32] = + stubModule.GetStubEntry(kungfu::StubId::STUB_HandleImportModulePrefId32); + bytecodeHandlers_[EcmaOpcode::STMODULEVAR_PREF_ID32] = + stubModule.GetStubEntry(kungfu::StubId::STUB_HandleStModuleVarPrefId32); + bytecodeHandlers_[EcmaOpcode::LDMODVARBYNAME_PREF_ID32_V8] = + stubModule.GetStubEntry(kungfu::StubId::STUB_HandleLdModVarByNamePrefId32V8); + #ifdef NDEBUG kungfu::LLVMStackMapParser::GetInstance().Print(); #endif diff --git a/ecmascript/runtime_trampolines.cpp b/ecmascript/runtime_trampolines.cpp index a989d8f9a8..5b679fbf44 100644 --- a/ecmascript/runtime_trampolines.cpp +++ b/ecmascript/runtime_trampolines.cpp @@ -539,4 +539,22 @@ JSTaggedType RuntimeTrampolines::StOwnByNameWithNameSet(uintptr_t argGlue, JSTag auto thread = JSThread::GlueToJSThread(argGlue); return SlowRuntimeStub::StOwnByValueWithNameSet(thread, JSTaggedValue(obj), JSTaggedValue(prop), JSTaggedValue(value)).GetRawData(); } + +JSTaggedType RuntimeTrampolines::ImportModule(uintptr_t argGlue, JSTaggedType moduleName) +{ + auto thread = JSThread::GlueToJSThread(argGlue); + return SlowRuntimeStub::ImportModule(thread, JSTaggedValue(moduleName)).GetRawData(); +} + +void RuntimeTrampolines::StModuleVar(uintptr_t argGlue, JSTaggedType exportName, JSTaggedType exportObj) +{ + auto thread = JSThread::GlueToJSThread(argGlue); + SlowRuntimeStub::StModuleVar(thread, JSTaggedValue(exportName), JSTaggedValue(exportObj)); +} + +JSTaggedType RuntimeTrampolines::LdModvarByName(uintptr_t argGlue, JSTaggedType moduleObj, JSTaggedType itemName) +{ + auto thread = JSThread::GlueToJSThread(argGlue); + return SlowRuntimeStub::LdModvarByName(thread, JSTaggedValue(moduleObj), JSTaggedValue(itemName)).GetRawData(); +} } // namespace panda::ecmascript diff --git a/ecmascript/runtime_trampolines.h b/ecmascript/runtime_trampolines.h index 72e0298cfc..2540f9f834 100644 --- a/ecmascript/runtime_trampolines.h +++ b/ecmascript/runtime_trampolines.h @@ -99,6 +99,9 @@ public: static void SetFunctionNameNoPrefix(uintptr_t argGlue, JSTaggedType argFunc, JSTaggedType argName); static JSTaggedType StOwnByValueWithNameSet(uintptr_t argGlue, JSTaggedType obj, JSTaggedType key, JSTaggedType value); static JSTaggedType StOwnByNameWithNameSet(uintptr_t argGlue, JSTaggedType obj, JSTaggedType key, JSTaggedType value); + static JSTaggedType ImportModule(uintptr_t argGlue, JSTaggedType moduleName); + static void StModuleVar(uintptr_t argGlue, JSTaggedType exportName, JSTaggedType exportObj); + static JSTaggedType LdModvarByName(uintptr_t argGlue, JSTaggedType moduleObj, JSTaggedType itemName); }; } // namespace panda::ecmascript #endif -- Gitee