Title: A Coalescing Algorithm for Aliased Registers
1A Coalescing Algorithm for Aliased Registers
- Mariza A S Bigonha
- Fabrice Rastello
- Fernando M Q Pereira
- Roberto S Bigonha
2Our Objectives
We want to design and implement a new coalescing
algorithm that takes register aliasing into
consideration.
- The most popular computer architectures have
aliasing. - Current coalescing schema are oblivious to
aliasing.
3Introduction
- International cooperation Brazil-France
- ENS Lyon (France) and UFMG (Brazil)
- Code generation and optimization
- Our end goal is to contribute in the construction
of compilers that help programmers to produce
efficient machine code, while still using high
level programming languages.
4Register Allocation
- Where to store the variables used in the program?
- Memory lots of space, but slow access.
- Registers lightning fast, but very few
a
a
a 2
a 2
b
b a
a
b
b 3
a
b
b
c a b
print(b)
5Register Coalescing
- Register coalescing is an optimization on top of
register allocation. The objective is to map both
variables used in copies to the same register.
R1 0 R1 R1 print(R1)
R1 0 R2 R1 print(R2)
a ? R1 b ? R2
int a 0 int b a print(b)
a ? R1 b ? R1
6The Importance of Register Coalescing
Execution speedup
Energy saving
7SSA Based Register Allocation
- 2005 SSA form programs have chordal
interference graphs Bouchez05, Hack06. - Chordal graphs can be optimally colored in
polynomial time. - Minimum register assignment has polynomial time
solution. - The SSA representation is a form of live range
splitting. - It inserts many copies in the source program
8Live Range Splitting
- Live range splitting is the inverse of register
coalescing. - A good coalescer is paramount to maximize the
benefits of live range splitting.
a
a1
a 2
a1 2
a1
a2 a1
a2
a
print(a)
print(a2)
a2
9Register Aliasing
Two registers alias when an assignment to one may
change the value of the other.
AX
BX
CX
DX
Ex. x86
AH
AL
BH
BL
CH
CL
DH
DL
D0
D15
Ex. PowerPC
F10
F1
F30
F31
And also ARM, UltraSparc, ST240, etc
10Aliasing and Coalescing
a ? AH b ? AL c ? AH d ? AL
AH 0 AL 1 out(AH, AL)
int a 0 int b 1 c a d b out(c, d)
(ideal assignment)
AH 0 AL 1 BX AX out(BH, BL)
a ? AH b ? AL c ? BH d ? BL
(acceptable assignment)
11The Coalescing Zoo
- Global the whole program.
- Local one basic block.
- Punctual two consecutive instructions.
12Complexity Results
- Global coalescing NP complete
- Local coalescing polynomial without aliasing,
but NP complete with aliasing, via reduction to
aligned coloring. - Punctual coalescing polynomial.
13Punctual lt Local lt Global
14Coalescing in Practice
- Long history Chaitin et al proposed aggressive
coalescing Chaitin 81 - Briggs et al brought in conservative coalescing
Briggs 94 - George and Appel invented incremental
conservative coalescing George 96 - Park et al came with optimistic coalescing Park
04 - These heuristics do not talk about aliasing.
15The Cooperating Parties
- Ecole Normale Superieure de Lyon
- Chair Fabrice Rastello
- Especially coalescing
- Universidade Federal de Minas Gerais
- Chair Mariza Bigonha
- Especially aliasing
Eg Florent Bouchez, Alain Darge,
Fabrice Rastello On the Complexity of
Register Coalescing. CGO 2007 102-114
Eg Fernando Magno Quintão Pereira, Jens
Palsberg Register allocation by puzzle solving.
PLDI 2008 216-226
16What we have so far
- We have an integer linear programming (ILP)
solution to global coalescing with aliasing. - We have been able to find optimal solutions to
more than 90 of the functions in SPEC CPU 2000. - Our model
- Live range splitting at each program point.
- Two level aliasing, like in floating point
registers of PowerPC. - We handle only register assignment no spilling.
17What we have so far
- Optimal solution to punctual coalescing for
elementary programs.
18The Plan
- Adapt existing coalescing approaches to handle
aliasing. Two candidates - Bouchezs incremental coalescing Cases 08.
- Hacks coalescing by graph recoloring PLDI 08.
- Compare with the punctual coalescing used in
register allocation by puzzle solving PLDI 2008.
19Candidate 1 incremental coalescing
- Greedy-K-colorable graph (GKC) a graph that can
be trivially colored by a greedy coloring
algorithm. - Let G be a GKC graph. Let G be the result of
coalescing two nodes of G. Is G still GKC? - Polynomial test to prove GKC property.
- Conservative coalescing.
- About 15 faster than optimistic approaches.
20Candidate 2 recoloring
- Color the graph without worrying about
coalescing. - Recolor as many nodes as possible, to satisfy as
many affinities as possible.
21The Big Picture
- ILP for global coalescing
- Optimal, but very slow
- Baseline for comparisons
- Heuristics for global coalescing
- Sub-Optimal, but Polynomial
- Default for compilation
- Punctual coalescing
- Optimal, fast, but restricted
- Just in time compilation
22The Cooperation
- French side
- Designed and implemented base coalescer.
- Design the new coalescing algorithm.
- Help in the implementation effort.
- Brazilian side
- Designed and implemented ILP and punctual
coalescing with aliasing. - Help in designing the algorithm.
- Implement the algorithm.
23(No Transcript)