Title: A Global Progressive Register Allocator
1A Global Progressive Register Allocator
- David Ryan Koes
- Seth Copen Goldstein
- Carnegie Mellon University
- dkoes,seth_at_cs.cmu.edu
2Register Allocation Problem
unbounded number of program variables
limited number of processor registers slow
memory
spill code optimization
v 1 w v 3 x w v u v t u
x print(x) print(w) print(t) print(u)
register preferences
rematerialization
register allocator
live range splitting
memory operands
3A More Principled Register Allocator
- fully utilize machine description
- explicit and expressive model of costs of
allocation for given architecture - optimal solutions
reg alloc
machine description
4Multi-commodity Network Flow An Expressive Model
- Given network (directed graph) with
- cost and capacity on each edge
- sources sinks for multiple commodities
- Find lowest cost flow of commodities
- NP-complete for integer flows
b
a
Example edges have unit capacity
0
1
b
a
5Register Allocation as a MCNF
Variables ? Commodities Variable Definition ?
Source Variable Last Use ? Sink Nodes ?
Allocation Classes (Reg/Mem/Const) Registers
Limits ? Node Capacities Spill Costs ? Edge
Costs Allocation ? Flow
r1
mem
1
3
Also need anti-variables to model persistent
memory
6Example
load cost
Source Code int example(int a, int b) int d
1 int c a - b return cd
insn pref cost
Pre-alloc Assembly MOVE 1 -gt d SUB a,b -gt c ADD
c,d -gt c MOVE c -gt r0
mem access cost
7Control Flow
- MCNF can only represent straight-line code
- need to link together networks from basic blocks
New nodes to handle block entry/exit constraints
a eax
a mem
8A More Principled Register Allocator
- fully utilize machine description
- explicit and expressive model of costs of
allocation for given architecture Global MCNF - optimal solutions
- NP-hard, so use progressive solution technique
9Solution Procedure
- Compute Lagrangian prices using iterative
subgradient optimization - guaranteed converge to optimal prices
- for linear relaxation of the problem
- Prices used by allocator to find solution
- solution improves as prices converge
- two allocators
- iterative heuristic allocator
- simultaneous heuristic allocator
10Solution Procedure
- Advantages
- iterative nature ? progressive
- Lagrangian relaxation theory provides means for
computing a good lower bound - Can compute optimality bound
- Disadvantages
- No guarantee of finding optimal solution
- Optimality bound poor if integrality gap large
99 of the time integrality gap 0
11Iterative Heuristic Allocator
Edges to/from memory cost 3
Allocation order a, b, c, d
Cost
Total 2
12Simultaneous Heuristic Allocator
Edges to/from memory cost 3
Current cost
-1
-3
-2
13Evaluation
- Implemented in gcc 3.4.3 targeting x86
- Optimize for code size
- perfect static evaluation
- important metric in its own right
- MediaBench, MiBench, Spec95, Spec2000
- over 10,000 functions
14Progressiveness
15Progressiveness
16Code Size
17Optimality
Proven maximum distance from optimal
Proven optimality
18Compile Time Slowdown -(
19A More Principled Register Allocator
- fully utilize machine description
- explicit and expressive model of costs of
allocation for given architecture Global MCNF - optimal solutions
- approach optimality using progressive solution
technique Lagrangian directed allocators
20Questions?
21(No Transcript)
22Accuracy of the Model
Global MCNF model correctly predicts costs of
register allocation within 2 for 71 of
functions compiled
23Code Size
24Compile Time Asymptotic Complexity
one iteration O(nv)
25Code Performance
26Compile Time Slowdown -(
10x slower