cmput 680 - compiler design and optimization1 borrowed from j. n. amaral, slightly modified...
TRANSCRIPT
![Page 1: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/1.jpg)
CMPUT 680 - Compiler Design and Optimization
1
Borrowed from J. N. Amaral, slightly modified http://www.cs.ualberta.ca/~amaral/courses/680
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
j := b
k := m + 4
LIVE-OUT: d k j
m
e
f
h
g
k j
b
c
d
kj
![Page 2: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/2.jpg)
CMPUT 680 - Compiler Design and Optimization
2
Example:Simplify (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(h,no-spill)
stack
![Page 3: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/3.jpg)
CMPUT 680 - Compiler Design and Optimization
3
Example:Simplify (K=4)
b mkj
g
d
c
e
f
(Appel, pp. 237)
(g, no-spill)(h, no-spill)
stack
![Page 4: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/4.jpg)
CMPUT 680 - Compiler Design and Optimization
4
Example:Simplify (K=4)
b mkj
d
c
e
f
(Appel, pp. 237)
(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 5: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/5.jpg)
CMPUT 680 - Compiler Design and Optimization
5
Example:Simplify (K=4)
b mj
d
c
e
f
(Appel, pp. 237)
(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 6: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/6.jpg)
CMPUT 680 - Compiler Design and Optimization
6
Example:Simplify (K=4)
b mj
d
c
e
(Appel, pp. 237)
(e, no-spill)(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 7: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/7.jpg)
CMPUT 680 - Compiler Design and Optimization
7
Example:Simplify (K=4)
b mj
d
c
(Appel, pp. 237)
(m, no-spill)(e, no-spill)(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 8: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/8.jpg)
CMPUT 680 - Compiler Design and Optimization
8
Example:Coalesce (K=4)
bj
d
c
(Appel, pp. 237)
(m, no-spill)(e, no-spill)(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
Why can’t we simplify?
Cannot simplify move-related nodes.
![Page 9: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/9.jpg)
CMPUT 680 - Compiler Design and Optimization
9
Example:Coalesce (K=4)
bj
d
c
(Appel, pp. 237)
(m, no-spill)(e, no-spill)(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 10: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/10.jpg)
CMPUT 680 - Compiler Design and Optimization
10
Example:Simplify (K=4)
bj
c-d
(Appel, pp. 237)
(c-d, no-spill)(m, no-spill)(e, no-spill)(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 11: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/11.jpg)
CMPUT 680 - Compiler Design and Optimization
11
Example:Coalesce (K=4)
bj
(Appel, pp. 237)
(c-d, no-spill)(m, no-spill)(e, no-spill)(f, no-spill)(k, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 12: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/12.jpg)
CMPUT 680 - Compiler Design and Optimization
12
Example:Simplify (K=4) greedy-4-colorable
b-j
(Appel, pp. 237)
(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)
stack
![Page 13: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/13.jpg)
CMPUT 680 - Compiler Design and Optimization
13
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 14: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/14.jpg)
CMPUT 680 - Compiler Design and Optimization
14
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 15: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/15.jpg)
CMPUT 680 - Compiler Design and Optimization
15
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 16: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/16.jpg)
CMPUT 680 - Compiler Design and Optimization
16
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 17: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/17.jpg)
CMPUT 680 - Compiler Design and Optimization
17
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 18: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/18.jpg)
CMPUT 680 - Compiler Design and Optimization
18
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 19: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/19.jpg)
CMPUT 680 - Compiler Design and Optimization
19
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 20: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/20.jpg)
CMPUT 680 - Compiler Design and Optimization
20
Example:Select (K=4)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(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)
stack
R1
R2
R3
R4
![Page 21: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/21.jpg)
CMPUT 680 - Compiler Design and Optimization
21
Example:Allocation with 4 registers
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
j := b
k := m + 4
LIVE-OUT: d k j
m
e
f
h
g
k j
b
c
d
j
k
![Page 22: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/22.jpg)
CMPUT 680 - Compiler Design and Optimization
22
Example:Allocation with 4 registers
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
m
e
f
h
g
k j
d
j
k
![Page 23: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/23.jpg)
CMPUT 680 - Compiler Design and Optimization
23
Could we do the allocation inthe previous example with 3
registers?
![Page 24: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/24.jpg)
CMPUT 680 - Compiler Design and Optimization
24
Example:Simplify (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
(h,no-spill)
stack
![Page 25: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/25.jpg)
CMPUT 680 - Compiler Design and Optimization
25
Example:Simplify (K=3)
b mkj
g
d
c
e
f
(Appel, pp. 237)
(g, no-spill)(h, no-spill)
stack
![Page 26: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/26.jpg)
CMPUT 680 - Compiler Design and Optimization
26
Example:Freeze (K=3)
b mkj
d
c
e
f
(Appel, pp. 237)
(g, no-spill)(h, no-spill)
stack
Coalescing may make things worse (not always).
George’s rule would coalesce the move d-c, Briggs’ rule would freeze.
![Page 27: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/27.jpg)
CMPUT 680 - Compiler Design and Optimization
27
Example:Simplify (K=3)
b mkj
d
c
e
f
(Appel, pp. 237)
(c, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 28: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/28.jpg)
CMPUT 680 - Compiler Design and Optimization
28
Example:Potential Spill (K=3)
b mkj
d
e
f
(Appel, pp. 237)
(e, may-spill)(c, no-spill)(g, no-spill)(h, no-spill)
stack
Neither coalescing norfreezing help us.
At this point we shoulduse some profitabilityanalysis to choose anode as may-spill.
![Page 29: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/29.jpg)
CMPUT 680 - Compiler Design and Optimization
29
Example:Simplify (K=3)
b mkj
d
f
(Appel, pp. 237)
(f, no-spill)(e, may-spill)(c, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 30: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/30.jpg)
CMPUT 680 - Compiler Design and Optimization
30
Example:Simplify (K=3)
b mkj
d
(Appel, pp. 237)
(m, no-spill)(f, no-spill)
(e, may-spill)(c, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 31: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/31.jpg)
CMPUT 680 - Compiler Design and Optimization
31
Example:Coalesce (K=3)
bkj
d
(Appel, pp. 237)
(m, no-spill)(f, no-spill)
(e, may-spill)(c, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 32: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/32.jpg)
CMPUT 680 - Compiler Design and Optimization
32
Example:Coalesce (K=3)
kj-b
d
(Appel, pp. 237)
(d, no-spill)(m, no-spill)(f, no-spill)
(e, may-spill)(c, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 33: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/33.jpg)
CMPUT 680 - Compiler Design and Optimization
33
Example:Coalesce (K=3)
kj-b
(Appel, pp. 237)
(k, no-spill)(d, no-spill)(m, no-spill)(f, no-spill)
(e, may-spill)(c, no-spill)(g, no-spill)(h, no-spill)
stack
![Page 34: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/34.jpg)
CMPUT 680 - Compiler Design and Optimization
34
Example:Coalesce (K=3)
j-b
(Appel, pp. 237)
(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)
stack
![Page 35: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/35.jpg)
CMPUT 680 - Compiler Design and Optimization
35
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 36: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/36.jpg)
CMPUT 680 - Compiler Design and Optimization
36
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 37: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/37.jpg)
CMPUT 680 - Compiler Design and Optimization
37
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 38: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/38.jpg)
CMPUT 680 - Compiler Design and Optimization
38
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 39: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/39.jpg)
CMPUT 680 - Compiler Design and Optimization
39
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 40: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/40.jpg)
CMPUT 680 - Compiler Design and Optimization
40
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
This is when our optimism couldhave paid off.
![Page 41: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/41.jpg)
CMPUT 680 - Compiler Design and Optimization
41
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 42: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/42.jpg)
CMPUT 680 - Compiler Design and Optimization
42
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 43: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/43.jpg)
CMPUT 680 - Compiler Design and Optimization
43
Example:Select (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
stack
R1
R2
R3
(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)
![Page 44: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/44.jpg)
CMPUT 680 - Compiler Design and Optimization
44
So, is it possible for K=3?
b mkj
gh
d
c
e
f
(Appel, pp. 237)
![Page 45: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/45.jpg)
CMPUT 680 - Compiler Design and Optimization
45
Example:Simplify (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
![Page 46: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/46.jpg)
CMPUT 680 - Compiler Design and Optimization
46
Example:Simplify (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
![Page 47: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/47.jpg)
CMPUT 680 - Compiler Design and Optimization
47
Example:Simplify (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
![Page 48: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/48.jpg)
CMPUT 680 - Compiler Design and Optimization
48
Example:Simplify (K=3)
b mkj
gh
d
c
e
f
(Appel, pp. 237)
Impossible!
But only 3 variables are live at any time…there may be a way?
![Page 49: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/49.jpg)
CMPUT 680 - Compiler Design and Optimization
49
Example as basic block:3 Registers by renaming k & j
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
j’ := b
k’ := m + 4
LIVE-OUT: d k’ j’
m
e
f
h
g
k j
b
c
dk’
j’
![Page 50: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/50.jpg)
CMPUT 680 - Compiler Design and Optimization
50
Example as basic block:3 Registers by renaming k & j
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’
m
e
f
h
g
k j
d
k’
j’
![Page 51: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/51.jpg)
CMPUT 680 - Compiler Design and Optimization
51
Example as basic block:A 3-coloring of the graph
b mkj
gh
d
c
e
f
(Appel, pp. 237)
The two assignments of k (resp. j) can be placed in two different registers.
k’
j’
![Page 52: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/52.jpg)
CMPUT 680 - Compiler Design and Optimization
52
Example as a loop: 3 Registers are enough!
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
j := b
k := m + 4
LIVE-OUT: d k j
m
f
h
g
k j
b
c
d
e
kj
![Page 53: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/53.jpg)
CMPUT 680 - Compiler Design and Optimization
53
Example as a loop: 3 Registers are enough!
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]
d := e + 8
k := m + 4
LIVE-OUT: d k j
m
f
h
g
k j
j
d
e
k
![Page 54: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/54.jpg)
CMPUT 680 - Compiler Design and Optimization
54
Example as a loop:3 Registers are enough!
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]
k := m + 4
d := e + 8
LIVE-OUT: d k j
m
f
h
g
k j
j
e
kd
![Page 55: CMPUT 680 - Compiler Design and Optimization1 Borrowed from J. N. Amaral, slightly modified amaral/courses/680 LIVE-IN: k j](https://reader035.vdocument.in/reader035/viewer/2022062417/551bffa1550346a84f8b4b52/html5/thumbnails/55.jpg)
CMPUT 680 - Compiler Design and Optimization
55
Example as a loop:3 Registers are enough!
LIVE-IN: k j
g := mem[j+12]
h := k -1
f := g + h
j’ := j
e := mem[j’+8]
m := mem[j’+16]
j := mem[f’]
k := m + 4
d := e + 8
LIVE-OUT: d k j
m
f
h
g
k j
j
d
e
f’ := fj’
f’
k