Single Static Assignment CSE 401 Section 10/10 Jack Eggleston, Aaron Johnston & Nate Yazdani Adapted from Laura Vonesson’s Wi17 Slides
The Final Stretch You are here SUN MON TUE WED THU FRI SAT Report M501 Compiler Additions Additions M501 Eternal Mastery Review Report Final Exam Session of Compilers (8:30) (4:30 EEB 045) Evals!!
Problem 1 (review of dataflow)
Single Static Assignment An intermediate representation where each variable has only one definition: ● Original SSA Form a := x + y a 1 := x 1 + y 1 b := a - 1 b 1 := a 1 - 1 a := y + b a 2 := y 1 + b 1 b := x * 4 b 2 := x 1 * 4 a := a + b a 3 := a 2 + b 2
SSA: Why We Love It Without SSA, all definitions and uses of a variable get mixed together ● Computing information about the definitions of a variable is an expensive but necessary ○ part of many dataflow analyses
SSA: Why We Love It Without SSA, all definitions and uses of a variable get mixed together ● Computing information about the definitions of a variable is an expensive but necessary ○ part of many dataflow analyses Doing the work of converting to SSA once makes many analyses + optimizations more ● efficient SSA can be thought of as an implicit representation of Definition/Use chains ○
SSA: Why We Love It Ex: Dead Store Elimination ● Without SSA: Compute live variables at every point, which requires working backwards ○ and using the dataflow sets to check for any path that does not kill the variable, and eliminate any stores that are not to a live variable. With SSA: Eliminate any store where the variable being assigned has 0 uses. ○
Phi-Functions A method of representing an uncertain value for a certain definition ● Not a “real” instruction -- only a formality needed for SSA ○ Original SSA Form
Dominators A node X dominates a node Y iff every path from the entry point of the control flow ● graph to Y includes X 0 1 2 Node 1 dominates nodes 1 and 3. It does not dominate 4 because there is another path that reaches it. 3 4
Strict Dominance A node X strictly dominates a node Y if X dominates Y and X ≠ Y. ● 0 1 2 Node 1 only strictly dominates node 3 because it is the only dominated node that is not equal to 1. 3 4
Dominance Frontiers A node Y is in the dominance frontier of ● node X if X dominates an immediate 0 predecessor of Y but X does not strictly dominate Y . Node 4 is in the 1 2 dominance frontier of Essentially, the border between ● node 1 because an dominated and non-dominated nodes immediate predecessor (node 3) 3 Note: a node can be in its own dominance ○ is dominated by 1. frontier This is where phi function merging is ● 4 necessary
Problem 2
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 1 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 5 1 2 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 5 1 ∅ 2 5 3 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 5 1 ∅ 2 5 3 ∅ 5 2 3 4 4 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 5 1 ∅ 2 5 3 ∅ 5 2 3 4 ∅ 4 4, 5 5 5
NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 5 1 ∅ 2 5 3 ∅ 5 2 3 4 ∅ 4 4, 5 ∅ ∅ 5 5
Problem 3
a = c + 2 B 0 d = a + b b = a + c c = b - d B 1 B 2 e = c + a B 4 d = b + 1 d = b * 2 B 3 g = 2 * 2 i = i + 1 B 5 c = d >> 4 f = e + d B 6 d = c + b
a 1 = Φ(a 0 , a 2 ) Solution d 1 = Φ(d 0 , d 7 ) f 1 = Φ(f 0 , f 2 ) c 1 = Φ(c 0 , c 4 ) e 1 = Φ(e 0 , e 3 ) B b 1 = Φ(b 0 , b 3 ) i 1 = Φ(i 0 , i 3 ) 0 g 1 = Φ(g 0 , g 4 ) a 2 = c 1 + 2 d 2 = a 2 + b 1 B B b 2 = a 2 + c 1 c 2 = b 1 - d 2 e 2 = c 2 + a 2 1 2 B B d 3 = b 2 * 2 d 4 = b 2 + 1 g 2 = 2 * 2 3 4 B d 5 = Φ(d 3 , d 4 ) g 3 = Φ(g 1 , g 2 ) 5 i 2 = i 1 + 1 c 4 = Φ(c 2 , c 3 ) c 3 = d 5 >> 4 e 3 = Φ(e 1 , e 2 ) b 3 = Φ(b 1 , b 2 ) i 3 = Φ(i 1 , i 2 ) B d 6 = Φ(d 2 , d 5 ) g 4 = Φ(g 1 , g 3 ) 6 f 2 = e 3 + d 6 d 7 = c 4 + b 3
Step 1 : Compute Dominance Frontiers a = c + 2 B 0 d = a + b NODE STRICTLY DOMINATES DOMINANCE FRONTIER b = a + c c = b - d B 1 B 2 e = c + a 1, 2, 3, 0 0 4, 5, 6 B 4 1 d = b + 1 ∅ d = b * 2 6 B 3 g = 2 * 2 2 3, 4, 5 6 3 ∅ 5 i = i + 1 B 5 c = d >> 4 4 ∅ 5 5 ∅ 6 f = e + d B 6 d = c + b 6 ∅ 0
Step 2 : Determine Necessary Merges Need to merge: a,d,f Each node in the dominance frontier of node X will a = c + 2 B 0 d = a + b merge definitions created in node X NODE STRICTLY DOMINATES DOMINANCE FRONTIER b = a + c c = b - d B 1 B 2 e = c + a 1, 2, 3, 0 0 4, 5, 6 B 4 1 d = b + 1 ∅ d = b * 2 6 B 3 g = 2 * 2 2 3, 4, 5 6 Need to merge: 3 ∅ 5 i = i + 1 B 5 d,g c = d >> 4 4 ∅ 5 5 ∅ 6 f = e + d B 6 d = c + b Need to merge: 6 ∅ 0 c,e,b,i
Step 3 : Continue Computing Merges Need to merge: a,d,f, c,e,b,i Each merge will create a new definition, and that a = c + 2 B 0 d = a + b definition may need to be merged again -- continue until there are no changes NODE STRICTLY DOMINATES DOMINANCE FRONTIER b = a + c c = b - d B 1 B 2 e = c + a 1, 2, 3, 0 0 4, 5, 6 B 4 1 d = b + 1 ∅ d = b * 2 6 B 3 g = 2 * 2 2 3, 4, 5 6 Need to merge: 3 ∅ 5 i = i + 1 B 5 d,g c = d >> 4 4 ∅ 5 5 ∅ 6 f = e + d B 6 d = c + b Need to merge: 6 ∅ 0 c,e,b,i, d,g
Step 3 : Continue Computing Merges Need to merge: a,d,f,c,e,b,i, g Each merge will create a new definition, and that a = c + 2 B 0 d = a + b definition may need to be merged again -- continue until there are no changes NODE STRICTLY DOMINATES DOMINANCE FRONTIER b = a + c c = b - d B 1 B 2 e = c + a 1, 2, 3, 0 0 4, 5, 6 B 4 1 d = b + 1 ∅ d = b * 2 6 B 3 g = 2 * 2 2 3, 4, 5 6 Need to merge: 3 ∅ 5 i = i + 1 B 5 d,g c = d >> 4 4 ∅ 5 5 ∅ 6 f = e + d B 6 d = c + b Need to merge: 6 ∅ 0 c,e,b,i,d,g
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. a 1 = Φ(a 0 , a 2 ) d 1 = Φ(d 0 , d 7 ) f 1 = Φ(f 0 , f 2 ) c 1 = Φ(c 0 , c 4 ) a = c + 2 e 1 = Φ(e 0 , e 3 ) B 0 B 0 d = a + b b 1 = Φ(b 0 , b 3 ) i 1 = Φ(i 0 , i 3 ) Need to merge: g 1 = Φ(g 0 , g 4 ) a,d,f,c,e,b,i,g a 2 = c 1 + 2 d 2 = a 2 + b 1
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. c = b - d c 2 = b 1 - d 2 B 1 B 1 e = c + a e 2 = c 2 + a 2 Nothing to merge
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. b = a + c b 2 = a 2 + c 1 B 2 B 2 Nothing to merge
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. d = b * 2 d 3 = b 2 * 2 B 3 B 3 g = 2 * 2 g 2 = 2 * 2 Nothing to merge
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. d = b + 1 d 4 = b 2 + 1 B 4 B 4 Nothing to merge
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. d 5 = Φ(d 3 , d 4 ) g 3 = Φ(g 1 , g 2 ) i 2 = i 1 + 1 i = i + 1 B 5 B 5 c 3 = d 5 >> 4 c = d >> 4 Need to merge: d,g
Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. c 4 = Φ(c 2 , c 3 ) e 3 = Φ(e 1 , e 2 ) b 3 = Φ(b 1 , b 2 ) i 3 = Φ(i 1 , i 2 ) f = e + d B 6 B 6 d 6 = Φ(d 2 , d 5 ) d = c + b g 4 = Φ(g 1 , g 3 ) f 2 = e 3 + d 6 Need to merge: d 7 = c 4 + b 3 c,e,b,i,d,g
Thanks for a Great Quarter! - The 401 18au Staff :)
Recommend
More recommend