SlideShare une entreprise Scribd logo
1  sur  173
Télécharger pour lire hors ligne
Challenge the future
Delft
University of
Technology
Course IN4303, 2016-2017
Compiler Construction
Guido Wachsmuth, Eelco Visser
Register Allocation
exercise
Register Allocation
Allocate Minimal Number of Registers
2
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
today’s lecture
Register Allocation
Overview
Interference graphs
• construction during liveness analysis
3
today’s lecture
Register Allocation
Overview
Interference graphs
• construction during liveness analysis
Graph Coloring
• assign registers to local variables and compiler temporaries
• store local variables and temporaries in memory
3
today’s lecture
Register Allocation
Overview
Interference graphs
• construction during liveness analysis
Graph Coloring
• assign registers to local variables and compiler temporaries
• store local variables and temporaries in memory
Coalescing
• handle move instructions
3
today’s lecture
Register Allocation
Overview
Interference graphs
• construction during liveness analysis
Graph Coloring
• assign registers to local variables and compiler temporaries
• store local variables and temporaries in memory
Coalescing
• handle move instructions
Pre-colored nodes
3
Register Allocation
Interference Graphs
I
4
terminology
Register Allocation
Recap: Liveness Analysis
5
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
definition a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
definition
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
usage
definition
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
usage
definition
live-in
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
usage
definition
live-in
live-out
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
usage
definition
live-in
live-in
live-out
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
usage
definition
live-in
live-out
live-in
live-out
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
terminology
Register Allocation
Recap: Liveness Analysis
5
usage
definition
usage
definition
live-in
live-out
live-out
live-in
live-out
a ← 0
b ← a + 1
c ← c + b
a ← 2 * b
if a < N
return c
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Recap: Liveness Analysis
6
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Interference Graphs
7
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Interference Graphs
7
a b
c
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Interference Graphs
7
a b
c
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Interference Graphs
7
a b
c
Register Allocation
Graph Coloring
II
8
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
example
Register Allocation
Graph Coloring
9
a b
c
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
a
example
Register Allocation
Graph Coloring
9
b
c
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
a b
example
Register Allocation
Graph Coloring
9
c
a ← 0
return c
if a < N
b ← a + 1
a ← 2 * b
c ← c + b
a b
c
example
Register Allocation
Graph Coloring
9
r1 ← 0
return r2
if r1 < N
r1 ← r1 + 1
r1 ← 2 * r1
r2 ← r2 + r1
a b
c
example
Register Allocation
Graph Coloring
10
steps
Register Allocation
Graph Coloring
Simplify
remove node of insignificant degree (fewer than k edges)
spill
remove node with k or more edges
Select
add node, select color
11
example with 2 colors
Register Allocation
Graph Coloring
12
a b
c
example with 2 colors
Register Allocation
Graph Coloring
12
b
c
a
a
example with 2 colors
Register Allocation
Graph Coloring
12
b
c
a
a
c
b
example with 2 colors
Register Allocation
Graph Coloring
12
c
a
a
c
b
c
example with 2 colors
Register Allocation
Graph Coloring
12
a
a
a b
c
example with 2 colors
Register Allocation
Graph Coloring
12
example with 4 colors
Register Allocation
Graph Coloring
13
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
j k
example with 4 colors
Register Allocation
Graph Coloring
14
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
example with 4 colors
Register Allocation
Graph Coloring
15
g
b m
e
f
h g d c
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
16
g
b m
e
f
h g d c
h
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
17
g
b m
e
f
h g d c
h
k
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
18
g
b m
e
f
h g d c
h
k
d
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
19
g
b m
e
f
h g d c
h
k
d
j
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
20
g
b m
e
f
h g d c
h
k
d
j
er1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
21
g
b m
e
f
h g d c
h
k
d
j
e
f
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
22
g
b m
e
f
h g d c
h
k
d
j
e
f
b
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
23
g
b m
e
f
h g d c
h
k
d
j
e
f
b
c
r1
r2
r3
r4
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
j k
example with 4 colors
Register Allocation
Graph Coloring
24
g
b m
e
f
h g d c
h
k
d
j
e
f
b
c
r1
r2
r3
r4
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
j k
example with 4 colors
Register Allocation
Graph Coloring
25
g
b m
e
f
h g d c
h
k
d
j
e
f
b
c
live-in: k j
g := mem[j + 12]
h := k - 1
f := g * h
e := mem[j + 8]
r1 := mem[j + 16]
b := mem[f]
c := e + 8
d := c
k := r1 + 4
j := b
live out: d k j
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
26
g
b m
e
f
h g d c
h
k
d
j
e
f
b
live-in: k j
g := mem[j + 12]
h := k - 1
f := g * h
e := mem[j + 8]
r1 := mem[j + 16]
b := mem[f]
r2 := e + 8
d := r2
k := r1 + 4
j := b
live out: d k j
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
27
g
b m
e
f
h g d c
h
k
d
j
e
f
live-in: k j
g := mem[j + 12]
h := k - 1
f := g * h
e := mem[j + 8]
r1 := mem[j + 16]
r3 := mem[f]
r2 := e + 8
d := r2
k := r1 + 4
j := r3
live out: d k j
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
28
g
b m
e
f
h g d c
h
k
d
j
e
live-in: k j
g := mem[j + 12]
h := k - 1
r3 := g * h
e := mem[j + 8]
r1 := mem[j + 16]
r3 := mem[r3]
r2 := e + 8
d := r2
k := r1 + 4
j := r3
live out: d k j
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
29
g
b m
e
f
h g d c
h
k
d
j
live-in: k j
g := mem[j + 12]
h := k - 1
r3 := g * h
r4 := mem[j + 8]
r1 := mem[j + 16]
r3 := mem[r3]
r2 := r4 + 8
d := r2
k := r1 + 4
j := r3
live out: d k j
r1
r2
r3
r4
j k
example with 4 colors
Register Allocation
Graph Coloring
30
g
b m
e
f
h g d c
h
k
d
r1
r2
r3
r4
live-in: k r2
g := mem[r2 + 12]
h := k - 1
r3 := g * h
r4 := mem[r2 + 8]
r1 := mem[r2 + 16]
r3 := mem[r3]
r2 := r4 + 8
d := r2
k := r1 + 4
r2 := r3
live out: d k r2
j k
example with 4 colors
Register Allocation
Graph Coloring
31
g
b m
e
f
h g d c
h
k
r1
r2
r3
r4
live-in: k r2
g := mem[r2 + 12]
h := k - 1
r3 := g * h
r4 := mem[r2 + 8]
r1 := mem[r2 + 16]
r3 := mem[r3]
r2 := r4 + 8
r4 := r2
k := r1 + 4
r2 := r3
live out: r4 k r2
j k
example with 4 colors
Register Allocation
Graph Coloring
32
g
b m
e
f
h g d c
h
r1
r2
r3
r4
live-in: r1 r2
g := mem[r2 + 12]
h := r1 - 1
r3 := g * h
r4 := mem[r2 + 8]
r1 := mem[r2 + 16]
r3 := mem[r3]
r2 := r4 + 8
r4 := r2
r1 := r1 + 4
r2 := r3
live out: r4 r1 r2
j k
example with 4 colors
Register Allocation
Graph Coloring
33
g
b m
e
f
h g d c
r1
r2
r3
r4
live-in: r1 r2
g := mem[r2 + 12]
r3 := r1 - 1
r3 := g * r3
r4 := mem[r2 + 8]
r1 := mem[r2 + 16]
r3 := mem[r3]
r2 := r4 + 8
r4 := r2
r1 := r1 + 4
r2 := r3
live out: r4 r1 r2
j k
example with 4 colors
Register Allocation
Graph Coloring
34
b m
e
f
h g d c
r1
r2
r3
r4
live-in: r1 r2
r4 := mem[r2 + 12]
r3 := r1 - 1
r3 := r4 * r3
r4 := mem[r2 + 8]
r1 := mem[r2 + 16]
r3 := mem[r3]
r2 := r4 + 8
r4 := r2
r1 := r1 + 4
r2 := r3
live out: r4 r1 r2
Register Allocation
Spilling
III
35
steps
Register Allocation
Optimistic Coloring
Simplify
remove node of insignificant degree (fewer than k edges)
Spill
remove node of significant degree (k or more edges)
Select
add node, select color
36
d
example with 2 colors
Register Allocation
Optimistic Coloring
37
a b
c
d
example with 2 colors
Register Allocation
Optimistic Coloring
37
b
c
a
a
d
example with 2 colors
Register Allocation
Optimistic Coloring
37
b
c
a
apotential spill
d
example with 2 colors
Register Allocation
Optimistic Coloring
37
b
c
a
a
c
potential spill
d
example with 2 colors
Register Allocation
Optimistic Coloring
37
c
a b
a
c
b
potential spill
d
example with 2 colors
Register Allocation
Optimistic Coloring
37
c
a b
a
c
b
potential spill
d
b
example with 2 colors
Register Allocation
Optimistic Coloring
37
c
a
a
c
potential spill
d
b
c
example with 2 colors
Register Allocation
Optimistic Coloring
37
a
apotential spill
d
a b
c
example with 2 colors
Register Allocation
Optimistic Coloring
37
steps
Register Allocation
Spilling
Simplify
remove node of insignificant degree (less than k edges)
Spill
remove node of significant degree (k or more edges)
Select
add node, select color
Actual spill
Start over
38
a
example with 2 colors
Register Allocation
Spilling
39
b
c
a
example with 2 colors
Register Allocation
Spilling
39
b
c
apotential spill
a
example with 2 colors
Register Allocation
Spilling
39
b
c
a
c
potential spill
a b
example with 2 colors
Register Allocation
Spilling
39
c
a
c
potential spill
a b
c
example with 2 colors
Register Allocation
Spilling
39
apotential spill
a b
c
example with 2 colors
Register Allocation
Spilling
39
aactual spill
return b
a ← c + a
c ← b + 1
b ← a + 1
example
Register Allocation
Spilling
40
a ← 1
example
Register Allocation
Spilling
41
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
a1 ← 1
M[42] ← a1
example
Register Allocation
Spilling
41
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
example
Register Allocation
Spilling
41
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
a4 ← c + a3
M[42] ← a4
a3 ← M[42]
example
Register Allocation
Spilling
41
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
42
a4 ← c + a3
M[42] ← a4
a3 ← M[42]
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
42
a4 ← c + a3
M[42] ← a4
a3 ← M[42]
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
42
a4 ← c + a3
M[42] ← a4
a3 ← M[42]
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
42
a4 ← c + a3
M[42] ← a4
a3 ← M[42]
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
42
a4 ← c + a3
M[42] ← a4
a3 ← M[42]
a1 ← 1
M[42] ← a1
b ← a2 + 1
a2 ← M[42]
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
43
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
b2 ← M[42]
c ← b2 + 1
example
Register Allocation
Spilling
43
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
example
Register Allocation
Spilling
43
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
return b3
b3 ← M[42]
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
example
Register Allocation
Spilling
43
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
44
return b3
b3 ← M[42]
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
44
return b3
b3 ← M[42]
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
44
return b3
b3 ← M[42]
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
44
return b3
b3 ← M[42]
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
example
Register Allocation
Spilling
44
return b3
b3 ← M[42]
b2 ← M[42]
c ← b2 + 1
M[42] ← b1
b1 ← a + 1
a ← c + a
c ← b + 1
b ← a + 1
a ← 1
return b
Register Allocation
Coalescing
IV
45
coalescing
Register Allocation
Eliminating Move Instructions
46
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
coalescing
Register Allocation
Eliminating Move Instructions
47
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
Register Allocation
Coalescing
48
coalesce |ˌkəʊəˈlɛs|

