Add options to wasmtime and wasm2obj to pick compilation strategy.

This commit is contained in:
Dan Gohman
2019-10-02 13:59:49 -07:00
parent d4353f03cb
commit 8d89c3b479
6 changed files with 72 additions and 24 deletions

View File

@@ -63,7 +63,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=<cache_config_file>] [--enable-simd] <file> -o <output>
wasm2obj [--target TARGET] [-Odg] [--disable-cache | --cache-config=<cache_config_file>] [--enable-simd] [--always-lightbeam | --always-cranelift] <file> -o <output>
wasm2obj --create-cache-config [--cache-config=<cache_config_file>]
wasm2obj --help | --version
@@ -80,6 +80,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
--enable-simd enable proposed SIMD instructions
-O, --optimize runs optimization passes on the translated functions
--version print the Cranelift version
@@ -97,6 +99,8 @@ struct Args {
flag_cache_config: Option<String>,
flag_create_cache_config: bool,
flag_enable_simd: bool,
flag_always_lightbeam: bool,
flag_always_cranelift: bool,
flag_optimize: bool,
}

View File

@@ -44,6 +44,7 @@ use std::path::{Path, PathBuf};
use std::process::exit;
use wabt;
use wasi_common::preopen_dir;
use wasmtime::pick_compilation_strategy;
use wasmtime_api::{Config, Engine, HostRef, Instance, Module, Store};
use wasmtime_environ::{cache_create_new_config, cache_init};
use wasmtime_interface_types::ModuleData;
@@ -62,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=<cache_config_file>] [--preload=<wasm>...] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] <file> [<arg>...]
wasmtime [-odg] [--enable-simd] [--wasi-c] [--disable-cache | --cache-config=<cache_config_file>] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> <file> [<arg>...]
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>] [--env=<env>...] [--dir=<dir>...] [--mapdir=<mapping>...] --invoke=<fn> [--always-lightbeam | --always-cranelift] <file> [<arg>...]
wasmtime --create-cache-config [--cache-config=<cache_config_file>]
wasmtime --help | --version
@@ -80,6 +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
--enable-simd enable proposed SIMD instructions
--wasi-c enable the wasi-c implementation of WASI
--preload=<wasm> load an additional wasm module before loading the main module
@@ -102,6 +105,8 @@ struct Args {
flag_debug: bool,
flag_g: bool,
flag_enable_simd: bool,
flag_always_lightbeam: bool,
flag_always_cranelift: bool,
flag_invoke: Option<String>,
flag_preload: Vec<String>,
flag_env: Vec<String>,
@@ -281,7 +286,16 @@ fn rmain() -> Result<(), Error> {
flag_builder.set("opt_level", "speed")?;
}
let config = Config::new(settings::Flags::new(flag_builder), features, debug_info);
// Decide how to compile.
let strategy =
pick_compilation_strategy(args.flag_always_cranelift, args.flag_always_lightbeam);
let config = Config::new(
settings::Flags::new(flag_builder),
features,
debug_info,
strategy,
);
let engine = HostRef::new(Engine::new(config));
let store = HostRef::new(Store::new(engine));

View File

@@ -33,8 +33,9 @@ use pretty_env_logger;
use serde::Deserialize;
use std::path::Path;
use std::process;
use wasmtime::pick_compilation_strategy;
use wasmtime_environ::{cache_create_new_config, cache_init};
use wasmtime_jit::{CompilationStrategy, Compiler, Features};
use wasmtime_jit::{Compiler, Features};
use wasmtime_wast::WastContext;
const USAGE: &str = "
@@ -153,17 +154,8 @@ fn main() {
}
// Decide how to compile.
let strategy = match (args.flag_always_lightbeam, args.flag_always_cranelift) {
#[cfg(feature = "lightbeam")]
(true, false) => CompilationStrategy::AlwaysLightbeam,
#[cfg(not(feature = "lightbeam"))]
(true, false) => panic!("--always-lightbeam given, but Lightbeam support is not enabled"),
(false, true) => CompilationStrategy::AlwaysCranelift,
(false, false) => CompilationStrategy::Auto,
(true, true) => {
panic!("Can't enable --always-cranelift and --always-lightbeam at the same time")
}
};
let strategy =
pick_compilation_strategy(args.flag_always_cranelift, args.flag_always_lightbeam);
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
let engine = Compiler::new(isa, strategy);