partial redundancy elimination
play

Partial Redundancy Elimination CS243 Review Session Full - PowerPoint PPT Presentation

Partial Redundancy Elimination CS243 Review Session Full Redundancy x = b + c y = b + c z = b + c Partial Redundancy x = b + c z = b + c Partial Redundancy t = b + c x = t t = b + c z = t B1 B2 B3 u = a + b B4 Original graph B5


  1. Partial Redundancy Elimination CS243 Review Session

  2. Full Redundancy x = b + c y = b + c z = b + c

  3. Partial Redundancy x = b + c z = b + c

  4. Partial Redundancy t = b + c x = t t = b + c z = t

  5. B1 B2 B3 u = a + b B4 Original graph B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  6. B1 B3 B2 u = a + b B4 Add blocks on critical edges B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  7. B1 B3 B2 u = a + b B4 B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  8. B1 B3 B2 u = a + b B4 Anticipated expressions: places where it is safe to place B5 B6 v = a + b a + b B7 B8 w = a + b B9 B10 b = read() B11

  9. B1 B3 B2 u = a + b B4 Can delete added blocks where a + b is not anticipated B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  10. B1 B3 B2 u = a + b B4 Available expressions: points where a + b could be made B5 B6 available v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  11. B1 B3 B2 u = a + b B4 Earliest: when can we earliest compute a + b B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  12. B1 B2 B3 u = a + b B4 Earliest: when can we earliest compute a + b B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  13. B1 B2 B3 u = a + b B4 How much can we postpone evaluating a + b ? B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  14. B1 B2 B3 u = a + b B4 Latest: need to compute a + b here B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  15. B1 B2 B3 u = a + b B4 Latest: need to compute a + b here B5 B6 v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  16. B1 B2 B3 u = a + b B4 Remove added blocks where we are not going to compute B5 B6 anything v = a + b B7 B8 w = a + b B9 B10 b = read() B11

  17. B1 t = a + b B2 B3 u = t B4 Use a temporary variable to store the result B5 B6 t = a + b v = t t = a + b B7 B8 w = t B9 B10 b = read() t = a + b B11

  18. B1 t = a + b B2 B3 u = t B4 B5 B6 t = a + b v = t t = a + b B7 B8 w = t B9 B10 b = read() t = a + b B11

  19. B1 t = a + b B2 B3 u = t B4 Result not used beyond the block in which the variable is B5 B6 t = a + b defined v = t t = a + b B7 B8 w = t B9 B10 b = read() t = a + b B11

  20. B1 t = a + b B2 B3 u = t B4 Clean up unrequired temporaries B5 B6 v = a + b t = a + b B7 B8 w = t B9 B10 b = read() t = a + b B11

  21. B1 t = a + b B2 B3 u = t B4 B5 B6 v = a + b t = a + b B7 B8 w = t B9 B10 b = read() t = a + b B11

  22. More Examples

  23. B0 B0 i = 0 i = 0 B1 B1 t = b + c a = b + c a = t i = i + 1 B2 i = i + 1 B2 i < 1000 i < 1000 z = b + c B3 z = t B3

  24. B0 B0 B1 i = 0 i = 0 B1 t = b + c a = b + c a = t i = i + 1 B2 i = i + 1 B2 i < 1000 i < 1000 z = b + c B3 z = t B3

  25. B1 B1 B2 B2 c = 2 c = 2 t = b + c B5 B5 a = b + c a = t B3 B3 B6 B6 B4 B4 t = b + c B7 B7 d = b + c d = t B8 B8 B9 B9 e = b + c e = t B10 B10 B11 B11

  26. B1 B1 B2 c = 2 t = b + c B2 B4 B4 c = 2 a = b + c a = t B3 B5 B5 B3 t = b + c B6 B6 d = b + c d = t B7 B7 B8 B8 e = b + c e = t B9 B9 B10 B10

  27. Dominators CS243 Review Session

  28. Example Draw the dominator tree for this control flow graph.

  29. Example IN = RED OUT = BLACK {M} {M} {M} {M,B} {M,C} {M} {M,C} {M,C} {M} {M,D} {M,C,F} {M,A} {M,C,G} {M} {M,D} {M} {M,C,G} {M,E} {M} {M,D,L} {M} {M,I} {M,C,G,J} {M,K} {M,H} Draw the dominator tree for this control flow graph.

  30. Example Dominator Tree IN = RED OUT = BLACK {M} {M} {M} {M,B} {M,C} {M} {M,C} {M,C} {M} {M,D} {M,C,F} {M,A} {M,C,G} {M} {M,D} {M} {M,C,G} {M} {M,E} {M,D,L} {M} {M,I} {M,C,G,J} {M,K} {M,H} Draw the dominator tree for this control flow graph.

  31. Example Dominator Tree Aside: there are algorithms for constructing the dominator tree directly ● Tarjan’s algorithm (based on DFS) ● Buchsbaum’s algorithm

  32. Example Dominator Tree IN = RED OUT = BLACK {M} {M} {M} {M,B} {M,C} {M} {M,C} {M,C} {M} {M,D} {M,C,F} {M,A} {M,C,G} {M} {M,D} {M} {M,C,G} {M} {M,E} {M,D,L} {M} {M,I} {M,C,G,J} {M,K} {M,H} Find the back edges and natural loops in this graph.

  33. Example IN = RED Dominator Tree OUT = BLACK BACK EDGE = ORANGE {M} {M} {M} {M,B} {M,C} {M} {M,C} {M,C} {M} {M,D} {M,C,F} {M,A} {M,C,G} {M} {M,D} {M} {M,C,G} {M} {M,E} {M,D,L} {M} {M,I} {M,C,G,J} {M,K} {M,H} Find the back edges and natural loops in this graph.

  34. Example IN = RED Dominator Tree OUT = BLACK BACK EDGE = ORANGE {M} {M} {M} {M,B} {M,C} {M} {M,C} {M,C} {M} {M,D} {M,C,F} {M,A} {M,C,G} {M} {M,D} {M} {M,C,G} {M} {M,E} {M,D,L} {M} {M,I} {M,C,G,J} {M,K} {M,H} Find the back edges and natural loops in this graph. Natural loop for back edge K → M: all nodes * All nodes can reach K without passing through M

  35. Post-dominators How would we compute the post-dominators for this graph?

  36. Definitions A block B dominates block B’ if every path from the entry to B’ goes through B A block B postdominates block B’ if every path from B’ to the exit of the graph goes through B If B dominates B’ and B’ postdominates B, B and B’ are control equivalent * One is executed when and only when the other is

  37. Example if (a == 0) goto L B1 c = b B2 e = d + d L: B3

  38. Example if (a == 0) goto L B1 c = b B2 e = d + d L: B3 1. B1 and B3 are control equivalent. 2. B1 dominates B2, but B2 does not postdominate B1. 3. B2 does not dominate, B3 but B3 posdominates B2.

  39. Code Motion If two blocks are control-equivalent, you may move instructions between the two (upward/downward code motion) assuming there are no conflicting data dependences More to come next week: instruction scheduling lecture

  40. SSA Construction of the static single assignment form (SSA) requires dominance frontier information. The dominance frontier of a node d is the set of all nodes n such that d dominates an immediate predecessor of n , but d does not strictly dominate n . More to come in Homework 3: converting to SSA form

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