This PR switches the default backend on x86, for both the `cranelift-codegen` crate and for Wasmtime, to the new (`MachInst`-style, `VCode`-based) backend that has been under development and testing for some time now. The old backend is still available by default in builds with the `old-x86-backend` feature, or by requesting `BackendVariant::Legacy` from the appropriate APIs. As part of that switch, it adds some more runtime-configurable plumbing to the testing infrastructure so that tests can be run using the appropriate backend. `clif-util test` is now capable of parsing a backend selector option from filetests and instantiating the correct backend. CI has been updated so that the old x86 backend continues to run its tests, just as we used to run the new x64 backend separately. At some point, we will remove the old x86 backend entirely, once we are satisfied that the new backend has not caused any unforeseen issues and we do not need to revert.
70 lines
2.4 KiB
Rust
70 lines
2.4 KiB
Rust
//! Test command for running CLIF files and verifying their results
|
|
//!
|
|
//! The `run` test command compiles each function on the host machine and executes it
|
|
|
|
use crate::function_runner::SingleFunctionCompiler;
|
|
use crate::subtest::{Context, SubTest};
|
|
use cranelift_codegen::ir;
|
|
use cranelift_reader::parse_run_command;
|
|
use cranelift_reader::TestCommand;
|
|
use log::trace;
|
|
use std::borrow::Cow;
|
|
use target_lexicon::Architecture;
|
|
|
|
struct TestRun;
|
|
|
|
pub fn subtest(parsed: &TestCommand) -> anyhow::Result<Box<dyn SubTest>> {
|
|
assert_eq!(parsed.command, "run");
|
|
if !parsed.options.is_empty() {
|
|
anyhow::bail!("No options allowed on {}", parsed);
|
|
}
|
|
Ok(Box::new(TestRun))
|
|
}
|
|
|
|
impl SubTest for TestRun {
|
|
fn name(&self) -> &'static str {
|
|
"run"
|
|
}
|
|
|
|
fn is_mutating(&self) -> bool {
|
|
false
|
|
}
|
|
|
|
fn needs_isa(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn run(&self, func: Cow<ir::Function>, context: &Context) -> anyhow::Result<()> {
|
|
// If this test requests to run on a completely different
|
|
// architecture than the host platform then we skip it entirely,
|
|
// since we won't be able to natively execute machine code.
|
|
let requested_arch = context.isa.unwrap().triple().architecture;
|
|
if requested_arch != Architecture::host() {
|
|
println!(
|
|
"skipped {}: host can't run {:?} programs",
|
|
context.file_path, requested_arch
|
|
);
|
|
return Ok(());
|
|
}
|
|
let variant = context.isa.unwrap().variant();
|
|
|
|
let mut compiler = SingleFunctionCompiler::with_host_isa(context.flags.clone(), variant);
|
|
for comment in context.details.comments.iter() {
|
|
if let Some(command) = parse_run_command(comment.text, &func.signature)? {
|
|
trace!("Parsed run command: {}", command);
|
|
|
|
// Note that here we're also explicitly ignoring `context.isa`,
|
|
// regardless of what's requested. We want to use the native
|
|
// host ISA no matter what here, so the ISA listed in the file
|
|
// is only used as a filter to not run into situations like
|
|
// running x86_64 code on aarch64 platforms.
|
|
let compiled_fn = compiler.compile(func.clone().into_owned())?;
|
|
command
|
|
.run(|_, args| Ok(compiled_fn.call(args)))
|
|
.map_err(|s| anyhow::anyhow!("{}", s))?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|