Advanced Conservative and Optimistic Register Coalescing
F. Bouchez A. Darte F. Rastello
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
ENS Lyon CNRS Inria
CASES’08
1 / 20
Outline 1
Where does the coalescing come from? Why to coalesce? Register allocation in two phases Coalescing is a difficult problem “Coalescing Challenge”
2
Advanced coalescing for greedy-k-colorable graphs Incremental rules Brute-force solution: checking greedy-k-colorability Experiments & results
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
2 / 20
Outline 1
Where does the coalescing come from? Why to coalesce? Register allocation in two phases Coalescing is a difficult problem “Coalescing Challenge”
2
Advanced coalescing for greedy-k-colorable graphs Incremental rules Brute-force solution: checking greedy-k-colorability Experiments & results
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
3 / 20
Why coalescing? Goal of coalescing Removing the register-to-register copies [move a,b] Numerous move due to: live-range splitting to avoid spilling
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
4 / 20
Why coalescing? Goal of coalescing Removing the register-to-register copies [move a,b] Numerous move due to: live-range splitting to avoid spilling register constraints
Bouchez—Darte—Rastello (ENS Lyon)
a ← ... b ← ... c ← f (a, b)
Conservative & Optimistic Coalescing
a ← ... b ← ... move R0 ,a move R1 ,b call f move c,R0
CASES’08
4 / 20
Why coalescing? Goal of coalescing Removing the register-to-register copies [move a,b] Numerous move due to: if (. . . )
live-range splitting to avoid spilling register constraints SSA destruction
a1 ← 1
a2 ← 2
a3 ← φ(a1 , a2 ) · · · ← a3 Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
4 / 20
Why coalescing? Goal of coalescing Removing the register-to-register copies [move a,b] Numerous move due to: if (. . . )
live-range splitting to avoid spilling register constraints SSA destruction
a1 ← 1 move a3 ,a1
a2 ← 2 move a3 ,a2
a3 ← φ(a1 , a2 ) · · · ← a3 Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
4 / 20
Why coalescing? Goal of coalescing Removing the register-to-register copies [move a,b] Numerous move due to: if (. . . )
live-range splitting to avoid spilling register constraints
a1 ← 1
SSA destruction Not a new problem, but never studied as a separate optimization after spilling.
Bouchez—Darte—Rastello (ENS Lyon)
move a3 ,a1
a2 ← 2 move a3 ,a2
a3 ← φ(a1 , a2 ) · · · ← a3
Conservative & Optimistic Coalescing
CASES’08
4 / 20
Register allocation in two phases 1
Spill + Split so that I I
2
Maxlive ≤ #registers Interference graph is greedy-k-colorable ( ∼ k-colorable `a la Chaitin)
Color + Coalesce to remove useless copies
One possibility: 1
SSA split + spill under SSA
2
Coalescing optimized for greedy-k-colorable graphs Note: also useful in the last phase of Chaitin-like register allocators (in case there is no potential spills)
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
5 / 20
Statement 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 a and b forces them to have the same color.
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
6 / 20
Statement 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 a and b forces them to have the same color.
a
d
d
Merge a and b b
Bouchez—Darte—Rastello (ENS Lyon)
ab
c
c Conservative & Optimistic Coalescing
CASES’08
6 / 20
Statement 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 a and b forces them to have the same color. Idea Express this as an “affinity” between a and b in the interference graph to drive the algorithm. a
d
d
Merge a and b b
Bouchez—Darte—Rastello (ENS Lyon)
ab
c
c Conservative & Optimistic Coalescing
CASES’08
6 / 20
Statement of the conservative coalescing problem Problem (conservative coalescing) G : k-colorable interference graph, A: set of affinities. Coalesce (merge) as many (a, b) ∈ A so that G stays k-colorable.
a1
a1 ← 1 if (. . . )
a1 ← 1
a2
a2 ← 2 · · · ← a1 a3
a3 ← φ(a1 , a2 ) Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
7 / 20
Statement of the conservative coalescing problem Problem (conservative coalescing) G : k-colorable interference graph, A: set of affinities. Coalesce (merge) as many (a, b) ∈ A so that G stays k-colorable.
a1
a1 ← 1 if (. . . )
a1 ← 1
a2
a2 ← 2 · · · ← a1 a3
a3 ← φ(a1 , a2 ) Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
7 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) Optimistic coalescing (Park & Moon)
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing not k-colorable
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
Bouchez—Darte—Rastello (ENS Lyon)
not k-colorable
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental B/G
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental B/G
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental B/G
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental B/G
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental B/G
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental B/G aggressive Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental
de-coalescing
B/G aggressive Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics Biased coloring Conservative rules (Briggs & George) à incremental coalescing Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing Conservative
not k-colorable
incremental
de-coalescing
B/G aggressive Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Existing conservative coalescing heuristics (complexity results from CGO’07) Biased coloring Conservative rules (Briggs & George) à incremental coalescing NP-complete (but not if G chordal) Optimistic coalescing (Park & Moon) à aggressive coalescing + de-coalescing both NP-complete
Conservative
not k-colorable
incremental
de-coalescing
B/G aggressive Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
8 / 20
Experiments with the “Coalescing Challenge” Questions Are existing conservative rules good? Are optimistic-like coalescing better that incremental-like?
Appel & George 2002 “Optimal spilling for CISC machines with few registers” à ‘Coalescing Challenge’ of 474 graphs ≈ 26.7 basic blocks per region & max ≈ 1090 ≈ 231 instructions & max ≈ 8300 ≈ 850 nodes & max ≈ 28000 Pentium (6 registers & register constraints) Split at each program point to optimize spilling Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
9 / 20
Example from the “Coalescing Challenge” graphs
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
10 / 20
Example from the “Coalescing Challenge” graphs
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
10 / 20
Outline 1
Where does the coalescing come from? Why to coalesce? Register allocation in two phases Coalescing is a difficult problem “Coalescing Challenge”
2
Advanced coalescing for greedy-k-colorable graphs Incremental rules Brute-force solution: checking greedy-k-colorability Experiments & results
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
11 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j
Stack
2
d0 1
c0
c
4
4
b
3
d
e
3
4
f 2
g0
1
3
i g
2
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j 2
Stack
d0 1
c0
j
c
4
4
b
3
d
e
3
4
f 2
g0
2
i g
2
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j 2
Stack
d0 1
c0 i j
c
4
4
b
3
d
e
3
3
f 2
g0
i g
1
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j 2
Stack
d0 1
c0 g i j
c
4
4
b
3
d
e
3
2
f 2
g0
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j 2
Stack
d0 1
f g i j
c0
c
4
4
b
3
d
e
2
f 1
g0
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j
Stack
2
d0 g0 f g i j
1
c0
c
4
4
b
3
d
e
1
g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j
Stack
2
d0 e g0 f g i j
1
c0
c
4
4
b
2
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
3
j
Stack
2
d0 d e g0 f g i j
1
c0
c
3
3
b
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a d0 d e g0 f g i j
3
j d0
1
c0
c
2
2
b
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a b d0 d e g0 f g i j
2
j d0
1
c0
c
1
b
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a c b d0 d e g0 f g i j
1
j d0
1
c0
c
b
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs
Stack
Check greedy-k-colorability: simplify nodes with < k neighbors.
a c b d0 d e g0 f g i j
a
j d0
c0
c
b
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs
Stack
Check greedy-k-colorability: simplify nodes with < k neighbors. c0 a c b d0 d e g0 f g i j
a
j d0
c0
c
b
d
e g0
f
i g
Hi-degree node Low-degree node
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs
Stack
Check greedy-k-colorability: simplify nodes with < k neighbors. c0 a c b d0 d e g0 f g i j
a
j d0
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs
Stack
Check greedy-k-colorability: simplify nodes with < k neighbors.
a c b d0 d e g0 f g i j
a
j d0
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a c b d0 d e g0 f g i j
j d0
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a b d0 d e g0 f g i j
j d0
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a d0 d e g0 f g i j
j d0
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a
j d0
d e g0 f g i j
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a
j d0
e g0 f g i j
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
Stack
a
j d0
g0 f g i j
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
j
Stack
d0
f g i j
c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
j
Stack
d0 c0
c
b
d
e g0
f
i g
g i j
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
j
Stack
d0 c0
c
b
d
e g0
f
i g
i j
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
j
Stack
d0 c0
c
b
d
e g0
f
i g
j
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
j
Stack
d0 c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Greedy-k-colorable graphs Check greedy-k-colorability: simplify nodes with < k neighbors.
a
j
Stack
d0 c0
c
Bouchez—Darte—Rastello (ENS Lyon)
b
d
e g0
Conservative & Optimistic Coalescing
f
i g
CASES’08
12 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’
c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
2
a
j 2
d’
3
d
e
4
c’
c
b
Bouchez—Darte—Rastello (ENS Lyon)
g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’
c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’
c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’
c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’ c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’ c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’ c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c’c
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Briggs Resulting node has < k high-degree neighbours
a
j d’
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j 3
d’ 3
c c’
d
e
3
b
Bouchez—Darte—Rastello (ENS Lyon)
g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
d
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
George
George
All high-degree neighbours are neighbours of the other node
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
f
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
2
a
j 3
d’ d c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e g’
3
f
3
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f g’
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f g’
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f g’
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i
g’
g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
i
f g’
g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i g’ g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i g’ g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Brute-force
George
Merge the nodes and check if resulting graph is greedy-k-colorable
Brute-force
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i g g’
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Chordal
George
Relies on optimal incremental coalescing for interval graphs. (May need to merge other nodes
Brute-force
to get a greedy-k-colorable graph.)
Chordal
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i g g’
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes Briggs
Chordal
George
Relies on optimal incremental coalescing for interval graphs. (May need to merge other nodes
Brute-force
to get a greedy-k-colorable graph.)
Chordal
2
2
a
j 3
d’ d 3
c c’
3
b
Bouchez—Darte—Rastello (ENS Lyon)
3
e
3
f
3
i 4
g g’
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes
c
j
f e
b a
i g
d
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i g g’
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes
c
j
f e
b a
i g
d
a
j d’ d
c c’
b
Bouchez—Darte—Rastello (ENS Lyon)
e
f
i g g’
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Coalescing two nodes. . . with additional merges
c
j
f e
b a
i g
d
adfj
e c
b
Bouchez—Darte—Rastello (ENS Lyon)
i g
Conservative & Optimistic Coalescing
CASES’08
13 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
freeze
pot. spill
Conservative & Optimistic Coalescing
select
act. spill
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
freeze
pot. spill
Conservative & Optimistic Coalescing
select
act. spill
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
freeze
select
Conservative & Optimistic Coalescing
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
freeze
select
Conservative & Optimistic Coalescing
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
freeze
Conservative & Optimistic Coalescing
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
freeze
Conservative & Optimistic Coalescing
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
Conservative & Optimistic Coalescing
freeze
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
Conservative & Optimistic Coalescing
freeze
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
coalesce
Conservative & Optimistic Coalescing
freeze
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Brute
Conservative & Optimistic Coalescing
freeze
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Brute
Conservative & Optimistic Coalescing
freeze
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Brute
Conservative & Optimistic Coalescing
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Brute
Conservative & Optimistic Coalescing
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Brute
Conservative & Optimistic Coalescing
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Brute
Conservative & Optimistic Coalescing
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Conservative & Optimistic Coalescing
Brute
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Conservative & Optimistic Coalescing
Brute
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Conservative & Optimistic Coalescing
Brute
select
CASES’08
14 / 20
Optimized brute-force coalescing Our incremental conservative algorithm 1
Fast check with Briggs&George rules (for all nodes, “pre-colored” or not)
2
If fails, longer check with optimized version of brute-force.
à uses same framework as Chaitin: easy to implement!
build
simplify
Bouchez—Darte—Rastello (ENS Lyon)
Briggs
George
Conservative & Optimistic Coalescing
simplify
select
CASES’08
14 / 20
A better de-coalescing scheme to be compared to Park&Moon’s optimistic De-coalesces affinities during “select” phase, when out of colors. à relies on some “biased coloring”
Our optimistic De-coalesces affinities during “simplify” phase so that the graph gets greedy-k-colorable again. à exploits the graph structure à allows the use of conservative rules afterwards
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
15 / 20
Comparison of coalescing heuristics 160 1.0
Weight Time
140 120 100
0.6 80
Time (s)
Ratio vs Optimal
0.8
60
0.4
40 0.2 20 0.0
Briggs/George
Bouchez—Darte—Rastello (ENS Lyon)
Optimistic
Our brute improved
Conservative & Optimistic Coalescing
Our de-coalescing
0
CASES’08
16 / 20
Time of basic brute-force vs. optimized version 104
Time (s)
102
Pure brute force y = C × x 2.03 Brute improved y = C 0 × x 1.85
100 10−2 10−4 101
Bouchez—Darte—Rastello (ENS Lyon)
102
103 # nodes
Conservative & Optimistic Coalescing
104
105
CASES’08
17 / 20
Time repartition in optimized brute-force
Brute rule 60.7%
Briggs’s & George’s rules 1.8% 5.5% Read graph + Bias affinities 31.5%
Chordal rule 0.5%
Bouchez—Darte—Rastello (ENS Lyon)
Graph + worklists maintenance
Conservative & Optimistic Coalescing
CASES’08
18 / 20
Effort of the coalescing rules Not in optimal
5632
BG coalescings
366978
1829
Other coalescings Not coalesced
7577
15 1127
Constrained
305 19172 1
50 9
24
ILP failed
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
Brute Chordal ILP ok ILP not k-greedy
CASES’08
18 / 20
Conclusion on the coalescing problem
Common belief: optimistic (i.e., aggressive) is better than B/G (i.e., incremental conservative) à not necessarily, brute-force performs better Register allocation in two phases makes the coalescing simpler: I I
no particular case for pre-colored nodes exploits greedy-k-colorability property
Greedy-k-colorable graphs: I I
easy check for incremental allows the re-use of conservative rules (even for our optimistic)
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
19 / 20
Conclusion: practical implications Traditionally, trade-off between splitting and spilling Now, good coalescing: splitting is not a problem anymore! à Don’t be afraid of introducing moves to model other problems: I I I I
split for spill register renaming constraints out of SSA conversion register allocation in two phases
And to rely on coalescing to clean up solutions. Whenever loads/stores are more costly that moves, the optimizations are now more hierarchical: the first phase optimizes the spilling, the second one optimizes the coalescing.
Bouchez—Darte—Rastello (ENS Lyon)
Conservative & Optimistic Coalescing
CASES’08
20 / 20