Commit 29e2d8d7 authored by Alessandro Pignotti's avatar Alessandro Pignotti Committed by V8 LUCI CQ

[wasm] Use constant table size when possible

This patch constantize the table size, both for primary and secondary tables, whenever the table size
is known to never change.

By default WebAssebly tables can be grown indefinitely, but producers can specify a maximal limit.
In particular, producers can specify that the initial size of the table also correspond to the
maximum size, in which case the table cannot be grown and the size is constant.

This is a common case, for example when generating WebAssembly from a C++ codebase the list
of indirectly called function does not need, in general, to change at runtime.

Change-Id: I7f6bab60841ee8eb8bdfd996c34513f69b74d5d2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2912586Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74760}
parent b1e7277b
......@@ -3012,9 +3012,18 @@ void WasmGraphBuilder::LoadIndirectFunctionTable(uint32_t table_index,
Node** ift_sig_ids,
Node** ift_targets,
Node** ift_instances) {
bool needs_dynamic_size = true;
const wasm::WasmTable& table = env_->module->tables[table_index];
if (table.has_maximum_size && table.maximum_size == table.initial_size) {
*ift_size = Int32Constant(table.initial_size);
needs_dynamic_size = false;
}
if (table_index == 0) {
*ift_size = LOAD_MUTABLE_INSTANCE_FIELD(IndirectFunctionTableSize,
MachineType::Uint32());
if (needs_dynamic_size) {
*ift_size = LOAD_MUTABLE_INSTANCE_FIELD(IndirectFunctionTableSize,
MachineType::Uint32());
}
*ift_sig_ids = LOAD_MUTABLE_INSTANCE_FIELD(IndirectFunctionTableSigIds,
MachineType::Pointer());
*ift_targets = LOAD_MUTABLE_INSTANCE_FIELD(IndirectFunctionTableTargets,
......@@ -3028,9 +3037,11 @@ void WasmGraphBuilder::LoadIndirectFunctionTable(uint32_t table_index,
MachineType::TaggedPointer());
Node* ift_table = gasm_->LoadFixedArrayElementAny(ift_tables, table_index);
*ift_size = gasm_->LoadFromObject(
MachineType::Int32(), ift_table,
wasm::ObjectAccess::ToTagged(WasmIndirectFunctionTable::kSizeOffset));
if (needs_dynamic_size) {
*ift_size = gasm_->LoadFromObject(
MachineType::Int32(), ift_table,
wasm::ObjectAccess::ToTagged(WasmIndirectFunctionTable::kSizeOffset));
}
*ift_sig_ids = gasm_->LoadFromObject(
MachineType::Pointer(), ift_table,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment