Skip to content

Commit 73405a4

Browse files
authored
Update calling conventions for wasm functions slightly (#6676)
* Update calling conventions for wasm functions slightly This resolves two issues from recent changes in #6649: * First the s390x calling convention for wasm functions is changed back to `WasmtimeSystemV` from `Fast`. This was an accidental omission from #6649 where the conclusion was that s390x will continue using a calling convention with little-endian lane order for lane arguments. The only calling convention that supports this today is `WasmtimeSystemV`, although the `Tail` calling convention will likely use it in the future as well. * Second the apple-aarch64 platform now uses the `Fast` calling convention instead of `AppleAarch64` calling convention. That convention was specified in #4195 but local testing shows that is not necessary in the sense that tests all pass with the `Fast` calling convention. This means that the prior comment why the `AppleAarch64` calling convention is required is no longer accurate and in the absence of a reason not to I went ahead and switched it to `Fast`. In the near future all wasm functions will unconditionally use the `Tail` calling convention and at that time the lane order can be specified on s390x to be little-endian to satisfy all the constraints here. Additionally any unwinding directives, if necessary for aarch64, can be specified as needed. * Fix compile
1 parent e6ef1ba commit 73405a4

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

crates/cranelift/src/lib.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cranelift_codegen::ir;
77
use cranelift_codegen::isa::{CallConv, TargetIsa};
88
use cranelift_entity::PrimaryMap;
99
use cranelift_wasm::{DefinedFuncIndex, WasmFuncType, WasmType};
10-
use target_lexicon::CallingConvention;
10+
use target_lexicon::Architecture;
1111
use wasmtime_cranelift_shared::CompiledFunctionMetadata;
1212

1313
pub use builder::builder;
@@ -126,18 +126,27 @@ fn array_call_signature(isa: &dyn TargetIsa) -> ir::Signature {
126126

127127
/// Get the internal Wasm calling convention signature for the given type.
128128
fn wasm_call_signature(isa: &dyn TargetIsa, wasm_func_ty: &WasmFuncType) -> ir::Signature {
129-
let call_conv = if isa.triple().default_calling_convention().ok()
130-
== Some(CallingConvention::AppleAarch64)
131-
{
132-
// FIXME: We need an Apple-specific calling convention, so that
133-
// Cranelift's ABI implementation generates unwinding directives
134-
// about pointer authentication usage, so we can't just use
135-
// `CallConv::Fast`.
136-
CallConv::AppleAarch64
137-
} else {
138-
CallConv::Fast
139-
};
129+
// NB: this calling convention in the near future is expected to be
130+
// unconditionally switched to the "tail" calling convention once all
131+
// platforms have support for tail calls.
132+
//
133+
// Also note that the calling convention for wasm functions is purely an
134+
// internal implementation detail of cranelift and Wasmtime. Native Rust
135+
// code does not interact with raw wasm functions and instead always
136+
// operates through trampolines either using the `array_call_signature` or
137+
// `native_call_signature` where the default platform ABI is used.
138+
let call_conv = match isa.triple().architecture {
139+
// On s390x the "wasmtime" calling convention is used to give vectors
140+
// little-endian lane order at the ABI layer which should reduce the
141+
// need for conversion when operating on vector function arguments. By
142+
// default vectors on s390x are otherwise in big-endian lane order which
143+
// would require conversions.
144+
Architecture::S390x => CallConv::WasmtimeSystemV,
140145

146+
// All other platforms pick "fast" as the calling convention since it's
147+
// presumably, well, the fastest.
148+
_ => CallConv::Fast,
149+
};
141150
let mut sig = blank_sig(isa, call_conv);
142151
let cvt = |ty: &WasmType| ir::AbiParam::new(value_type(isa, *ty));
143152
sig.params.extend(wasm_func_ty.params().iter().map(&cvt));

0 commit comments

Comments
 (0)