Skip to content

Commit

Permalink
LibJS: Replace SetLocal instruction usage with Mov
Browse files Browse the repository at this point in the history
No need for separate instuction to set a local.
  • Loading branch information
kalenikaliaksandr committed May 14, 2024
1 parent 46ee2b5 commit 857a750
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 48 deletions.
2 changes: 1 addition & 1 deletion Userland/Libraries/LibJS/Bytecode/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bytecode::Op::SetLocal>(identifier.local_variable_index(), value);
emit<Bytecode::Op::Mov>(local(identifier.local_variable_index()), value);
} else {
emit<Bytecode::Op::SetVariable>(intern_identifier(identifier.string()), value, initialization_mode, mode);
}
Expand Down
1 change: 0 additions & 1 deletion Userland/Libraries/LibJS/Bytecode/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
O(ScheduleJump) \
O(SetArgument) \
O(SetVariable) \
O(SetLocal) \
O(StrictlyEquals) \
O(StrictlyInequals) \
O(Sub) \
Expand Down
20 changes: 0 additions & 20 deletions Userland/Libraries/LibJS/Bytecode/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -364,12 +363,6 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
for (;;) {
goto* bytecode_dispatch_table[static_cast<size_t>((*reinterpret_cast<Instruction const*>(&bytecode[program_counter])).type())];

handle_SetLocal: {
auto& instruction = *reinterpret_cast<Op::SetLocal const*>(&bytecode[program_counter]);
registers_and_constants_and_locals[instruction.index()] = get(instruction.src());
DISPATCH_NEXT(SetLocal);
}

handle_GetArgument: {
auto const& instruction = *reinterpret_cast<Op::GetArgument const*>(&bytecode[program_counter]);
set(instruction.dst(), arguments[instruction.index()]);
Expand Down Expand Up @@ -1396,12 +1389,6 @@ ThrowCompletionOr<void> SetVariable::execute_impl(Bytecode::Interpreter& interpr
return {};
}

ThrowCompletionOr<void> SetLocal::execute_impl(Bytecode::Interpreter&) const
{
// Handled in the interpreter loop.
__builtin_unreachable();
}

ThrowCompletionOr<void> SetArgument::execute_impl(Bytecode::Interpreter&) const
{
// Handled in the interpreter loop.
Expand Down Expand Up @@ -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));
Expand Down
26 changes: 0 additions & 26 deletions Userland/Libraries/LibJS/Bytecode/Op.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,32 +699,6 @@ class SetVariable final : public Instruction {
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<void> execute_impl(Bytecode::Interpreter&) const;
ByteString to_byte_string_impl(Bytecode::Executable const&) const;
void visit_operands_impl(Function<void(Operand&)> 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)
Expand Down

0 comments on commit 857a750

Please sign in to comment.