diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 0fbab3c7459..c47fe41357d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -394,21 +394,10 @@ VM::InterpreterExecutionScope Interpreter::ast_interpreter_scope(Realm& realm) return { *m_ast_interpreter }; } -AK::Array, static_cast>(Interpreter::OptimizationLevel::__Count)> Interpreter::s_optimization_pipelines {}; - -Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::OptimizationLevel level) +Bytecode::PassManager& Interpreter::optimization_pipeline() { - auto underlying_level = to_underlying(level); - VERIFY(underlying_level <= to_underlying(Interpreter::OptimizationLevel::__Count)); - auto& entry = s_optimization_pipelines[underlying_level]; - - if (entry) - return *entry; - - auto pm = make(); - if (level == OptimizationLevel::None) { - // No optimization. - } else if (level == OptimizationLevel::Optimize) { + static auto s_optimization_pipeline = [] { + auto pm = make(); pm->add(); pm->add(); pm->add(); @@ -420,14 +409,9 @@ Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::Optimizat pm->add(); pm->add(); pm->add(); - } else { - VERIFY_NOT_REACHED(); - } - - auto& passes = *pm; - entry = move(pm); - - return passes; + return pm; + }(); + return *s_optimization_pipeline; } size_t Interpreter::pc() const @@ -448,12 +432,16 @@ ThrowCompletionOr> compile(VM& vm, ASTNode c auto bytecode_executable = executable_result.release_value(); bytecode_executable->name = name; - auto& passes = Bytecode::Interpreter::optimization_pipeline(); - passes.perform(*bytecode_executable); - if constexpr (JS_BYTECODE_DEBUG) { - dbgln("Optimisation passes took {}us", passes.elapsed()); - dbgln("Compiled Bytecode::Block for function '{}':", name); + + if (s_optimizations_enabled) { + auto& passes = Bytecode::Interpreter::optimization_pipeline(); + passes.perform(*bytecode_executable); + if constexpr (JS_BYTECODE_DEBUG) { + dbgln("Optimisation passes took {}us", passes.elapsed()); + dbgln("Compiled Bytecode::Block for function '{}':", name); + } } + if (Bytecode::g_dump_bytecode) bytecode_executable->dump(); diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.h b/Userland/Libraries/LibJS/Bytecode/Interpreter.h index 9f871dac892..1245e08030f 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.h +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.h @@ -86,13 +86,7 @@ public: size_t pc() const; DeprecatedString debug_position() const; - enum class OptimizationLevel { - None, - Optimize, - __Count, - Default = None, - }; - static Bytecode::PassManager& optimization_pipeline(OptimizationLevel = OptimizationLevel::Default); + static Bytecode::PassManager& optimization_pipeline(); VM::InterpreterExecutionScope ast_interpreter_scope(Realm&); @@ -109,8 +103,6 @@ private: MarkedVector& registers() { return window().registers; } - static AK::Array, static_cast>(Interpreter::OptimizationLevel::__Count)> s_optimization_pipelines; - VM& m_vm; Vector, RegisterWindow*>> m_register_windows; Optional m_pending_jump;