Wasmtime: allow using the experimental Cranelift x64 backend in cli;

This introduces two changes:

- first, a Cargo feature is added to make it possible to use the
Cranelift x64 backend directly from wasmtime's CLI.
- second, when passing a `cranelift-flags` parameter, and the given
parameter's name doesn't exist at the target-independent flag level, try
to set it as a target-dependent setting.

These two changes make it possible to try out the new x64 backend with:

    cargo run --features experimental_x64 -- run --cranelift-flags use_new_backend=true -- /path/to/a.wasm

Right now, this will fail because most opcodes required by the
trampolines are actually not implemented yet.
This commit is contained in:
Benjamin Bouvier
2020-06-15 17:13:10 +02:00
parent eb548e263d
commit c2692ecb8a
5 changed files with 29 additions and 6 deletions

View File

@@ -81,6 +81,10 @@ lightbeam = [
jitdump = ["wasmtime/jitdump"]
vtune = ["wasmtime/vtune"]
# Try the experimental, work-in-progress new x86_64 backend. This is not stable
# as of June 2020.
experimental_x64 = ["wasmtime-jit/experimental_x64"]
[badges]
maintenance = { status = "actively-developed" }

View File

@@ -150,6 +150,7 @@ pub enum LookupError {
/// Builder for a `TargetIsa`.
/// Modify the ISA-specific settings before creating the `TargetIsa` trait object with `finish`.
#[derive(Clone)]
pub struct Builder {
triple: Triple,
setup: settings::Builder,

View File

@@ -10,11 +10,13 @@ pub mod ir {
}
pub mod settings {
pub use cranelift_codegen::settings::{builder, Builder, Configurable, Flags};
pub use cranelift_codegen::settings::{builder, Builder, Configurable, Flags, SetError};
}
pub mod isa {
pub use cranelift_codegen::isa::{unwind, CallConv, RegUnit, TargetFrontendConfig, TargetIsa};
pub use cranelift_codegen::isa::{
unwind, Builder, CallConv, RegUnit, TargetFrontendConfig, TargetIsa,
};
}
pub mod entity {

View File

@@ -39,5 +39,9 @@ lightbeam = ["wasmtime-environ/lightbeam"]
jitdump = ["wasmtime-profiling/jitdump"]
vtune = ["wasmtime-profiling/vtune"]
# Try the experimental, work-in-progress new x86_64 backend. This is not stable
# as of June 2020.
experimental_x64 = ["cranelift-codegen/x64"]
[badges]
maintenance = { status = "actively-developed" }

View File

@@ -14,8 +14,8 @@ use std::path::Path;
use std::rc::{Rc, Weak};
use std::sync::Arc;
use wasmparser::{OperatorValidatorConfig, ValidatingParserConfig};
use wasmtime_environ::settings::{self, Configurable};
use wasmtime_environ::{ir, isa::TargetIsa, wasm, CacheConfig, Tunables};
use wasmtime_environ::settings::{self, Configurable, SetError};
use wasmtime_environ::{ir, isa, isa::TargetIsa, wasm, CacheConfig, Tunables};
use wasmtime_jit::{native, CompilationStrategy, Compiler};
use wasmtime_profiling::{JitDumpAgent, NullProfilerAgent, ProfilingAgent, VTuneAgent};
use wasmtime_runtime::{
@@ -36,6 +36,7 @@ use wasmtime_runtime::{
#[derive(Clone)]
pub struct Config {
pub(crate) flags: settings::Builder,
pub(crate) isa_flags: isa::Builder,
pub(crate) validating_config: ValidatingParserConfig,
pub(crate) tunables: Tunables,
pub(crate) strategy: CompilationStrategy,
@@ -94,6 +95,7 @@ impl Config {
},
},
flags,
isa_flags: native::builder(),
strategy: CompilationStrategy::Auto,
cache_config: CacheConfig::new_cache_disabled(),
profiler: Arc::new(NullProfilerAgent),
@@ -377,7 +379,15 @@ impl Config {
/// This method can fail if the flag's name does not exist, or the value is not appropriate for
/// the flag type.
pub unsafe fn cranelift_other_flag(&mut self, name: &str, value: &str) -> Result<&mut Self> {
self.flags.set(name, value)?;
if let Err(err) = self.flags.set(name, value) {
match err {
SetError::BadName(_) => {
// Try the target-specific flags.
self.isa_flags.set(name, value)?;
}
_ => bail!(err),
}
}
Ok(self)
}
@@ -600,7 +610,9 @@ impl Config {
}
pub(crate) fn target_isa(&self) -> Box<dyn TargetIsa> {
native::builder().finish(settings::Flags::new(self.flags.clone()))
self.isa_flags
.clone()
.finish(settings::Flags::new(self.flags.clone()))
}
fn build_compiler(&self) -> Compiler {