data flow analysis (contd…)
TRANSCRIPT
![Page 1: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/1.jpg)
Program Analysis https://www.cse.iitb.ac.in/~karkare/cs618/
Amey Karkare Dept of Computer Science and Engg
IIT Kanpur Visiting IIT Bombay
[email protected] [email protected]
Data Flow Analysis (contd…)
![Page 2: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/2.jpg)
Available Expressions
2
![Page 3: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/3.jpg)
Available Expressions
• Expression e is available at a point p:
2
![Page 4: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/4.jpg)
Available Expressions
• Expression e is available at a point p: – Every path from entry to p has at least one
evaluation of e
2
![Page 5: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/5.jpg)
Available Expressions
• Expression e is available at a point p: – Every path from entry to p has at least one
evaluation of e – There is no assignment to any component
variable of e after last evaluation of e prior to p
2
![Page 6: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/6.jpg)
Available Expressions
• Expression e is available at a point p: – Every path from entry to p has at least one
evaluation of e – There is no assignment to any component
variable of e after last evaluation of e prior to p
• Expression e is generated by its evaluation
2
![Page 7: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/7.jpg)
Available Expressions
• Expression e is available at a point p: – Every path from entry to p has at least one
evaluation of e – There is no assignment to any component
variable of e after last evaluation of e prior to p
• Expression e is generated by its evaluation • Expression e is killed by assignment to its
component variables 2
![Page 8: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/8.jpg)
Available Expr Analysis
3
d: x = y+z s1
![Page 9: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/9.jpg)
Available Expr Analysis
gen(s1) = {y+z}
3
d: x = y+z s1
![Page 10: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/10.jpg)
Available Expr Analysis
gen(s1) = {y+z}
kill(s1) = Ex // Ex : set of all expressions having x as a component
3
d: x = y+z s1
![Page 11: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/11.jpg)
Available Expr Analysis
gen(s1) = {y+z}
kill(s1) = Ex // Ex : set of all expressions having x as a component
out(s1) = in(s1) - kill(s1) U gen(s1)
3
d: x = y+z s1
![Page 12: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/12.jpg)
Available Expr Analysis
gen(s1) = {y+z}
kill(s1) = Ex // Ex : set of all expressions having x as a component
out(s1) = in(s1) - kill(s1) U gen(s1) THIS MAY NOT WORK IN GENERAL! WHY?
3
d: x = y+z s1
![Page 13: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/13.jpg)
Available Expr Analysis
4
d: x = x+z s1
![Page 14: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/14.jpg)
Available Expr Analysis
INCORRECT FORMULATION
4
d: x = x+z s1
![Page 15: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/15.jpg)
Available Expr Analysis
INCORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1)
4
d: x = x+z s1
![Page 16: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/16.jpg)
Available Expr Analysis
INCORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1) gen(s1) = {x+z}
4
d: x = x+z s1
![Page 17: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/17.jpg)
Available Expr Analysis
INCORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1) gen(s1) = {x+z}
kill(s1) = Ex // Ex : set of all expressions having x as a component
4
d: x = x+z s1
![Page 18: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/18.jpg)
Available Expr Analysis
INCORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1) gen(s1) = {x+z} kill(s1) = Ex // Ex : set of all expressions having x as
a component
5
d: x = x+z s1
![Page 19: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/19.jpg)
Available Expr Analysis
6
lhs = rhs s1
![Page 20: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/20.jpg)
Available Expr Analysis
CORRECT FORMULATION
6
lhs = rhs s1
![Page 21: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/21.jpg)
Available Expr Analysis
CORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1)
6
lhs = rhs s1
![Page 22: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/22.jpg)
Available Expr Analysis
CORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1) gen(s1) = { rhs | lhs is not part of rhs }
6
lhs = rhs s1
![Page 23: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/23.jpg)
Available Expr Analysis
CORRECT FORMULATION out(s1) = in(s1) - kill(s1) U gen(s1) gen(s1) = { rhs | lhs is not part of rhs }
kill(s1) = Elhs // Elhs : set of all expressions having lhs as a component
6
lhs = rhs s1
![Page 24: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/24.jpg)
Available Expr Analysis
7
S S1
S2
![Page 25: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/25.jpg)
Available Expr Analysis
gen(s) = gen(s2) U (gen(s1) – kill(s2))
7
S S1
S2
![Page 26: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/26.jpg)
Available Expr Analysis
gen(s) = gen(s2) U (gen(s1) – kill(s2)) kill(s) = kill(s2) U (kill(s1) – gen(s2))
7
S S1
S2
![Page 27: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/27.jpg)
Available Expr Analysis
gen(s) = gen(s2) U (gen(s1) – kill(s2)) kill(s) = kill(s2) U (kill(s1) – gen(s2))
in(s1) = in(s)
7
S S1
S2
![Page 28: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/28.jpg)
Available Expr Analysis
gen(s) = gen(s2) U (gen(s1) – kill(s2)) kill(s) = kill(s2) U (kill(s1) – gen(s2))
in(s1) = in(s) in(s2) = out(s1)
7
S S1
S2
![Page 29: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/29.jpg)
Available Expr Analysis
gen(s) = gen(s2) U (gen(s1) – kill(s2)) kill(s) = kill(s2) U (kill(s1) – gen(s2))
in(s1) = in(s) in(s2) = out(s1) out(s) = out(s2)
7
S S1
S2
![Page 30: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/30.jpg)
S
Analysis of Structured Programs
8
S1 S2
![Page 31: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/31.jpg)
S
Analysis of Structured Programs
gen(s) = gen(s1) ∩ gen(s2)
8
S1 S2
![Page 32: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/32.jpg)
S
Analysis of Structured Programs
gen(s) = gen(s1) ∩ gen(s2) kill(s) = kill(s1) U kill(s2)
8
S1 S2
![Page 33: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/33.jpg)
S
Analysis of Structured Programs
gen(s) = gen(s1) ∩ gen(s2) kill(s) = kill(s1) U kill(s2)
in(s1) = in(s2) = in(s)
8
S1 S2
![Page 34: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/34.jpg)
S
Analysis of Structured Programs
gen(s) = gen(s1) ∩ gen(s2) kill(s) = kill(s1) U kill(s2)
in(s1) = in(s2) = in(s) out(s) = out(s1) ∩ out(s2)
8
S1 S2
![Page 35: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/35.jpg)
S
Available Expr Analysis
9
S1
![Page 36: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/36.jpg)
S
Available Expr Analysis
gen(s) = gen(s1)
9
S1
![Page 37: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/37.jpg)
S
Available Expr Analysis
gen(s) = gen(s1) kill(s) = kill(s1)
9
S1
![Page 38: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/38.jpg)
S
Available Expr Analysis
gen(s) = gen(s1) kill(s) = kill(s1)
in(s1) = in(s) ∩ gen(s1)
9
S1
![Page 39: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/39.jpg)
S
Available Expr Analysis
gen(s) = gen(s1) kill(s) = kill(s1)
in(s1) = in(s) ∩ gen(s1)
9
S1
z = x*y; do {} while(…); // is x*y available // here?
![Page 40: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/40.jpg)
S
Available Expr Analysis
gen(s) = gen(s1) kill(s) = kill(s1)
in(s1) = in(s) ∩ gen(s1)
9
S1
gen out(s1)
z = x*y; do {} while(…); // is x*y available // here?
![Page 41: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/41.jpg)
S
Available Expr Analysis
gen(s) = gen(s1) kill(s) = kill(s1)
in(s1) = in(s) ∩ gen(s1) out(s) = out(s1)
9
S1
gen out(s1)
z = x*y; do {} while(…); // is x*y available // here?
![Page 42: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/42.jpg)
S
Again: Conservative Analysis
10
S1 S2
![Page 43: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/43.jpg)
S
Again: Conservative Analysis
• Assumption: All paths are feasible.
10
S1 S2
![Page 44: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/44.jpg)
S
Again: Conservative Analysis
• Assumption: All paths are feasible. – Consider: if (true) s1; else s2 – s2 is never executed
10
S1 S2
![Page 45: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/45.jpg)
S
Again: Conservative Analysis
• Assumption: All paths are feasible. – Consider: if (true) s1; else s2 – s2 is never executed gen(s) = gen(s1) ⊇ gen(s1) ∩ gen(s2) kill(s) = kill(s1) ⊆ kill(s1) ∪ kill(s2)
10
S1 S2
![Page 46: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/46.jpg)
S
Again: Conservative Analysis
• Thus: true gen (s) ⊇ analysis gen(s) true kill (s) ⊆ analysis kill(s)
• True is what is computed at run time • This is SAFE estimate
– prevents optimization – but no wrong optimization 11
S1 S2
![Page 47: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/47.jpg)
Available Expressions
12
![Page 48: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/48.jpg)
Available Expressions
• Expr e is available at the start of a block
12
![Page 49: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/49.jpg)
Available Expressions
• Expr e is available at the start of a block –It is available at the end of all
predecessors
12
![Page 50: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/50.jpg)
Available Expressions
• Expr e is available at the start of a block –It is available at the end of all
predecessors
in(B) = ∩ P is pred of B out(P)
12
![Page 51: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/51.jpg)
Available Expressions
• Expr e is available at the start of a block –It is available at the end of all
predecessors
in(B) = ∩ P is pred of B out(P) • Expr e is available at the end of a block
– either it is generated by the block – or it is available at the start of the block and
not killed by the block
out(B) = in(B) –kill(B) ∪ gen(B) 12
![Page 52: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/52.jpg)
Available Expressions
• Kill & gen known for each block.
13
![Page 53: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/53.jpg)
Available Expressions
• Kill & gen known for each block. • A program with N blocks has 2N
equations with 2N unknowns –solution is possible. – iterative approach (on next slide)
13
![Page 54: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/54.jpg)
14
![Page 55: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/55.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs }
14
![Page 56: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/56.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs } out(Entry) = ϕ; // remember reaching defs?
14
![Page 57: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/57.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs } out(Entry) = ϕ; // remember reaching defs? change = true; while (change) { }
14
![Page 58: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/58.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs } out(Entry) = ϕ; // remember reaching defs? change = true; while (change) { change = false; }
14
![Page 59: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/59.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs } out(Entry) = ϕ; // remember reaching defs? change = true; while (change) { change = false; for each block B other than Entry { } }
14
![Page 60: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/60.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs } out(Entry) = ϕ; // remember reaching defs? change = true; while (change) { change = false; for each block B other than Entry { in(B) = ∩P is pred of B out(P); oldOut = out(B); out(B) = in(B) - kill(B) ∪ gen(B); } }
14
![Page 61: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/61.jpg)
for each block B { out(B) = U; // U = “universal” set of all exprs } out(Entry) = ϕ; // remember reaching defs? change = true; while (change) { change = false; for each block B other than Entry { in(B) = ∩P is pred of B out(P); oldOut = out(B); out(B) = in(B) - kill(B) ∪ gen(B); if (oldOut != out(B)) then { change = true; } } }
14
![Page 62: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/62.jpg)
Some Issues
• What is the set of all expressions? • How to compute it efficiently? • Why Entry block is initialized differently?
15
![Page 63: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/63.jpg)
Available Expressions
16
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
B1
B2
B3
B4
U = {a*b, c+d} We are not interested in other expressions/variables
![Page 64: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/64.jpg)
Available Expressions
16
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
B1
B2
B3
B4
BLOCK GEN KILL
B1 {a*b, c+d} {}
B2 {c+d} {a*b}
B3 {a*b} {}
B4 {a*b} {c+d}
U = {a*b, c+d} We are not interested in other expressions/variables
![Page 65: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/65.jpg)
Available Expressions
17
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 66: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/66.jpg)
B1 B2 B3 B4
init In
Out
pass1 In
Out
pass2 In
Out
pass3 In
Out
Available Expressions
17
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 67: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/67.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In
Out
pass2 In
Out
pass3 In
Out
Available Expressions
18
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 68: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/68.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In ϕ
Out {a*b,c+d}
pass2 In
Out
pass3 In
Out
Available Expressions
19
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 69: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/69.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In ϕ
{a*b,c+d}
Out {a*b,c+d} {c+d}
pass2 In
Out
pass3 In
Out
Available Expressions
20
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 70: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/70.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In ϕ
{a*b,c+d}
{c+d}
Out {a*b,c+d} {c+d}
{a*b, c+d}
pass2 In
Out
pass3 In
Out
Available Expressions
21
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 71: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/71.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In ϕ
{a*b,c+d}
{c+d} {c+d}
Out {a*b,c+d} {c+d}
{a*b, c+d}
{a*b}
pass2 In
Out
pass3 In
Out
Available Expressions
22
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 72: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/72.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In ϕ
{a*b,c+d}
{c+d} {c+d}
Out {a*b,c+d} {c+d}
{a*b, c+d}
{a*b}
pass2 In ϕ {a*b} {c+d} {c+d}
Out {a*b,c+d} {c+d} {a*b, c+d}
{a*b}
pass3 In
Out
Available Expressions
23
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 73: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/73.jpg)
B1 B2 B3 B4
init In - - - -
Out U U U U
pass1 In ϕ
{a*b,c+d}
{c+d} {c+d}
Out {a*b,c+d} {c+d}
{a*b, c+d}
{a*b}
pass2 In ϕ {a*b} {c+d} {c+d}
Out {a*b,c+d} {c+d} {a*b, c+d}
{a*b}
pass3 In ϕ {a*b} {c+d} {c+d}
Out {a*b,c+d} {c+d} {a*b, c+d}
{a*b}
Available Expressions
24
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 74: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/74.jpg)
B1 B2 B3 B4
init In - - - -
Out 11 11 11 11
pass1 In 00
11 01 01
Out 11 01 11 10
pass2 In 00 10 01 01
Out 11 01 11 10
pass3 In 00 10 01 01
Out 11 01 11 10
Available Expressions: Bitvectors
25
a*b c+d bits for each expression
B1
B2
B3
B4
ENTRY
…= a*b …= c+d
… = c+d a = a*b
… = a*b
c = a*b
EXIT
![Page 75: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/75.jpg)
Available Expressions: Bitvectors
in(B) = ∩ P is pred of B out(P) out(B) = in(B) –kill(B) ∪ gen(B)
• With bit vectors, in(B) = ∧ P is pred of B out(P)
out(B) = (in(B) ∧ ¬kill(B)) ∨ gen(B) • Bitwise ∧, ∨, ¬ operations.
![Page 76: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/76.jpg)
Available Expressions: Application
27
![Page 77: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/77.jpg)
Available Expressions: Application
• Common subexpression elimination in a block B – Expression e available at the entry of B – e is also computed at a point p in B – Components of e are not modified from entry
of B to p
27
![Page 78: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/78.jpg)
Available Expressions: Application
• Common subexpression elimination in a block B – Expression e available at the entry of B – e is also computed at a point p in B – Components of e are not modified from entry
of B to p
• e is “upward exposed” in B
27
![Page 79: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/79.jpg)
Available Expressions: Application
• Common subexpression elimination in a block B – Expression e available at the entry of B – e is also computed at a point p in B – Components of e are not modified from entry
of B to p
• e is “upward exposed” in B • Expressions generated in B are “downward
exposed”
27
![Page 80: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/80.jpg)
Recap: Summary of Reaching Definitions
gen = { dx | dx in B defines variable x and is not followed by another definition of x in B} kill = { dx | block contains some definition of x } in(B) = ∪P is pred of B out(P) out(B) = in(B) –kill(B) ∪ gen(B) meet ( Λ ) operator is ∪ Initialization: out(Bentry) = Entry Info = ϕ out(B) = ϕ
28
![Page 81: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/81.jpg)
Summary of Available Expressions
gen = downward exposed expressions kill = { ex | block contains some definition of x } in(B) = ∩ P is pred of B out(P) out(B) = in(B) –kill(B) ∪ gen(B) meet ( Λ ) operator is ∩ Initialization: out(Bentry) = Entry Info = ϕ out(B) = U
29
![Page 82: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/82.jpg)
Comparing Reaching Definition and Available Expressions Analysis
• Class Discussion about –Similarities –Differences
30
![Page 83: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/83.jpg)
Summary of Available Expressions
31
![Page 84: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/84.jpg)
Summary of Available Expressions
• What if we Initialize: out(Bentry) = Entry Info = ϕ out(B) = ϕ
31
![Page 85: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/85.jpg)
Summary of Available Expressions
• What if we Initialize: out(Bentry) = Entry Info = ϕ out(B) = ϕ
• We might miss some expressions that are available
31
![Page 86: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/86.jpg)
Summary of Available Expressions
• What if we Initialize: out(Bentry) = Entry Info = ϕ out(B) = ϕ
• We might miss some expressions that are available
• Loose on opportunity to optimize!
31
![Page 87: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/87.jpg)
32
What are the expressions available at B2 when out(B) initialized with i) U ii) ϕ
ENTRY
…= a*b …= c+d
…= a*b …= c+d
B1
B2
![Page 88: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/88.jpg)
Live Variable Analysis
• A variable x is live at a point p if –There is a point p’ along some path in
the flow graph starting at p to the EXIT –Value of x could be used at p’ –There is no definition of x between p
and p’ along this path • Otherwise x is dead at p
33
![Page 89: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/89.jpg)
Live Variable Analysis: Gen
• gen(B) • Set of variables whose values may
be used in B prior to any definition • Also called “use(B)” • “upward exposed” use of a
variable is generated by B
![Page 90: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/90.jpg)
Live Variable Analysis: Kill
• kill(B) • Set of variables defined in B prior
to any use • Also called “def(B)” • “upward exposed” definition of a
variable kills its liveness in B
![Page 91: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/91.jpg)
Live Variable Analysis
out(B) = ∪ S is succ of B in(S) in(B) = out(B) –kill(B) ∪ gen(B)
Alt: in(B) = out(B) – def(B) ∪ use(B) • With bit vectors,
out(B) = ∨ S is succ of B in(S) in(B) = (out(B) ∧ ¬kill(B)) ∨ gen(B)
• Bitwise ∧, ∨, ¬ operations.
![Page 92: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/92.jpg)
Very Busy Expressions
37
![Page 93: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/93.jpg)
Very Busy Expressions
• Expression e is very busy at a point p
37
![Page 94: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/94.jpg)
Very Busy Expressions
• Expression e is very busy at a point p –Every path from p to exit has at least
one evaluation of e
37
![Page 95: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/95.jpg)
Very Busy Expressions
• Expression e is very busy at a point p –Every path from p to exit has at least
one evaluation of e –There is no assignment to any
component variable of e before first evaluation of e following p
37
![Page 96: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/96.jpg)
Very Busy Expressions
• Expression e is very busy at a point p –Every path from p to exit has at least
one evaluation of e –There is no assignment to any
component variable of e before first evaluation of e following p
• Also called Anticipable expression
37
![Page 97: Data Flow Analysis (contd…)](https://reader030.vdocuments.us/reader030/viewer/2022012423/6178115a0fdba2616e69ed93/html5/thumbnails/97.jpg)
Very Busy Expression
• Practice Assignment –Set the data flow equations for
Very Busy Expression –Hint: Available Expression
Analysis