single static assignment
play

Single Static Assignment CSE 401 Section 10/10 Aaron Johnston & - PowerPoint PPT Presentation

Single Static Assignment CSE 401 Section 10/10 Aaron Johnston & Nate Yazdani Adapted from Laura Vonessons Wi17 Slides The Final Stretch You are here SUN MON TUE WED THU FRI SAT Report M501 Compiler Additions Additions M501


  1. Single Static Assignment CSE 401 Section 10/10 Aaron Johnston & Nate Yazdani Adapted from Laura Vonesson’s Wi17 Slides

  2. 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!!

  3. Problem 1 (review of dataflow)

  4. Single Static Assignment An intermediate representation where each variable has only one definition: ● Original SSA Form

  5. 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 ○

  6. 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. ○

  7. 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

  8. 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

  9. 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

  10. 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

  11. Problem 2

  12. NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1 1 2 3 2 3 4 4 5 5

  13. NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1 1 2 3 2 3 4 4 5 5

  14. NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 1 1 2 3 2 3 4 4 5 5

  15. NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 1 2 3 2 3 4 4 5 5

  16. NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 1 2 3 2 3 4 4 5 5

  17. NODE STRICTLY DOMINATES DOMINANCE FRONTIER 0 0 1, 2, 3, 4, 5 ∅ 1 2, 3 1 2 3 2 3 4 4 5 5

  18. 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

  19. 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

  20. 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

  21. 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

  22. 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

  23. Problem 3

  24. 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

  25. 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

  26. 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

  27. 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

  28. 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

  29. 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

  30. 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

  31. Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. c 2 = b 1 - d 2 c = b - d B 1 B 1 e 2 = c 2 + e = c + a a 2 Nothing to merge

  32. Step 4 : Write SSA Definitions Merges go first, and each successive definition of a variable should increment its index by 1. b 2 = a 2 + B 2 B 2 b = a + c c 1 Nothing to merge

  33. 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

  34. 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

  35. 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

  36. 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

  37. Thanks for a Great Quarter! - The 401 18sp Staff :)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend