1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

LibJS/JIT: Stub out the JIT compiler on everything but ARCH(X86_64)

We don't support other architectures yet!
This commit is contained in:
Andreas Kling 2023-10-27 15:14:49 +02:00
parent d1c701f79f
commit a645b9c6c3
2 changed files with 100 additions and 81 deletions

View file

@ -5,6 +5,7 @@
*/ */
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/Platform.h>
#include <LibJS/Bytecode/CommonImplementations.h> #include <LibJS/Bytecode/CommonImplementations.h>
#include <LibJS/Bytecode/Instruction.h> #include <LibJS/Bytecode/Instruction.h>
#include <LibJS/Bytecode/Interpreter.h> #include <LibJS/Bytecode/Interpreter.h>
@ -17,23 +18,25 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#define LOG_JIT_SUCCESS 1 #if ARCH(X86_64)
#define LOG_JIT_FAILURE 1
#define DUMP_JIT_MACHINE_CODE_TO_STDOUT 0
#define TRY_OR_SET_EXCEPTION(expression) \ # define LOG_JIT_SUCCESS 1
({ \ # define LOG_JIT_FAILURE 1
/* Ignore -Wshadow to allow nesting the macro. */ \ # define DUMP_JIT_MACHINE_CODE_TO_STDOUT 0
AK_IGNORE_DIAGNOSTIC("-Wshadow", \
auto&& _temporary_result = (expression)); \ # define TRY_OR_SET_EXCEPTION(expression) \
static_assert(!::AK::Detail::IsLvalueReference<decltype(_temporary_result.release_value())>, \ ({ \
"Do not return a reference from a fallible expression"); \ /* Ignore -Wshadow to allow nesting the macro. */ \
if (_temporary_result.is_error()) [[unlikely]] { \ AK_IGNORE_DIAGNOSTIC("-Wshadow", \
vm.bytecode_interpreter().reg(Bytecode::Register::exception()) = _temporary_result.release_error().value().value(); \ auto&& _temporary_result = (expression)); \
return {}; \ static_assert(!::AK::Detail::IsLvalueReference<decltype(_temporary_result.release_value())>, \
} \ "Do not return a reference from a fallible expression"); \
_temporary_result.release_value(); \ if (_temporary_result.is_error()) [[unlikely]] { \
}) vm.bytecode_interpreter().reg(Bytecode::Register::exception()) = _temporary_result.release_error().value().value(); \
return {}; \
} \
_temporary_result.release_value(); \
})
namespace JS::JIT { namespace JS::JIT {
@ -434,23 +437,23 @@ static ThrowCompletionOr<Value> typed_equals(VM&, Value src1, Value src2)
return Value(is_strictly_equal(src1, src2)); return Value(is_strictly_equal(src1, src2));
} }
#define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ # define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \
static Value cxx_##snake_case_name(VM& vm, Value lhs, Value rhs) \ static Value cxx_##snake_case_name(VM& vm, Value lhs, Value rhs) \
{ \ { \
return TRY_OR_SET_EXCEPTION(snake_case_name(vm, lhs, rhs)); \ return TRY_OR_SET_EXCEPTION(snake_case_name(vm, lhs, rhs)); \
} \ } \
\ \
void Compiler::compile_##snake_case_name(Bytecode::Op::TitleCaseName const& op) \ void Compiler::compile_##snake_case_name(Bytecode::Op::TitleCaseName const& op) \
{ \ { \
load_vm_register(ARG1, op.lhs()); \ load_vm_register(ARG1, op.lhs()); \
load_vm_register(ARG2, Bytecode::Register::accumulator()); \ load_vm_register(ARG2, Bytecode::Register::accumulator()); \
m_assembler.native_call((void*)cxx_##snake_case_name); \ m_assembler.native_call((void*)cxx_##snake_case_name); \
store_vm_register(Bytecode::Register::accumulator(), RET); \ store_vm_register(Bytecode::Register::accumulator(), RET); \
check_exception(); \ check_exception(); \
} }
JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP) JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP)
#undef DO_COMPILE_COMMON_BINARY_OP # undef DO_COMPILE_COMMON_BINARY_OP
static Value cxx_less_than(VM& vm, Value lhs, Value rhs) static Value cxx_less_than(VM& vm, Value lhs, Value rhs)
{ {
@ -509,22 +512,22 @@ static ThrowCompletionOr<Value> typeof_(VM& vm, Value value)
return PrimitiveString::create(vm, value.typeof()); return PrimitiveString::create(vm, value.typeof());
} }
#define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \ # define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \
static Value cxx_##snake_case_name(VM& vm, Value value) \ static Value cxx_##snake_case_name(VM& vm, Value value) \
{ \ { \
return TRY_OR_SET_EXCEPTION(snake_case_name(vm, value)); \ return TRY_OR_SET_EXCEPTION(snake_case_name(vm, value)); \
} \ } \
\ \
void Compiler::compile_##snake_case_name(Bytecode::Op::TitleCaseName const&) \ void Compiler::compile_##snake_case_name(Bytecode::Op::TitleCaseName const&) \
{ \ { \
load_vm_register(ARG1, Bytecode::Register::accumulator()); \ load_vm_register(ARG1, Bytecode::Register::accumulator()); \
m_assembler.native_call((void*)cxx_##snake_case_name); \ m_assembler.native_call((void*)cxx_##snake_case_name); \
store_vm_register(Bytecode::Register::accumulator(), RET); \ store_vm_register(Bytecode::Register::accumulator(), RET); \
check_exception(); \ check_exception(); \
} }
JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP) JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP)
#undef DO_COMPILE_COMMON_UNARY_OP # undef DO_COMPILE_COMMON_UNARY_OP
void Compiler::compile_return(Bytecode::Op::Return const&) void Compiler::compile_return(Bytecode::Op::Return const&)
{ {
@ -1016,19 +1019,19 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
compiler.compile_less_than(static_cast<Bytecode::Op::LessThan const&>(op)); compiler.compile_less_than(static_cast<Bytecode::Op::LessThan const&>(op));
break; break;
#define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \ # define DO_COMPILE_COMMON_BINARY_OP(TitleCaseName, snake_case_name) \
case Bytecode::Instruction::Type::TitleCaseName: \ case Bytecode::Instruction::Type::TitleCaseName: \
compiler.compile_##snake_case_name(static_cast<Bytecode::Op::TitleCaseName const&>(op)); \ compiler.compile_##snake_case_name(static_cast<Bytecode::Op::TitleCaseName const&>(op)); \
break; break;
JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP) JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP)
#undef DO_COMPILE_COMMON_BINARY_OP # undef DO_COMPILE_COMMON_BINARY_OP
#define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \ # define DO_COMPILE_COMMON_UNARY_OP(TitleCaseName, snake_case_name) \
case Bytecode::Instruction::Type::TitleCaseName: \ case Bytecode::Instruction::Type::TitleCaseName: \
compiler.compile_##snake_case_name(static_cast<Bytecode::Op::TitleCaseName const&>(op)); \ compiler.compile_##snake_case_name(static_cast<Bytecode::Op::TitleCaseName const&>(op)); \
break; break;
JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP) JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP)
#undef DO_COMPILE_COMMON_UNARY_OP # undef DO_COMPILE_COMMON_UNARY_OP
default: default:
if constexpr (LOG_JIT_FAILURE) { if constexpr (LOG_JIT_FAILURE) {
@ -1088,3 +1091,5 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
} }
} }
#endif

View file

@ -6,10 +6,11 @@
#pragma once #pragma once
#include <LibJIT/Assembler.h> #if ARCH(X86_64)
#include <LibJS/Bytecode/Executable.h> # include <LibJIT/Assembler.h>
#include <LibJS/Bytecode/Op.h> # include <LibJS/Bytecode/Executable.h>
#include <LibJS/JIT/NativeExecutable.h> # include <LibJS/Bytecode/Op.h>
# include <LibJS/JIT/NativeExecutable.h>
namespace JS::JIT { namespace JS::JIT {
@ -20,6 +21,7 @@ public:
static OwnPtr<NativeExecutable> compile(Bytecode::Executable&); static OwnPtr<NativeExecutable> compile(Bytecode::Executable&);
private: private:
# if ARCH(X86_64)
static constexpr auto GPR0 = Assembler::Reg::RAX; static constexpr auto GPR0 = Assembler::Reg::RAX;
static constexpr auto GPR1 = Assembler::Reg::RCX; static constexpr auto GPR1 = Assembler::Reg::RCX;
static constexpr auto ARG0 = Assembler::Reg::RDI; static constexpr auto ARG0 = Assembler::Reg::RDI;
@ -33,6 +35,7 @@ private:
static constexpr auto REGISTER_ARRAY_BASE = Assembler::Reg::R13; static constexpr auto REGISTER_ARRAY_BASE = Assembler::Reg::R13;
static constexpr auto LOCALS_ARRAY_BASE = Assembler::Reg::R14; static constexpr auto LOCALS_ARRAY_BASE = Assembler::Reg::R14;
static constexpr auto UNWIND_CONTEXT_BASE = Assembler::Reg::R15; static constexpr auto UNWIND_CONTEXT_BASE = Assembler::Reg::R15;
# endif
void compile_load_immediate(Bytecode::Op::LoadImmediate const&); void compile_load_immediate(Bytecode::Op::LoadImmediate const&);
void compile_load(Bytecode::Op::Load const&); void compile_load(Bytecode::Op::Load const&);
@ -51,40 +54,40 @@ private:
void compile_to_numeric(Bytecode::Op::ToNumeric const&); void compile_to_numeric(Bytecode::Op::ToNumeric const&);
void compile_resolve_this_binding(Bytecode::Op::ResolveThisBinding const&); void compile_resolve_this_binding(Bytecode::Op::ResolveThisBinding const&);
#define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \ # define JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(O) \
O(Add, add) \ O(Add, add) \
O(Sub, sub) \ O(Sub, sub) \
O(Mul, mul) \ O(Mul, mul) \
O(Div, div) \ O(Div, div) \
O(Exp, exp) \ O(Exp, exp) \
O(Mod, mod) \ O(Mod, mod) \
O(In, in) \ O(In, in) \
O(InstanceOf, instance_of) \ O(InstanceOf, instance_of) \
O(GreaterThan, greater_than) \ O(GreaterThan, greater_than) \
O(GreaterThanEquals, greater_than_equals) \ O(GreaterThanEquals, greater_than_equals) \
O(LessThanEquals, less_than_equals) \ O(LessThanEquals, less_than_equals) \
O(LooselyInequals, abstract_inequals) \ O(LooselyInequals, abstract_inequals) \
O(LooselyEquals, abstract_equals) \ O(LooselyEquals, abstract_equals) \
O(StrictlyInequals, typed_inequals) \ O(StrictlyInequals, typed_inequals) \
O(StrictlyEquals, typed_equals) \ O(StrictlyEquals, typed_equals) \
O(BitwiseAnd, bitwise_and) \ O(BitwiseAnd, bitwise_and) \
O(BitwiseOr, bitwise_or) \ O(BitwiseOr, bitwise_or) \
O(BitwiseXor, bitwise_xor) \ O(BitwiseXor, bitwise_xor) \
O(LeftShift, left_shift) \ O(LeftShift, left_shift) \
O(RightShift, right_shift) \ O(RightShift, right_shift) \
O(UnsignedRightShift, unsigned_right_shift) O(UnsignedRightShift, unsigned_right_shift)
#define DO_COMPILE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \ # define DO_COMPILE_COMMON_BINARY_OP(OpTitleCase, op_snake_case) \
void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&); void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);
JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP) JS_ENUMERATE_COMMON_BINARY_OPS_WITHOUT_FAST_PATH(DO_COMPILE_COMMON_BINARY_OP)
#undef DO_COMPILE_COMMON_BINARY_OP # undef DO_COMPILE_COMMON_BINARY_OP
#define DO_COMPILE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \ # define DO_COMPILE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&); void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);
JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP) JS_ENUMERATE_COMMON_UNARY_OPS(DO_COMPILE_COMMON_UNARY_OP)
#undef DO_COMPILE_COMMON_UNARY_OP # undef DO_COMPILE_COMMON_UNARY_OP
void compile_less_than(Bytecode::Op::LessThan const&); void compile_less_than(Bytecode::Op::LessThan const&);
@ -157,3 +160,14 @@ private:
}; };
} }
#else
namespace JS::JIT {
class Compiler {
public:
static OwnPtr<NativeExecutable> compile(Bytecode::Executable&) { return nullptr; }
};
}
#endif