1 / 55

Borrowed from J. N. Amaral, slightly modified cs.ualberta/~amaral/courses/680

LIVE-IN: k j. g. g := mem[j+12]. h. h := k -1. f. f := g + h. e. e := mem[j+8]. m. m := mem[j+16]. b. b := mem[f]. c. c := e + 8. d. d := c. k := m + 4. j := b. LIVE-OUT: d k j.

shania
Télécharger la présentation

Borrowed from J. N. Amaral, slightly modified cs.ualberta/~amaral/courses/680

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LIVE-IN: k j g g := mem[j+12] h h := k -1 f f := g + h e e := mem[j+8] m m := mem[j+16] b b := mem[f] c c := e + 8 d d := c k := m + 4 j := b LIVE-OUT: d k j Borrowed from J. N. Amaral, slightly modified http://www.cs.ualberta.ca/~amaral/courses/680 k j k j CMPUT 680 - Compiler Design and Optimization

  2. Example:Simplify (K=4) stack f (h,no-spill) e j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  3. Example:Simplify (K=4) stack f (g, no-spill) (h, no-spill) e j k b m d c g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  4. Example:Simplify (K=4) stack f (k, no-spill) (g, no-spill) (h, no-spill) e j k b m d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  5. Example:Simplify (K=4) stack f (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) e j b m d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  6. Example:Simplify (K=4) stack (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) e j b m d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  7. Example:Simplify (K=4) stack (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) j b m d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  8. Example:Coalesce (K=4) stack (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) j b d c Why can’t we simplify? Cannot simplify move-related nodes. CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  9. Example:Coalesce (K=4) stack (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) j b d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  10. Example:Simplify (K=4) stack (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) j b c-d CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  11. Example:Coalesce (K=4) stack (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) j b CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  12. Example:Simplify (K=4) greedy-4-colorable stack (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) b-j CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  13. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  14. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  15. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  16. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  17. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  18. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  19. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  20. Example:Select (K=4) stack f e (b-j, no-spill) (c-d, no-spill) (m, no-spill) (e, no-spill) (f, no-spill) (k, no-spill) (g, no-spill) (h, no-spill) R1 R2 j k b m R3 d R4 c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  21. LIVE-IN: k j g := mem[j+12] h := k -1 f := g + h e := mem[j+8] m := mem[j+16] b := mem[f] c := e + 8 d := c k := m + 4 j := b LIVE-OUT: d k j Example:Allocation with 4 registers k j g h f e m b c d k j CMPUT 680 - Compiler Design and Optimization

  22. LIVE-IN: k j g := mem[j+12] h := k -1 f := g + h e := mem[j+8] m := mem[j+16] j := mem[f] d := e + 8 k := m + 4 LIVE-OUT: d k j Example:Allocation with 4 registers k j g h f e m j d k CMPUT 680 - Compiler Design and Optimization

  23. Could we do the allocation in the previous example with 3 registers? CMPUT 680 - Compiler Design and Optimization

  24. Example:Simplify (K=3) stack f (h,no-spill) e j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  25. Example:Simplify (K=3) stack f (g, no-spill) (h, no-spill) e j k b m d c g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  26. Example:Freeze (K=3) stack f (g, no-spill) (h, no-spill) e j k b m Coalescing may make things worse (not always). George’s rule would coalesce the move d-c, Briggs’ rule would freeze. d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  27. Example:Simplify (K=3) stack f (c, no-spill) (g, no-spill) (h, no-spill) e j k b m d c CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  28. Example:Potential Spill (K=3) stack f (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e j k b m Neither coalescing nor freezing help us. At this point we should use some profitability analysis to choose a node as may-spill. d CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  29. Example:Simplify (K=3) stack f (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) j k b m d CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  30. Example:Simplify (K=3) stack (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) j k b m d CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  31. Example:Coalesce (K=3) stack (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) j k b d CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  32. Example:Coalesce (K=3) stack (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) j-b k d CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  33. Example:Coalesce (K=3) stack (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) j-b k CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  34. Example:Coalesce (K=3) stack (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) j-b CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  35. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  36. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  37. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  38. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  39. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  40. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g This is when our optimism could have paid off. CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  41. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  42. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  43. Example:Select (K=3) stack f (j-b, no-spill) (k, no-spill) (d, no-spill) (m, no-spill) (f, no-spill) (e, may-spill) (c, no-spill) (g, no-spill) (h, no-spill) e R1 R2 j k b m R3 d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  44. So, is it possible for K=3? f e j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  45. Example:Simplify (K=3) f e j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  46. Example:Simplify (K=3) f e j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  47. Example:Simplify (K=3) f e j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  48. Example:Simplify (K=3) f e Impossible! But only 3 variables are live at any time…there may be a way? j k b m d c h g CMPUT 680 - Compiler Design and Optimization (Appel, pp. 237)

  49. LIVE-IN: k j g := mem[j+12] h := k -1 f := g + h e := mem[j+8] m := mem[j+16] b := mem[f] c := e + 8 d := c k’ := m + 4 j’ := b LIVE-OUT: d k’ j’ Example as basic block:3 Registers by renaming k & j k j g h f e m b c d k’ j’ CMPUT 680 - Compiler Design and Optimization

  50. LIVE-IN: k j g := mem[j+12] h := k -1 f := g + h e := mem[j+8] m := mem[j+16] j’ := mem[f] d := e + 8 k’ := m + 4 LIVE-OUT: d k’ j’ Example as basic block:3 Registers by renaming k & j k j g h f e m j’ d k’ CMPUT 680 - Compiler Design and Optimization

More Related