cranelift-wasm: Pass ir::Tables into all the translate_table_* methods
This serves two purposes: 1. It ensures that we call `get_or_create_table` to ensure that the embedder already had a chance to create the given table (although this is mostly redundant due to validation). 2. It allows the embedder to easily get the `ir::TableData` associated with this table, and more easily emit whatever inline JIT code to translate the table instruction (rather than falling back to VM calls).
This commit is contained in:
@@ -533,7 +533,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
// `index` is the index of the function's signature and `table_index` is the index of
|
// `index` is the index of the function's signature and `table_index` is the index of
|
||||||
// the table to search the function in.
|
// the table to search the function in.
|
||||||
let (sigref, num_args) = state.get_indirect_sig(builder.func, *index, environ)?;
|
let (sigref, num_args) = state.get_indirect_sig(builder.func, *index, environ)?;
|
||||||
let table = state.get_table(builder.func, *table_index, environ)?;
|
let table = state.get_or_create_table(builder.func, *table_index, environ)?;
|
||||||
let callee = state.pop1();
|
let callee = state.pop1();
|
||||||
|
|
||||||
// Bitcast any vector arguments to their default type, I8X16, before calling.
|
// Bitcast any vector arguments to their default type, I8X16, before calling.
|
||||||
@@ -1163,41 +1163,50 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
environ.translate_data_drop(builder.cursor(), *segment)?;
|
environ.translate_data_drop(builder.cursor(), *segment)?;
|
||||||
}
|
}
|
||||||
Operator::TableSize { table: index } => {
|
Operator::TableSize { table: index } => {
|
||||||
let table = state.get_table(builder.func, *index, environ)?;
|
let table = state.get_or_create_table(builder.func, *index, environ)?;
|
||||||
state.push1(environ.translate_table_size(
|
state.push1(environ.translate_table_size(
|
||||||
builder.cursor(),
|
builder.cursor(),
|
||||||
TableIndex::from_u32(*index),
|
TableIndex::from_u32(*index),
|
||||||
table,
|
table,
|
||||||
)?);
|
)?);
|
||||||
}
|
}
|
||||||
Operator::TableGrow { table } => {
|
Operator::TableGrow { table: index } => {
|
||||||
let table_index = TableIndex::from_u32(*table);
|
let table_index = TableIndex::from_u32(*index);
|
||||||
|
let table = state.get_or_create_table(builder.func, *index, environ)?;
|
||||||
let delta = state.pop1();
|
let delta = state.pop1();
|
||||||
let init_value = state.pop1();
|
let init_value = state.pop1();
|
||||||
state.push1(environ.translate_table_grow(
|
state.push1(environ.translate_table_grow(
|
||||||
builder.cursor(),
|
builder.cursor(),
|
||||||
table_index,
|
table_index,
|
||||||
|
table,
|
||||||
delta,
|
delta,
|
||||||
init_value,
|
init_value,
|
||||||
)?);
|
)?);
|
||||||
}
|
}
|
||||||
Operator::TableGet { table } => {
|
Operator::TableGet { table: index } => {
|
||||||
let table_index = TableIndex::from_u32(*table);
|
let table_index = TableIndex::from_u32(*index);
|
||||||
|
let table = state.get_or_create_table(builder.func, *index, environ)?;
|
||||||
let index = state.pop1();
|
let index = state.pop1();
|
||||||
state.push1(environ.translate_table_get(builder.cursor(), table_index, index)?);
|
state.push1(environ.translate_table_get(
|
||||||
|
builder.cursor(),
|
||||||
|
table_index,
|
||||||
|
table,
|
||||||
|
index,
|
||||||
|
)?);
|
||||||
}
|
}
|
||||||
Operator::TableSet { table } => {
|
Operator::TableSet { table: index } => {
|
||||||
let table_index = TableIndex::from_u32(*table);
|
let table_index = TableIndex::from_u32(*index);
|
||||||
|
let table = state.get_or_create_table(builder.func, *index, environ)?;
|
||||||
let value = state.pop1();
|
let value = state.pop1();
|
||||||
let index = state.pop1();
|
let index = state.pop1();
|
||||||
environ.translate_table_set(builder.cursor(), table_index, value, index)?;
|
environ.translate_table_set(builder.cursor(), table_index, table, value, index)?;
|
||||||
}
|
}
|
||||||
Operator::TableCopy {
|
Operator::TableCopy {
|
||||||
dst_table: dst_table_index,
|
dst_table: dst_table_index,
|
||||||
src_table: src_table_index,
|
src_table: src_table_index,
|
||||||
} => {
|
} => {
|
||||||
let dst_table = state.get_table(builder.func, *dst_table_index, environ)?;
|
let dst_table = state.get_or_create_table(builder.func, *dst_table_index, environ)?;
|
||||||
let src_table = state.get_table(builder.func, *src_table_index, environ)?;
|
let src_table = state.get_or_create_table(builder.func, *src_table_index, environ)?;
|
||||||
let len = state.pop1();
|
let len = state.pop1();
|
||||||
let src = state.pop1();
|
let src = state.pop1();
|
||||||
let dest = state.pop1();
|
let dest = state.pop1();
|
||||||
@@ -1223,7 +1232,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
|||||||
segment,
|
segment,
|
||||||
table: table_index,
|
table: table_index,
|
||||||
} => {
|
} => {
|
||||||
let table = state.get_table(builder.func, *table_index, environ)?;
|
let table = state.get_or_create_table(builder.func, *table_index, environ)?;
|
||||||
let len = state.pop1();
|
let len = state.pop1();
|
||||||
let src = state.pop1();
|
let src = state.pop1();
|
||||||
let dest = state.pop1();
|
let dest = state.pop1();
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_table_index: TableIndex,
|
_table_index: TableIndex,
|
||||||
|
_table: ir::Table,
|
||||||
_delta: ir::Value,
|
_delta: ir::Value,
|
||||||
_init_value: ir::Value,
|
_init_value: ir::Value,
|
||||||
) -> WasmResult<ir::Value> {
|
) -> WasmResult<ir::Value> {
|
||||||
@@ -445,6 +446,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut pos: FuncCursor,
|
mut pos: FuncCursor,
|
||||||
_table_index: TableIndex,
|
_table_index: TableIndex,
|
||||||
|
_table: ir::Table,
|
||||||
_index: ir::Value,
|
_index: ir::Value,
|
||||||
) -> WasmResult<ir::Value> {
|
) -> WasmResult<ir::Value> {
|
||||||
Ok(pos.ins().null(self.reference_type()))
|
Ok(pos.ins().null(self.reference_type()))
|
||||||
@@ -454,6 +456,7 @@ impl<'dummy_environment> FuncEnvironment for DummyFuncEnvironment<'dummy_environ
|
|||||||
&mut self,
|
&mut self,
|
||||||
_pos: FuncCursor,
|
_pos: FuncCursor,
|
||||||
_table_index: TableIndex,
|
_table_index: TableIndex,
|
||||||
|
_table: ir::Table,
|
||||||
_value: ir::Value,
|
_value: ir::Value,
|
||||||
_index: ir::Value,
|
_index: ir::Value,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
|
|||||||
@@ -355,6 +355,7 @@ pub trait FuncEnvironment: TargetEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
table_index: TableIndex,
|
table_index: TableIndex,
|
||||||
|
table: ir::Table,
|
||||||
delta: ir::Value,
|
delta: ir::Value,
|
||||||
init_value: ir::Value,
|
init_value: ir::Value,
|
||||||
) -> WasmResult<ir::Value>;
|
) -> WasmResult<ir::Value>;
|
||||||
@@ -364,6 +365,7 @@ pub trait FuncEnvironment: TargetEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
table_index: TableIndex,
|
table_index: TableIndex,
|
||||||
|
table: ir::Table,
|
||||||
index: ir::Value,
|
index: ir::Value,
|
||||||
) -> WasmResult<ir::Value>;
|
) -> WasmResult<ir::Value>;
|
||||||
|
|
||||||
@@ -372,6 +374,7 @@ pub trait FuncEnvironment: TargetEnvironment {
|
|||||||
&mut self,
|
&mut self,
|
||||||
pos: FuncCursor,
|
pos: FuncCursor,
|
||||||
table_index: TableIndex,
|
table_index: TableIndex,
|
||||||
|
table: ir::Table,
|
||||||
value: ir::Value,
|
value: ir::Value,
|
||||||
index: ir::Value,
|
index: ir::Value,
|
||||||
) -> WasmResult<()>;
|
) -> WasmResult<()>;
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ pub struct FuncTranslationState {
|
|||||||
heaps: HashMap<MemoryIndex, ir::Heap>,
|
heaps: HashMap<MemoryIndex, ir::Heap>,
|
||||||
|
|
||||||
// Map of tables that have been created by `FuncEnvironment::make_table`.
|
// Map of tables that have been created by `FuncEnvironment::make_table`.
|
||||||
tables: HashMap<TableIndex, ir::Table>,
|
pub(crate) tables: HashMap<TableIndex, ir::Table>,
|
||||||
|
|
||||||
// Map of indirect call signatures that have been created by
|
// Map of indirect call signatures that have been created by
|
||||||
// `FuncEnvironment::make_indirect_sig()`.
|
// `FuncEnvironment::make_indirect_sig()`.
|
||||||
@@ -446,7 +446,7 @@ impl FuncTranslationState {
|
|||||||
|
|
||||||
/// Get the `Table` reference that should be used to access table `index`.
|
/// Get the `Table` reference that should be used to access table `index`.
|
||||||
/// Create the reference if necessary.
|
/// Create the reference if necessary.
|
||||||
pub(crate) fn get_table<FE: FuncEnvironment + ?Sized>(
|
pub(crate) fn get_or_create_table<FE: FuncEnvironment + ?Sized>(
|
||||||
&mut self,
|
&mut self,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
index: u32,
|
index: u32,
|
||||||
|
|||||||
@@ -622,6 +622,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
|
|||||||
&mut self,
|
&mut self,
|
||||||
mut pos: cranelift_codegen::cursor::FuncCursor<'_>,
|
mut pos: cranelift_codegen::cursor::FuncCursor<'_>,
|
||||||
table_index: TableIndex,
|
table_index: TableIndex,
|
||||||
|
_table: ir::Table,
|
||||||
delta: ir::Value,
|
delta: ir::Value,
|
||||||
init_value: ir::Value,
|
init_value: ir::Value,
|
||||||
) -> WasmResult<ir::Value> {
|
) -> WasmResult<ir::Value> {
|
||||||
@@ -649,6 +650,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
|
|||||||
&mut self,
|
&mut self,
|
||||||
_: cranelift_codegen::cursor::FuncCursor<'_>,
|
_: cranelift_codegen::cursor::FuncCursor<'_>,
|
||||||
_: TableIndex,
|
_: TableIndex,
|
||||||
|
_: ir::Table,
|
||||||
_: ir::Value,
|
_: ir::Value,
|
||||||
) -> WasmResult<ir::Value> {
|
) -> WasmResult<ir::Value> {
|
||||||
Err(WasmError::Unsupported(
|
Err(WasmError::Unsupported(
|
||||||
@@ -660,6 +662,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m
|
|||||||
&mut self,
|
&mut self,
|
||||||
_: cranelift_codegen::cursor::FuncCursor<'_>,
|
_: cranelift_codegen::cursor::FuncCursor<'_>,
|
||||||
_: TableIndex,
|
_: TableIndex,
|
||||||
|
_: ir::Table,
|
||||||
_: ir::Value,
|
_: ir::Value,
|
||||||
_: ir::Value,
|
_: ir::Value,
|
||||||
) -> WasmResult<()> {
|
) -> WasmResult<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user