mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-08 18:46:03 +00:00
LibWasm: Hold on to the stack depth for expressions in the validator
This allows preallocating the value stack when pushing frames, avoiding repeated reallocs and copies.
This commit is contained in:
parent
3f77aa8521
commit
dc67f0ad4e
Notes:
github-actions[bot]
2025-08-08 10:56:54 +00:00
Author: https://github.com/alimpfard
Commit: dc67f0ad4e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5060
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/R-Goc
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/gmta
4 changed files with 17 additions and 1 deletions
|
@ -21,6 +21,8 @@ public:
|
|||
{
|
||||
Label label(frame.arity(), frame.expression().instructions().size(), m_value_stack.size());
|
||||
frame.label_index() = m_label_stack.size();
|
||||
if (auto hint = frame.expression().stack_usage_hint(); hint.has_value())
|
||||
m_value_stack.ensure_capacity(*hint);
|
||||
m_frame_stack.append(move(frame));
|
||||
m_label_stack.append(label);
|
||||
}
|
||||
|
|
|
@ -3736,6 +3736,8 @@ ErrorOr<Validator::ExpressionTypeResult, ValidationError> Validator::validate(Ex
|
|||
m_frames.take_last();
|
||||
VERIFY(m_frames.is_empty());
|
||||
|
||||
expression.set_stack_usage_hint(stack.max_known_size());
|
||||
|
||||
return ExpressionTypeResult { stack.release_vector(), is_constant_expression };
|
||||
}
|
||||
|
||||
|
|
|
@ -228,6 +228,7 @@ public:
|
|||
void append(StackEntry entry)
|
||||
{
|
||||
Vector<StackEntry>::append(entry);
|
||||
m_max_known_size = max(m_max_known_size, size());
|
||||
}
|
||||
|
||||
ErrorOr<StackEntry, ValidationError> take(ValueType type, SourceLocation location = SourceLocation::current())
|
||||
|
@ -254,10 +255,17 @@ public:
|
|||
return {};
|
||||
}
|
||||
|
||||
Vector<StackEntry> release_vector() { return exchange(static_cast<Vector<StackEntry>&>(*this), Vector<StackEntry> {}); }
|
||||
Vector<StackEntry> release_vector()
|
||||
{
|
||||
m_max_known_size = 0;
|
||||
return exchange(static_cast<Vector<StackEntry>&>(*this), Vector<StackEntry> {});
|
||||
}
|
||||
|
||||
size_t max_known_size() const { return m_max_known_size; }
|
||||
|
||||
private:
|
||||
Vector<Frame> const& m_frames;
|
||||
size_t m_max_known_size { 0 };
|
||||
};
|
||||
|
||||
struct ExpressionTypeResult {
|
||||
|
|
|
@ -708,8 +708,12 @@ public:
|
|||
|
||||
static ParseResult<Expression> parse(ConstrainedStream& stream, Optional<size_t> size_hint = {});
|
||||
|
||||
void set_stack_usage_hint(size_t value) const { m_stack_usage_hint = value; }
|
||||
auto stack_usage_hint() const { return m_stack_usage_hint; }
|
||||
|
||||
private:
|
||||
Vector<Instruction> m_instructions;
|
||||
mutable Optional<size_t> m_stack_usage_hint;
|
||||
};
|
||||
|
||||
class GlobalSection {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue