lecture1
lecture1
Propagation
Control-Flow Graph
• A graph representation of intermediate code
• With nodes as basic- blocks and edges as the control-flow
• Flow Function: Abstracts the effect of a program construct to its effect on the corresponding lattice
elements.
• Termination: Finite lattice height combined with monotonicity of flow functions guarantee termination of
data-flow analysis algorithms
Constant Propagation: Example
• Aims at determining the variables that have constant values on all
executions of a program
1. a = 1;
•2. b = 4; 1. Is the value of ‘b’ constant at Line 8?
3. while (a > 0) {
4. if (a == 1) { 2. Is the value of ‘a’ constant at Line 4?
5. c = 9; 3. Is the value of ‘c’ constant at Line 11?
6. a = 4; 4. What is the output of the program?
7. } else {
8. c = b + 5;
9. a = a – b;
10. }
11. print c;
12. }
Uses of constant propagation
• Expressions can be evaluated at compile time (such expression in
loops save many evaluations at execution time)
• x ⊓ ⊤= x and x ⊓ ⊥ = ⊥, ∀x ∈ L
• c1 ⊓ c1 = c1 , c1 is a constant
• Output:
• in(B) for each B ∈ N
• out(B) for each B ∈ N
Flow Analysis
(Kildall’s
worklist-based Apply flow function
algorithm)
Propagate data-flow
facts to successors
Constant Propagation: Statements of Interest
Assignment Statements:
• y = c, y ∈ Var, c ∈ Const
• y = 5;
• y = input(), y ∈ Var
• scanf(“%d”,&y);
• y = z, y ∈ Var, z ∈ Var
• y = e, y ∈ Var, e ∈ Expr
• ‘y = z + 5;’, ‘y = z * w;’, ‘y = y/z;’ etc.
IDFA Specific to Constant Propagation
• Assumption: one basic block per statement and start with the entry node
• Data flow values are given by a map m: Var → Vals (from Lattice L)
Effect f4 ⇒ [u → ⊥, v → ⊥, w → ⊥]
cond
[u → 1, v → 2, w → 3] ⊓ [u → 2, v → 1, w → 3] =
[u → ⊥, v → ⊥, w → 3]