From dfe1b474d09906c877c477207a146e07d227c191 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Thu, 14 Dec 2023 13:44:20 +0000 Subject: [PATCH] Use first-level instruction of definefieldbyname Issue:https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8OJ77 Signed-off-by: ctw-ian Change-Id: I9b81300014c64309e38341c54a06db671f3af5ce --- es2panda/compiler/core/function.cpp | 5 +---- es2panda/compiler/core/pandagen.cpp | 14 ++++++++++---- es2panda/compiler/core/pandagen.h | 1 + es2panda/ir/expressions/callExpression.cpp | 7 ++----- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index b51e0521b0..57676ef623 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -215,7 +215,6 @@ static void CompileFunction(PandaGen *pg) const auto *classDef = util::Helpers::GetClassDefiniton(decl); if (classDef->Super() == nullptr && classDef->NeedInstanceInitializer()) { RegScope rs(pg); - auto callee = pg->AllocReg(); auto thisReg = pg->AllocReg(); pg->GetThis(decl); @@ -223,9 +222,7 @@ static void CompileFunction(PandaGen *pg) auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); pg->LoadLexicalVar(decl, level, slot); - pg->StoreAccumulator(decl, callee); - - pg->CallThis(decl, callee, 1); + pg->CallInit(decl, thisReg); } } diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 5f7527ddbc..b2cb94055d 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -475,7 +475,7 @@ void PandaGen::DefineClassField(const ir::AstNode *node, VReg obj, const Operand void PandaGen::DefineClassPrivateField(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj) { - ra_.Emit(node, level, slot, obj); + ra_.Emit(node, 0, level, slot, obj); } void PandaGen::StoreOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop, bool nameSetting) @@ -577,7 +577,7 @@ void PandaGen::StoreObjByName(const ir::AstNode *node, VReg obj, const util::Str void PandaGen::DefineFieldByName(const ir::AstNode *node, VReg obj, const util::StringView &prop) { - ra_.Emit(node, prop, obj); + ra_.Emit(node, 0, prop, obj); strings_.insert(prop); } @@ -614,12 +614,12 @@ void PandaGen::StoreObjByIndex(const ir::AstNode *node, VReg obj, int64_t index) void PandaGen::DefineFieldByValue(const ir::AstNode *node, VReg obj, VReg prop) { - ra_.Emit(node, prop, obj); + ra_.Emit(node, 0, prop, obj); } void PandaGen::DefineFieldByIndex(const ir::AstNode *node, VReg obj, int64_t index) { - ra_.Emit(node, index, obj); + ra_.Emit(node, 0, index, obj); } void PandaGen::StOwnByName(const ir::AstNode *node, VReg obj, const util::StringView &prop, bool nameSetting) @@ -1357,6 +1357,12 @@ void PandaGen::NotifyConcurrentResult(const ir::AstNode *node) } } +void PandaGen::CallInit(const ir::AstNode *node, VReg thisReg) +{ + // callee is in acc + ra_.Emit(node, 0, thisReg); +} + void PandaGen::NewObject(const ir::AstNode *node, VReg startReg, size_t argCount) { if (argCount <= util::Helpers::MAX_INT8) { diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index 7d76bda3ac..f8028ba21c 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -378,6 +378,7 @@ public: void SuperCall(const ir::AstNode *node, VReg startReg, size_t argCount); void SuperCallSpread(const ir::AstNode *node, VReg vs); void NotifyConcurrentResult(const ir::AstNode *node); + void CallInit(const ir::AstNode *node, VReg thisReg); void NewObject(const ir::AstNode *node, VReg startReg, size_t argCount); void DefineFunction(const ir::AstNode *node, const ir::ScriptFunction *realNode, const util::StringView &name); diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index e09d1f989a..0956850bfc 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -124,16 +124,13 @@ void CallExpression::Compile(compiler::PandaGen *pg) const const auto *classDef = util::Helpers::GetClassDefiniton(util::Helpers::GetContainingConstructor(this)); if (classDef->NeedInstanceInitializer()) { - auto callee = pg->AllocReg(); auto thisReg = pg->AllocReg(); + pg->MoveVreg(this, thisReg, newThis); auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); pg->LoadLexicalVar(this, level, slot); - pg->StoreAccumulator(this, callee); - - pg->MoveVreg(this, thisReg, newThis); - pg->CallThis(this, callee, 1); + pg->CallInit(this, thisReg); } return; } -- Gitee