Update Cranelift to 0.93.0

Closes #1352
This commit is contained in:
bjorn3 2023-02-01 14:19:47 +00:00
parent 10c3c7207b
commit a563e11918
6 changed files with 40 additions and 298 deletions

49
Cargo.lock generated
View File

@ -57,18 +57,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cranelift-bforest"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f3d54eab028f5805ae3b26fd60eca3f3a9cfb76b989d9bab173be3f61356cc3"
checksum = "91b18cf92869a6ae85cde3af4bc4beb6154efa8adef03b18db2ad413d5bce3a2"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-codegen"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2be1d5f2c3cca1efb691844bc1988b89c77291f13f778499a3f3c0cf49c0ed61"
checksum = "567d9f6e919bac076f39b902a072686eaf9e6d015baa34d10a61b85105b7af59"
dependencies = [
"arrayvec",
"bumpalo",
@ -87,30 +87,30 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9b1b1089750ce4005893af7ee00bb08a2cf1c9779999c0f7164cbc8ad2e0d2"
checksum = "1e72b2d5ec8917b2971fe83850187373d0a186db4748a7c23a5f48691b8d92bb"
dependencies = [
"cranelift-codegen-shared",
]
[[package]]
name = "cranelift-codegen-shared"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc5fbaec51de47297fd7304986fd53c8c0030abbe69728a60d72e1c63559318d"
checksum = "3461c0e0c2ebbeb92533aacb27e219289f60dc84134ef34fbf2d77c9eddf07ef"
[[package]]
name = "cranelift-entity"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dab984c94593f876090fae92e984bdcc74d9b1acf740ab5f79036001c65cba13"
checksum = "af684f7f7b01427b1942c7102673322a51b9d6f261e9663dc5e5595786775531"
[[package]]
name = "cranelift-frontend"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e0cb3102d21a2fe5f3210af608748ddd0cd09825ac12d42dc56ed5ed8725fe0"
checksum = "7d361ed0373cf5f086b49c499aa72227b646a64f899f32e34312f97c0fadff75"
dependencies = [
"cranelift-codegen",
"log",
@ -120,15 +120,15 @@ dependencies = [
[[package]]
name = "cranelift-isle"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72101dd1f441d629735143c41e00b3428f9267738176983ef588ff43382af0a0"
checksum = "cef4f8f3984d772c199a48896d2fb766f96301bf71b371e03a2b99f4f3b7b931"
[[package]]
name = "cranelift-jit"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6557f8ce44d498777f2495aa58d9692a4a37d6f84aa445750d666cef770b6a5c"
checksum = "9c9909222db472fcc98d9e4e7192fa9d064dac63a3fa657df8c6daae86fb2604"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -145,9 +145,9 @@ dependencies = [
[[package]]
name = "cranelift-module"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88807e1c0c47ec02fe433333ccbe56b480425418b1470e333205e11650697d72"
checksum = "68689b83e52e605ba48652882d3fccc2e2e136abf139eb64ae667888ba0d52f8"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -155,9 +155,9 @@ dependencies = [
[[package]]
name = "cranelift-native"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c22b0d9fcbe3fc5a1af9e7021b44ce42b930bcefac446ce22e02e8f9a0d67120"
checksum = "f98e4e99a353703475d5acb402b9c13482d41d8a4008b352559bd560afb90363"
dependencies = [
"cranelift-codegen",
"libc",
@ -166,9 +166,9 @@ dependencies = [
[[package]]
name = "cranelift-object"
version = "0.92.0"
version = "0.93.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "341375758d7c3fedc0b5315f552e6f0feac46baf87c450a15e9455ef47c2b261"
checksum = "b7a006ce1d8dd11df67567d8673e5920f3a56441812aed52a007ffce8f1b20e9"
dependencies = [
"anyhow",
"cranelift-codegen",
@ -333,6 +333,7 @@ dependencies = [
"cranelift-frontend",
"cranelift-jit",
"cranelift-module",
"cranelift-native",
"cranelift-object",
"gimli",
"indexmap",
@ -381,9 +382,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasmtime-jit-icache-coherence"
version = "5.0.0"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08fcba5ebd96da2a9f0747ab6337fe9788adfb3f63fa2c180520d665562d257e"
checksum = "ec1fd0f0dd79e7cc0f55b102e320d7c77ab76cd272008a8fd98e25b5777e2636"
dependencies = [
"cfg-if",
"libc",

View File

@ -15,14 +15,12 @@ crate-type = ["dylib"]
[dependencies]
# These have to be in sync with each other
cranelift-codegen = { version = "0.92", features = ["unwind", "all-arch"] }
cranelift-frontend = { version = "0.92" }
cranelift-module = { version = "0.92" }
# NOTE vendored as src/cranelift_native.rs
# FIXME revert back to the external crate with Cranelift 0.93
#cranelift-native = { version = "0.92" }
cranelift-jit = { version = "0.92", optional = true }
cranelift-object = { version = "0.92" }
cranelift-codegen = { version = "0.93", features = ["unwind", "all-arch"] }
cranelift-frontend = { version = "0.93" }
cranelift-module = { version = "0.93" }
cranelift-native = { version = "0.93" }
cranelift-jit = { version = "0.93", optional = true }
cranelift-object = { version = "0.93" }
target-lexicon = "0.12.0"
gimli = { version = "0.26.0", default-features = false, features = ["write"]}
object = { version = "0.29.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

View File

@ -365,11 +365,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
fx.bcx.set_cold_block(failure);
if *expected {
fx.bcx.ins().brz(cond, failure, &[]);
fx.bcx.ins().brif(cond, target, &[], failure, &[]);
} else {
fx.bcx.ins().brnz(cond, failure, &[]);
fx.bcx.ins().brif(cond, failure, &[], target, &[]);
};
fx.bcx.ins().jump(target, &[]);
fx.bcx.switch_to_block(failure);
fx.bcx.ins().nop();
@ -425,11 +424,9 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
}
} else {
if test_zero {
fx.bcx.ins().brz(discr, then_block, &[]);
fx.bcx.ins().jump(else_block, &[]);
fx.bcx.ins().brif(discr, else_block, &[], then_block, &[]);
} else {
fx.bcx.ins().brnz(discr, then_block, &[]);
fx.bcx.ins().jump(else_block, &[]);
fx.bcx.ins().brif(discr, then_block, &[], else_block, &[]);
}
}
} else {
@ -751,8 +748,7 @@ fn codegen_stmt<'tcx>(
fx.bcx.switch_to_block(loop_block);
let done = fx.bcx.ins().icmp_imm(IntCC::Equal, index, times as i64);
fx.bcx.ins().brnz(done, done_block, &[]);
fx.bcx.ins().jump(loop_block2, &[]);
fx.bcx.ins().brif(done, done_block, &[], loop_block2, &[]);
fx.bcx.switch_to_block(loop_block2);
let to = lval.place_index(fx, index);

View File

@ -1,248 +0,0 @@
// Vendored from https://github.com/bytecodealliance/wasmtime/blob/b58a197d33f044193c3d608010f5e6ec394ac07e/cranelift/native/src/lib.rs
// which is licensed as
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// unlike rustc_codegen_cranelift itself. Also applies a small change to remove #![cfg_attr] that
// rust's CI complains about and to fix formatting to match rustc.
// FIXME revert back to the external crate with Cranelift 0.93
#![allow(warnings)]
//! Performs autodetection of the host for the purposes of running
//! Cranelift to generate code to run on the same machine.
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates, unstable_features)]
#![warn(unused_import_braces)]
use cranelift_codegen::isa;
use target_lexicon::Triple;
/// Return an `isa` builder configured for the current host
/// machine, or `Err(())` if the host machine is not supported
/// in the current configuration.
pub fn builder() -> Result<isa::Builder, &'static str> {
builder_with_options(true)
}
/// Return an `isa` builder configured for the current host
/// machine, or `Err(())` if the host machine is not supported
/// in the current configuration.
///
/// Selects the given backend variant specifically; this is
/// useful when more than oen backend exists for a given target
/// (e.g., on x86-64).
pub fn builder_with_options(infer_native_flags: bool) -> Result<isa::Builder, &'static str> {
let mut isa_builder = isa::lookup(Triple::host()).map_err(|err| match err {
isa::LookupError::SupportDisabled => "support for architecture disabled at compile time",
isa::LookupError::Unsupported => "unsupported architecture",
})?;
#[cfg(target_arch = "x86_64")]
{
use cranelift_codegen::settings::Configurable;
if !std::is_x86_feature_detected!("sse2") {
return Err("x86 support requires SSE2");
}
if !infer_native_flags {
return Ok(isa_builder);
}
// These are temporarily enabled by default (see #3810 for
// more) so that a default-constructed `Flags` can work with
// default Wasmtime features. Otherwise, the user must
// explicitly use native flags or turn these on when on x86-64
// platforms to avoid a configuration panic. In order for the
// "enable if detected" logic below to work, we must turn them
// *off* (differing from the default) and then re-enable below
// if present.
isa_builder.set("has_sse3", "false").unwrap();
isa_builder.set("has_ssse3", "false").unwrap();
isa_builder.set("has_sse41", "false").unwrap();
isa_builder.set("has_sse42", "false").unwrap();
if std::is_x86_feature_detected!("sse3") {
isa_builder.enable("has_sse3").unwrap();
}
if std::is_x86_feature_detected!("ssse3") {
isa_builder.enable("has_ssse3").unwrap();
}
if std::is_x86_feature_detected!("sse4.1") {
isa_builder.enable("has_sse41").unwrap();
}
if std::is_x86_feature_detected!("sse4.2") {
isa_builder.enable("has_sse42").unwrap();
}
if std::is_x86_feature_detected!("popcnt") {
isa_builder.enable("has_popcnt").unwrap();
}
if std::is_x86_feature_detected!("avx") {
isa_builder.enable("has_avx").unwrap();
}
if std::is_x86_feature_detected!("avx2") {
isa_builder.enable("has_avx2").unwrap();
}
if std::is_x86_feature_detected!("fma") {
isa_builder.enable("has_fma").unwrap();
}
if std::is_x86_feature_detected!("bmi1") {
isa_builder.enable("has_bmi1").unwrap();
}
if std::is_x86_feature_detected!("bmi2") {
isa_builder.enable("has_bmi2").unwrap();
}
if std::is_x86_feature_detected!("avx512bitalg") {
isa_builder.enable("has_avx512bitalg").unwrap();
}
if std::is_x86_feature_detected!("avx512dq") {
isa_builder.enable("has_avx512dq").unwrap();
}
if std::is_x86_feature_detected!("avx512f") {
isa_builder.enable("has_avx512f").unwrap();
}
if std::is_x86_feature_detected!("avx512vl") {
isa_builder.enable("has_avx512vl").unwrap();
}
if std::is_x86_feature_detected!("avx512vbmi") {
isa_builder.enable("has_avx512vbmi").unwrap();
}
if std::is_x86_feature_detected!("lzcnt") {
isa_builder.enable("has_lzcnt").unwrap();
}
}
#[cfg(target_arch = "aarch64")]
{
use cranelift_codegen::settings::Configurable;
if !infer_native_flags {
return Ok(isa_builder);
}
if std::arch::is_aarch64_feature_detected!("lse") {
isa_builder.enable("has_lse").unwrap();
}
if std::arch::is_aarch64_feature_detected!("paca") {
isa_builder.enable("has_pauth").unwrap();
}
if cfg!(target_os = "macos") {
// Pointer authentication is always available on Apple Silicon.
isa_builder.enable("sign_return_address").unwrap();
// macOS enforces the use of the B key for return addresses.
isa_builder.enable("sign_return_address_with_bkey").unwrap();
}
}
// There is no is_s390x_feature_detected macro yet, so for now
// we use getauxval from the libc crate directly.
#[cfg(all(target_arch = "s390x", target_os = "linux"))]
{
use cranelift_codegen::settings::Configurable;
if !infer_native_flags {
return Ok(isa_builder);
}
let v = unsafe { libc::getauxval(libc::AT_HWCAP) };
const HWCAP_S390X_VXRS_EXT2: libc::c_ulong = 32768;
if (v & HWCAP_S390X_VXRS_EXT2) != 0 {
isa_builder.enable("has_vxrs_ext2").unwrap();
// There is no separate HWCAP bit for mie2, so assume
// that any machine with vxrs_ext2 also has mie2.
isa_builder.enable("has_mie2").unwrap();
}
}
// `is_riscv_feature_detected` is nightly only for now, use
// getauxval from the libc crate directly as a temporary measure.
#[cfg(all(target_arch = "riscv64", target_os = "linux"))]
{
use cranelift_codegen::settings::Configurable;
if !infer_native_flags {
return Ok(isa_builder);
}
let v = unsafe { libc::getauxval(libc::AT_HWCAP) };
const HWCAP_RISCV_EXT_A: libc::c_ulong = 1 << (b'a' - b'a');
const HWCAP_RISCV_EXT_C: libc::c_ulong = 1 << (b'c' - b'a');
const HWCAP_RISCV_EXT_D: libc::c_ulong = 1 << (b'd' - b'a');
const HWCAP_RISCV_EXT_F: libc::c_ulong = 1 << (b'f' - b'a');
const HWCAP_RISCV_EXT_M: libc::c_ulong = 1 << (b'm' - b'a');
const HWCAP_RISCV_EXT_V: libc::c_ulong = 1 << (b'v' - b'a');
if (v & HWCAP_RISCV_EXT_A) != 0 {
isa_builder.enable("has_a").unwrap();
}
if (v & HWCAP_RISCV_EXT_C) != 0 {
isa_builder.enable("has_c").unwrap();
}
if (v & HWCAP_RISCV_EXT_D) != 0 {
isa_builder.enable("has_d").unwrap();
}
if (v & HWCAP_RISCV_EXT_F) != 0 {
isa_builder.enable("has_f").unwrap();
// TODO: There doesn't seem to be a bit associated with this extension
// rust enables it with the `f` extension:
// https://github.com/rust-lang/stdarch/blob/790411f93c4b5eada3c23abb4c9a063fb0b24d99/crates/std_detect/src/detect/os/linux/riscv.rs#L43
isa_builder.enable("has_zicsr").unwrap();
}
if (v & HWCAP_RISCV_EXT_M) != 0 {
isa_builder.enable("has_m").unwrap();
}
if (v & HWCAP_RISCV_EXT_V) != 0 {
isa_builder.enable("has_v").unwrap();
}
// TODO: ZiFencei does not have a bit associated with it
// TODO: Zbkb does not have a bit associated with it
}
// squelch warnings about unused mut/variables on some platforms.
drop(&mut isa_builder);
drop(infer_native_flags);
Ok(isa_builder)
}
#[cfg(test)]
mod tests {
use super::builder;
use cranelift_codegen::isa::CallConv;
use cranelift_codegen::settings;
#[test]
fn test() {
if let Ok(isa_builder) = builder() {
let flag_builder = settings::builder();
let isa = isa_builder.finish(settings::Flags::new(flag_builder)).unwrap();
if cfg!(all(target_os = "macos", target_arch = "aarch64")) {
assert_eq!(isa.default_call_conv(), CallConv::AppleAarch64);
} else if cfg!(any(unix, target_os = "nebulet")) {
assert_eq!(isa.default_call_conv(), CallConv::SystemV);
} else if cfg!(windows) {
assert_eq!(isa.default_call_conv(), CallConv::WindowsFastcall);
}
if cfg!(target_pointer_width = "64") {
assert_eq!(isa.pointer_bits(), 64);
} else if cfg!(target_pointer_width = "32") {
assert_eq!(isa.pointer_bits(), 32);
} else if cfg!(target_pointer_width = "16") {
assert_eq!(isa.pointer_bits(), 16);
}
}
}
}
/// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

View File

@ -279,9 +279,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
fx.tcx.sess.span_warn(span, "Index argument for `simd_extract` is not a constant");
let trap_block = fx.bcx.create_block();
let true_ = fx.bcx.ins().iconst(types::I8, 1);
fx.bcx.ins().brnz(true_, trap_block, &[]);
let ret_block = fx.get_block(target);
fx.bcx.ins().jump(ret_block, &[]);
fx.bcx.ins().brif(true_, trap_block, &[], ret_block, &[]);
fx.bcx.switch_to_block(trap_block);
crate::trap::trap_unimplemented(
fx,
@ -825,8 +824,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let next = fx.bcx.create_block();
let res_lane = fx.bcx.append_block_param(next, lane_clif_ty);
fx.bcx.ins().brnz(mask_lane, if_enabled, &[]);
fx.bcx.ins().jump(if_disabled, &[]);
fx.bcx.ins().brif(mask_lane, if_enabled, &[], if_disabled, &[]);
fx.bcx.seal_block(if_enabled);
fx.bcx.seal_block(if_disabled);
@ -864,8 +862,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let if_enabled = fx.bcx.create_block();
let next = fx.bcx.create_block();
fx.bcx.ins().brnz(mask_lane, if_enabled, &[]);
fx.bcx.ins().jump(next, &[]);
fx.bcx.ins().brif(mask_lane, if_enabled, &[], next, &[]);
fx.bcx.seal_block(if_enabled);
fx.bcx.switch_to_block(if_enabled);

View File

@ -57,8 +57,6 @@ mod compiler_builtins;
mod concurrency_limiter;
mod config;
mod constant;
// FIXME revert back to the external crate with Cranelift 0.93
mod cranelift_native;
mod debuginfo;
mod discriminant;
mod driver;
@ -246,7 +244,7 @@ fn target_triple(sess: &Session) -> target_lexicon::Triple {
}
}
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::TargetIsa + 'static> {
fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::TargetIsa + 'static> {
use target_lexicon::BinaryFormat;
let target_triple = crate::target_triple(sess);