pub struct Budget { /* private fields */ }Expand description
A budget of work steps that every pass draws from.
A step is one unit of analysis or rewrite work (roughly: one instruction,
block, edge, or value visited). Each pass charges its cost before it changes
anything; a pass that cannot be paid for does nothing and marks the budget
exhausted, so the function is always left valid. Every pass is linear in the
function except where noted on PassKind, and those
non-linear parts (nested loops in LICM, repeated re-examination in copy
propagation, hash collisions in GVN) are charged step by step, so a hostile
function cannot make optimization take more than budget steps.
§Examples
use opt_lang::Budget;
let mut b = Budget::new(10);
assert_eq!(b.remaining(), 10);
assert!(!b.is_exhausted());
assert!(Budget::unlimited().remaining() > 1 << 60);Implementations§
Source§impl Budget
impl Budget
Sourcepub const fn unlimited() -> Budget
pub const fn unlimited() -> Budget
A budget that never runs out in practice (u64::MAX steps).
§Examples
assert!(!opt_lang::Budget::unlimited().is_exhausted());Sourcepub const fn is_exhausted(&self) -> bool
pub const fn is_exhausted(&self) -> bool
Whether a pass was refused (or stopped early) because the budget ran out.
§Examples
use ir_lang::{Linkage, Module, Signature};
use opt_lang::{Budget, PassKind};
let mut m = Module::new("m");
let f = m.declare_function("f", &Signature::new(&[], &[]), Linkage::Export)?;
m.build(f)?.ret(&[])?;
let mut budget = Budget::new(0);
let changed = opt_lang::run_pass(&mut m.edit(f)?, PassKind::Dce, &mut budget)?;
assert!(!changed && budget.is_exhausted());Trait Implementations§
impl Copy for Budget
impl Eq for Budget
impl StructuralPartialEq for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl RefUnwindSafe for Budget
impl Send for Budget
impl Sync for Budget
impl Unpin for Budget
impl UnsafeUnpin for Budget
impl UnwindSafe for Budget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more