Global Register Allocation
(Slides from Andrew Myers)
Monday, October 17, 2011
Main idea
• Want to replace temporary variables with
some fixed set of registers
• First
: need to know which variables are
live after each instruction
– Two simultaneously live variables cannot be
allocated to the same register
Monday, October 17, 2011
Register allocation
• For every node
n
in CFG, we have
out[n]
– Set of temporaries live out of n
• Two variables
interfere
if
– both initially live (ie: function args), or
– both appear in out[n] for any n
• How to assign registers to variables?
Monday, October 17, 2011
Interference graph
• Nodes
of the graph = variables
• Edges
connect variables that interfere with
one another
• Nodes will be assigned a
color
corresponding to the register assigned to
the variable
• Two colors can’t be next to one another in
the graph
Monday, October 17, 2011
Interference graph
Instructions
Live vars
b = a + 2
c = b * b
b = c + 1
return b * a
Monday, October 17, 2011
Interference graph
Instructions
Live vars
b = a + 2
c = b * b
b = c + 1
b,a
return b * a
Monday, October 17, 2011
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentInterference graph
Instructions
Live vars
b = a + 2
c = b * b
a,c
b = c + 1
b,a
return b * a
Monday, October 17, 2011
Interference graph
Instructions
Live vars
b = a + 2
b,a
c = b * b
a,c
b = c + 1
b,a
return b * a
Monday, October 17, 2011
Interference graph
Instructions
Live vars
a
b = a + 2
b,a
c = b * b
a,c
b = c + 1
b,a
return b * a
Monday, October 17, 2011
Interference graph
Instructions
Live vars
a
b = a + 2
a,b
c = b * b
a,c
b = c + 1
a,b
return b * a
a
c
b
eax
ebx
color
register
Monday, October 17, 2011
Interference graph
Instructions
Live vars
a
b = a + 2
a,b
c = b * b
a,c
b = c + 1
a,b
return b * a
a
c
b
eax
ebx
color
register
Monday, October 17, 2011
Graph coloring
• Questions:
– Can we efficiently find a coloring of the graph
whenever possible?
– Can we efficiently find the optimum coloring of
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 TEST
 Graph Theory, Monday, Graph coloring, register allocation

Click to edit the document details