LibWasm: Try really hard to avoid touching the value stack

This commit adds a register allocator, with 8 available "register"
slots.
In testing with various random blobs, this moves anywhere from 30% to
74% of value accesses into predefined slots, and is about a ~20% perf
increase end-to-end.

To actually make this usable, a few structural changes were also made:
- we no longer do one instruction per interpret call
- trapping is an (unlikely) exit condition
- the label and frame stacks are replaced with linked lists with a huge
  node cache size, as we only need to touch the last element and
  push/pop is very frequent.
This commit is contained in:
Ali Mohammad Pur 2025-08-02 20:30:44 +02:00 committed by Ali Mohammad Pur
parent 998454028c
commit 0e5ecef848
Notes: github-actions[bot] 2025-08-08 10:55:57 +00:00
9 changed files with 3217 additions and 1824 deletions

View file

@ -435,6 +435,8 @@ void Printer::print(Wasm::Instruction const& instruction)
print_indent();
print("({}", instruction_name(instruction.opcode()));
if (instruction.arguments().has<u8>()) {
if (instruction.opcode() == Instructions::local_get || instruction.opcode() == Instructions::local_set || instruction.opcode() == Instructions::local_tee)
print(" (local index {})", instruction.local_index());
print(")\n");
} else {
print(" ");
@ -478,7 +480,10 @@ void Printer::print(Wasm::Instruction const& instruction)
[&](Instruction::TableTableArgs const& args) { print("(table_table (table index {}) (table index {}))", args.lhs.value(), args.rhs.value()); },
[&](ValueType const& type) { print(type); },
[&](Vector<ValueType> const&) { print("(types...)"); },
[&](auto const& value) { print("{}", value); });
[&](auto const& value) { print("(const {})", value); });
if (instruction.local_index().value())
print(" (local index {})", instruction.local_index().value());
print(")\n");
}