Forráskód Böngészése

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

We don't support other architectures yet!
Andreas Kling 1 éve
szülő
commit
a645b9c6c3

+ 55 - 50
Userland/Libraries/LibJS/JIT/Compiler.cpp

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

+ 47 - 33
Userland/Libraries/LibJS/JIT/Compiler.h

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