diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-06-13 20:40:20 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-06-15 22:06:33 +0430 |
commit | 1414c7b049c5a8858f400a5e677cd20894463b32 (patch) | |
tree | 3b5255b2688222739f515819bed19c982a45baca /Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | |
parent | e81fd7106b47d93345e11059bb80600a66b4daf3 (diff) | |
download | serenity-1414c7b049c5a8858f400a5e677cd20894463b32.zip |
LibJS: Add a basic pass manager and add some basic passes
This commit adds a bunch of passes, the most interesting of which is a
pass that merges blocks together, and a pass that places blocks that
flow into each other next to each other, and a very simply pass that
removes duplicate basic blocks.
Note that this does not remove the jump at the end of each block in that
pass to avoid scope creep in the passes.
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode/Interpreter.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Interpreter.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index eb63d3f895..4d4441cd7d 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -165,4 +165,38 @@ void Interpreter::continue_pending_unwind(Label const& resume_label) jump(resume_label); } } + +AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> Interpreter::s_optimization_pipelines {}; + +Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::OptimizationLevel level) +{ + 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<PassManager>(); + if (level == OptimizationLevel::Default) { + 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>(); + } else { + VERIFY_NOT_REACHED(); + } + + auto& passes = *pm; + entry = move(pm); + + return passes; +} + } |