110 likes | 253 Views
This lecture covers essential code optimization techniques focusing on constant propagation and folding. Constant propagation involves substituting variables with constant values, enhancing performance. It also includes evaluating expressions when all operands are constants, and analyzing branch outcomes to utilize non-executable paths. The concept of Data Flow Analysis is introduced, depicting the lattice structure for variables and values. The example worklist algorithm highlights the importance of maintaining lattice values at node entry and exit, optimizing information propagation along executable paths.
E N D
CS 201Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding
Constant Propagation & Folding 1. Use of var replaced by a constant value - propagation. 2. Exp. is evaluated or folded if all of its operands are constants.
Constant Propagation & Folding • Evaluation of branch • outcomes may be • enabled. • 2. Can take advantage • of non-executable • paths.
Data Flow Analysis Constant Prop. Lattice for a Single variable.
Contd.. Meet Operator for a Single variable.
Contd.. Lattice for all variables (L,∧‘) VAR – set of variables VAL – set of values (all constants, Τ, ) L = {β: β is a total function β: VARVAL} i.e., set of all states of variables. forall v ε VAR β1 ∧’ β2(v) = β1 (v) ∧ β2 (v)
Contd.. Transfer Function S: A = B op C fS(β) – transfer function of S. fS(β) =
Worklist Algorithm • Each node is a single statement • IN and OUT contain the lattice values at node entry and exit • Algorithm will take advantage of resolved branches. How ? • Mark edges as executable or non-executable and propagate information only along executable edges • Branch (true) (false) (true or false) – mark edges executable accordingly