Struct wasm_opt::OptimizationOptions
source · pub struct OptimizationOptions {
pub reader: ReaderOptions,
pub writer: WriterOptions,
pub inlining: InliningOptions,
pub passopts: PassOptions,
pub passes: Passes,
pub features: Features,
pub converge: bool,
}
Expand description
Optimization options and optimization builder.
This type declares all supported Binaryen options. It can be modified directly or by its builder-pattern methods.
Call OptimizationOptions::run
to perform the optimizations.
Fields§
§reader: ReaderOptions
Options for reading the unoptimized wasm module.
writer: WriterOptions
Options for writing the optimized wasm module.
inlining: InliningOptions
Options related to inlining.
passopts: PassOptions
Options that affect how optimization passes behave.
passes: Passes
The set of optimization passes to apply.
features: Features
The set of wasm-features.
converge: bool
Run passes to convergence, continuing while binary size decreases.
Implementations§
source§impl OptimizationOptions
impl OptimizationOptions
Constructors.
sourcepub fn new_optimize_for_size() -> Self
pub fn new_optimize_for_size() -> Self
Optimize for size.
This corresponds to the -Os
argument to wasm-opt
,
and also the -O
argument to wasm-opt
.
It applies
sourcepub fn new_optimize_for_size_aggressively() -> Self
pub fn new_optimize_for_size_aggressively() -> Self
Optimize for size, but even more.
It applies
This corresponds to the -Oz
argument to wasm-opt
.
sourcepub fn new_opt_level_0() -> Self
pub fn new_opt_level_0() -> Self
Do not optimize.
It applies
It adds no default passes.
This corresponds to the -O0
argument to wasm-opt
,
and also to calling wasm-opt
with no -O*
optional at all.
sourcepub fn new_opt_level_1() -> Self
pub fn new_opt_level_1() -> Self
Apply basic optimizations.
Useful for fast iteration.
It applies
This corresponds to the -O1
argument to wasm-opt
.
sourcepub fn new_opt_level_2() -> Self
pub fn new_opt_level_2() -> Self
Apply most optimizations.
This level of optimization is appropriate for most applications. Higher optimization levels will not necessarily yield better performance, but will take longer to optimize.
It applies
This corresponds to the -O2
argument to wasm-opt
.
sourcepub fn new_opt_level_3() -> Self
pub fn new_opt_level_3() -> Self
Apply slower optimizations.
Spends potentially a lot of time on optimizations.
It applies
This corresponds to the -O3
argument to wasm-opt
.
sourcepub fn new_opt_level_4() -> Self
pub fn new_opt_level_4() -> Self
Apply the most aggressive optimizations.
Flattens the IR, which can take a lot of time and memory, but may be useful on nested / complex / less-optimized input.
It applies
This corresponds to the -O4
argument to wasm-opt
.
source§impl OptimizationOptions
impl OptimizationOptions
Builder methods.
sourcepub fn reader_file_type(&mut self, value: FileType) -> &mut Self
pub fn reader_file_type(&mut self, value: FileType) -> &mut Self
Sets ReaderOptions::file_type
.
sourcepub fn writer_file_type(&mut self, value: FileType) -> &mut Self
pub fn writer_file_type(&mut self, value: FileType) -> &mut Self
Sets WriterOptions::file_type
.
sourcepub fn set_converge(&mut self) -> &mut Self
pub fn set_converge(&mut self) -> &mut Self
sourcepub fn always_inline_max_size(&mut self, value: u32) -> &mut Self
pub fn always_inline_max_size(&mut self, value: u32) -> &mut Self
sourcepub fn one_caller_inline_max_size(&mut self, value: u32) -> &mut Self
pub fn one_caller_inline_max_size(&mut self, value: u32) -> &mut Self
sourcepub fn flexible_inline_max_size(&mut self, value: u32) -> &mut Self
pub fn flexible_inline_max_size(&mut self, value: u32) -> &mut Self
sourcepub fn allow_functions_with_loops(&mut self, value: bool) -> &mut Self
pub fn allow_functions_with_loops(&mut self, value: bool) -> &mut Self
sourcepub fn partial_inlining_ifs(&mut self, value: u32) -> &mut Self
pub fn partial_inlining_ifs(&mut self, value: u32) -> &mut Self
sourcepub fn validate(&mut self, value: bool) -> &mut Self
pub fn validate(&mut self, value: bool) -> &mut Self
Sets PassOptions::validate
.
sourcepub fn validate_globally(&mut self, value: bool) -> &mut Self
pub fn validate_globally(&mut self, value: bool) -> &mut Self
sourcepub fn optimize_level(&mut self, value: OptimizeLevel) -> &mut Self
pub fn optimize_level(&mut self, value: OptimizeLevel) -> &mut Self
sourcepub fn shrink_level(&mut self, value: ShrinkLevel) -> &mut Self
pub fn shrink_level(&mut self, value: ShrinkLevel) -> &mut Self
sourcepub fn traps_never_happen(&mut self, value: bool) -> &mut Self
pub fn traps_never_happen(&mut self, value: bool) -> &mut Self
sourcepub fn low_memory_unused(&mut self, value: bool) -> &mut Self
pub fn low_memory_unused(&mut self, value: bool) -> &mut Self
sourcepub fn fast_math(&mut self, value: bool) -> &mut Self
pub fn fast_math(&mut self, value: bool) -> &mut Self
Sets PassOptions::fast_math
.
sourcepub fn zero_filled_memory(&mut self, value: bool) -> &mut Self
pub fn zero_filled_memory(&mut self, value: bool) -> &mut Self
sourcepub fn debug_info(&mut self, value: bool) -> &mut Self
pub fn debug_info(&mut self, value: bool) -> &mut Self
Sets PassOptions::debug_info
.
sourcepub fn set_pass_arg(&mut self, key: &str, value: &str) -> &mut Self
pub fn set_pass_arg(&mut self, key: &str, value: &str) -> &mut Self
Adds a pass argument to PassOptions::arguments
.
sourcepub fn add_default_passes(&mut self, value: bool) -> &mut Self
pub fn add_default_passes(&mut self, value: bool) -> &mut Self
sourcepub fn add_pass(&mut self, value: Pass) -> &mut Self
pub fn add_pass(&mut self, value: Pass) -> &mut Self
Adds a pass to Passes::more_passes
.
sourcepub fn mvp_features_only(&mut self) -> &mut Self
pub fn mvp_features_only(&mut self) -> &mut Self
Sets the baseline feature set to FeatureBaseline::MvpOnly
.
sourcepub fn all_features(&mut self) -> &mut Self
pub fn all_features(&mut self) -> &mut Self
Sets the baseline feature set to FeatureBaseline::All
.
sourcepub fn enable_feature(&mut self, feature: Feature) -> &mut Self
pub fn enable_feature(&mut self, feature: Feature) -> &mut Self
Enables a feature.
This adds the feature to Features::enabled
, and is equivalent to the
--enable-{feature}
command line arguments.
sourcepub fn disable_feature(&mut self, feature: Feature) -> &mut Self
pub fn disable_feature(&mut self, feature: Feature) -> &mut Self
Disables a feature.
This adds the feature to Features::disabled
, and is equivalent to
the --disable-{feature}
command line arguments.
source§impl OptimizationOptions
impl OptimizationOptions
Execution.
sourcepub fn run(
&self,
infile: impl AsRef<Path>,
outfile: impl AsRef<Path>
) -> Result<(), OptimizationError>
pub fn run( &self, infile: impl AsRef<Path>, outfile: impl AsRef<Path> ) -> Result<(), OptimizationError>
Run the Binaryen wasm optimizer.
This loads a module from a file, runs optimization passes, and writes the module back to a file.
To supply sourcemaps for the input module,
and preserve them for the output module,
use OptimizationOptions::run_with_sourcemaps
.
§Errors
Returns error on I/O failure, or if the input fails to parse.
If PassOptions::validate
is true, it returns an error
if the input module fails to validate, or if the optimized
module fails to validate.
The Rust API does not support reading a module on stdin, as the CLI
does. If infile
is empty or “-”,
OptimizationError::InvalidStdinPath
is returned.
sourcepub fn run_with_sourcemaps(
&self,
infile: impl AsRef<Path>,
infile_sourcemap: Option<impl AsRef<Path>>,
outfile: impl AsRef<Path>,
outfile_sourcemap: Option<impl AsRef<Path>>,
sourcemap_url: Option<impl AsRef<str>>
) -> Result<(), OptimizationError>
pub fn run_with_sourcemaps( &self, infile: impl AsRef<Path>, infile_sourcemap: Option<impl AsRef<Path>>, outfile: impl AsRef<Path>, outfile_sourcemap: Option<impl AsRef<Path>>, sourcemap_url: Option<impl AsRef<str>> ) -> Result<(), OptimizationError>
Run the Binaryen wasm optimizer.
This loads a module from a file, runs optimization passes, and writes the module back to a file.
The sourcemap arguments are optional, and only have effect
when reading or writing binary wasm
files. When using
text wat
files the respective sourcemap argument is ignored.
§Errors
Returns error on I/O failure, or if the input fails to parse.
If PassOptions::validate
is true, it returns an error
if the input module fails to validate, or if the optimized
module fails to validate.
The Rust API does not support reading a module on stdin, as the CLI
does. If infile
is empty or “-”,
OptimizationError::InvalidStdinPath
is returned.
Trait Implementations§
source§impl Clone for OptimizationOptions
impl Clone for OptimizationOptions
source§fn clone(&self) -> OptimizationOptions
fn clone(&self) -> OptimizationOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more