mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS/Bytecode: Elide jumps that land in the very next block
Jumping to the next block is effectively a no-op, so let's save time and space by just not emitting those jumps.
This commit is contained in:
parent
3a73eb99ac
commit
24d8b056c7
Notes:
sideshowbarker
2024-07-16 20:39:14 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/24d8b056c7 Pull-request: https://github.com/SerenityOS/serenity/pull/24240 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 14 additions and 0 deletions
|
@ -118,6 +118,20 @@ CodeGenerationErrorOr<NonnullGCPtr<Executable>> Generator::generate(VM& vm, ASTN
|
|||
Bytecode::InstructionStreamIterator it(block->instruction_stream());
|
||||
while (!it.at_end()) {
|
||||
auto& instruction = const_cast<Instruction&>(*it);
|
||||
|
||||
// OPTIMIZATION: Don't emit jumps that just jump to the next block.
|
||||
if (instruction.type() == Instruction::Type::Jump) {
|
||||
auto& jump = static_cast<Bytecode::Op::Jump&>(instruction);
|
||||
if (jump.target().basic_block_index() == block->index() + 1) {
|
||||
if (basic_block_start_offsets.last() == bytecode.size()) {
|
||||
// This block is empty, just skip it.
|
||||
basic_block_start_offsets.take_last();
|
||||
}
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
instruction.visit_labels([&](Label& label) {
|
||||
size_t label_offset = bytecode.size() + (bit_cast<FlatPtr>(&label) - bit_cast<FlatPtr>(&instruction));
|
||||
label_offsets.append(label_offset);
|
||||
|
|
Loading…
Reference in a new issue