Skip to main content

Stats

Struct Stats 

Source
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

Source

pub const fn functions(&self) -> usize

The number of function bodies optimized.

See Stats for an example.

Source

pub const fn insts_before(&self) -> usize

Live instructions before optimization (terminators excluded).

See Stats for an example.

Source

pub const fn insts_after(&self) -> usize

Live instructions after optimization (terminators excluded).

See Stats for an example.

Source

pub const fn blocks_before(&self) -> usize

Live blocks before optimization.

See Stats for an example.

Source

pub const fn blocks_after(&self) -> usize

Live blocks after optimization.

See Stats for an example.

Source

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);
Source

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.

Source

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);
Source

pub fn pass(&self, kind: PassKind) -> PassStats

The counts of one pass.

See PassStats for an example.

Source

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());

Trait Implementations§

Source§

impl Clone for Stats

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Stats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Stats

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Stats

Source§

impl PartialEq for Stats

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Stats

Auto Trait Implementations§

§

impl Freeze for Stats

§

impl RefUnwindSafe for Stats

§

impl Send for Stats

§

impl Sync for Stats

§

impl Unpin for Stats

§

impl UnsafeUnpin for Stats

§

impl UnwindSafe for Stats

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.