mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
LibJS/Bytecode: Do basic compare-and-jump peephole optimization
We now fuse sequences like [LessThan, JumpIf] to JumpLessThan. This is only allowed for temporaries (i.e VM registers) with no other references to them.
This commit is contained in:
parent
9bcb0feb4d
commit
7654da3851
Notes:
sideshowbarker
2024-07-18 00:41:35 +09:00
Author: https://github.com/awesomekling
Commit: 7654da3851
Pull-request: https://github.com/SerenityOS/serenity/pull/24276
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/shannonbooth
8 changed files with 166 additions and 28 deletions
|
@ -77,6 +77,7 @@ public:
|
|||
{
|
||||
VERIFY(!is_current_block_terminated());
|
||||
size_t slot_offset = m_current_basic_block->size();
|
||||
m_current_basic_block->set_last_instruction_start_offset(slot_offset);
|
||||
grow(sizeof(OpType));
|
||||
void* slot = m_current_basic_block->data() + slot_offset;
|
||||
new (slot) OpType(forward<Args>(args)...);
|
||||
|
@ -93,6 +94,7 @@ public:
|
|||
|
||||
size_t size_to_allocate = round_up_to_power_of_two(sizeof(OpType) + extra_slot_count * sizeof(ExtraSlotType), alignof(void*));
|
||||
size_t slot_offset = m_current_basic_block->size();
|
||||
m_current_basic_block->set_last_instruction_start_offset(slot_offset);
|
||||
grow(size_to_allocate);
|
||||
void* slot = m_current_basic_block->data() + slot_offset;
|
||||
new (slot) OpType(forward<Args>(args)...);
|
||||
|
@ -115,6 +117,8 @@ public:
|
|||
emit_with_extra_slots<OpType, Value>(extra_operand_slots, forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void emit_jump_if(ScopedOperand const& condition, Label true_target, Label false_target);
|
||||
|
||||
struct ReferenceOperands {
|
||||
Optional<ScopedOperand> base {}; // [[Base]]
|
||||
Optional<ScopedOperand> referenced_name {}; // [[ReferencedName]] as an operand
|
||||
|
@ -309,6 +313,9 @@ private:
|
|||
|
||||
void grow(size_t);
|
||||
|
||||
// Returns true if a fused instruction was emitted.
|
||||
[[nodiscard]] bool fuse_compare_and_jump(ScopedOperand const& condition, Label true_target, Label false_target);
|
||||
|
||||
struct LabelableScope {
|
||||
Label bytecode_target;
|
||||
Vector<DeprecatedFlyString> language_label_set;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue