1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 16:15:10 +00:00

LibJS: Remove the concept of bytecode optimization levels

While this would be useful in the future for implementing a multi-tiered
optimization strategy, currently a binary on/off is enough for us. This
removes the confusingly on-by-default `OptimizationLevel::None` option
which made the optimization pipeline a no-op even if
`Bytecode::Interpreter::set_optimizations_enabled` had been called.

Fixes #15982
This commit is contained in:
Daniel Bertalan 2023-06-26 20:10:11 +02:00 committed by Ali Mohammad Pur
parent e012565898
commit cc9ec6693b
2 changed files with 16 additions and 36 deletions

View file

@ -394,21 +394,10 @@ VM::InterpreterExecutionScope Interpreter::ast_interpreter_scope(Realm& realm)
return { *m_ast_interpreter }; return { *m_ast_interpreter };
} }
AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> Interpreter::s_optimization_pipelines {}; Bytecode::PassManager& Interpreter::optimization_pipeline()
Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::OptimizationLevel level)
{ {
auto underlying_level = to_underlying(level); static auto s_optimization_pipeline = [] {
VERIFY(underlying_level <= to_underlying(Interpreter::OptimizationLevel::__Count)); auto pm = make<Bytecode::PassManager>();
auto& entry = s_optimization_pipelines[underlying_level];
if (entry)
return *entry;
auto pm = make<PassManager>();
if (level == OptimizationLevel::None) {
// No optimization.
} else if (level == OptimizationLevel::Optimize) {
pm->add<Passes::GenerateCFG>(); pm->add<Passes::GenerateCFG>();
pm->add<Passes::UnifySameBlocks>(); pm->add<Passes::UnifySameBlocks>();
pm->add<Passes::GenerateCFG>(); pm->add<Passes::GenerateCFG>();
@ -420,14 +409,9 @@ Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::Optimizat
pm->add<Passes::GenerateCFG>(); pm->add<Passes::GenerateCFG>();
pm->add<Passes::PlaceBlocks>(); pm->add<Passes::PlaceBlocks>();
pm->add<Passes::EliminateLoads>(); pm->add<Passes::EliminateLoads>();
} else { return pm;
VERIFY_NOT_REACHED(); }();
} return *s_optimization_pipeline;
auto& passes = *pm;
entry = move(pm);
return passes;
} }
size_t Interpreter::pc() const size_t Interpreter::pc() const
@ -448,12 +432,16 @@ ThrowCompletionOr<NonnullOwnPtr<Bytecode::Executable>> compile(VM& vm, ASTNode c
auto bytecode_executable = executable_result.release_value(); auto bytecode_executable = executable_result.release_value();
bytecode_executable->name = name; bytecode_executable->name = name;
auto& passes = Bytecode::Interpreter::optimization_pipeline();
passes.perform(*bytecode_executable); if (s_optimizations_enabled) {
if constexpr (JS_BYTECODE_DEBUG) { auto& passes = Bytecode::Interpreter::optimization_pipeline();
dbgln("Optimisation passes took {}us", passes.elapsed()); passes.perform(*bytecode_executable);
dbgln("Compiled Bytecode::Block for function '{}':", name); if constexpr (JS_BYTECODE_DEBUG) {
dbgln("Optimisation passes took {}us", passes.elapsed());
dbgln("Compiled Bytecode::Block for function '{}':", name);
}
} }
if (Bytecode::g_dump_bytecode) if (Bytecode::g_dump_bytecode)
bytecode_executable->dump(); bytecode_executable->dump();

View file

@ -86,13 +86,7 @@ public:
size_t pc() const; size_t pc() const;
DeprecatedString debug_position() const; DeprecatedString debug_position() const;
enum class OptimizationLevel { static Bytecode::PassManager& optimization_pipeline();
None,
Optimize,
__Count,
Default = None,
};
static Bytecode::PassManager& optimization_pipeline(OptimizationLevel = OptimizationLevel::Default);
VM::InterpreterExecutionScope ast_interpreter_scope(Realm&); VM::InterpreterExecutionScope ast_interpreter_scope(Realm&);
@ -109,8 +103,6 @@ private:
MarkedVector<Value>& registers() { return window().registers; } MarkedVector<Value>& registers() { return window().registers; }
static AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> s_optimization_pipelines;
VM& m_vm; VM& m_vm;
Vector<Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>> m_register_windows; Vector<Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>> m_register_windows;
Optional<BasicBlock const*> m_pending_jump; Optional<BasicBlock const*> m_pending_jump;