Applications
How Data Flows on CFG? How application-specific Data Flows through the Nodes (BB) and Edges (control flows) of CFG (a program)
- may analysis: over-approximation
- must analysis: under-approximation
- input and output statses
- Transfer Function
- forward analysis:
- backward analysis:
- Control Flow
- Key
- Domain, Direction, May/Must, Boundary, Initialization, Transfer function, Meet
Reaching Definitions Analysis
- definition of a variable: a statement that assigns to a value
- whether the a definition d is reachable at program point p
- usage
- detect possible undefined variables
Live Variables Analysis
- whether the value of variable v at program point p could be used along som path in CFG starting at p
- usage
- register allocations
Available Expressions Analysis
- whether an expression must be constant at a point
- x op y is available if
- all paths from the entry to p must pass through the evalution of x op y
- after the last evaluation of x op y, there is no redefinition of x or y
- must-analysis
Constant Propagation
- Given a variable at program point , determine whether is guaranteed to hold a constant value at
- nondistributivity
Lattice
- Partial Order: poset is binary relation that defines a partial ordering over , has the following properties:
- reflexity:
- antisymmetry:
- transtivity:
- upper bound :
- lower bound :
- least upper bound(lub or join) :
- two elements:
- greatest lower bound(glb or meet) :
- two elements:
- lub and glb is unique
- lattice:
- semilattice:
- only exists, is called a join semilattice
- only exists, is called a meet semilattice
- complete lattice:
- greatest element
- least element
- Every finite lattice is a complete lattice
- Product Lattice:
- A product lattice is a lattice
- if a product lattice is a product of complete lattices, then is also complete
- monotonicity:
- fixed-point theorem: if is monotonic and is finite, then the least fixed point of can be found by iterating until a fixed point is reached, greatest fixed point of can be found by iterating
- height of a lattice : the length of the longest path from Top to Bottom in the lattice
- distributed :
Foundation
-
Iterative Algorithm (IN/OUT equation system)
- Input: CFG (kill and gen computed for each basic block B)
- Output IN[B] and OUT[B] for each basic block B
- Algorithm
OUT[entry] = {}
for (each basic block B-entry)
OUT[B] = {}
while (changes to any OUT occur)
for (each basic block B-entry){
IN[B] = union_{P a predecessor of B} OUT[P]
OUT[B] = gen_B union (IN[B] - kill_B)
}
- CFG with nodes:
- fixed point
- Data Flow Analysis Framework
- : a direction of data flow
- : a lattice including domain of the values and a meet or join operator
- : a family of transfer functions from to
- Lattice height , number of nodes , at most iterations
- may analysis
- bottom : unsafe = no definitions can reach
- top : safe but useless result = all definitions may reach
- truth
- least fixed point
- must analysis
- top : unsafe - all expressions must be available
- bottom : safe but useless result - no expressions are availble
- greatest fixed point

- MOP(Meet Over all Paths):
- MOP Ours
- distributive then (Bit-vecotr or Gen/Kill problem)
- Worklist Algorithm: add successors of changed B to Worklist