Optimize generated code via the CLI by default (#973)
* Optimize generated code via the CLI by default This commit updates the behavior of the CLI and adds a new flag. It first enables the `--optimize` flag by default, ensuring that usage of the `wasmtime` CLI will enable cranelift optimizations by default. Next it also adds a `--opt-level` flag which is similar to Rust's `-Copt-level` where it takes a string argument of how to optimize. This is updates to support 0/1/2/s, where 1 is currently the same as 2 but added for consistency with other compilers. The default setting is `--opt-level=2`. When the `-O` flag is not passed the `--opt-level` flag is used, otherwise `-O` takes precedent in the sense that it implies `--opt-level=2` which is the highest optimization level. The thinking is that these flags will in general select the highest optimization level specified as the final optimization level. * Add inline docs * fix a test
This commit is contained in:
13
src/obj.rs
13
src/obj.rs
@@ -19,7 +19,7 @@ pub fn compile_to_obj(
|
||||
target: Option<&Triple>,
|
||||
strategy: Strategy,
|
||||
enable_simd: bool,
|
||||
optimize: bool,
|
||||
opt_level: wasmtime::OptLevel,
|
||||
debug_info: bool,
|
||||
artifact_name: String,
|
||||
cache_config: &CacheConfig,
|
||||
@@ -38,8 +38,15 @@ pub fn compile_to_obj(
|
||||
flag_builder.enable("enable_simd").unwrap();
|
||||
}
|
||||
|
||||
if optimize {
|
||||
flag_builder.set("opt_level", "speed").unwrap();
|
||||
match opt_level {
|
||||
wasmtime::OptLevel::None => {}
|
||||
wasmtime::OptLevel::Speed => {
|
||||
flag_builder.set("opt_level", "speed").unwrap();
|
||||
}
|
||||
wasmtime::OptLevel::SpeedAndSize => {
|
||||
flag_builder.set("opt_level", "speed_and_size").unwrap();
|
||||
}
|
||||
other => bail!("unknown optimization level {:?}", other),
|
||||
}
|
||||
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
|
||||
Reference in New Issue
Block a user