pub struct ConstantPropagator { /* private fields */ }Expand description
The constant propagation compiler pass.
Performs a bottom-up sweep over a TLExpr tree, evaluating subexpressions
at compile time when all operands are TLExpr::Constant(f64) values.
Runs to a fixed point (i.e. repeated until no further changes occur) or
until config.max_passes is reached.
Implementations§
Source§impl ConstantPropagator
impl ConstantPropagator
Sourcepub fn new(config: ConstPropConfig) -> Self
pub fn new(config: ConstPropConfig) -> Self
Create a new propagator with the supplied configuration.
Sourcepub fn with_default() -> Self
pub fn with_default() -> Self
Create a new propagator with default configuration.
Sourcepub fn run(&self, expr: TLExpr) -> (TLExpr, ConstPropStats)
pub fn run(&self, expr: TLExpr) -> (TLExpr, ConstPropStats)
Run constant propagation to a fixed point.
Returns (simplified_expr, stats).
Sourcepub fn as_constant(expr: &TLExpr) -> Option<f64>
pub fn as_constant(expr: &TLExpr) -> Option<f64>
Extract the numeric value if expr is a Constant, otherwise None.
Sourcepub fn count_nodes(expr: &TLExpr) -> u64
pub fn count_nodes(expr: &TLExpr) -> u64
Count the total number of nodes in an expression tree.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConstantPropagator
impl RefUnwindSafe for ConstantPropagator
impl Send for ConstantPropagator
impl Sync for ConstantPropagator
impl Unpin for ConstantPropagator
impl UnsafeUnpin for ConstantPropagator
impl UnwindSafe for ConstantPropagator
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