Skip to content

Commit

Permalink
Plumb the winch calling convention through Tunables
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Mar 12, 2024
1 parent bfdfda8 commit 6ae2b77
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ fn wasm_call_signature(
CallConv::Tail
}

// The winch calling convention is only implemented for x64 and aarch64
arch if tunables.tail_callable => {
assert!(
matches!(arch, Architecture::X86_64 | Architecture::Aarch64(_)),
"https://github.com/bytecodealliance/wasmtime/issues/6530"
);
CallConv::Winch
}

// On s390x the "wasmtime" calling convention is used to give vectors
// little-endian lane order at the ABI layer which should reduce the
// need for conversion when operating on vector function arguments. By
Expand Down
4 changes: 4 additions & 0 deletions crates/environ/src/tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub struct Tunables {

/// Whether or not Wasm functions can be tail-called or not.
pub tail_callable: bool,

/// Whether or not Wasm functions target the winch abi.
pub winch_callable: bool,
}

impl Tunables {
Expand Down Expand Up @@ -106,6 +109,7 @@ impl Tunables {
debug_adapter_modules: false,
relaxed_simd_deterministic: false,
tail_callable: false,
winch_callable: false,
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,13 @@ impl Config {
tail_callable
}

// If we're going to compile with winch, we must use the winch calling convention.
tunables.winch_callable = match self.compiler_config.strategy {
Strategy::Auto => !cfg!(feature = "cranelift") && cfg!(feature = "winch"),
Strategy::Cranelift => false,
Strategy::Winch => true,
};

if tunables.static_memory_offset_guard_size < tunables.dynamic_memory_offset_guard_size {
bail!("static memory guard size cannot be smaller than dynamic memory guard size");
}
Expand Down
6 changes: 6 additions & 0 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ impl Metadata<'_> {
guard_before_linear_memory,
relaxed_simd_deterministic,
tail_callable,
winch_callable,

// This doesn't affect compilation, it's just a runtime setting.
dynamic_memory_growth_reserve: _,
Expand Down Expand Up @@ -402,6 +403,11 @@ impl Metadata<'_> {
"relaxed simd deterministic semantics",
)?;
Self::check_bool(tail_callable, other.tail_callable, "WebAssembly tail calls")?;
Self::check_bool(
winch_callable,
other.winch_callable,
"Winch calling convention",
)?;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions crates/winch/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl CompilerBuilder for Builder {
}

fn set_tunables(&mut self, tunables: wasmtime_environ::Tunables) -> Result<()> {
assert!(tunables.winch_callable);
self.cranelift.set_tunables(tunables)?;
Ok(())
}
Expand Down

0 comments on commit 6ae2b77

Please sign in to comment.