mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
LibJS/JIT: Consolidate exits from the jitted code
Instead of emitting the "restore callee-saved registers and return" sequence again and again, just emit it once at the end of the generated code, and have everyone jump to it. This is a code size optimization that saves 207KiB on Kraken/ai-astar.js
This commit is contained in:
parent
0768bf2623
commit
9afd12a8ba
2 changed files with 15 additions and 4 deletions
|
@ -337,7 +337,7 @@ void Compiler::check_exception()
|
|||
Assembler::Operand::Imm(0),
|
||||
handle_exception);
|
||||
|
||||
m_assembler.exit();
|
||||
jump_to_exit();
|
||||
|
||||
// handle_exception:
|
||||
handle_exception.link(m_assembler);
|
||||
|
@ -593,7 +593,7 @@ void Compiler::compile_return(Bytecode::Op::Return const&)
|
|||
// normal_return:
|
||||
normal_return.link(m_assembler);
|
||||
store_vm_register(Bytecode::Register::return_value(), GPR0);
|
||||
m_assembler.exit();
|
||||
jump_to_exit();
|
||||
}
|
||||
|
||||
static Value cxx_new_string(VM& vm, DeprecatedString const& string)
|
||||
|
@ -971,7 +971,7 @@ void Compiler::compile_continue_pending_unwind(Bytecode::Op::ContinuePendingUnwi
|
|||
|
||||
// finish the pending return from the try block
|
||||
store_vm_register(Bytecode::Register::return_value(), GPR0);
|
||||
m_assembler.exit();
|
||||
jump_to_exit();
|
||||
}
|
||||
|
||||
static void cxx_create_lexical_environment(VM& vm)
|
||||
|
@ -999,6 +999,11 @@ void Compiler::compile_leave_lexical_environment(Bytecode::Op::LeaveLexicalEnvir
|
|||
m_assembler.native_call((void*)cxx_leave_lexical_environment);
|
||||
}
|
||||
|
||||
void Compiler::jump_to_exit()
|
||||
{
|
||||
m_assembler.jump(m_exit_label);
|
||||
}
|
||||
|
||||
OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_executable)
|
||||
{
|
||||
if (!getenv("LIBJS_JIT"))
|
||||
|
@ -1158,9 +1163,12 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
|
|||
++it;
|
||||
}
|
||||
if (!block->is_terminated())
|
||||
compiler.m_assembler.exit();
|
||||
compiler.jump_to_exit();
|
||||
}
|
||||
|
||||
compiler.m_exit_label.link(compiler.m_assembler);
|
||||
compiler.m_assembler.exit();
|
||||
|
||||
auto* executable_memory = mmap(nullptr, compiler.m_output.size(), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
|
||||
if (executable_memory == MAP_FAILED) {
|
||||
dbgln("mmap: {}", strerror(errno));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue