mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibJS/Bytecode: Reuse bytecode registers
This patch adds a register freelist to Bytecode::Generator and switches all operands inside the generator to a new ScopedOperand type that is ref-counted and automatically frees the register when nothing uses it. This dramatically reduces the size of bytecode executable register windows, which were often in the several thousands of registers for large functions. Most functions now use less than 100 registers.
This commit is contained in:
parent
f537d0b3cf
commit
cea59b6642
Notes:
sideshowbarker
2024-07-17 01:55:29 +09:00
Author: https://github.com/awesomekling
Commit: cea59b6642
Pull-request: https://github.com/SerenityOS/serenity/pull/24260
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/mattco98
10 changed files with 505 additions and 381 deletions
47
Userland/Libraries/LibJS/Bytecode/ScopedOperand.h
Normal file
47
Userland/Libraries/LibJS/Bytecode/ScopedOperand.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibJS/Bytecode/Operand.h>
|
||||
|
||||
namespace JS::Bytecode {
|
||||
|
||||
class ScopedOperandImpl : public RefCounted<ScopedOperandImpl> {
|
||||
public:
|
||||
ScopedOperandImpl(Generator& generator, Operand operand)
|
||||
: m_generator(generator)
|
||||
, m_operand(operand)
|
||||
{
|
||||
}
|
||||
|
||||
~ScopedOperandImpl();
|
||||
|
||||
[[nodiscard]] Operand operand() const { return m_operand; }
|
||||
|
||||
private:
|
||||
Generator& m_generator;
|
||||
Operand m_operand;
|
||||
};
|
||||
|
||||
class ScopedOperand {
|
||||
public:
|
||||
explicit ScopedOperand(Generator& generator, Operand operand)
|
||||
: m_impl(adopt_ref(*new ScopedOperandImpl(generator, operand)))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] Operand operand() const { return m_impl->operand(); }
|
||||
operator Operand() const { return operand(); }
|
||||
|
||||
[[nodiscard]] bool operator==(ScopedOperand const& other) const { return operand() == other.operand(); }
|
||||
|
||||
private:
|
||||
NonnullRefPtr<ScopedOperandImpl> m_impl;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue