pub fn optimize(module: &mut Module) -> Result<Stats, OptError>Expand description
Optimizes every function of module with the default pipeline (Tier 1).
The same as Optimizer::new().run(module): DEFAULT_PIPELINE run to a
fixpoint (at most DEFAULT_MAX_ITERATIONS sweeps), with the default
budget, validation between passes in debug builds, and changed functions
compacted.
§Errors
OptError::InvalidInput if a function does not validate; the other
variants only for a defect in a pass.
§Examples
use ir_lang::{Linkage, Module, Signature, Type};
let mut m = Module::new("m");
let f = m.declare_function("f", &Signature::new(&[], &[Type::I32]), Linkage::Export)?;
let mut b = m.build(f)?;
let unused = b.iconst(Type::I32, 1)?;
let v = b.iconst(Type::I32, 2)?;
b.ret(&[v])?;
let stats = opt_lang::optimize(&mut m)?;
assert_eq!(stats.insts_after(), 1);
m.validate()?;