View
2
Download
0
Category
Preview:
Citation preview
Introduction Difficulty of register allocation The coalescing problem Conclusion
A Study of Spilling and Coalescing in RegisterAllocation as Two Separate Phases
Ph.D. Defense
Florent Bouchezflorent.bouchez@ens-lyon.org
CompsysLIP UMR CNRS — Inria — ENS Lyon — UCBL
France
April 30th 2009
BU
1 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Compilation
foo.c foo.bin
Our interest
Register allocation, one of the latest steps.
ZO
2 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
French folklore: Les Shadoks
MEU
3 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Shadoks have a very small brain
BU GA
4 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Shadoks have a very small brain
BU GA
4 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Shadoks have a very small brain
BU GA
4 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Shadoks have a very small brain
BU GA
4 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Shadoks have a very small brain
BU GA
4 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Shadoks have a very small brain
BU GA
4 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The shadoks at the library
BU BU
5 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is register allocation?
Assign variables to memorylocations
Registers: , , , . . .
Memory: infinite
Rules of the game
two interfering variablesà different registers
not enough registersà spill to memory
a← 3425n← 0
a 6= 1 ?
n← n + 1a even ?
a← a/2 a← 3× a + 1
print nBU ZO
6 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is register allocation?
Assign variables to memorylocations
Registers: , , , . . .
Memory: infinite
Rules of the game
two interfering variablesà different registers
not enough registersà spill to memory
Plus constraints:
register constraints
pre-colored variables
register pairing,aliasing,. . .
BU ZO
6 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin et al. model
Live-in: k jg := mem[j+12]h := k-1f := g+he := mem[j+8]m := mem[j+16]b := mem[f]c := e+8d := ck := m+4j := b
Live-out: d k j
Live-rangesg
h
f
e
m
b
c
d
g
h
f
e
m
b
c
d
kj
jk
BU MEU
7 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin et al. model
Interference graph
k
j
g
h
f
e
mb c
d
Live-rangesg
h
f
e
m
b
c
d
g
h
f
e
m
b
c
d
kj
jk
BU MEU
7 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin et al. model
Interference graph
k
j
g
h
f
e
mb c
d
Live-rangesg
h
f
e
m
b
c
d
g
h
f
e
m
b
c
d
kj
jk
BU MEU
7 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.
Problem
Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)
à register allocation is NP-complete in this model.
A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme
If coloring fails, usually spill.Disadvantages:
The scheme might fail even when there is a solution.
à need to spill more than necessary
A variable is supposed to be in exactly one register.
à restriction on the coloring
ZO GA
8 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.
Problem
Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)
à register allocation is NP-complete in this model.
A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme
If coloring fails, usually spill.
Disadvantages: The scheme might fail even when there is a solution.
à need to spill more than necessary
A variable is supposed to be in exactly one register.
à restriction on the coloring
ZO GA
8 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.
Problem
Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)
à register allocation is NP-complete in this model.
A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme
If coloring fails, usually spill.Disadvantages:
The scheme might fail even when there is a solution.
à need to spill more than necessary
A variable is supposed to be in exactly one register.
à restriction on the coloring
ZO GA
8 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.
Problem
Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)
à register allocation is NP-complete in this model.
A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme
If coloring fails, usually spill.Disadvantages:
The scheme might fail even when there is a solution.à need to spill more than necessary
A variable is supposed to be in exactly one register.à restriction on the coloring
ZO GA
8 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Outline
1 IntroductionLes ShadoksRegister allocation
2 Difficulty of register allocationStrict SSA graphs are chordalQuestions with register allocation in two phases
3 The coalescing problemIntroduction to coalescingIncremental coalescing
ZO BU
9 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Outline
1 IntroductionLes ShadoksRegister allocation
2 Difficulty of register allocationStrict SSA graphs are chordalQuestions with register allocation in two phases
3 The coalescing problemIntroduction to coalescingIncremental coalescing
ZO ZO
10 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
SSA interference graphs are chordal
In 2002, Darte realized that the interference graph of programs understrict SSA are chordal.(The same discovery was made independently by Brisk and Hack in 2004-2005.)
à Starting point of this thesis
Theorem
The interference graph of a program under strict SSA form is chordal.
ZO MEU
11 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
SSA interference graphs are chordal
In 2002, Darte realized that the interference graph of programs understrict SSA are chordal.(The same discovery was made independently by Brisk and Hack in 2004-2005.)
à Starting point of this thesis
Theorem
The interference graph of a program under strict SSA form is chordal.
ZO MEU
11 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a b c
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
d
e
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
d
e
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
d
e
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
d
e
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
d
e
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs
Definition (Chordal graph)
A graph is chordal iff every cycle of size ≥ 4 has a chord.
a
b
c
d
e
Chordal graphs are perfect and easy to color.
MEU GA
12 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Static Single AssignmentSSA : exactly one textual definition per variable
strictness : SSA where the definition always dominates its uses
MEU BU
13 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Static Single AssignmentSSA : exactly one textual definition per variable
strictness : SSA where the definition always dominates its uses
Example (Straight code converted to SSA form)
a← . . ....
. . .← a...
a← . . ....
. . .← a
a1 ← . . ....
. . .← a1...
a2 ← . . ....
. . .← a2
MEU BU
13 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Static Single AssignmentSSA : exactly one textual definition per variable
strictness : SSA where the definition always dominates its uses
Example (Conditional code converted to SSA form)
if (. . . )
a← 1 a← 2
. . .← a
if (. . . )
a1 ← 1 a2 ← 2
a3 ← φ(a1, a2). . .← a3
MEU BU
13 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Static Single AssignmentSSA : exactly one textual definition per variable
strictness : SSA where the definition always dominates its uses
Example (strict SSA or SSA with dominance property)
if (. . . )
a1 ← 1 . . .
. . .← a1
if (. . . )
a1 ← 1 . . .
a2 ← φ(a1,⊥). . .← a2
MEU BU
13 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Proof that strict SSA interference graphs are chordal
Theorem
The interference graph of a program under strict SSA form is chordal.
Proof.
a
b
c
d
e
dominance property
a and b interfere ⇒ def (a) dominates def (b)(or the converse)
direct each edge with dominance
def (d) is dominated by def (c) and def (e)
c and e are live at def (d)
MEU ZO
14 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Proof that strict SSA interference graphs are chordal
Theorem
The interference graph of a program under strict SSA form is chordal.
Proof.
a
b
c
d
e
dominance property
a and b interfere ⇒ def (a) dominates def (b)(or the converse)
direct each edge with dominance
def (d) is dominated by def (c) and def (e)
c and e are live at def (d)
MEU ZO
14 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Proof that strict SSA interference graphs are chordal
Theorem
The interference graph of a program under strict SSA form is chordal.
Proof.
a
b
c
d
e
dominance property
a and b interfere ⇒ def (a) dominates def (b)(or the converse)
direct each edge with dominance
def (d) is dominated by def (c) and def (e)
c and e are live at def (d)
MEU ZO
14 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Proof that strict SSA interference graphs are chordal
Theorem
The interference graph of a program under strict SSA form is chordal.
Proof.
a
b
c
d
e
dominance property
a and b interfere ⇒ def (a) dominates def (b)(or the converse)
direct each edge with dominance
def (d) is dominated by def (c) and def (e)
c and e are live at def (d)
MEU ZO
14 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Proof that strict SSA interference graphs are chordal
Theorem
The interference graph of a program under strict SSA form is chordal.
Proof.
a
b
c
d
e
dominance property
a and b interfere ⇒ def (a) dominates def (b)(or the converse)
direct each edge with dominance
def (d) is dominated by def (c) and def (e)
c and e are live at def (d)
MEU ZO
14 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Proof that strict SSA interference graphs are chordal
Theorem
The interference graph of a program under strict SSA form is chordal.
Proof.
a
b
c
d
e
dominance property
a and b interfere ⇒ def (a) dominates def (b)(or the converse)
direct each edge with dominance
def (d) is dominated by def (c) and def (e)
c and e are live at def (d)
MEU ZO
14 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Strict SSA programs are easy to colorChordal graphs are perfect graphs, hence easy to color. We proved more:
Theorem
Chordal graphs are colorable using Chaitin et al. greedy scheme.They are greedy-k-colorable.
General program:NP-complete
strict SSA program:greedy-k-colorable
Under strict SSA, Maxlive, the maximum number of simultaneously livevariables, is the coloring indicator:
Maxlive ≤ R
MEU MEU
15 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Strict SSA programs are easy to colorChordal graphs are perfect graphs, hence easy to color. We proved more:
Theorem
Chordal graphs are colorable using Chaitin et al. greedy scheme.They are greedy-k-colorable.
General program:NP-complete
strict SSA program:greedy-k-colorable
Under strict SSA, Maxlive, the maximum number of simultaneously livevariables, is the coloring indicator:
Maxlive ≤ R
MEU MEU
15 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Register allocation in two phases
Using Maxlive, it seems possible to use a very simple register allocationscheme:
1 spill variables until Maxlive ≤ R
2 transform program into strict SSA form
3 allocate variables using R registers
4 go out of colored SSA form
Questions
SSA seems to transform an NP-complete problem into polynomial one. . .Where is the complexity now? What else is simplified?
BU GA GA
16 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Register allocation in two phases
Using Maxlive, it seems possible to use a very simple register allocationscheme:
1 spill variables until Maxlive ≤ R
2 transform program into strict SSA form
3 allocate variables using R registers
4 go out of colored SSA form
Questions
SSA seems to transform an NP-complete problem into polynomial one. . .Where is the complexity now? What else is simplified?
BU GA GA
16 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
BU GA BU
17 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
revisitChaitin’s
proof
criticalflow-edgesplitting
swapproblem
# simult.defs
BU GA BU
17 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin’s proof revisited
No Yes
* on basic block borders only
Proofcriti
cal edges
variable
splitting
complexity
Chaitin et al.NP-complete
Thm. 3.1NP-complete
Sec. 3.2.1 (SSA) *polynomial
Thm. 3.2 *NP-complete
Thm. 3.4 (Col. prop.)polynomial
Thm. 3.3NP-complete
BU GA ZO
18 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin’s proof revisited
No Yes
* on basic block borders only
Proofcriti
cal edges
variable
splitting
complexity
Chaitin et al.NP-complete
Thm. 3.1NP-complete
Sec. 3.2.1 (SSA) *polynomial
Thm. 3.2 *NP-complete
Thm. 3.4 (Col. prop.)polynomial
Thm. 3.3NP-complete
BU GA ZO
18 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin’s proof revisited
No Yes* on basic block borders only
Proofcriti
cal edges
variable
splitting
Swap instructio
n
complexity
Chaitin et al.NP-complete
Thm. 3.1NP-complete
Sec. 3.2.1 (SSA) *polynomial
Thm. 3.2 *NP-complete
Thm. 3.4 (Col. prop.)polynomial
Thm. 3.3NP-complete
BU GA ZO
18 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin’s proof revisited
No Yes* on basic block borders only
Proofcriti
cal edges
variable
splitting
Swap instructio
n
complexity
Chaitin et al.NP-complete
Thm. 3.1NP-complete
Sec. 3.2.1 (SSA) *polynomial
Thm. 3.2 *NP-complete
Thm. 3.4 (Col. prop.)polynomial
Thm. 3.3NP-complete
BU GA ZO
18 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chaitin’s proof revisited
No Yes* on basic block borders only
Proofcriti
cal edges
variable
splitting
Swap instructio
n
2 simult.
def.
complexity
Chaitin et al.NP-complete
Thm. 3.1NP-complete
Sec. 3.2.1 (SSA) *polynomial
Thm. 3.2 *NP-complete
Thm. 3.4 (Col. prop.)polynomial
Thm. 3.3NP-complete
BU GA ZO
18 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
revisitChaitin’s
proof
criticalflow-edgesplitting
swapproblem
# simult.defs
BU GA MEU
19 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
revisitChaitin’s
proof
criticalflow-edgesplitting
swapproblem
# simult.defs
criticalflow-edgesplitting
π-motion
BU GA MEU
19 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not.
Short answer: No
BU BU GA
20 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No
BU BU GA
20 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No
Longer answer:
Chordal graph= SSA case
Interval graph= basic block
weighted
no
yes
no
yes
Ω′ ≤ C
dyn. prog.
Ω′ ≤ R
furthest use
ILP
Ω′ ≤ Ω− 1
X3C
dyn. prog.
polynomial NP-complete new result
Previous studies by Belady, Yannakakis&Gavril, and Liberatore.
BU BU GA
20 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No
Longer answer:
Chordal graph= SSA case
Interval graph= basic block
weighted
no
yes
no
yes
Ω′ ≤ C
dyn. prog.
Ω′ ≤ R
furthest use
ILP
Ω′ ≤ Ω− 1
X3C
dyn. prog.
polynomial NP-complete new result
Previous studies by Belady, Yannakakis&Gavril, and Liberatore.
BU BU GA
20 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No
The problem of “holes.”
On RISC architectures, spilled variables leave small intervals behind.
a← . . ..... . .← a.... . .← a
spill a
a1 ← . . .store a1...a2 ← load. . .← a2...a3 ← load. . .← a3
BU BU GA
20 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No
With “holes,” it becomes harder even on a basic block:
h = 1
h ≥ 2
h notbounded
weight
no
yes
no
yes
no
yes
Ω′ ≤ C
dyn. prog.
Ω′ ≤ R
?
stable set
stable set
Ω′ ≤ Ω− C
dyn. prog.
Ω′ ≤ Ω− 1
set cover
polynomial NP-complete new result
BU BU GA
20 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
revisitChaitin’s
proof
criticalflow-edgesplitting
swapproblem
# simult.defs
criticalflow-edgesplitting
π-motion
spilling NOTsimplifiedby SSA
BU BU BU
21 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
revisitChaitin’s
proof
criticalflow-edgesplitting
swapproblem
# simult.defs
criticalflow-edgesplitting
π-motion
spilling NOTsimplifiedby SSA
Coalescing(out-of-SSA)
edgesplitting
π-motion
heuristicscomplexity
BU BU BU
21 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Outline
1 IntroductionLes ShadoksRegister allocation
2 Difficulty of register allocationStrict SSA graphs are chordalQuestions with register allocation in two phases
3 The coalescing problemIntroduction to coalescingIncremental coalescing
BU BU ZO
22 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is coalescing?
Goal of coalescing
Removing the register-to-register copies [move a← b]
Numerous move due to:
live-range splitting toavoid spilling
register constraints
SSA destruction
Not a new problem, butnever studied not intermixedwith spilling.
BU BU MEU
23 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is coalescing?
Goal of coalescing
Removing the register-to-register copies [move a← b]
Numerous move due to:
live-range splitting toavoid spilling
register constraints
SSA destruction
Not a new problem, butnever studied not intermixedwith spilling.
a← . . .b← . . .c← f(a, b)
a← . . .b← . . .move R0,amove R1,bcall fmove c,R0
BU BU MEU
23 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is coalescing?
Goal of coalescing
Removing the register-to-register copies [move a← b]
Numerous move due to:
live-range splitting toavoid spilling
register constraints
SSA destruction
Not a new problem, butnever studied not intermixedwith spilling.
if (. . . )
a1 ← 1 a2 ← 2
a3 ← φ(a1, a2)· · · ← a3
BU BU MEU
23 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is coalescing?
Goal of coalescing
Removing the register-to-register copies [move a← b]
Numerous move due to:
live-range splitting toavoid spilling
register constraints
SSA destruction
Not a new problem, butnever studied not intermixedwith spilling.
if (. . . )
a1 ← 1 a2 ← 2
a3 ← φ(a1, a2)· · · ← a3
move a3 ← a1 move a3 ← a2
BU BU MEU
23 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
What is coalescing?
Goal of coalescing
Removing the register-to-register copies [move a← b]
Numerous move due to:
live-range splitting toavoid spilling
register constraints
SSA destruction
Not a new problem, butnever studied not intermixedwith spilling.
if (. . . )
a1 ← 1 a2 ← 2
a3 ← φ(a1, a2)· · · ← a3
move a3 ← a1 move a3 ← a2
BU BU MEU
23 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Traditional modeling of the coalescing problem
Given an instruction [move a← b]
Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.
Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.
a
b c
d
Merge a and bab
c
d
We work on graphs instead of programs.
BU ZO GA
24 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Traditional modeling of the coalescing problem
Given an instruction [move a← b]
Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.
Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.
a
b c
d
Merge a and bab
c
d
We work on graphs instead of programs.
BU ZO GA
24 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Traditional modeling of the coalescing problem
Given an instruction [move a← b]
Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.
Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.
a
b c
d
Merge a and bab
c
d
We work on graphs instead of programs.
BU ZO GA
24 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Traditional modeling of the coalescing problem
Given an instruction [move a← b]
Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.
Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.
a
b c
d
Merge a and bab
c
d
We work on graphs instead of programs.
BU ZO GA
24 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
Incremental
Conservative
Optimistic
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
Coalesce as many affinitiesas possible.
Incremental
Conservative
Optimistic
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
Conservative
Optimistic
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
Conservative
Coalesce as many affinities aspossible but remains k-colorable.
Optimistic
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
Conservative
a
b
d
c
e
a
b
d
c
e
x〈a,c〉
y〈a,c〉x〈b,a〉
y〈b,a〉
x〈d,b〉
y〈d,b〉 x〈c,d〉
y〈c,d〉
x〈c,e〉
y〈c,e〉
graph k-coloring
Optimistic
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
Conservative
a
b
d
c
e
a
b
d
c
e
x〈a,c〉
y〈a,c〉x〈b,a〉
y〈b,a〉
x〈d,b〉
y〈d,b〉 x〈c,d〉
y〈c,d〉
x〈c,e〉
y〈c,e〉
graph k-coloring
Optimistic
Perform aggressive coalescing, thende-coalescing to get k-colorable.
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
Conservative
a
b
d
c
e
a
b
d
c
e
x〈a,c〉
y〈a,c〉x〈b,a〉
y〈b,a〉
x〈d,b〉
y〈d,b〉 x〈c,d〉
y〈c,d〉
x〈c,e〉
y〈c,e〉
graph k-coloring
Optimistic
cv
v1
v2
v3cv
c′v
v1
v2
v3
cv
v1
v2
v3
3-vertex-cover
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
Coalesce one affinity while stayingk-colorable.
Conservative
a
b
d
c
e
a
b
d
c
e
x〈a,c〉
y〈a,c〉x〈b,a〉
y〈b,a〉
x〈d,b〉
y〈d,b〉 x〈c,d〉
y〈c,d〉
x〈c,e〉
y〈c,e〉
graph k-coloring
Optimistic
cv
v1
v2
v3cv
c′v
v1
v2
v3
cv
v1
v2
v3
3-vertex-cover
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
T
F
R
ci,1bi,1
ai,1yi,1
ai,2yi,2
ci,2bi,2
ai,3yi,3
ai,4yi,4
3-SAT
NP-complete for general graphs.
Polynomial for chordal graphs.
Conservative
a
b
d
c
e
a
b
d
c
e
x〈a,c〉
y〈a,c〉x〈b,a〉
y〈b,a〉
x〈d,b〉
y〈d,b〉 x〈c,d〉
y〈c,d〉
x〈c,e〉
y〈c,e〉
graph k-coloring
Optimistic
cv
v1
v2
v3cv
c′v
v1
v2
v3
cv
v1
v2
v3
3-vertex-cover
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Different coalescing problems
Aggressive
s1s2
s3
uw
v
edge removeds1
s2
s3
uw
v
affinity notcoalesced
multiway-cut
Incremental
T
F
R
ci,1bi,1
ai,1yi,1
ai,2yi,2
ci,2bi,2
ai,3yi,3
ai,4yi,4
3-SAT
NP-complete for general graphs.
Polynomial for chordal graphs.
Conservative
a
b
d
c
e
a
b
d
c
e
x〈a,c〉
y〈a,c〉x〈b,a〉
y〈b,a〉
x〈d,b〉
y〈d,b〉 x〈c,d〉
y〈c,d〉
x〈c,e〉
y〈c,e〉
graph k-coloring
Optimistic
cv
v1
v2
v3cv
c′v
v1
v2
v3
cv
v1
v2
v3
3-vertex-cover
BU ZO BU
25 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
The problem of incremental coalescing
The goal of incremental is to perform conservative coalescing bycoalescing affinities one by one.
Problem (Incremental coalescing)
Given a k-colorable graph G and two nodes x and y, is it possible to colorG such that x and y have the same color?
Theorem
The incremental coalescing problem is NP-complete.
BU ZO ZO
26 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
x
x
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
x
x
y
y
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
x
x
y
yzz
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
x
x
y
yzz
w
w
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
x
x
y
yzz
w
w
v
v
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
First, equivalence between graph-3-coloring and 4-SAT.
3 nodes for True, False, and X
2 nodes for each variable: v and v
. . . and a widget to forbid everyvariable of a clause to be false
X
T F
x
x
y
yzz
w
w
v
v
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
w
z
y
x
T
F
X
Need a widget that is 3-colorable only if not all 4 variables are false.
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
w
z
y
x
T
F
X
Need a widget that is 3-colorable only if not all 4 variables are false.
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
w
z
y
x
T
F
X
If all 4 variables are false, not 3-colorable.
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
w
z
y
x
T
F
X
If at least one variable is true
, 3-colorable.
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
w
z
y
x
T
F
X
If at least one variable is true
, 3-colorable.
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
w
z
y
x
T
F
X
If at least one variable is true, 3-colorable.
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
Now, transform 3-SAT instance into 4-SAT by adding x0 to every clause:
(y ∨ z ∨ w) ∧ · · · ∧ (z ∨ y ∨ u)
becomes
(x0 ∨ y ∨ z ∨ w) ∧ · · · ∧ (x0 ∨ z ∨ y ∨ u)
Clearly, x0 =True satisfies the equation (i.e., the graph is 3-colorable).
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
Now, transform 3-SAT instance into 4-SAT by adding x0 to every clause:
(y ∨ z ∨ w) ∧ · · · ∧ (z ∨ y ∨ u)
becomes
(x0 ∨ y ∨ z ∨ w) ∧ · · · ∧ (x0 ∨ z ∨ y ∨ u)
Clearly, x0 =True satisfies the equation (i.e., the graph is 3-colorable).
Now, ask x0 and False to be coalesced. . .
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).
Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).
To conclude:
3-SAT is true ⇐⇒ 4-SAT is true with x0 = False
⇐⇒ graph is 3-colorable with x0 in red/False
⇐⇒ incremental coalescing of x0 with False is possible
BU ZO MEU
27 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Incremental coalescing for chordal graphs
Problem (Incremental coalescing for chordal graphs)
Given a k-colorable chordal graph G and two nodes x and y. Is it possibleto color G such that x and y have the same color?
This problem is polynomial!
Moreover, if the answer is yes, it is possible to modify G so that x and y are
merged and G stays chordal.
The same question with greedy-k-colorable graphs is still open.
BU MEU GA
28 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Example on a chordal graph
Let us consider a 3-colorable chordal graph.
Demo: graph in ubigraph
BU MEU BU
29 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs as subtrees of a tree
BU MEU ZO
30 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs as subtrees of a tree
BU MEU ZO
30 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Chordal graphs as subtrees of a tree
BU MEU ZO
30 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
xy
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.
x y
BU MEU MEU
31 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
A simple algorithmic strategy for chordal incrementalcoalescing
Building the representation of a chordal graph as subtrees of a tree ispainful.
We have devised an algorithmic strategy that works directly on the graph,using the same ideas as in Chaitin et al.’s greedy coloring algorithm.
ZO GA GA
32 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Demonstration of coalescingDemonstration of conservative coalescing on graph #311 of the“Coalescing Challenge.” (Appel&George)
Demo: conservative coalescing ZO GA BU
33 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Questions raised by register allocation in two phases
SSA = chordal(2002)
spillingsimplifiedby SSA?
Coalescing(out-of-SSA)
Chaitin’sproof
revisitChaitin’s
proof
criticalflow-edgesplitting
swapproblem
# simult.defs
criticalflow-edgesplitting
π-motion
spilling NOTsimplifiedby SSA
Coalescing(out-of-SSA)
edgesplitting
π-motion
heuristicscomplexity
WDDD’06
LCPC’06 (ext)LCTES’07 CGO’07
(best paper) CASES’08
not published
ZO GA ZO
34 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Conclusion: practical work going on
This work was part of a collaboration with STMicroelectronics in Grenoble.Practical experiments were made during this thesis (coalescing). But a lotmore are going on, including:
including Hack’s spilling in LAO
experimenting new coalescing strategies in LAO
experimenting the permutation motion to avoid splitting edges
ZO GA MEU
35 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Conclusion
Why are those results important for register allocation?The idea of separating register allocation in two phases has been aroundfor a while:
spilling is the most important issue
splitting helps (Briggs, Cooper) but copies are hard to remove
greedy coloring is not a good indicator for spilling
Assuming that some copies are always better than a spill:
Maxlive is an “oracle” for spilling
spilling can be optimized first so that Maxlive ≤ R
good coalescing strategies: do not worry about splitting anymore
ZO BU GA
36 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
Remaining problems to work on
continuing the work on permutation motion
improving the spilling as a first phase
having a better “oracle” that handles registers constraints(Pereira&Palsberg)
register allocation in two phases for JIT
Maxlive indicator can be used for better instruction scheduling
Bonus: what will be written left to the pumping shadoks in next slide?
ZO BU BU
37 / 39
Introduction Difficulty of register allocation The coalescing problem Conclusion
That’s all for today
Answer: ZO BU ZO
ZO BU ZO
38 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
i
j
c ′
d ′
g ′
1
2
34
2
332
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
i
j
j
c ′
d ′
g ′ 2
24
2
332
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
g
i
j
j
c ′
d ′
g ′
13
2
332
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
g
i
i
j
j
c ′
d ′
g ′
2
2
332
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e
f
f
g
g
i
i
j
j
c ′
d ′
g ′1
232
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e
f
f
g
g
i
i
j
j
c ′
d ′
g ′g ′
132
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d
e
e
f
f
g
g
i
i
j
j
c ′
d ′
g ′g ′
22
4 4
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′
g ′g ′
2
3 3
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′2 2
3
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
b
c
c
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′1
2
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
b
b
c
c
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′
1
1
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a a
b
b
c
c
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a a
b
b
c
c
dd
e
e
f
f
g
g
i
i
j
jc ′
c ′
d ′ d ′
g ′g ′
Hi-degree nodeLow-degree node
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a a
b
b
c
c
dd
e
e
f
f
g
g
i
i
j
jc ′
c ′
d ′ d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a a
b
b
c
c
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
b
b
c
c
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
b
c
c
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′ d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
dd
e
e
f
f
g
g
i
i
j
j
c ′
d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d
e
e
f
f
g
g
i
i
j
j
c ′
d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e
f
f
g
g
i
i
j
j
c ′
d ′
g ′g ′
Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e
f
f
g
g
i
i
j
j
c ′
d ′
g ′Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
g
i
i
j
j
c ′
d ′
g ′Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
g
i
j
j
c ′
d ′
g ′Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
i
j
j
c ′
d ′
g ′Return
ZO BU MEU
39 / 39
Greedy coloring scheme of Chaitin et al.
Greedy-k-colorable-graphs: simplify nodes with < k neighbors.
Sta
ck
a
bc
d e f
g
i
j
c ′
d ′
g ′Return
ZO BU MEU
39 / 39
Recommended