diff options
| author | Muhammad Mominul Huque <mominul2082@gmail.com> | 2021-04-23 19:55:52 +0600 |
|---|---|---|
| committer | Muhammad Mominul Huque <mominul2082@gmail.com> | 2021-04-23 19:55:52 +0600 |
| commit | 8eb96b85171bd5cb5b36c87f43f460f324ba078f (patch) | |
| tree | e2ec8732c3d664116ed4915e1ed2177432745342 | |
| parent | e16ccba3945e06a9e687dd13de9053d981cc4fad (diff) | |
| download | rust-8eb96b85171bd5cb5b36c87f43f460f324ba078f.tar.gz rust-8eb96b85171bd5cb5b36c87f43f460f324ba078f.zip | |
Handle native target-cpu variant
and raise fatal error if the specified target cpu is not supported
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/lib.rs | 29 |
3 files changed, 24 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock index 16c2732eac9..e6792def567 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -306,6 +306,7 @@ dependencies = [ "cranelift-frontend", "cranelift-jit", "cranelift-module", + "cranelift-native", "cranelift-object", "gimli", "indexmap", diff --git a/Cargo.toml b/Cargo.toml index 248540cf1a3..2789207c655 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ crate-type = ["dylib"] cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", features = ["unwind"] } cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } +cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", optional = true } cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } target-lexicon = "0.12.0" @@ -28,6 +29,7 @@ smallvec = "1.6.1" #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } #cranelift-frontend = { path = "../wasmtime/cranelift/frontend" } #cranelift-module = { path = "../wasmtime/cranelift/module" } +#cranelift-native = { path = ../wasmtime/cranelift/native" } #cranelift-jit = { path = "../wasmtime/cranelift/jit" } #cranelift-object = { path = "../wasmtime/cranelift/object" } diff --git a/src/lib.rs b/src/lib.rs index 02518cc0b19..b7a6e692e34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -272,15 +272,28 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::Tar let flags = settings::Flags::new(flags_builder); let variant = cranelift_codegen::isa::BackendVariant::MachInst; - let mut isa_builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); + + let isa_builder = match sess.opts.cg.target_cpu.as_deref() { + Some("native") => { + let builder = cranelift_native::builder_with_options(variant, true).unwrap(); + builder + } + Some(value) => { + let mut builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); + if let Err(_) = builder.enable(value) { + sess.fatal("The target cpu isn't currently supported by Cranelift."); + } + builder + } + None => { + let mut builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); + // Don't use "haswell" as the default, as it implies `has_lzcnt`. + // macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`. + builder.enable("nehalem").unwrap(); + builder + } + }; - if let Some(target_cpu) = sess.opts.cg.target_cpu.as_ref() { - isa_builder.enable(target_cpu).unwrap(); - } else { - // Don't use "haswell" as the default, as it implies `has_lzcnt`. - // macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`. - isa_builder.enable("nehalem").unwrap(); - } isa_builder.finish(flags) } |
