pub struct StrengthReductionPass { /* private fields */ }Expand description
The strength-reduction optimization pass.
Usage:
use oxilean_codegen::opt_strength::{StrengthReductionPass, StrengthConfig};
let mut pass = StrengthReductionPass::new(StrengthConfig::default());
// pass.run(&mut decls);Implementations§
Source§impl StrengthReductionPass
impl StrengthReductionPass
Sourcepub fn new(config: StrengthConfig) -> Self
pub fn new(config: StrengthConfig) -> Self
Create a new pass with the given configuration.
Sourcepub fn run(&mut self, decls: &mut [LcnfFunDecl])
pub fn run(&mut self, decls: &mut [LcnfFunDecl])
Run strength reduction on all function declarations.
Sourcepub fn reduce_expr(&mut self, expr: &LcnfExpr) -> LcnfExpr
pub fn reduce_expr(&mut self, expr: &LcnfExpr) -> LcnfExpr
Apply strength reduction to a single expression.
Sourcepub fn detect_induction_vars(
&self,
decl: &LcnfFunDecl,
) -> Vec<InductionVariable>
pub fn detect_induction_vars( &self, decl: &LcnfFunDecl, ) -> Vec<InductionVariable>
Detect induction variables in a function declaration.
A simple heuristic: look for parameters whose name contains “i”, “n”, “k”, or “idx”, and where the recursive tail call increments that parameter by a constant step.
Sourcepub fn reduce_iv_uses(
&mut self,
expr: &LcnfExpr,
iv: &InductionVariable,
) -> LcnfExpr
pub fn reduce_iv_uses( &mut self, expr: &LcnfExpr, iv: &InductionVariable, ) -> LcnfExpr
Apply operator strength reduction for a known induction variable.
Rewrites uses of a * iv + b within expr (where iv is the
induction variable’s LcnfVarId) into uses of a helper variable
that is updated by cheaper additions.
Sourcepub fn report(&self) -> StrengthReport
pub fn report(&self) -> StrengthReport
Return the accumulated report.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StrengthReductionPass
impl RefUnwindSafe for StrengthReductionPass
impl Send for StrengthReductionPass
impl Sync for StrengthReductionPass
impl Unpin for StrengthReductionPass
impl UnsafeUnpin for StrengthReductionPass
impl UnwindSafe for StrengthReductionPass
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