1 / 11

CS 201 Compiler Construction

CS 201 Compiler 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.

chaman
Télécharger la présentation

CS 201 Compiler Construction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 201Compiler Construction Lecture 6 Code Optimizations: Constant Propagation & Folding

  2. 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.

  3. Constant Propagation & Folding • Evaluation of branch • outcomes may be • enabled. • 2. Can take advantage • of non-executable • paths.

  4. Data Flow Analysis Constant Prop. Lattice for a Single variable.

  5. Contd.. Meet Operator for a Single variable.

  6. Contd.. Lattice for all variables (L,∧‘) VAR – set of variables VAL – set of values (all constants, Τ, ) L = {β: β is a total function β: VARVAL} i.e., set of all states of variables. forall v ε VAR β1 ∧’ β2(v) = β1 (v) ∧ β2 (v)

  7. Contd.. Transfer Function S: A = B op C fS(β) – transfer function of S. fS(β) =

  8. Example

  9. 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

  10. Algorithm: Initialization

  11. Algorithm: Analysis

More Related