From c2692ecb8a5ea04f2e14c295ad32f93426e7156d Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 15 Jun 2020 17:13:10 +0200 Subject: [PATCH] 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. --- Cargo.toml | 4 ++++ cranelift/codegen/src/isa/mod.rs | 1 + crates/environ/src/data_structures.rs | 6 ++++-- crates/jit/Cargo.toml | 4 ++++ crates/wasmtime/src/runtime.rs | 20 ++++++++++++++++---- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7b22090f4..147c2d6c5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/cranelift/codegen/src/isa/mod.rs b/cranelift/codegen/src/isa/mod.rs index ad0d292c37..3bd84fbc6e 100644 --- a/cranelift/codegen/src/isa/mod.rs +++ b/cranelift/codegen/src/isa/mod.rs @@ -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, diff --git a/crates/environ/src/data_structures.rs b/crates/environ/src/data_structures.rs index c9aaa5c920..60ea62c2e3 100644 --- a/crates/environ/src/data_structures.rs +++ b/crates/environ/src/data_structures.rs @@ -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 { diff --git a/crates/jit/Cargo.toml b/crates/jit/Cargo.toml index 696b2e8e75..b1ce6d468f 100644 --- a/crates/jit/Cargo.toml +++ b/crates/jit/Cargo.toml @@ -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" } diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rs index f57fdc8a29..d42860b9b9 100644 --- a/crates/wasmtime/src/runtime.rs +++ b/crates/wasmtime/src/runtime.rs @@ -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 { - 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 {