cranelift: introduce a new WasmtimeAppleAarch64 calling convention

The previous choice to use the WasmtimeSystemV calling convention for
apple-aarch64 devices was incorrect: padding of arguments was
incorrectly computed. So we have to use some flavor of the apple-aarch64
ABI there.

Since we want to support the wasmtime custom convention for multiple
returns on apple-aarch64 too, a new custom Wasmtime calling convention
was introduced to support this.
This commit is contained in:
Benjamin Bouvier
2021-06-01 11:29:52 +02:00
parent aa2c0cd0ec
commit 51edea9e57
6 changed files with 25 additions and 11 deletions

View File

@@ -183,7 +183,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
args_or_rets: ArgsOrRets,
add_ret_area_ptr: bool,
) -> CodegenResult<(Vec<ABIArg>, i64, Option<usize>)> {
let is_apple_cc = call_conv == isa::CallConv::AppleAarch64;
let is_apple_cc = call_conv.extends_apple_aarch64();
let is_baldrdash = call_conv.extends_baldrdash();
let has_baldrdash_tls = call_conv == isa::CallConv::Baldrdash2020;

View File

@@ -18,7 +18,7 @@ pub enum CallConv {
SystemV,
/// Windows "fastcall" convention, also used for x64 and ARM.
WindowsFastcall,
/// Mac aarch64 calling convention, which is a tweak aarch64 ABI.
/// Mac aarch64 calling convention, which is a tweaked aarch64 ABI.
AppleAarch64,
/// SpiderMonkey WebAssembly convention on systems using natively SystemV.
BaldrdashSystemV,
@@ -39,6 +39,10 @@ pub enum CallConv {
///
/// Differs from fastcall in the same way as `WasmtimeSystemV`.
WasmtimeFastcall,
/// Wasmtime equivalent of AppleAarch64, not ABI-stable.
///
/// Differs from apple-aarch64 in the same way as `WasmtimeSystemV`.
WasmtimeAppleAarch64,
}
impl CallConv {
@@ -78,6 +82,14 @@ impl CallConv {
}
}
/// Is the calling convention extending the Apple aarch64 ABI?
pub fn extends_apple_aarch64(self) -> bool {
match self {
Self::AppleAarch64 | Self::WasmtimeAppleAarch64 => true,
_ => false,
}
}
/// Is the calling convention extending the Baldrdash ABI?
pub fn extends_baldrdash(self) -> bool {
match self {
@@ -89,7 +101,7 @@ impl CallConv {
/// Is the calling convention extending the Wasmtime ABI?
pub fn extends_wasmtime(self) -> bool {
match self {
Self::WasmtimeSystemV | Self::WasmtimeFastcall => true,
Self::WasmtimeSystemV | Self::WasmtimeFastcall | Self::WasmtimeAppleAarch64 => true,
_ => false,
}
}
@@ -109,6 +121,7 @@ impl fmt::Display for CallConv {
Self::Probestack => "probestack",
Self::WasmtimeSystemV => "wasmtime_system_v",
Self::WasmtimeFastcall => "wasmtime_fastcall",
Self::WasmtimeAppleAarch64 => "wasmtime_apple_aarch64",
})
}
}
@@ -128,6 +141,7 @@ impl str::FromStr for CallConv {
"probestack" => Ok(Self::Probestack),
"wasmtime_system_v" => Ok(Self::WasmtimeSystemV),
"wasmtime_fastcall" => Ok(Self::WasmtimeFastcall),
"wasmtime_apple_aarch64" => Ok(Self::WasmtimeAppleAarch64),
_ => Err(()),
}
}

View File

@@ -906,7 +906,7 @@ fn get_intreg_for_retval(
_ => None,
},
CallConv::BaldrdashWindows | CallConv::Probestack => todo!(),
CallConv::AppleAarch64 => unreachable!(),
CallConv::AppleAarch64 | CallConv::WasmtimeAppleAarch64 => unreachable!(),
}
}
@@ -936,7 +936,7 @@ fn get_fltreg_for_retval(
_ => None,
},
CallConv::BaldrdashWindows | CallConv::Probestack => todo!(),
CallConv::AppleAarch64 => unreachable!(),
CallConv::AppleAarch64 | CallConv::WasmtimeAppleAarch64 => unreachable!(),
}
}
@@ -1005,7 +1005,7 @@ fn get_callee_saves(call_conv: &CallConv, regs: &Set<Writable<RealReg>>) -> Vec<
.filter(|r| is_callee_save_fastcall(r.to_reg()))
.collect(),
CallConv::Probestack => todo!("probestack?"),
CallConv::AppleAarch64 => unreachable!(),
CallConv::AppleAarch64 | CallConv::WasmtimeAppleAarch64 => unreachable!(),
};
// Sort registers for deterministic code output. We can do an unstable sort because the
// registers will be unique (there are no dups).

View File

@@ -514,7 +514,7 @@ pub fn prologue_epilogue(func: &mut ir::Function, isa: &dyn TargetIsa) -> Codege
}
CallConv::Probestack => unimplemented!("probestack calling convention"),
CallConv::Baldrdash2020 => unimplemented!("Baldrdash ABI 2020"),
CallConv::AppleAarch64 => unreachable!(),
CallConv::AppleAarch64 | CallConv::WasmtimeAppleAarch64 => unreachable!(),
}
}