Skip to main content

Module constant_propagation

Module constant_propagation 

Source
Expand description

Constant propagation/folding pass.

Applies Sparse Conditional Constant Propagation to the given function. We use abstract interpretation to record known constant values for identifiers, with lack of a value indicating that the identifier does not have a known constant value.

Instructions which can be compile-time evaluated and whose operands are known constants are replaced with the resulting constant value.

This pass also exploits SSA form, tracking constant values of local variables. For example, in let x = 4; let y = x + 1 we know that x = 4 in the binary expression and can replace it with Constant 5.

This pass also visits conditionals (currently only IfTerminal) and can prune unreachable branches when the condition is a known truthy/falsey constant. The pass uses fixpoint iteration, looping until no additional updates can be performed.

Analogous to TS Optimization/ConstantPropagation.ts.

Functionsยง

constant_propagation