1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:47:44 +00:00

LibJS: Work-in-progress JIT compiler :^)

This commit is contained in:
Andreas Kling 2023-10-14 14:37:48 +02:00
parent f52e4fa5c2
commit babdc0a25b
11 changed files with 634 additions and 4 deletions

View file

@ -43,6 +43,16 @@ public:
DeprecatedString const& name() const { return m_name; }
// ==============================================================
// FIXME: This is JIT state and shouldn't be part of BasicBlock itself.
// Offset into the instruction stream where this code block starts.
size_t offset { 0 };
// Offsets into the instruction stream where we have RIP-relative jump offsets to here that need patching.
Vector<size_t> jumps_to_here;
// ==============================================================
private:
explicit BasicBlock(DeprecatedString name);

View file

@ -13,6 +13,7 @@
#include <LibJS/Bytecode/Instruction.h>
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Bytecode/Op.h>
#include <LibJS/JIT/Compiler.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/BigInt.h>
@ -349,7 +350,16 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executa
else
push_call_frame(make<CallFrame>(), executable.number_of_registers);
run_bytecode();
if (auto native_executable = JIT::Compiler::compile(executable)) {
native_executable->run(vm());
for (size_t i = 0; i < vm().running_execution_context().local_variables.size(); ++i) {
dbgln("%{}: {}", i, vm().running_execution_context().local_variables[i]);
}
} else {
run_bytecode();
}
dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter did run unit {:p}", &executable);

View file

@ -80,6 +80,9 @@ public:
void visit_edges(Cell::Visitor&);
Span<Value> registers() { return m_current_call_frame; }
ReadonlySpan<Value> registers() const { return m_current_call_frame; }
private:
void run_bytecode();
@ -93,9 +96,6 @@ private:
return const_cast<Interpreter*>(this)->call_frame();
}
Span<Value> registers() { return m_current_call_frame; }
ReadonlySpan<Value> registers() const { return m_current_call_frame; }
void push_call_frame(Variant<NonnullOwnPtr<CallFrame>, CallFrame*>, size_t register_count);
[[nodiscard]] Variant<NonnullOwnPtr<CallFrame>, CallFrame*> pop_call_frame();

View file

@ -115,6 +115,8 @@ private:
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const; \
DeprecatedString to_deprecated_string_impl(Bytecode::Executable const&) const; \
\
Register lhs() const { return m_lhs_reg; } \
\
private: \
Register m_lhs_reg; \
};