Handle native target-cpu variant
and raise fatal error if the specified target cpu is not supported
This commit is contained in:
parent
e16ccba394
commit
8eb96b8517
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -306,6 +306,7 @@ dependencies = [
|
||||
"cranelift-frontend",
|
||||
"cranelift-jit",
|
||||
"cranelift-module",
|
||||
"cranelift-native",
|
||||
"cranelift-object",
|
||||
"gimli",
|
||||
"indexmap",
|
||||
|
@ -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" }
|
||||
|
||||
|
29
src/lib.rs
29
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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user