From 5ccdf13b1180b1dbf5d7710b73bc1f38cacf8dce Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 4 Oct 2019 17:02:31 -0700 Subject: [PATCH] Rename --always-cranelift to --cranelift. Also, enable use of Lightbeam in wasm2obj. --- build.rs | 8 +++---- fuzz/fuzz_targets/compile.rs | 4 ++-- src/bin/wasm2obj.rs | 45 ++++++++++++++++++++++++++---------- src/bin/wasmtime.rs | 15 ++++++------ src/bin/wast.rs | 6 ++--- src/lib.rs | 10 ++++---- wasmtime-jit/src/compiler.rs | 10 ++++---- 7 files changed, 58 insertions(+), 40 deletions(-) diff --git a/build.rs b/build.rs index d883e3961c..9697d9903a 100644 --- a/build.rs +++ b/build.rs @@ -15,9 +15,9 @@ fn main() { .expect("error generating test source file"); for strategy in &[ - "AlwaysCranelift", + "Cranelift", #[cfg(feature = "lightbeam")] - "AlwaysLightbeam", + "Lightbeam", ] { writeln!(out, "#[allow(non_snake_case)]").expect("generating tests"); writeln!(out, "mod {} {{", strategy).expect("generating tests"); @@ -151,11 +151,11 @@ fn write_testsuite_tests( fn ignore(testsuite: &str, name: &str, strategy: &str) -> bool { match strategy { #[cfg(feature = "lightbeam")] - "AlwaysLightbeam" => match (testsuite, name) { + "Lightbeam" => match (testsuite, name) { ("single_file_spec_test", "simd_const") => return true, _ => (), }, - "AlwaysCranelift" => {} + "Cranelift" => {} _ => panic!("unrecognized strategy"), } diff --git a/fuzz/fuzz_targets/compile.rs b/fuzz/fuzz_targets/compile.rs index daf06c6565..1749fdffd8 100644 --- a/fuzz/fuzz_targets/compile.rs +++ b/fuzz/fuzz_targets/compile.rs @@ -24,7 +24,7 @@ fuzz_target!(|data: &[u8]| { panic!("host machine is not a supported target"); }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut compiler = Compiler::new(isa, CompilationStrategy::AlwaysCranelift); + let mut compiler = Compiler::new(isa, CompilationStrategy::Cranelift); let mut resolver = NullResolver {}; let global_exports = Rc::new(RefCell::new(HashMap::new())); let _compiled = @@ -44,7 +44,7 @@ fuzz_target!(|data: &[u8]| { panic!("host machine is not a supported target"); }); let isa = isa_builder.finish(settings::Flags::new(flag_builder)); - let mut compiler = Compiler::new(isa, CompilationStrategy::AlwaysLightbeam); + let mut compiler = Compiler::new(isa, CompilationStrategy::Lightbeam); let mut resolver = NullResolver {}; let global_exports = Rc::new(RefCell::new(HashMap::new())); let _compiled = diff --git a/src/bin/wasm2obj.rs b/src/bin/wasm2obj.rs index c796636750..7300771f43 100644 --- a/src/bin/wasm2obj.rs +++ b/src/bin/wasm2obj.rs @@ -49,11 +49,13 @@ use std::process; use std::str; use std::str::FromStr; use target_lexicon::Triple; +use wasmtime::pick_compilation_strategy; use wasmtime_debug::{emit_debugsections, read_debuginfo}; use wasmtime_environ::{cache_create_new_config, cache_init}; use wasmtime_environ::{ Compiler, Cranelift, ModuleEnvironment, ModuleVmctxInfo, Tunables, VMOffsets, }; +use wasmtime_jit::CompilationStrategy; use wasmtime_obj::emit_module; const USAGE: &str = " @@ -63,7 +65,7 @@ The translation is dependent on the environment chosen. The default is a dummy environment that produces placeholder values. Usage: - wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=] [--enable-simd] [--always-lightbeam | --always-cranelift] -o + wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=] [--enable-simd] [--lightbeam | --cranelift] -o wasm2obj --create-cache-config [--cache-config=] wasm2obj --help | --version @@ -80,8 +82,8 @@ Options: creates default configuration and writes it to the disk, use with --cache-config to specify custom config file instead of default one - --always-lightbeam use Lightbeam for all compilation - --always-cranelift use Cranelift for all compilation + --lightbeam use Lightbeam for all compilation + --cranelift use Cranelift for all compilation --enable-simd enable proposed SIMD instructions -O, --optimize runs optimization passes on the translated functions --version print the Cranelift version @@ -99,8 +101,8 @@ struct Args { flag_cache_config: Option, flag_create_cache_config: bool, flag_enable_simd: bool, - flag_always_lightbeam: bool, - flag_always_cranelift: bool, + flag_lightbeam: bool, + flag_cranelift: bool, flag_optimize: bool, } @@ -168,6 +170,8 @@ fn main() { args.flag_g, args.flag_enable_simd, args.flag_optimize, + args.flag_cranelift, + args.flag_lightbeam, ) { Ok(()) => {} Err(message) => { @@ -184,6 +188,8 @@ fn handle_module( generate_debug_info: bool, enable_simd: bool, enable_optimize: bool, + cranelift: bool, + lightbeam: bool, ) -> Result<(), String> { let data = match read_wasm_file(path) { Ok(data) => data, @@ -227,6 +233,9 @@ fn handle_module( // TODO: Expose the tunables as command-line flags. let tunables = Tunables::default(); + // Decide how to compile. + let strategy = pick_compilation_strategy(cranelift, lightbeam); + let (module, lazy_function_body_inputs, lazy_data_initializers, target_config) = { let environ = ModuleEnvironment::new(isa.frontend_config(), tunables); @@ -244,13 +253,25 @@ fn handle_module( // TODO: use the traps information let (compilation, relocations, address_transform, value_ranges, stack_slots, _traps) = - Cranelift::compile_module( - &module, - lazy_function_body_inputs, - &*isa, - generate_debug_info, - ) - .map_err(|e| e.to_string())?; + match strategy { + CompilationStrategy::Auto | CompilationStrategy::Cranelift => { + Cranelift::compile_module( + &module, + lazy_function_body_inputs, + &*isa, + generate_debug_info, + ) + .map_err(|e| e.to_string())? + } + #[cfg(feature = "lightbeam")] + CompilationStrategy::Lightbeam => Lightbeam::compile_module( + &module, + lazy_function_body_inputs, + &*isa, + generate_debug_info, + ) + .map_err(|e| e.to_string())?, + }; let module_vmctx_info = { let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); diff --git a/src/bin/wasmtime.rs b/src/bin/wasmtime.rs index f3a6e4d812..22a141d9a3 100644 --- a/src/bin/wasmtime.rs +++ b/src/bin/wasmtime.rs @@ -63,8 +63,8 @@ including calling the start function if one is present. Additional functions given with --invoke are then called. Usage: - wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=] [--preload=...] [--env=...] [--dir=...] [--mapdir=...] [--always-lightbeam | --always-cranelift] [...] - wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=] [--env=...] [--dir=...] [--mapdir=...] --invoke= [--always-lightbeam | --always-cranelift] [...] + wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=] [--preload=...] [--env=...] [--dir=...] [--mapdir=...] [--lightbeam | --cranelift] [...] + wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=] [--env=...] [--dir=...] [--mapdir=...] --invoke= [--lightbeam | --cranelift] [...] wasmtime --create-cache-config [--cache-config=] wasmtime --help | --version @@ -81,8 +81,8 @@ Options: instead of default one -g generate debug information -d, --debug enable debug output on stderr/stdout - --always-lightbeam use Lightbeam for all compilation - --always-cranelift use Cranelift for all compilation + --lightbeam use Lightbeam for all compilation + --cranelift use Cranelift for all compilation --enable-simd enable proposed SIMD instructions --wasi-c enable the wasi-c implementation of WASI --preload= load an additional wasm module before loading the main module @@ -105,8 +105,8 @@ struct Args { flag_debug: bool, flag_g: bool, flag_enable_simd: bool, - flag_always_lightbeam: bool, - flag_always_cranelift: bool, + flag_lightbeam: bool, + flag_cranelift: bool, flag_invoke: Option, flag_preload: Vec, flag_env: Vec, @@ -287,8 +287,7 @@ fn rmain() -> Result<(), Error> { } // Decide how to compile. - let strategy = - pick_compilation_strategy(args.flag_always_cranelift, args.flag_always_lightbeam); + let strategy = pick_compilation_strategy(args.flag_cranelift, args.flag_lightbeam); let config = Config::new( settings::Flags::new(flag_builder), diff --git a/src/bin/wast.rs b/src/bin/wast.rs index 4820d248b0..a05acb0631 100644 --- a/src/bin/wast.rs +++ b/src/bin/wast.rs @@ -42,7 +42,7 @@ const USAGE: &str = " Wast test runner. Usage: - wast [-do] [--enable-simd] [--disable-cache | --cache-config=] [--always-lightbeam | --always-cranelift] ... + wast [-do] [--enable-simd] [--disable-cache | --cache-config=] [--lightbeam | --cranelift] ... wast --create-cache-config [--cache-config=] wast --help | --version @@ -58,8 +58,8 @@ Options: creates default configuration and writes it to the disk, use with --cache-config to specify custom config file instead of default one - --always-lightbeam use Lightbeam for all compilation - --always-cranelift use Cranelift for all compilation + --lightbeam use Lightbeam for all compilation + --cranelift use Cranelift for all compilation -d, --debug enable debug output on stderr/stdout --enable-simd enable proposed SIMD instructions "; diff --git a/src/lib.rs b/src/lib.rs index c2d5ce31a6..fcc29d3207 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,14 +7,12 @@ pub fn pick_compilation_strategy( // Decide how to compile. match (always_lightbeam, always_cranelift) { #[cfg(feature = "lightbeam")] - (true, false) => CompilationStrategy::AlwaysLightbeam, + (true, false) => CompilationStrategy::Lightbeam, #[cfg(not(feature = "lightbeam"))] - (true, false) => panic!("--always-lightbeam given, but Lightbeam support is not enabled"), - (false, true) => CompilationStrategy::AlwaysCranelift, + (true, false) => panic!("--lightbeam given, but Lightbeam support is not enabled"), + (false, true) => CompilationStrategy::Cranelift, (false, false) => CompilationStrategy::Auto, - (true, true) => { - panic!("Can't enable --always-cranelift and --always-lightbeam at the same time") - } + (true, true) => panic!("Can't enable --cranelift and --lightbeam at the same time"), } } diff --git a/wasmtime-jit/src/compiler.rs b/wasmtime-jit/src/compiler.rs index 07aacf1b46..0cf7bf8625 100644 --- a/wasmtime-jit/src/compiler.rs +++ b/wasmtime-jit/src/compiler.rs @@ -32,11 +32,11 @@ pub enum CompilationStrategy { Auto, /// Compile all functions with Cranelift. - AlwaysCranelift, + Cranelift, /// Compile all functions with Lightbeam. #[cfg(feature = "lightbeam")] - AlwaysLightbeam, + Lightbeam, } /// A WebAssembly code JIT compiler. @@ -117,9 +117,9 @@ impl Compiler { > { let (compilation, relocations, address_transform, value_ranges, stack_slots, traps) = match self.strategy { - // For now, interpret `Auto` as `AlwaysCranelift` since that's the most stable + // For now, interpret `Auto` as `Cranelift` since that's the most stable // implementation. - CompilationStrategy::Auto | CompilationStrategy::AlwaysCranelift => { + CompilationStrategy::Auto | CompilationStrategy::Cranelift => { wasmtime_environ::cranelift::Cranelift::compile_module( module, function_body_inputs, @@ -128,7 +128,7 @@ impl Compiler { ) } #[cfg(feature = "lightbeam")] - CompilationStrategy::AlwaysLightbeam => { + CompilationStrategy::Lightbeam => { wasmtime_environ::lightbeam::Lightbeam::compile_module( module, function_body_inputs,