1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 03:47:34 +00:00

LibJS/Bytecode: Bring back the bytecode optimization pipeline

...minus the EliminateLoads pass, since it was not compatible with the
new bytecode format.
This commit is contained in:
Andreas Kling 2024-02-25 17:59:20 +01:00
parent 836d93f7e3
commit 5b29974bfa
15 changed files with 962 additions and 65 deletions

View file

@ -15,6 +15,7 @@
#include <LibJS/Bytecode/Interpreter.h>
#include <LibJS/Bytecode/Label.h>
#include <LibJS/Bytecode/Op.h>
#include <LibJS/Bytecode/PassManager.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/BigInt.h>
@ -532,6 +533,25 @@ void Interpreter::enter_object_environment(Object& object)
vm().running_execution_context().lexical_environment = new_object_environment(object, true, old_environment);
}
static PassManager& optimization_pipeline()
{
static auto s_optimization_pipeline = [] {
auto pm = make<PassManager>();
pm->add<Passes::GenerateCFG>();
pm->add<Passes::UnifySameBlocks>();
pm->add<Passes::GenerateCFG>();
pm->add<Passes::MergeBlocks>();
pm->add<Passes::GenerateCFG>();
pm->add<Passes::UnifySameBlocks>();
pm->add<Passes::GenerateCFG>();
pm->add<Passes::MergeBlocks>();
pm->add<Passes::GenerateCFG>();
pm->add<Passes::PlaceBlocks>();
return pm;
}();
return *s_optimization_pipeline;
}
ThrowCompletionOr<NonnullGCPtr<Bytecode::Executable>> compile(VM& vm, ASTNode const& node, ReadonlySpan<FunctionParameter> parameters, FunctionKind kind, DeprecatedFlyString const& name)
{
auto executable_result = Bytecode::Generator::generate(vm, node, parameters, kind);
@ -541,6 +561,13 @@ ThrowCompletionOr<NonnullGCPtr<Bytecode::Executable>> compile(VM& vm, ASTNode co
auto bytecode_executable = executable_result.release_value();
bytecode_executable->name = name;
auto& passes = 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();