Expand description
Dead code elimination optimization pass.
This module provides optimizations that remove unreachable or redundant code from TLExpr expressions. Examples include:
if true then A else B→Aif false then A else B→BAND(false, x)→false(short-circuit)OR(true, x)→true(short-circuit)EXISTS x. constant→constant(if x is not free in constant)- Remove unused subexpressions that don’t affect the result
§Examples
use tensorlogic_compiler::optimize::eliminate_dead_code;
use tensorlogic_ir::{TLExpr, Term};
// if true then A else B → A
let a = TLExpr::pred("a", vec![Term::var("i")]);
let b = TLExpr::pred("b", vec![Term::var("i")]);
let expr = TLExpr::IfThenElse {
condition: Box::new(TLExpr::Constant(1.0)),
then_branch: Box::new(a.clone()),
else_branch: Box::new(b),
};
let (optimized, stats) = eliminate_dead_code(&expr);
assert!(stats.branches_eliminated > 0);Structs§
- Dead
Code Stats - Statistics from dead code elimination.
Functions§
- eliminate_
dead_ code - Apply dead code elimination to an expression.