verb [no object]

come together to form one mass or whole: the puddles had coalesced
into shallow streams.

• [with object] combine (elements) in a mass or whole: his idea served to
coalesce all that happened into one connected whole.
j k
example
Register Allocation
Recap: Graph Coloring
49
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
example
Register Allocation
Recap: Graph Coloring
49
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
example
Register Allocation
Recap: Graph Coloring
49
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
better solution
Register Allocation
Coalescing
50
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
better solution
Register Allocation
Coalescing
50
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
better solution
Register Allocation
Coalescing
50
b m
e
f
h g d c
r1
r2
r3
r4
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
jb k
coalescing nodes
Register Allocation
Coalescing
51
m
e
f
h g cd
r1
r2
r3
r4
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
conservative strategies
Register Allocation
Coalescing
Briggs
• a/b has fewer than k neighbours of significant degree
• nodes of insignificant degree and a/b can be simplified
• remaining graph is colorable
George
• all neighbours of a of significant degree interfere also with b
• neighbours of a of insignificant degree can be simplified
• subgraph of original graph is colorable
52
steps
Register Allocation
Graph Coloring
Simplify
remove non-move-related node of insignificant degree
Coalesce
Freeze
turn move-related node of insignificant degree into non-move-related
Spill
Select
Start over
53
j k
example
Register Allocation
Coalescing
54
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
example
Register Allocation
Coalescing
55
g
b m
e
f
h g d c
r1
r2
r3
r4
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
j k
example
Register Allocation
Coalescing
56
g
b m
e
f
h g d c
h
r1
r2
r3
r4
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
j k
example
Register Allocation
Coalescing
57
g
b m
e
f
h g d c
h
k
r1
r2
r3
r4
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
j k
example
Register Allocation
Coalescing
58
g
b m
e
f
h g
h
k
cd
r1
r2
r3
r4
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
cd
jb k
example
Register Allocation
Coalescing
59
g
m
e
f
h g
h
k
r1
r2
r3
r4
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
cd
jb k
example
Register Allocation
Coalescing
60
g
m
e
f
h g
h
k
cd
r1
r2
r3
r4
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
cd
jb k
example
Register Allocation
Coalescing
61
g
m
e
f
h g
h
k
cd
jb
r1
r2
r3
r4
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
cd
jb k
example
Register Allocation
Coalescing
62
g
m
e
f
h g
h
k
cd
jb
fr1
r2
r3
r4
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
cd
jb k
example
Register Allocation
Coalescing
63
g
m
e
f
h g
h
k
cd
jb
f
m
r1
r2
r3
r4
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
cd
jb k
example
Register Allocation
Coalescing
64
g
m
e
f
h g
h
k
cd
jb
f
m
r1
r2
r3
r4
live-in: k j
g := mem[j + 12]
h := k - 1
f := g * h
r1 := mem[j + 8]
m := mem[j + 16]
b := mem[f]
c := r1 + 8
d := c
k := m + 4
j := b
live out: d k j
cd
jb k
example
Register Allocation
Coalescing
65
g
m
e
f
h g
h
k
cd
jb
fr1
r2
r3
r4
live-in: k j
g := mem[j + 12]
h := k - 1
f := g * h
r1 := mem[j + 8]
r2 := mem[j + 16]
b := mem[f]
c := r1 + 8
d := c
k := r2 + 4
j := b
live out: d k j
cd
jb k
example
Register Allocation
Coalescing
66
g
m
e
f
h g
h
k
cd
jb
r1
r2
r3
r4
live-in: k j
g := mem[j + 12]
h := k - 1
r3 := g * h
r1 := mem[j + 8]
r2 := mem[j + 16]
b := mem[r3]
c := r1 + 8
d := c
k := r2 + 4
j := b
live out: d k j
cd
jb k
example
Register Allocation
Coalescing
67
g
m
e
f
h g
h
k
cd
r1
r2
r3
r4
live-in: k r4
g := mem[r4 + 12]
h := k - 1
r3 := g * h
r1 := mem[r4 + 8]
r2 := mem[r4 + 16]
b := mem[r3]
c := r1 + 8
d := c
k := r2 + 4
r4 := r4
live out: d k r4
cd
jb k
example
Register Allocation
Coalescing
68
g
m
e
f
h g
h
k
r1
r2
r3
r4
live-in: k r4
g := mem[r4 + 12]
h := k - 1
r3 := g * h
r1 := mem[r4 + 8]
r2 := mem[r4 + 16]
b := mem[r3]
r1 := r1 + 8
r1 := r1
k := r2 + 4
r4 := r4
live out: r1 k r4
cd
jb k
example
Register Allocation
Coalescing
69
g
m
e
f
h g
h
r1
r2
r3
r4
live-in: r2 r4
g := mem[r4 + 12]
h := r2 - 1
r3 := g * h
r1 := mem[r4 + 8]
r2 := mem[r4 + 16]
b := mem[r3]
r1 := r1 + 8
r1 := r1
k := r2 + 4
r4 := r4
live out: r1 r2 r4
cd
jb k
example
Register Allocation
Coalescing
70
g
m
e
f
h g
r1
r2
r3
r4
live-in: r2 r4
g := mem[r4 + 12]
r2 := r2 - 1
r3 := g * r2
r1 := mem[r4 + 8]
r2 := mem[r4 + 16]
b := mem[r3]
r1 := r1 + 8
r1 := r1
k := r2 + 4
r4 := r4
live out: r1 r2 r4
jb k
coalescing nodes
Register Allocation
Coalescing
71
m
e
f
h g cd
r1
r2
r3
r4
live-in: r2 r4
r1 := mem[r4 + 12]
r2 := r2 - 1
r3 := r1 * r2
r1 := mem[r4 + 8]
r2 := mem[r4 + 16]
b := mem[r3]
r1 := r1 + 8
r1 := r1
k := r2 + 4
r4 := r4
live out: r1 r2 r4
Register Allocation
Pre-Colored Nodes
V
72
CDECL
Register Allocation
Recap: Calling Conventions
Caller
• push parameters right-to-left on the stack
• clean-up stack after call
Callee
• save old BP
• initialise new BP
• save registers
• return result in AX
• restore registers
• restore BP
73
push 21
push 42
call _f
add ESP 8
push EBP
mov EBP ESP
mov EAX [EBP + 8]
mov EDX [EBP + 12]
add EAX EDX
pop EBP
ret
STDCALL
Register Allocation
Recap: Calling Conventions
Caller
• push parameters right-to-left on the stack
Callee
• save old BP
• initialise new BP
• save registers
• return result in AX
• restore registers
• restore BP
74
push 21
push 42
call _f@8
push EBP
mov EBP ESP
mov EAX [EBP + 8]
mov EDX [EBP + 12]
add EAX EDX
pop EBP
ret 8
FASTCALL
Register Allocation
Recap: Calling Conventions
Caller
• passes parameters in registers
• pushes additional parameters right-to-left on the stack
• cleans up the stack
Callee
• save old BP, initialise new BP
• save registers
• return result in AX
• restore registers
• restore BP
75
mov ECX 21
mov EDX 42
call @f@8
push EBP
mov EBP ESP
mov EAX ECX
add EAX EDX
pop EBP
ret
saving registers
Register Allocation
Recap: Calling Conventions
Not enough registers for all local variables across life time
• save register to memory to free for other use
Caller-save registers
• Caller is responsible for saving and restoring register
Callee-save registers
• Callee is responsible for saving and restoring register
Use callee-save registers to pass parameters
76
representing registers
Register Allocation
Pre-Colored Nodes
Nodes
• register = pre-colored node
• no simplify, no spill
• coalesce possible
Edges
• all registers interfere with each other
• explicit usage of registers
• call and return instructions influence liveness
77
pre-colored nodes
Register Allocation
Callee-Save Register in Temporary
78
enter: def(r7)
…
exit: use(r7)
enter: def(r7)
t ← r7
…
r7 ← t
exit: use(r7)
example
Register Allocation
Pre-Colored Nodes
79
enter : c ← r3 // callee-save
a ← r1 // caller-save
b ← r2 // caller-save
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3 live out)
int f(int a, int b) {
int d = 0;
int e = a;
do {
d = d + b;
e = e - 1;
} while (e > 0);
return d;
}
machine has 3 registers
example
Register Allocation
Pre-Colored Nodes
80
r3
r2
b e
r1 a
d
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
example
Register Allocation
Pre-Colored Nodes
81
r3
r2
b e
r1 a
d
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
c
spill c
example
Register Allocation
Pre-Colored Nodes
82
r3
r2
b
r1 ae
d
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
c
coalesce a and e
example
Register Allocation
Pre-Colored Nodes
83
r3
br2
r1 ae
d
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
c
coalesce r2 and b
example
Register Allocation
Pre-Colored Nodes
84
r3
br2
r1ae d
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
c
coalesce r1 and ae
example
Register Allocation
Pre-Colored Nodes
85
r3
br2
r1ae d
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
c
simplify d
d
example
Register Allocation
Pre-Colored Nodes
86
r3
br2
r1ae r3
c
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
c
color d as r3
example
Register Allocation
Pre-Colored Nodes
87
r3
br2
r1ae r3
c
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
c
spill c
example
Register Allocation
Pre-Colored Nodes
88
r3
br2
r1ae r3
c
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
spill c
examples
Register Allocation
Pre-Colored Nodes
89
r3
r2
b e
r1 a
d
c
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
start over
examples
Register Allocation
Pre-Colored Nodes
90
r3
r2
b e
r1 a
d
c
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
examples
Register Allocation
Pre-Colored Nodes
91
r3
r2
b e
r1 a
d
c1
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
c2
new graph
examples
Register Allocation
Pre-Colored Nodes
92
r3
r2
b e
r1 a
d
c1
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
c2
coalesce c1, c2, r3
examples
Register Allocation
Pre-Colored Nodes
93
c1c2r3
r2
b e
r1 a
d
c1
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
c2
coalesce c1, c2, r3
examples
Register Allocation
Pre-Colored Nodes
94
c1c2r3
r2
b e
r1 a
d
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
coalesce (b, r2) and (a, e)
examples
Register Allocation
Pre-Colored Nodes
95
c1c2r3 br2
r1 ae
d
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
coalesce (ae, r1)
examples
Register Allocation
Pre-Colored Nodes
96
c1c2r3 br2
r1ae d
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
simplify d
d
examples
Register Allocation
Pre-Colored Nodes
97
c1c2r3 br2
r1ae r3
enter : c1 ← r3
M[cloc] ← c1
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c2
c2 ← M[cloc]
return (r1, r3)
color d as r3
d
examples
Register Allocation
Pre-Colored Nodes
98
c1c2r3 br2
r1ae r3
enter : r3 ← r3
M[cloc] ← r3
r1 ← r1
r2 ← r2
r3 ← 0
r1 ← r1
loop : r3 ← r3 + r2
r1 ← r1 - 1
if r1 > 0 goto loop
r1 ← r3
r3 ← r3
r3 ← M[cloc]
return (r1, r3)
apply register assigment
example
Register Allocation
Pre-Colored Nodes
99
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
enter : r3 ← r3
M[cloc] ← r3
r1 ← r1
r2 ← r2
r3 ← 0
r1 ← r1
loop : r3 ← r3 + r2
r1 ← r1 - 1
if r1 > 0 goto loop
r1 ← r3
r3 ← r3
r3 ← M[cloc]
return (r1, r3)
example
Register Allocation
Pre-Colored Nodes
100
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
enter : r3 ← r3
M[cloc] ← r3
r1 ← r1
r2 ← r2
r3 ← 0
r1 ← r1
loop : r3 ← r3 + r2
r1 ← r1 - 1
if r1 > 0 goto loop
r1 ← r3
r3 ← r3
r3 ← M[cloc]
return (r1, r3)
example
Register Allocation
Pre-Colored Nodes
101
enter : c ← r3
a ← r1
b ← r2
d ← 0
e ← a
loop : d ← d + b
e ← e - 1
if e > 0 goto loop
r1 ← d
r3 ← c
return (r1, r3)
enter : M[cloc] ← r3
r3 ← 0
loop : r3 ← r3 + r2
r1 ← r1 - 1
if r1 > 0 goto loop
r1 ← r3
r3 ← M[cloc]
return (r1, r3)
example
Register Allocation
Pre-Colored Nodes
102
enter : M[cloc] ← r3
r3 ← 0
loop : r3 ← r3 + r2
r1 ← r1 - 1
if r1 > 0 goto loop
r3 ← M[cloc]
return (r1, r3)
int f(int a, int b) {
int d = 0;
int e = a;
do {
d = d + b;
e = e - 1;
} while (e > 0);
return d;
}
Register Allocation
Summary
VI
103
lessons learned
Register Allocation
Summary
How can we assign registers to local variables and temporaries?
• perform liveness analysis
• build interference graph
• color interference graph
What to do if the graph is not colorable?
• keep local variables in memory
How to handle move instructions efficiently?
• coalesce nodes safely
104
learn more
Register Allocation
Literature
Andrew W. Appel, Jens Palsberg: Modern Compiler
Implementation in Java, 2nd edition. 2002
Lal George, Andrew W. Appel: Iterative Register Coalescing.
POPL 1996
Lal George, Andrew W. Appel: Iterative Register Coalescing.
TOPLAS 18(3), 1996
105
coming next
Register Allocation
Outlook
Compiler components & their generators
• Lecture 12: Data-Flow Analysis Dec 6
• Lecture 13: Register Allocation Dec 13
• Lecture 14: LL Parsing Dec 20
• Lecture 15: LR Parsing Jan 10
Exam preparation
• Question & Answer & Outlook Jan 24
• Exam Jan 31
106
Register Allocation
Copyrights
107
Register Allocation 108
attribution & copyrights
Register Allocation
Pictures
Slide 1:
Colors #2 by Carmelo Speltino, some rights reserved
Slide 40:
Tchibo by Dominica Williamson, some rights reserved
109

Contenu connexe

Tendances

DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data RepresentationWang Hsiangkai
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTUREMandeep Singh
 
LLVM Instruction Selection
LLVM Instruction SelectionLLVM Instruction Selection
LLVM Instruction SelectionShiva Chen
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdbOwen Hsu
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expressionAnimesh Chaturvedi
 
Vivado hls勉強会3(axi4 lite slave)
Vivado hls勉強会3(axi4 lite slave)Vivado hls勉強会3(axi4 lite slave)
Vivado hls勉強会3(axi4 lite slave)marsee101
 
Bca 2nd sem-u-3.2-basic computer programming and micro programmed control
Bca 2nd sem-u-3.2-basic computer programming and micro programmed controlBca 2nd sem-u-3.2-basic computer programming and micro programmed control
Bca 2nd sem-u-3.2-basic computer programming and micro programmed controlRai University
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle pptsheetal singh
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorDarling Jemima
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfixSelf-Employed
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 

Tendances (20)

DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data Representation
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
LLVM Instruction Selection
LLVM Instruction SelectionLLVM Instruction Selection
LLVM Instruction Selection
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
Verilog HDL- 2
Verilog HDL- 2Verilog HDL- 2
Verilog HDL- 2
 
Regular language and Regular expression
Regular language and Regular expressionRegular language and Regular expression
Regular language and Regular expression
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Execution
ExecutionExecution
Execution
 
Vivado hls勉強会3(axi4 lite slave)
Vivado hls勉強会3(axi4 lite slave)Vivado hls勉強会3(axi4 lite slave)
Vivado hls勉強会3(axi4 lite slave)
 
Bca 2nd sem-u-3.2-basic computer programming and micro programmed control
Bca 2nd sem-u-3.2-basic computer programming and micro programmed controlBca 2nd sem-u-3.2-basic computer programming and micro programmed control
Bca 2nd sem-u-3.2-basic computer programming and micro programmed control
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 
Introduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM ProcessorIntroduction to Processor Design and ARM Processor
Introduction to Processor Design and ARM Processor
 
Code Generation
Code GenerationCode Generation
Code Generation
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Heap sort
Heap sortHeap sort
Heap sort
 

En vedette

Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
Programming languages
Programming languagesProgramming languages
Programming languagesEelco Visser
 
Software languages
Software languagesSoftware languages
Software languagesEelco Visser
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedGuido Wachsmuth
 

En vedette (11)

Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Type analysis
Type analysisType analysis
Type analysis
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
LL Parsing
LL ParsingLL Parsing
LL Parsing
 
Software languages
Software languagesSoftware languages
Software languages
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Pure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and RegainedPure and Declarative Syntax Definition: Paradise Lost and Regained
Pure and Declarative Syntax Definition: Paradise Lost and Regained
 
Dynamic Semantics
Dynamic SemanticsDynamic Semantics
Dynamic Semantics
 
Language
LanguageLanguage
Language
 
Syntax Definition
Syntax DefinitionSyntax Definition
Syntax Definition
 

Similaire à Register Allocation

Sesion de aprendizaje de logaritmos algebra pre u ccesa007
Sesion de aprendizaje de logaritmos algebra pre u ccesa007Sesion de aprendizaje de logaritmos algebra pre u ccesa007
Sesion de aprendizaje de logaritmos algebra pre u ccesa007Demetrio Ccesa Rayme
 
multiplying polynomials 2 .pptx
multiplying polynomials 2          .pptxmultiplying polynomials 2          .pptx
multiplying polynomials 2 .pptxJonalyn34
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationGuido Wachsmuth
 
0015.register allocation-graph-coloring
0015.register allocation-graph-coloring0015.register allocation-graph-coloring
0015.register allocation-graph-coloringsean chen
 
Binomial Theorem
Binomial TheoremBinomial Theorem
Binomial Theoremitutor
 
098A_exponents_factoring.ppt
098A_exponents_factoring.ppt098A_exponents_factoring.ppt
098A_exponents_factoring.pptMarjorie Malveda
 
098A_exponents_factoring.ppt
098A_exponents_factoring.ppt098A_exponents_factoring.ppt
098A_exponents_factoring.pptElmabethDelaCruz1
 
CS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.pptCS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.pptssuser0be977
 
Karnaugh maps
Karnaugh mapsKarnaugh maps
Karnaugh mapsAJAL A J
 
ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1
ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1
ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1zukun
 
Mathnasium Presentation (1)
Mathnasium Presentation (1)Mathnasium Presentation (1)
Mathnasium Presentation (1)Muhammad Arslan
 
Module 5 Indices PMR
Module 5 Indices PMRModule 5 Indices PMR
Module 5 Indices PMRroszelan
 

Similaire à Register Allocation (20)

