Optimistic Register Coalescing

Optimistic Register Coalescing
Sobeeh Almukhaizim
UC San Diego
Computer Science & Engineering
Based on the work of:
J. Park and S. Moon
School of Electrical Engineering
Seoul National University
1
Outline
•
•
•
•
Motivation and problem definition.
Register Allocation
Copy Coalescing
Optimistic Coalescing
• Aggressive coalescing.
• Live range splitting.
• Experimental Results and Analyses
• Summary
2
Motivation and problem definition.
• Register allocation and copy coalescing.
• Goal: Minimize number of registers for a
program ( faster execution ).
• Live range variables that interfere with each
other  interference graph with minimum
color k ( number of registers ).
• NP-complete  search for heuristics.
3
Register Allocation
• Interference Graph
– A node represents a live range
– An edge represents concurrent liveness
• Coloring Theorem
– In a graph G, a node x with degree lower than k
will have a color no matter how G-{x} is colored
4
Register Allocators
• Yorktown Allocator (Chaitin et. al)
– Spills a node whenever every node is significant
• Optimistic Coloring Register Allocator
(Briggs et. al)
– Delays spill decision later
– Differentiates potential-spill and actual-spill
5
Copy Coalescing
• Coalescing in Graph Coloring
– Merging two non-interfering nodes
– Makes two nodes have the same color
– Effective for copy elimination
• Copy Coalescing
– Merging two non-interfering copy-related nodes
– Makes copies meaningless
• Includes both negative and positive impact on
colorability
6
Coalescing Impact on Colorability
• Negative Impact
– Produce higher-degree coalesced nodes
• Positive Impact
– Reduce the degrees of neighbors by one
a
1
b
2
a
ab
2
b
ad
1
b
k=2
c
d
c
Negative Impact
d
c
d
1
c
Positive Impact
7
Previous Coalescing Heuristics
– Aggressive Coalescing(Chaitin et. al)
• Coalesce any non-interfering copy operands
– Conservative Coalescing(Briggs et. al)
• Coalesce if the coalesced node will not be potentiallyspilled
– Iterated Coalescing(George and Appel)
• Repeat simplification and conservative coalescing
Aggressive
Conservative
Iterated
Copy Removal
best
worst
mid
Positive Impact
big
small
mid
Negative Impact
big
none
none
8
Optimistic Coalescing
• Aggressive Coalescing
• Live Range Splitting
Motivation of Optimistic Coalescing
Copy Removal
Positive Impact
Aggressive Coalescing
Optimistic View
Negative Impact
Live Range Splitting
9
Aggressive Coalescing
• Advantages of Aggressive Coalescing
– Removes many copies
– Fully exploits the positive impact
– Optimistically, aggressively coalesced node is not
necessarily spilled
d
k=3
b
e
g
a
c
f
h
c
h
f
e
g
d
a
b
1
2
3
1
3
2
3
spill
stack
d
a
e
g
f
h
bc
bc
h
f
e
g
d
a
1
2
3
2
1
3
2
stack
10
Live Range Splitting
• Compensate for Negative Impact
– What to Split
• Coalesced live ranges
– When to Split
• At the color phase before spilling them actually
– How to Split
• Reproduce the primitive live ranges by undoing
coalescing
11
Example of Live Range Splitting
a
k=3
b
e
e
stack
d
f
abcd
f
g
c
g
Aggressive coalescing
e=1
Graph simplification
ab=3
e=1
d
f=2
f=2
g=3
c=1
g=3
Allocation result
12
Register Allocator Implementation
• Base-case allocator
– Yorktown allocator with aggressive coalescing
• Briggs’ allocators with four different heuristics
–
–
–
–
with conservative coalescing (conservative)
with iterated coalescing (iterated)
with aggressive coalescing (aggressive)
with optimistic coalescing (optimistic)
13
Experimental Results
Ratio of introduced spill ops
Ratio of removed copies
110%
130%
95.6%
96.0%
100%
110%
90%
90%
66.6%
71.4%
62.8%
70%
84.3%
85.0%
76.0%
80%
70%
60%
50%
50%
iterated
aggressive
E
ip
RA
G
AV
E
gz
d
cc
se
pr
m
co
ya
s
es
li
es
pr
es
eq
nt
ot
t
E
ER
AG
ip
AV
gz
se
d
cc
ya
es
s
m
pr
li
tt
es
so
es
pr
to
eq
n
co
conservative
so
30%
40%
optimistic
14
Analysis of
Aggressive Coalescing and Spilling
Num. Of
Benchmark Coalesced
Nodes
eqntott
espresso
li
compress
yacc
sed
gzip
average
1649
12731
1478
104
5765
1172
4366
Num. Of
Aggressive
Optimistic
Aggressively
Num. Of
Num. Of
Coalesced Nodes
Spilled
Ratio
Spilled
Ratio
(Ratio)
Nodes
Nodes
1042 (63.2%)
98
9.4%
53
5.1%
9659 (75.9%)
911
9.4%
629
6.5%
830 (56.2%)
10
1.2%
4
0.5%
68 (65.4%)
0
0.0%
0
0.0%
3964 (68.8%)
186
4.7%
121
3.1%
674 (57.5%)
24
3.6%
12
1.8%
3277 (75.1%)
365
11.1%
187
5.7%
(66.0%)
5.6%
3.2%
• Due to aggressiveness, aggressive coalescing coalesces 66.0%
more nodes
• Due to optimistic view, aggressive coalescing spills only 5.6%
of aggressively coalesced nodes
• Due to live range splitting, optimistic coalescing reduces spills
15
by 2.4%
Analysis of Live Range Splitting
Num. Of
Spilled Nodes
Colored Nodes
Successful
Nodes in
in Fully
in Partially
in Fully
Benchmark
Coloring
Candidate Spilled
Spilled/Colored
Colored
Ratio
Chunks
Chunks
Chunks
Chunks
eqntott
114
12
41
55
6
53.5%
espresso
1065
275
354
387
49
40.9%
li
12
0
4
4
4
66.7%
compress
0
0
0
0
0
0.0%
yacc
217
48
73
85
11
44.2%
sed
24
0
12
12
0
50.0%
gzip
429
48
139
227
15
56.4%
average
52.0%
• Due to live range splitting, 52% of otherwise spilled
nodes are colored
16
Analysis of Positive impact
Benchmar
k
eqntott
espresso
li
compress
yacc
sed
gzip
average
Num. Of
Original
Edges
83523
744637
103457
9228
326276
71366
234617
Num. Of Deleted Edges
Conservative
1674
7530
1554
106
4740
1399
3106
(2.0% )
(1.0% )
(1.5% )
(1.1% )
(1.5% )
(2.0% )
(1.3% )
(1.5% )
Iterated
2506
16818
2311
217
8982
3156
5933
(3.0% )
(2.3% )
(2.2% )
(2.4% )
(2.8% )
(4.4% )
(2.5% )
(2.8% )
Aggressive
and Optimistic
8598 (10.3% )
103032 (13.8% )
6524
(6.3% )
866
(9.4% )
40977 (12.6% )
6614
(9.3% )
30111 (12.8% )
(10.6% )
• Due to positive impact, coalescing removes
interference edges
• Optimistic coalescing exploits 3.8 times more positive
impact than iterated coalescing
17
Summary
•Optimistic Coalescing
–Aggressive coalescing
•Aggressive copy elimination
•Positive impact
•Optimistic view
–Live range splitting
•Reduce negative impact
18