From caffd485b8bbd27547fbb07d958d0663b7610d31 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 14 May 2024 04:40:47 +0200 Subject: [PATCH] LibJS: Replace SetLocal instruction usage with Mov No need for separate instuction to set a local. --- .../Libraries/LibJS/Bytecode/Generator.cpp | 2 +- .../Libraries/LibJS/Bytecode/Instruction.h | 1 - .../Libraries/LibJS/Bytecode/Interpreter.cpp | 20 -------------- Userland/Libraries/LibJS/Bytecode/Op.h | 26 ------------------- 4 files changed, 1 insertion(+), 48 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.cpp b/Userland/Libraries/LibJS/Bytecode/Generator.cpp index 75b1a2ffba..513e9ab477 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Generator.cpp @@ -814,7 +814,7 @@ void Generator::emit_set_variable(JS::Identifier const& identifier, ScopedOperan // Moving a local to itself is a no-op. return; } - emit(identifier.local_variable_index(), value); + emit(local(identifier.local_variable_index()), value); } else { emit(intern_identifier(identifier.string()), value, initialization_mode, mode); } diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index 2999f164bb..199eededf7 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -123,7 +123,6 @@ O(ScheduleJump) \ O(SetArgument) \ O(SetVariable) \ - O(SetLocal) \ O(StrictlyEquals) \ O(StrictlyInequals) \ O(Sub) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index c0e01a5756..9de1d768bd 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -328,7 +328,6 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point) auto& running_execution_context = this->running_execution_context(); auto* arguments = running_execution_context.arguments.data(); - auto* registers_and_constants_and_locals = running_execution_context.registers_and_constants_and_locals.data(); auto& accumulator = this->accumulator(); auto& executable = current_executable(); auto const* bytecode = executable.bytecode.data(); @@ -364,12 +363,6 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point) for (;;) { goto* bytecode_dispatch_table[static_cast((*reinterpret_cast(&bytecode[program_counter])).type())]; - handle_SetLocal: { - auto& instruction = *reinterpret_cast(&bytecode[program_counter]); - registers_and_constants_and_locals[instruction.index()] = get(instruction.src()); - DISPATCH_NEXT(SetLocal); - } - handle_GetArgument: { auto const& instruction = *reinterpret_cast(&bytecode[program_counter]); set(instruction.dst(), arguments[instruction.index()]); @@ -1396,12 +1389,6 @@ ThrowCompletionOr SetVariable::execute_impl(Bytecode::Interpreter& interpr return {}; } -ThrowCompletionOr SetLocal::execute_impl(Bytecode::Interpreter&) const -{ - // Handled in the interpreter loop. - __builtin_unreachable(); -} - ThrowCompletionOr SetArgument::execute_impl(Bytecode::Interpreter&) const { // Handled in the interpreter loop. @@ -2156,13 +2143,6 @@ ByteString SetVariable::to_byte_string_impl(Bytecode::Executable const& executab mode_string, initialization_mode_name); } -ByteString SetLocal::to_byte_string_impl(Bytecode::Executable const& executable) const -{ - return ByteString::formatted("SetLocal {}, {}", - format_operand("dst"sv, dst(), executable), - format_operand("src"sv, src(), executable)); -} - ByteString GetArgument::to_byte_string_impl(Bytecode::Executable const& executable) const { return ByteString::formatted("GetArgument {}, {}", index(), format_operand("dst"sv, dst(), executable)); diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 485f0e75bf..d3b941d177 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -699,32 +699,6 @@ private: mutable EnvironmentCoordinate m_cache; }; -class SetLocal final : public Instruction { -public: - SetLocal(size_t index, Operand src) - : Instruction(Type::SetLocal) - , m_dst(Operand(Operand::Type::Local, index)) - , m_src(src) - { - } - - ThrowCompletionOr execute_impl(Bytecode::Interpreter&) const; - ByteString to_byte_string_impl(Bytecode::Executable const&) const; - void visit_operands_impl(Function visitor) - { - visitor(m_dst); - visitor(m_src); - } - - u32 index() const { return m_dst.index(); } - Operand dst() const { return m_dst; } - Operand src() const { return m_src; } - -private: - Operand m_dst; - Operand m_src; -}; - class SetArgument final : public Instruction { public: SetArgument(size_t index, Operand src)