mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-09 19:16:02 +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());
|
Label label(frame.arity(), frame.expression().instructions().size(), m_value_stack.size());
|
||||||
frame.label_index() = m_label_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_frame_stack.append(move(frame));
|
||||||
m_label_stack.append(label);
|
m_label_stack.append(label);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3736,6 +3736,8 @@ ErrorOr<Validator::ExpressionTypeResult, ValidationError> Validator::validate(Ex
|
||||||
m_frames.take_last();
|
m_frames.take_last();
|
||||||
VERIFY(m_frames.is_empty());
|
VERIFY(m_frames.is_empty());
|
||||||
|
|
||||||
|
expression.set_stack_usage_hint(stack.max_known_size());
|
||||||
|
|
||||||
return ExpressionTypeResult { stack.release_vector(), is_constant_expression };
|
return ExpressionTypeResult { stack.release_vector(), is_constant_expression };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,6 +228,7 @@ public:
|
||||||
void append(StackEntry entry)
|
void append(StackEntry entry)
|
||||||
{
|
{
|
||||||
Vector<StackEntry>::append(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())
|
ErrorOr<StackEntry, ValidationError> take(ValueType type, SourceLocation location = SourceLocation::current())
|
||||||
|
@ -254,10 +255,17 @@ public:
|
||||||
return {};
|
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:
|
private:
|
||||||
Vector<Frame> const& m_frames;
|
Vector<Frame> const& m_frames;
|
||||||
|
size_t m_max_known_size { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ExpressionTypeResult {
|
struct ExpressionTypeResult {
|
||||||
|
|
|
@ -708,8 +708,12 @@ public:
|
||||||
|
|
||||||
static ParseResult<Expression> parse(ConstrainedStream& stream, Optional<size_t> size_hint = {});
|
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:
|
private:
|
||||||
Vector<Instruction> m_instructions;
|
Vector<Instruction> m_instructions;
|
||||||
|
mutable Optional<size_t> m_stack_usage_hint;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlobalSection {
|
class GlobalSection {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue