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:
Andreas Kling 2024-05-09 15:13:31 +02:00 committed by Alexander Kalenik
commit 7654da3851
Notes: sideshowbarker 2024-07-18 00:41:35 +09:00
8 changed files with 166 additions and 28 deletions

View file

@ -36,6 +36,12 @@ public:
u8 const* data() const { return m_buffer.data(); }
size_t size() const { return m_buffer.size(); }
void rewind()
{
m_buffer.resize_and_keep_capacity(m_last_instruction_start_offset);
m_terminated = false;
}
void grow(size_t additional_size);
void terminate(Badge<Generator>) { m_terminated = true; }
@ -55,6 +61,9 @@ public:
auto const& this_() const { return m_this; }
void set_this(ScopedOperand operand) { m_this = operand; }
[[nodiscard]] size_t last_instruction_start_offset() const { return m_last_instruction_start_offset; }
void set_last_instruction_start_offset(size_t offset) { m_last_instruction_start_offset = offset; }
private:
explicit BasicBlock(u32 index, String name);
@ -68,6 +77,8 @@ private:
HashMap<size_t, SourceRecord> m_source_map;
Optional<ScopedOperand> m_this;
size_t m_last_instruction_start_offset { 0 };
};
}