mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 21:29:06 +00:00
LibJS/Bytecode: Turn JumpIf condition,@a,@next into JumpTrue/JumpFalse
If one of the jump targets is the very next block, we can convert the jump instruction into a smaller JumpTrue or JumpFalse.
This commit is contained in:
parent
37d722f4a6
commit
fae1527a18
Notes:
sideshowbarker
2024-07-17 23:00:03 +09:00
Author: https://github.com/awesomekling
Commit: fae1527a18
Pull-request: https://github.com/SerenityOS/serenity/pull/24240
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/trflynn89 ✅
4 changed files with 120 additions and 0 deletions
|
@ -1110,6 +1110,58 @@ private:
|
|||
Label m_false_target;
|
||||
};
|
||||
|
||||
class JumpTrue final : public Instruction {
|
||||
public:
|
||||
constexpr static bool IsTerminator = true;
|
||||
|
||||
explicit JumpTrue(Operand condition, Label target)
|
||||
: Instruction(Type::JumpTrue, sizeof(*this))
|
||||
, m_condition(condition)
|
||||
, m_target(target)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||
ByteString to_byte_string_impl(Bytecode::Executable const&) const;
|
||||
void visit_labels_impl(Function<void(Label&)> visitor)
|
||||
{
|
||||
visitor(m_target);
|
||||
}
|
||||
|
||||
Operand condition() const { return m_condition; }
|
||||
auto& target() const { return m_target; }
|
||||
|
||||
private:
|
||||
Operand m_condition;
|
||||
Label m_target;
|
||||
};
|
||||
|
||||
class JumpFalse final : public Instruction {
|
||||
public:
|
||||
constexpr static bool IsTerminator = true;
|
||||
|
||||
explicit JumpFalse(Operand condition, Label target)
|
||||
: Instruction(Type::JumpFalse, sizeof(*this))
|
||||
, m_condition(condition)
|
||||
, m_target(target)
|
||||
{
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> execute_impl(Bytecode::Interpreter&) const;
|
||||
ByteString to_byte_string_impl(Bytecode::Executable const&) const;
|
||||
void visit_labels_impl(Function<void(Label&)> visitor)
|
||||
{
|
||||
visitor(m_target);
|
||||
}
|
||||
|
||||
Operand condition() const { return m_condition; }
|
||||
auto& target() const { return m_target; }
|
||||
|
||||
private:
|
||||
Operand m_condition;
|
||||
Label m_target;
|
||||
};
|
||||
|
||||
class JumpNullish final : public Instruction {
|
||||
public:
|
||||
constexpr static bool IsTerminator = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue