ladybird/Userland/Libraries/LibJS/Bytecode/ScopedOperand.cpp
Andreas Kling cea59b6642 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.
2024-05-09 09:12:13 +02:00

23 lines
505 B
C++

/*
* Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Bytecode/ScopedOperand.h>
namespace JS::Bytecode {
ScopedOperandImpl::~ScopedOperandImpl()
{
if (!m_generator.is_finished() && m_operand.is_register() && m_operand.as_register().index() != 0)
m_generator.free_register(m_operand.as_register());
}
Register Operand::as_register() const
{
return Register { m_index };
}
}