1
A Deeper Look at Data-flow Analysis Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at Rice University have explicit permission to make copies of these materials for their personal use. Faculty from other educational institutions may use these materials for nonprofit educational purposes, provided this copyright notice is preserved. Comp 512 Spring 2011

2
COMP 512, Rice University2 Data-flow Analysis Definition Data-flow analysis is a collection of techniques for compile-time reasoning about the run-time flow of values We use the results of DFA to prove safety & identify opportunities  Not an end unto itself Almost always involves building a graph  Control-flow graph, call graph, or derivatives thereof  Sparse evaluation graphs to model flow of values (efficiency) Usually formulated as a set of simultaneous equations  Sets attached to nodes and edges  Often use sets with a lattice or semilattice structure Desired result is usually meet over all paths solution  “What is true on every path from the entry?”  “Can this happen on any path from the entry?”

8
Data-flow Analysis The basics Data-flow sets are drawn from a semi-lattice, L, of facts Sets are modified by transfer functions, f i, that model effect of code on contents of the sets  Function space of all possible transfer functions is F Properties of L and F govern termination, correctness, & speed To reason about the properties of a ( proposed ) data-flow problem, we cast it into a lattice-theory framework and prove some simple theorems about the problem COMP 512, Rice University8

11
COMP 512, Rice University11 Data-flow Analysis How does this relate to data-flow analysis? Choose a semilattice to represent the facts Attach a meaning to each a  L Each a  L is a distinct set of known facts With each node n, associate a function f n : L  L f n models behavior of code in block corresponding to n Let F be the set of all functions that the code might generate Example — DOM Semilattice is (2 N,  ), where N is the set of nodes in the flow graph and  is , and  is Ø For a node n, f n has the form f n (x) = x World’s simplest data-flow equation

12
COMP 512, Rice University12 Data-flow Analysis How does this relate to data-flow analysis? Choose a semilattice to represent the facts Attach a meaning to each a  L Each a  L is a distinct set of known facts With each node n, associate a function f n : L  L f n models behavior of code in block corresponding to n Let F be the set of all functions that the code might generate Example — Live Semilattice is (2 Vars,  ), where Vars is the set of names in the code and  is ∪, and  is Vars For a node n, f n has the form f n (x) = a ∪ (x ∩ b), where a & b are constants ( UEVAR & VARKILL respectively ) A common form for a data-flow equation

17
COMP 512, Rice University17 Iterative Data-flow Analysis If a data-flow framework meets those admissibility conditions then it has a unique fixed-point solution The iterative algorithm finds the (best) answer The solution does not depend on order of computation Algorithm can choose an order that converges quickly Intuition Choose an order that propagates changes as far as possible on each “sweep”  Process a node’s predecessors before the node Cycles pose problems, of course  Ignore back edges when computing the order? *