Rename --always-cranelift to --cranelift.

Also, enable use of Lightbeam in wasm2obj.
This commit is contained in:
Dan Gohman
2019-10-04 17:02:31 -07:00
parent 36756613b8
commit 5ccdf13b11
7 changed files with 58 additions and 40 deletions

View File

@@ -15,9 +15,9 @@ fn main() {
.expect("error generating test source file"); .expect("error generating test source file");
for strategy in &[ for strategy in &[
"AlwaysCranelift", "Cranelift",
#[cfg(feature = "lightbeam")] #[cfg(feature = "lightbeam")]
"AlwaysLightbeam", "Lightbeam",
] { ] {
writeln!(out, "#[allow(non_snake_case)]").expect("generating tests"); writeln!(out, "#[allow(non_snake_case)]").expect("generating tests");
writeln!(out, "mod {} {{", strategy).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 { fn ignore(testsuite: &str, name: &str, strategy: &str) -> bool {
match strategy { match strategy {
#[cfg(feature = "lightbeam")] #[cfg(feature = "lightbeam")]
"AlwaysLightbeam" => match (testsuite, name) { "Lightbeam" => match (testsuite, name) {
("single_file_spec_test", "simd_const") => return true, ("single_file_spec_test", "simd_const") => return true,
_ => (), _ => (),
}, },
"AlwaysCranelift" => {} "Cranelift" => {}
_ => panic!("unrecognized strategy"), _ => panic!("unrecognized strategy"),
} }

View File

@@ -24,7 +24,7 @@ fuzz_target!(|data: &[u8]| {
panic!("host machine is not a supported target"); panic!("host machine is not a supported target");
}); });
let isa = isa_builder.finish(settings::Flags::new(flag_builder)); 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 mut resolver = NullResolver {};
let global_exports = Rc::new(RefCell::new(HashMap::new())); let global_exports = Rc::new(RefCell::new(HashMap::new()));
let _compiled = let _compiled =
@@ -44,7 +44,7 @@ fuzz_target!(|data: &[u8]| {
panic!("host machine is not a supported target"); panic!("host machine is not a supported target");
}); });
let isa = isa_builder.finish(settings::Flags::new(flag_builder)); 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 mut resolver = NullResolver {};
let global_exports = Rc::new(RefCell::new(HashMap::new())); let global_exports = Rc::new(RefCell::new(HashMap::new()));
let _compiled = let _compiled =

View File

@@ -49,11 +49,13 @@ use std::process;
use std::str; use std::str;
use std::str::FromStr; use std::str::FromStr;
use target_lexicon::Triple; use target_lexicon::Triple;
use wasmtime::pick_compilation_strategy;
use wasmtime_debug::{emit_debugsections, read_debuginfo}; use wasmtime_debug::{emit_debugsections, read_debuginfo};
use wasmtime_environ::{cache_create_new_config, cache_init}; use wasmtime_environ::{cache_create_new_config, cache_init};
use wasmtime_environ::{ use wasmtime_environ::{
Compiler, Cranelift, ModuleEnvironment, ModuleVmctxInfo, Tunables, VMOffsets, Compiler, Cranelift, ModuleEnvironment, ModuleVmctxInfo, Tunables, VMOffsets,
}; };
use wasmtime_jit::CompilationStrategy;
use wasmtime_obj::emit_module; use wasmtime_obj::emit_module;
const USAGE: &str = " 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. The default is a dummy environment that produces placeholder values.
Usage: Usage:
wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=<cache_config_file>] [--enable-simd] [--always-lightbeam | --always-cranelift] <file> -o <output> wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=<cache_config_file>] [--enable-simd] [--lightbeam | --cranelift] <file> -o <output>
wasm2obj --create-cache-config [--cache-config=<cache_config_file>] wasm2obj --create-cache-config [--cache-config=<cache_config_file>]
wasm2obj --help | --version wasm2obj --help | --version
@@ -80,8 +82,8 @@ Options:
creates default configuration and writes it to the disk, creates default configuration and writes it to the disk,
use with --cache-config to specify custom config file use with --cache-config to specify custom config file
instead of default one instead of default one
--always-lightbeam use Lightbeam for all compilation --lightbeam use Lightbeam for all compilation
--always-cranelift use Cranelift for all compilation --cranelift use Cranelift for all compilation
--enable-simd enable proposed SIMD instructions --enable-simd enable proposed SIMD instructions
-O, --optimize runs optimization passes on the translated functions -O, --optimize runs optimization passes on the translated functions
--version print the Cranelift version --version print the Cranelift version
@@ -99,8 +101,8 @@ struct Args {
flag_cache_config: Option<String>, flag_cache_config: Option<String>,
flag_create_cache_config: bool, flag_create_cache_config: bool,
flag_enable_simd: bool, flag_enable_simd: bool,
flag_always_lightbeam: bool, flag_lightbeam: bool,
flag_always_cranelift: bool, flag_cranelift: bool,
flag_optimize: bool, flag_optimize: bool,
} }
@@ -168,6 +170,8 @@ fn main() {
args.flag_g, args.flag_g,
args.flag_enable_simd, args.flag_enable_simd,
args.flag_optimize, args.flag_optimize,
args.flag_cranelift,
args.flag_lightbeam,
) { ) {
Ok(()) => {} Ok(()) => {}
Err(message) => { Err(message) => {
@@ -184,6 +188,8 @@ fn handle_module(
generate_debug_info: bool, generate_debug_info: bool,
enable_simd: bool, enable_simd: bool,
enable_optimize: bool, enable_optimize: bool,
cranelift: bool,
lightbeam: bool,
) -> Result<(), String> { ) -> Result<(), String> {
let data = match read_wasm_file(path) { let data = match read_wasm_file(path) {
Ok(data) => data, Ok(data) => data,
@@ -227,6 +233,9 @@ fn handle_module(
// TODO: Expose the tunables as command-line flags. // TODO: Expose the tunables as command-line flags.
let tunables = Tunables::default(); 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 (module, lazy_function_body_inputs, lazy_data_initializers, target_config) = {
let environ = ModuleEnvironment::new(isa.frontend_config(), tunables); let environ = ModuleEnvironment::new(isa.frontend_config(), tunables);
@@ -244,13 +253,25 @@ fn handle_module(
// TODO: use the traps information // TODO: use the traps information
let (compilation, relocations, address_transform, value_ranges, stack_slots, _traps) = let (compilation, relocations, address_transform, value_ranges, stack_slots, _traps) =
match strategy {
CompilationStrategy::Auto | CompilationStrategy::Cranelift => {
Cranelift::compile_module( Cranelift::compile_module(
&module, &module,
lazy_function_body_inputs, lazy_function_body_inputs,
&*isa, &*isa,
generate_debug_info, generate_debug_info,
) )
.map_err(|e| e.to_string())?; .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 module_vmctx_info = {
let ofs = VMOffsets::new(target_config.pointer_bytes(), &module); let ofs = VMOffsets::new(target_config.pointer_bytes(), &module);

View File

@@ -63,8 +63,8 @@ including calling the start function if one is present. Additional functions
given with --invoke are then called. given with --invoke are then called.
Usage: Usage:
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] [--always-lightbeam | --always-cranelift] <file> [<arg>...] wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] [--lightbeam | --cranelift] <file> [<arg>...]
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> [--always-lightbeam | --always-cranelift] <file> [<arg>...] wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> [--lightbeam | --cranelift] <file> [<arg>...]
wasmtime --create-cache-config [--cache-config=<cache_config_file>] wasmtime --create-cache-config [--cache-config=<cache_config_file>]
wasmtime --help | --version wasmtime --help | --version
@@ -81,8 +81,8 @@ Options:
instead of default one instead of default one
-g generate debug information -g generate debug information
-d, --debug enable debug output on stderr/stdout -d, --debug enable debug output on stderr/stdout
--always-lightbeam use Lightbeam for all compilation --lightbeam use Lightbeam for all compilation
--always-cranelift use Cranelift for all compilation --cranelift use Cranelift for all compilation
--enable-simd enable proposed SIMD instructions --enable-simd enable proposed SIMD instructions
--wasi-c enable the wasi-c implementation of WASI --wasi-c enable the wasi-c implementation of WASI
--preload=<wasm> load an additional wasm module before loading the main module --preload=<wasm> load an additional wasm module before loading the main module
@@ -105,8 +105,8 @@ struct Args {
flag_debug: bool, flag_debug: bool,
flag_g: bool, flag_g: bool,
flag_enable_simd: bool, flag_enable_simd: bool,
flag_always_lightbeam: bool, flag_lightbeam: bool,
flag_always_cranelift: bool, flag_cranelift: bool,
flag_invoke: Option<String>, flag_invoke: Option<String>,
flag_preload: Vec<String>, flag_preload: Vec<String>,
flag_env: Vec<String>, flag_env: Vec<String>,
@@ -287,8 +287,7 @@ fn rmain() -> Result<(), Error> {
} }
// Decide how to compile. // Decide how to compile.
let strategy = let strategy = pick_compilation_strategy(args.flag_cranelift, args.flag_lightbeam);
pick_compilation_strategy(args.flag_always_cranelift, args.flag_always_lightbeam);
let config = Config::new( let config = Config::new(
settings::Flags::new(flag_builder), settings::Flags::new(flag_builder),

View File

@@ -42,7 +42,7 @@ const USAGE: &str = "
Wast test runner. Wast test runner.
Usage: Usage:
wast [-do] [--enable-simd] [--disable-cache | --cache-config=<cache_config_file>] [--always-lightbeam | --always-cranelift] <file>... wast [-do] [--enable-simd] [--disable-cache | --cache-config=<cache_config_file>] [--lightbeam | --cranelift] <file>...
wast --create-cache-config [--cache-config=<cache_config_file>] wast --create-cache-config [--cache-config=<cache_config_file>]
wast --help | --version wast --help | --version
@@ -58,8 +58,8 @@ Options:
creates default configuration and writes it to the disk, creates default configuration and writes it to the disk,
use with --cache-config to specify custom config file use with --cache-config to specify custom config file
instead of default one instead of default one
--always-lightbeam use Lightbeam for all compilation --lightbeam use Lightbeam for all compilation
--always-cranelift use Cranelift for all compilation --cranelift use Cranelift for all compilation
-d, --debug enable debug output on stderr/stdout -d, --debug enable debug output on stderr/stdout
--enable-simd enable proposed SIMD instructions --enable-simd enable proposed SIMD instructions
"; ";

View File

@@ -7,14 +7,12 @@ pub fn pick_compilation_strategy(
// Decide how to compile. // Decide how to compile.
match (always_lightbeam, always_cranelift) { match (always_lightbeam, always_cranelift) {
#[cfg(feature = "lightbeam")] #[cfg(feature = "lightbeam")]
(true, false) => CompilationStrategy::AlwaysLightbeam, (true, false) => CompilationStrategy::Lightbeam,
#[cfg(not(feature = "lightbeam"))] #[cfg(not(feature = "lightbeam"))]
(true, false) => panic!("--always-lightbeam given, but Lightbeam support is not enabled"), (true, false) => panic!("--lightbeam given, but Lightbeam support is not enabled"),
(false, true) => CompilationStrategy::AlwaysCranelift, (false, true) => CompilationStrategy::Cranelift,
(false, false) => CompilationStrategy::Auto, (false, false) => CompilationStrategy::Auto,
(true, true) => { (true, true) => panic!("Can't enable --cranelift and --lightbeam at the same time"),
panic!("Can't enable --always-cranelift and --always-lightbeam at the same time")
}
} }
} }

View File

@@ -32,11 +32,11 @@ pub enum CompilationStrategy {
Auto, Auto,
/// Compile all functions with Cranelift. /// Compile all functions with Cranelift.
AlwaysCranelift, Cranelift,
/// Compile all functions with Lightbeam. /// Compile all functions with Lightbeam.
#[cfg(feature = "lightbeam")] #[cfg(feature = "lightbeam")]
AlwaysLightbeam, Lightbeam,
} }
/// A WebAssembly code JIT compiler. /// A WebAssembly code JIT compiler.
@@ -117,9 +117,9 @@ impl Compiler {
> { > {
let (compilation, relocations, address_transform, value_ranges, stack_slots, traps) = let (compilation, relocations, address_transform, value_ranges, stack_slots, traps) =
match self.strategy { 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. // implementation.
CompilationStrategy::Auto | CompilationStrategy::AlwaysCranelift => { CompilationStrategy::Auto | CompilationStrategy::Cranelift => {
wasmtime_environ::cranelift::Cranelift::compile_module( wasmtime_environ::cranelift::Cranelift::compile_module(
module, module,
function_body_inputs, function_body_inputs,
@@ -128,7 +128,7 @@ impl Compiler {
) )
} }
#[cfg(feature = "lightbeam")] #[cfg(feature = "lightbeam")]
CompilationStrategy::AlwaysLightbeam => { CompilationStrategy::Lightbeam => {
wasmtime_environ::lightbeam::Lightbeam::compile_module( wasmtime_environ::lightbeam::Lightbeam::compile_module(
module, module,
function_body_inputs, function_body_inputs,