pub struct Stats { /* private fields */ }Expand description
The result of an optimization run: sizes before and after, iterations, and per-pass counts.
Sizes count live instructions (terminators excluded) and live blocks.
§Examples
use ir_lang::{CmpOp, Linkage, Module, Signature, Type};
// if 1 < 2 { ret 10 } else { ret 20 }: folds to `ret 10`.
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 (one, two) = (b.iconst(Type::I32, 1)?, b.iconst(Type::I32, 2)?);
let c = b.compare(CmpOp::Lt, one, two)?;
let (t, e) = (b.create_block(&[])?, b.create_block(&[])?);
b.branch(c, t, &[], e, &[])?;
b.switch_to(t)?;
let ten = b.iconst(Type::I32, 10)?;
b.ret(&[ten])?;
b.switch_to(e)?;
let twenty = b.iconst(Type::I32, 20)?;
b.ret(&[twenty])?;
let stats = opt_lang::optimize(&mut m)?;
assert_eq!(stats.functions(), 1);
assert_eq!((stats.insts_before(), stats.blocks_before()), (5, 3));
assert_eq!((stats.insts_after(), stats.blocks_after()), (1, 1));
assert_eq!(stats.converged(), 1);Implementations§
Source§impl Stats
impl Stats
Sourcepub const fn functions(&self) -> usize
pub const fn functions(&self) -> usize
The number of function bodies optimized.
See Stats for an example.
Sourcepub const fn insts_before(&self) -> usize
pub const fn insts_before(&self) -> usize
Live instructions before optimization (terminators excluded).
See Stats for an example.
Sourcepub const fn insts_after(&self) -> usize
pub const fn insts_after(&self) -> usize
Live instructions after optimization (terminators excluded).
See Stats for an example.
Sourcepub const fn blocks_before(&self) -> usize
pub const fn blocks_before(&self) -> usize
Live blocks before optimization.
See Stats for an example.
Sourcepub const fn blocks_after(&self) -> usize
pub const fn blocks_after(&self) -> usize
Live blocks after optimization.
See Stats for an example.
Sourcepub const fn iterations(&self) -> usize
pub const fn iterations(&self) -> usize
Pipeline sweeps run, summed over functions (a sweep runs every pass once).
§Examples
assert_eq!(opt_lang::Stats::default().iterations(), 0);Sourcepub const fn converged(&self) -> usize
pub const fn converged(&self) -> usize
Functions whose last sweep changed nothing (they reached the pipeline’s fixpoint within the iteration limit).
See Stats for an example.
Sourcepub const fn budget_exhausted(&self) -> usize
pub const fn budget_exhausted(&self) -> usize
Functions where a pass was skipped or cut short because the budget ran out. Those functions are valid but may be less optimized.
§Examples
assert_eq!(opt_lang::Stats::default().budget_exhausted(), 0);Sourcepub fn pass(&self, kind: PassKind) -> PassStats
pub fn pass(&self, kind: PassKind) -> PassStats
The counts of one pass.
See PassStats for an example.
Sourcepub fn passes(&self) -> &[PassStats]
pub fn passes(&self) -> &[PassStats]
The counts of every pass, in PassKind::ALL order.
§Examples
assert_eq!(opt_lang::Stats::default().passes().len(), opt_lang::PassKind::ALL.len());