Skip to content

Commit 31b2963

Browse files
authored
Merge pull request #1163 from mominul/target_cpu
Support -Ctarget-cpu
2 parents cdc0aa1 + c4f50fb commit 31b2963

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ crate-type = ["dylib"]
1212
cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", features = ["unwind"] }
1313
cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" }
1414
cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" }
15+
cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" }
1516
cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", optional = true }
1617
cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" }
1718
target-lexicon = "0.12.0"
@@ -28,6 +29,7 @@ smallvec = "1.6.1"
2829
#cranelift-codegen = { path = "../wasmtime/cranelift/codegen" }
2930
#cranelift-frontend = { path = "../wasmtime/cranelift/frontend" }
3031
#cranelift-module = { path = "../wasmtime/cranelift/module" }
32+
#cranelift-native = { path = ../wasmtime/cranelift/native" }
3133
#cranelift-jit = { path = "../wasmtime/cranelift/jit" }
3234
#cranelift-object = { path = "../wasmtime/cranelift/object" }
3335

src/lib.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,28 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box<dyn isa::Tar
272272
let flags = settings::Flags::new(flags_builder);
273273

274274
let variant = cranelift_codegen::isa::BackendVariant::MachInst;
275-
let mut isa_builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap();
276-
// Don't use "haswell", as it implies `has_lzcnt`.macOS CI is still at Ivy Bridge EP, so `lzcnt`
277-
// is interpreted as `bsr`.
278-
isa_builder.enable("nehalem").unwrap();
275+
276+
let isa_builder = match sess.opts.cg.target_cpu.as_deref() {
277+
Some("native") => {
278+
let builder = cranelift_native::builder_with_options(variant, true).unwrap();
279+
builder
280+
}
281+
Some(value) => {
282+
let mut builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap();
283+
if let Err(_) = builder.enable(value) {
284+
sess.fatal("The specified target cpu isn't currently supported by Cranelift.");
285+
}
286+
builder
287+
}
288+
None => {
289+
let mut builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap();
290+
// Don't use "haswell" as the default, as it implies `has_lzcnt`.
291+
// macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`.
292+
builder.enable("nehalem").unwrap();
293+
builder
294+
}
295+
};
296+
279297
isa_builder.finish(flags)
280298
}
281299

0 commit comments

Comments
 (0)