Optimization: Collapse consecutive constant additions
This commit is contained in:
parent
37c809f5c0
commit
a2b68cc73e
8
opt.py
8
opt.py
|
@ -29,6 +29,12 @@ def eliminate_single_let(expr: Expression) -> Option[Expression]:
|
|||
case _:
|
||||
return None
|
||||
|
||||
def collapse_constant_additions(expr: Expression) -> Option[Expression]:
|
||||
match expr:
|
||||
case Application(Builtin(Builtin.BB_PLUS_CONST(x)), Application(Builtin(Builtin.BB_PLUS_CONST(y)), val)):
|
||||
return Some(Application(Builtin(Builtin.BB_PLUS_CONST(x+y)), val))
|
||||
return None
|
||||
|
||||
def apply_opts(optimizations: Collection[Optimization], expression: Expression) -> Tuple[Expression, int]:
|
||||
count: int
|
||||
optimized_expr: Expression
|
||||
|
@ -77,4 +83,4 @@ def optimize_to_fixpoint(optimizations: Collection[Optimization], expression: Ex
|
|||
return optimize_to_fixpoint(optimizations, optimized_expression)
|
||||
raise Exception('Unreachable')
|
||||
|
||||
all_optimizations: Sequence[Optimization] = (eliminate_single_let,)
|
||||
all_optimizations: Sequence[Optimization] = (eliminate_single_let, collapse_constant_additions)
|
Loading…
Reference in a new issue