Dataflow Analysis
Dataflow AnalysisDataflow Analysis
Dataflow Analysis
 
Sesion de aprendizaje de logaritmos algebra pre u ccesa007
Sesion de aprendizaje de logaritmos algebra pre u ccesa007Sesion de aprendizaje de logaritmos algebra pre u ccesa007
Sesion de aprendizaje de logaritmos algebra pre u ccesa007
 
multiplying polynomials 2 .pptx
multiplying polynomials 2          .pptxmultiplying polynomials 2          .pptx
multiplying polynomials 2 .pptx
 
Compiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register AllocationCompiling Imperative and Object-Oriented Languages - Register Allocation
Compiling Imperative and Object-Oriented Languages - Register Allocation
 
4.3b & 4 Rr
4.3b & 4 Rr4.3b & 4 Rr
4.3b & 4 Rr
 
0015.register allocation-graph-coloring
0015.register allocation-graph-coloring0015.register allocation-graph-coloring
0015.register allocation-graph-coloring
 
Binomial Theorem
Binomial TheoremBinomial Theorem
Binomial Theorem
 
Binomial theorem
Binomial theorem Binomial theorem
Binomial theorem
 
098A_exponents_factoring.ppt
098A_exponents_factoring.ppt098A_exponents_factoring.ppt
098A_exponents_factoring.ppt
 
098A_exponents_factoring.ppt
098A_exponents_factoring.ppt098A_exponents_factoring.ppt
098A_exponents_factoring.ppt
 
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
3rd Semester Computer Science and Engineering  (ACU-2022) Question papers3rd Semester Computer Science and Engineering  (ACU-2022) Question papers
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
CS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.pptCS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.ppt
 
Code Optimization.ppt
Code Optimization.pptCode Optimization.ppt
Code Optimization.ppt
 
Karnaugh maps
Karnaugh mapsKarnaugh maps
Karnaugh maps
 
ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1
ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1
ECCV2008: MAP Estimation Algorithms in Computer Vision - Part 1
 
Chapter 31 logarithms
Chapter 31 logarithmsChapter 31 logarithms
Chapter 31 logarithms
 
Mathnasium Presentation (1)
Mathnasium Presentation (1)Mathnasium Presentation (1)
Mathnasium Presentation (1)
 
Module 5 Indices PMR
Module 5 Indices PMRModule 5 Indices PMR
Module 5 Indices PMR
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 

Plus de Eelco Visser

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingEelco Visser
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesEelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingEelco Visser
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionEelco Visser
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionEelco Visser
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesEelco Visser
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with StatixEelco Visser
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionEelco Visser
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Eelco Visser
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementEelco Visser
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersEelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationEelco Visser
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesEelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksEelco Visser
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisEelco Visser
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionEelco Visser
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsEelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco Visser
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisEelco Visser
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingEelco Visser
 

Plus de Eelco Visser (20)

CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
CS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic ServicesCS4200 2019 | Lecture 4 | Syntactic Services
CS4200 2019 | Lecture 4 | Syntactic Services
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
CS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definitionCS4200 2019 | Lecture 2 | syntax-definition
CS4200 2019 | Lecture 2 | syntax-definition
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
 
Declarative Type System Specification with Statix
Declarative Type System Specification with StatixDeclarative Type System Specification with Statix
Declarative Type System Specification with Statix
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
Compiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint ResolutionCompiler Construction | Lecture 9 | Constraint Resolution
Compiler Construction | Lecture 9 | Constraint Resolution
 
Compiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type ConstraintsCompiler Construction | Lecture 8 | Type Constraints
Compiler Construction | Lecture 8 | Type Constraints
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 

Dernier

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 

Dernier (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 

Register Allocation

  • 1. Challenge the future Delft University of Technology Course IN4303, 2016-2017 Compiler Construction Guido Wachsmuth, Eelco Visser Register Allocation
  • 2. exercise Register Allocation Allocate Minimal Number of Registers 2 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
  • 3. today’s lecture Register Allocation Overview Interference graphs • construction during liveness analysis 3
  • 4. today’s lecture Register Allocation Overview Interference graphs • construction during liveness analysis Graph Coloring • assign registers to local variables and compiler temporaries • store local variables and temporaries in memory 3
  • 5. today’s lecture Register Allocation Overview Interference graphs • construction during liveness analysis Graph Coloring • assign registers to local variables and compiler temporaries • store local variables and temporaries in memory Coalescing • handle move instructions 3
  • 6. today’s lecture Register Allocation Overview Interference graphs • construction during liveness analysis Graph Coloring • assign registers to local variables and compiler temporaries • store local variables and temporaries in memory Coalescing • handle move instructions Pre-colored nodes 3
  • 8. terminology Register Allocation Recap: Liveness Analysis 5 a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 9. terminology Register Allocation Recap: Liveness Analysis 5 definition a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 10. terminology Register Allocation Recap: Liveness Analysis 5 usage definition a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 11. terminology Register Allocation Recap: Liveness Analysis 5 usage definition definition a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 12. terminology Register Allocation Recap: Liveness Analysis 5 usage definition usage definition a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 13. terminology Register Allocation Recap: Liveness Analysis 5 usage definition usage definition live-in a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 14. terminology Register Allocation Recap: Liveness Analysis 5 usage definition usage definition live-in live-out a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 15. terminology Register Allocation Recap: Liveness Analysis 5 usage definition usage definition live-in live-in live-out a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 16. terminology Register Allocation Recap: Liveness Analysis 5 usage definition usage definition live-in live-out live-in live-out a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 17. terminology Register Allocation Recap: Liveness Analysis 5 usage definition usage definition live-in live-out live-out live-in live-out a ← 0 b ← a + 1 c ← c + b a ← 2 * b if a < N return c
  • 18. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 19. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 20. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 21. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 22. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 23. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 24. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 25. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 26. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 27. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 28. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Recap: Liveness Analysis 6
  • 29. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Interference Graphs 7
  • 30. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Interference Graphs 7 a b c
  • 31. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Interference Graphs 7 a b c
  • 32. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Interference Graphs 7 a b c
  • 34. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b example Register Allocation Graph Coloring 9 a b c
  • 35. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b a example Register Allocation Graph Coloring 9 b c
  • 36. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b a b example Register Allocation Graph Coloring 9 c
  • 37. a ← 0 return c if a < N b ← a + 1 a ← 2 * b c ← c + b a b c example Register Allocation Graph Coloring 9
  • 38. r1 ← 0 return r2 if r1 < N r1 ← r1 + 1 r1 ← 2 * r1 r2 ← r2 + r1 a b c example Register Allocation Graph Coloring 10
  • 39. steps Register Allocation Graph Coloring Simplify remove node of insignificant degree (fewer than k edges) spill remove node with k or more edges Select add node, select color 11
  • 40. example with 2 colors Register Allocation Graph Coloring 12 a b c
  • 41. example with 2 colors Register Allocation Graph Coloring 12 b c a a
  • 42. example with 2 colors Register Allocation Graph Coloring 12 b c a a c
  • 43. b example with 2 colors Register Allocation Graph Coloring 12 c a a c
  • 44. b c example with 2 colors Register Allocation Graph Coloring 12 a a
  • 45. a b c example with 2 colors Register Allocation Graph Coloring 12
  • 46. example with 4 colors Register Allocation Graph Coloring 13 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
  • 47. j k example with 4 colors Register Allocation Graph Coloring 14 b m e f h g d c r1 r2 r3 r4 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
  • 48. j k example with 4 colors Register Allocation Graph Coloring 15 g b m e f h g d c r1 r2 r3 r4
  • 49. j k example with 4 colors Register Allocation Graph Coloring 16 g b m e f h g d c h r1 r2 r3 r4
  • 50. j k example with 4 colors Register Allocation Graph Coloring 17 g b m e f h g d c h k r1 r2 r3 r4
  • 51. j k example with 4 colors Register Allocation Graph Coloring 18 g b m e f h g d c h k d r1 r2 r3 r4
  • 52. j k example with 4 colors Register Allocation Graph Coloring 19 g b m e f h g d c h k d j r1 r2 r3 r4
  • 53. j k example with 4 colors Register Allocation Graph Coloring 20 g b m e f h g d c h k d j er1 r2 r3 r4
  • 54. j k example with 4 colors Register Allocation Graph Coloring 21 g b m e f h g d c h k d j e f r1 r2 r3 r4
  • 55. j k example with 4 colors Register Allocation Graph Coloring 22 g b m e f h g d c h k d j e f b r1 r2 r3 r4
  • 56. j k example with 4 colors Register Allocation Graph Coloring 23 g b m e f h g d c h k d j e f b c r1 r2 r3 r4 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
  • 57. j k example with 4 colors Register Allocation Graph Coloring 24 g b m e f h g d c h k d j e f b c r1 r2 r3 r4 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
  • 58. j k example with 4 colors Register Allocation Graph Coloring 25 g b m e f h g d c h k d j e f b c live-in: k j g := mem[j + 12] h := k - 1 f := g * h e := mem[j + 8] r1 := mem[j + 16] b := mem[f] c := e + 8 d := c k := r1 + 4 j := b live out: d k j r1 r2 r3 r4
  • 59. j k example with 4 colors Register Allocation Graph Coloring 26 g b m e f h g d c h k d j e f b live-in: k j g := mem[j + 12] h := k - 1 f := g * h e := mem[j + 8] r1 := mem[j + 16] b := mem[f] r2 := e + 8 d := r2 k := r1 + 4 j := b live out: d k j r1 r2 r3 r4
  • 60. j k example with 4 colors Register Allocation Graph Coloring 27 g b m e f h g d c h k d j e f live-in: k j g := mem[j + 12] h := k - 1 f := g * h e := mem[j + 8] r1 := mem[j + 16] r3 := mem[f] r2 := e + 8 d := r2 k := r1 + 4 j := r3 live out: d k j r1 r2 r3 r4
  • 61. j k example with 4 colors Register Allocation Graph Coloring 28 g b m e f h g d c h k d j e live-in: k j g := mem[j + 12] h := k - 1 r3 := g * h e := mem[j + 8] r1 := mem[j + 16] r3 := mem[r3] r2 := e + 8 d := r2 k := r1 + 4 j := r3 live out: d k j r1 r2 r3 r4
  • 62. j k example with 4 colors Register Allocation Graph Coloring 29 g b m e f h g d c h k d j live-in: k j g := mem[j + 12] h := k - 1 r3 := g * h r4 := mem[j + 8] r1 := mem[j + 16] r3 := mem[r3] r2 := r4 + 8 d := r2 k := r1 + 4 j := r3 live out: d k j r1 r2 r3 r4
  • 63. j k example with 4 colors Register Allocation Graph Coloring 30 g b m e f h g d c h k d r1 r2 r3 r4 live-in: k r2 g := mem[r2 + 12] h := k - 1 r3 := g * h r4 := mem[r2 + 8] r1 := mem[r2 + 16] r3 := mem[r3] r2 := r4 + 8 d := r2 k := r1 + 4 r2 := r3 live out: d k r2
  • 64. j k example with 4 colors Register Allocation Graph Coloring 31 g b m e f h g d c h k r1 r2 r3 r4 live-in: k r2 g := mem[r2 + 12] h := k - 1 r3 := g * h r4 := mem[r2 + 8] r1 := mem[r2 + 16] r3 := mem[r3] r2 := r4 + 8 r4 := r2 k := r1 + 4 r2 := r3 live out: r4 k r2
  • 65. j k example with 4 colors Register Allocation Graph Coloring 32 g b m e f h g d c h r1 r2 r3 r4 live-in: r1 r2 g := mem[r2 + 12] h := r1 - 1 r3 := g * h r4 := mem[r2 + 8] r1 := mem[r2 + 16] r3 := mem[r3] r2 := r4 + 8 r4 := r2 r1 := r1 + 4 r2 := r3 live out: r4 r1 r2
  • 66. j k example with 4 colors Register Allocation Graph Coloring 33 g b m e f h g d c r1 r2 r3 r4 live-in: r1 r2 g := mem[r2 + 12] r3 := r1 - 1 r3 := g * r3 r4 := mem[r2 + 8] r1 := mem[r2 + 16] r3 := mem[r3] r2 := r4 + 8 r4 := r2 r1 := r1 + 4 r2 := r3 live out: r4 r1 r2
  • 67. j k example with 4 colors Register Allocation Graph Coloring 34 b m e f h g d c r1 r2 r3 r4 live-in: r1 r2 r4 := mem[r2 + 12] r3 := r1 - 1 r3 := r4 * r3 r4 := mem[r2 + 8] r1 := mem[r2 + 16] r3 := mem[r3] r2 := r4 + 8 r4 := r2 r1 := r1 + 4 r2 := r3 live out: r4 r1 r2
  • 69. steps Register Allocation Optimistic Coloring Simplify remove node of insignificant degree (fewer than k edges) Spill remove node of significant degree (k or more edges) Select add node, select color 36
  • 70. d example with 2 colors Register Allocation Optimistic Coloring 37 a b c
  • 71. d example with 2 colors Register Allocation Optimistic Coloring 37 b c a a
  • 72. d example with 2 colors Register Allocation Optimistic Coloring 37 b c a apotential spill
  • 73. d example with 2 colors Register Allocation Optimistic Coloring 37 b c a a c potential spill
  • 74. d example with 2 colors Register Allocation Optimistic Coloring 37 c a b a c b potential spill
  • 75. d example with 2 colors Register Allocation Optimistic Coloring 37 c a b a c b potential spill
  • 76. d b example with 2 colors Register Allocation Optimistic Coloring 37 c a a c potential spill
  • 77. d b c example with 2 colors Register Allocation Optimistic Coloring 37 a apotential spill
  • 78. d a b c example with 2 colors Register Allocation Optimistic Coloring 37
  • 79. steps Register Allocation Spilling Simplify remove node of insignificant degree (less than k edges) Spill remove node of significant degree (k or more edges) Select add node, select color Actual spill Start over 38
  • 80. a example with 2 colors Register Allocation Spilling 39 b c
  • 81. a example with 2 colors Register Allocation Spilling 39 b c apotential spill
  • 82. a example with 2 colors Register Allocation Spilling 39 b c a c potential spill
  • 83. a b example with 2 colors Register Allocation Spilling 39 c a c potential spill
  • 84. a b c example with 2 colors Register Allocation Spilling 39 apotential spill
  • 85. a b c example with 2 colors Register Allocation Spilling 39 aactual spill
  • 86. return b a ← c + a c ← b + 1 b ← a + 1 example Register Allocation Spilling 40 a ← 1
  • 87. example Register Allocation Spilling 41 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 88. a1 ← 1 M[42] ← a1 example Register Allocation Spilling 41 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 89. a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] example Register Allocation Spilling 41 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 90. a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] a4 ← c + a3 M[42] ← a4 a3 ← M[42] example Register Allocation Spilling 41 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 91. example Register Allocation Spilling 42 a4 ← c + a3 M[42] ← a4 a3 ← M[42] a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 92. example Register Allocation Spilling 42 a4 ← c + a3 M[42] ← a4 a3 ← M[42] a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 93. example Register Allocation Spilling 42 a4 ← c + a3 M[42] ← a4 a3 ← M[42] a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 94. example Register Allocation Spilling 42 a4 ← c + a3 M[42] ← a4 a3 ← M[42] a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 95. example Register Allocation Spilling 42 a4 ← c + a3 M[42] ← a4 a3 ← M[42] a1 ← 1 M[42] ← a1 b ← a2 + 1 a2 ← M[42] a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 96. example Register Allocation Spilling 43 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 97. b2 ← M[42] c ← b2 + 1 example Register Allocation Spilling 43 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 98. b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 example Register Allocation Spilling 43 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 99. return b3 b3 ← M[42] b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 example Register Allocation Spilling 43 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 100. example Register Allocation Spilling 44 return b3 b3 ← M[42] b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 101. example Register Allocation Spilling 44 return b3 b3 ← M[42] b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 102. example Register Allocation Spilling 44 return b3 b3 ← M[42] b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 103. example Register Allocation Spilling 44 return b3 b3 ← M[42] b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 104. example Register Allocation Spilling 44 return b3 b3 ← M[42] b2 ← M[42] c ← b2 + 1 M[42] ← b1 b1 ← a + 1 a ← c + a c ← b + 1 b ← a + 1 a ← 1 return b
  • 106. coalescing Register Allocation Eliminating Move Instructions 46 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
  • 107. coalescing Register Allocation Eliminating Move Instructions 47 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
  • 108. Register Allocation Coalescing 48 coalesce |ˌkəʊəˈlɛs| verb [no object] come together to form one mass or whole: the puddles had coalesced into shallow streams. • [with object] combine (elements) in a mass or whole: his idea served to coalesce all that happened into one connected whole.
  • 109. j k example Register Allocation Recap: Graph Coloring 49 b m e f h g d c r1 r2 r3 r4 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
  • 110. j k example Register Allocation Recap: Graph Coloring 49 b m e f h g d c r1 r2 r3 r4 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
  • 111. j k example Register Allocation Recap: Graph Coloring 49 b m e f h g d c r1 r2 r3 r4 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
  • 112. j k better solution Register Allocation Coalescing 50 b m e f h g d c r1 r2 r3 r4 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
  • 113. j k better solution Register Allocation Coalescing 50 b m e f h g d c r1 r2 r3 r4 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
  • 114. j k better solution Register Allocation Coalescing 50 b m e f h g d c r1 r2 r3 r4 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
  • 115. jb k coalescing nodes Register Allocation Coalescing 51 m e f h g cd r1 r2 r3 r4 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
  • 116. conservative strategies Register Allocation Coalescing Briggs • a/b has fewer than k neighbours of significant degree • nodes of insignificant degree and a/b can be simplified • remaining graph is colorable George • all neighbours of a of significant degree interfere also with b • neighbours of a of insignificant degree can be simplified • subgraph of original graph is colorable 52
  • 117. steps Register Allocation Graph Coloring Simplify remove non-move-related node of insignificant degree Coalesce Freeze turn move-related node of insignificant degree into non-move-related Spill Select Start over 53
  • 118. j k example Register Allocation Coalescing 54 b m e f h g d c r1 r2 r3 r4 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
  • 119. j k example Register Allocation Coalescing 55 g b m e f h g d c r1 r2 r3 r4 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
  • 120. j k example Register Allocation Coalescing 56 g b m e f h g d c h r1 r2 r3 r4 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
  • 121. j k example Register Allocation Coalescing 57 g b m e f h g d c h k r1 r2 r3 r4 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
  • 122. j k example Register Allocation Coalescing 58 g b m e f h g h k cd r1 r2 r3 r4 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
  • 123. cd jb k example Register Allocation Coalescing 59 g m e f h g h k r1 r2 r3 r4 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
  • 124. cd jb k example Register Allocation Coalescing 60 g m e f h g h k cd r1 r2 r3 r4 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
  • 125. cd jb k example Register Allocation Coalescing 61 g m e f h g h k cd jb r1 r2 r3 r4 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
  • 126. cd jb k example Register Allocation Coalescing 62 g m e f h g h k cd jb fr1 r2 r3 r4 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
  • 127. cd jb k example Register Allocation Coalescing 63 g m e f h g h k cd jb f m r1 r2 r3 r4 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
  • 128. cd jb k example Register Allocation Coalescing 64 g m e f h g h k cd jb f m r1 r2 r3 r4 live-in: k j g := mem[j + 12] h := k - 1 f := g * h r1 := mem[j + 8] m := mem[j + 16] b := mem[f] c := r1 + 8 d := c k := m + 4 j := b live out: d k j
  • 129. cd jb k example Register Allocation Coalescing 65 g m e f h g h k cd jb fr1 r2 r3 r4 live-in: k j g := mem[j + 12] h := k - 1 f := g * h r1 := mem[j + 8] r2 := mem[j + 16] b := mem[f] c := r1 + 8 d := c k := r2 + 4 j := b live out: d k j
  • 130. cd jb k example Register Allocation Coalescing 66 g m e f h g h k cd jb r1 r2 r3 r4 live-in: k j g := mem[j + 12] h := k - 1 r3 := g * h r1 := mem[j + 8] r2 := mem[j + 16] b := mem[r3] c := r1 + 8 d := c k := r2 + 4 j := b live out: d k j
  • 131. cd jb k example Register Allocation Coalescing 67 g m e f h g h k cd r1 r2 r3 r4 live-in: k r4 g := mem[r4 + 12] h := k - 1 r3 := g * h r1 := mem[r4 + 8] r2 := mem[r4 + 16] b := mem[r3] c := r1 + 8 d := c k := r2 + 4 r4 := r4 live out: d k r4
  • 132. cd jb k example Register Allocation Coalescing 68 g m e f h g h k r1 r2 r3 r4 live-in: k r4 g := mem[r4 + 12] h := k - 1 r3 := g * h r1 := mem[r4 + 8] r2 := mem[r4 + 16] b := mem[r3] r1 := r1 + 8 r1 := r1 k := r2 + 4 r4 := r4 live out: r1 k r4
  • 133. cd jb k example Register Allocation Coalescing 69 g m e f h g h r1 r2 r3 r4 live-in: r2 r4 g := mem[r4 + 12] h := r2 - 1 r3 := g * h r1 := mem[r4 + 8] r2 := mem[r4 + 16] b := mem[r3] r1 := r1 + 8 r1 := r1 k := r2 + 4 r4 := r4 live out: r1 r2 r4
  • 134. cd jb k example Register Allocation Coalescing 70 g m e f h g r1 r2 r3 r4 live-in: r2 r4 g := mem[r4 + 12] r2 := r2 - 1 r3 := g * r2 r1 := mem[r4 + 8] r2 := mem[r4 + 16] b := mem[r3] r1 := r1 + 8 r1 := r1 k := r2 + 4 r4 := r4 live out: r1 r2 r4
  • 135. jb k coalescing nodes Register Allocation Coalescing 71 m e f h g cd r1 r2 r3 r4 live-in: r2 r4 r1 := mem[r4 + 12] r2 := r2 - 1 r3 := r1 * r2 r1 := mem[r4 + 8] r2 := mem[r4 + 16] b := mem[r3] r1 := r1 + 8 r1 := r1 k := r2 + 4 r4 := r4 live out: r1 r2 r4
  • 137. CDECL Register Allocation Recap: Calling Conventions Caller • push parameters right-to-left on the stack • clean-up stack after call Callee • save old BP • initialise new BP • save registers • return result in AX • restore registers • restore BP 73 push 21 push 42 call _f add ESP 8 push EBP mov EBP ESP mov EAX [EBP + 8] mov EDX [EBP + 12] add EAX EDX pop EBP ret
  • 138. STDCALL Register Allocation Recap: Calling Conventions Caller • push parameters right-to-left on the stack Callee • save old BP • initialise new BP • save registers • return result in AX • restore registers • restore BP 74 push 21 push 42 call _f@8 push EBP mov EBP ESP mov EAX [EBP + 8] mov EDX [EBP + 12] add EAX EDX pop EBP ret 8
  • 139. FASTCALL Register Allocation Recap: Calling Conventions Caller • passes parameters in registers • pushes additional parameters right-to-left on the stack • cleans up the stack Callee • save old BP, initialise new BP • save registers • return result in AX • restore registers • restore BP 75 mov ECX 21 mov EDX 42 call @f@8 push EBP mov EBP ESP mov EAX ECX add EAX EDX pop EBP ret
  • 140. saving registers Register Allocation Recap: Calling Conventions Not enough registers for all local variables across life time • save register to memory to free for other use Caller-save registers • Caller is responsible for saving and restoring register Callee-save registers • Callee is responsible for saving and restoring register Use callee-save registers to pass parameters 76
  • 141. representing registers Register Allocation Pre-Colored Nodes Nodes • register = pre-colored node • no simplify, no spill • coalesce possible Edges • all registers interfere with each other • explicit usage of registers • call and return instructions influence liveness 77
  • 142. pre-colored nodes Register Allocation Callee-Save Register in Temporary 78 enter: def(r7) … exit: use(r7) enter: def(r7) t ← r7 … r7 ← t exit: use(r7)
  • 143. example Register Allocation Pre-Colored Nodes 79 enter : c ← r3 // callee-save a ← r1 // caller-save b ← r2 // caller-save d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3 live out) int f(int a, int b) { int d = 0; int e = a; do { d = d + b; e = e - 1; } while (e > 0); return d; } machine has 3 registers
  • 144. example Register Allocation Pre-Colored Nodes 80 r3 r2 b e r1 a d c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3)
  • 145. example Register Allocation Pre-Colored Nodes 81 r3 r2 b e r1 a d c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) c spill c
  • 146. example Register Allocation Pre-Colored Nodes 82 r3 r2 b r1 ae d c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) c coalesce a and e
  • 147. example Register Allocation Pre-Colored Nodes 83 r3 br2 r1 ae d c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) c coalesce r2 and b
  • 148. example Register Allocation Pre-Colored Nodes 84 r3 br2 r1ae d c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) c coalesce r1 and ae
  • 149. example Register Allocation Pre-Colored Nodes 85 r3 br2 r1ae d c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) c simplify d d
  • 150. example Register Allocation Pre-Colored Nodes 86 r3 br2 r1ae r3 c enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) c color d as r3
  • 151. example Register Allocation Pre-Colored Nodes 87 r3 br2 r1ae r3 c enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) c spill c
  • 152. example Register Allocation Pre-Colored Nodes 88 r3 br2 r1ae r3 c enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) spill c
  • 153. examples Register Allocation Pre-Colored Nodes 89 r3 r2 b e r1 a d c enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) start over
  • 154. examples Register Allocation Pre-Colored Nodes 90 r3 r2 b e r1 a d c enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3)
  • 155. examples Register Allocation Pre-Colored Nodes 91 r3 r2 b e r1 a d c1 enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) c2 new graph
  • 156. examples Register Allocation Pre-Colored Nodes 92 r3 r2 b e r1 a d c1 enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) c2 coalesce c1, c2, r3
  • 157. examples Register Allocation Pre-Colored Nodes 93 c1c2r3 r2 b e r1 a d c1 enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) c2 coalesce c1, c2, r3
  • 158. examples Register Allocation Pre-Colored Nodes 94 c1c2r3 r2 b e r1 a d enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) coalesce (b, r2) and (a, e)
  • 159. examples Register Allocation Pre-Colored Nodes 95 c1c2r3 br2 r1 ae d enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) coalesce (ae, r1)
  • 160. examples Register Allocation Pre-Colored Nodes 96 c1c2r3 br2 r1ae d enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) simplify d d
  • 161. examples Register Allocation Pre-Colored Nodes 97 c1c2r3 br2 r1ae r3 enter : c1 ← r3 M[cloc] ← c1 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c2 c2 ← M[cloc] return (r1, r3) color d as r3 d
  • 162. examples Register Allocation Pre-Colored Nodes 98 c1c2r3 br2 r1ae r3 enter : r3 ← r3 M[cloc] ← r3 r1 ← r1 r2 ← r2 r3 ← 0 r1 ← r1 loop : r3 ← r3 + r2 r1 ← r1 - 1 if r1 > 0 goto loop r1 ← r3 r3 ← r3 r3 ← M[cloc] return (r1, r3) apply register assigment
  • 163. example Register Allocation Pre-Colored Nodes 99 enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) enter : r3 ← r3 M[cloc] ← r3 r1 ← r1 r2 ← r2 r3 ← 0 r1 ← r1 loop : r3 ← r3 + r2 r1 ← r1 - 1 if r1 > 0 goto loop r1 ← r3 r3 ← r3 r3 ← M[cloc] return (r1, r3)
  • 164. example Register Allocation Pre-Colored Nodes 100 enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) enter : r3 ← r3 M[cloc] ← r3 r1 ← r1 r2 ← r2 r3 ← 0 r1 ← r1 loop : r3 ← r3 + r2 r1 ← r1 - 1 if r1 > 0 goto loop r1 ← r3 r3 ← r3 r3 ← M[cloc] return (r1, r3)
  • 165. example Register Allocation Pre-Colored Nodes 101 enter : c ← r3 a ← r1 b ← r2 d ← 0 e ← a loop : d ← d + b e ← e - 1 if e > 0 goto loop r1 ← d r3 ← c return (r1, r3) enter : M[cloc] ← r3 r3 ← 0 loop : r3 ← r3 + r2 r1 ← r1 - 1 if r1 > 0 goto loop r1 ← r3 r3 ← M[cloc] return (r1, r3)
  • 166. example Register Allocation Pre-Colored Nodes 102 enter : M[cloc] ← r3 r3 ← 0 loop : r3 ← r3 + r2 r1 ← r1 - 1 if r1 > 0 goto loop r3 ← M[cloc] return (r1, r3) int f(int a, int b) { int d = 0; int e = a; do { d = d + b; e = e - 1; } while (e > 0); return d; }
  • 168. lessons learned Register Allocation Summary How can we assign registers to local variables and temporaries? • perform liveness analysis • build interference graph • color interference graph What to do if the graph is not colorable? • keep local variables in memory How to handle move instructions efficiently? • coalesce nodes safely 104
  • 169. learn more Register Allocation Literature Andrew W. Appel, Jens Palsberg: Modern Compiler Implementation in Java, 2nd edition. 2002 Lal George, Andrew W. Appel: Iterative Register Coalescing. POPL 1996 Lal George, Andrew W. Appel: Iterative Register Coalescing. TOPLAS 18(3), 1996 105
  • 170. coming next Register Allocation Outlook Compiler components & their generators • Lecture 12: Data-Flow Analysis Dec 6 • Lecture 13: Register Allocation Dec 13 • Lecture 14: LL Parsing Dec 20 • Lecture 15: LR Parsing Jan 10 Exam preparation • Question & Answer & Outlook Jan 24 • Exam Jan 31 106
  • 173. attribution & copyrights Register Allocation Pictures Slide 1: Colors #2 by Carmelo Speltino, some rights reserved Slide 40: Tchibo by Dominica Williamson, some rights reserved 109