Download presentation
Presentation is loading. Please wait.
1
School of Computer Science A Global Progressive Register Allocator David Ryan Koes Seth Copen Goldstein Carnegie Mellon University {dkoes,seth}@cs.cmu.edu
2
School of Computer Science 1 Register Allocation Problem … v =1 w = v + 3 x = w + v u = v t = u + x print(x); print(w); print(t); print(u); … unbounded number of program variables limited number of processor registers + slow memory eax ebx ecx edx esi edi ebp esp spill code optimization memory operands register preferences rematerializationrematerialization live range splitting
3
School of Computer Science 2 A 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
4
School of Computer Science 3 Multi-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 Example: edges have unit capacity a b a b 01
5
School of Computer Science 4 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 Register Allocation as a MCNF a a r0r1mem1 r1mem1 r0r1mem1 3 Also need anti-variables to model persistent memory
6
School of Computer Science 5 Example Source Code int example(int a, int b) { int d = 1; int c = a - b; return c+d; } Pre-alloc Assembly MOVE 1 -> d SUB a,b -> c ADD c,d -> c MOVE c -> r0 load cost insn pref cost mem access cost
7
School of Computer Science 6 Control Flow MCNF can only represent straight-line code –need to link together networks from basic blocks a: %eax a: mem New nodes to handle block entry/exit constraints NormalMergeSplit
8
School of Computer Science 7 A 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 Compile Time Allocation Quality Lagrangian relaxation directed allocators Technique: reg alloc machine description
9
School of Computer Science 8 Solution 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
10
School of Computer Science 9 Solution 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
11
School of Computer Science 10 Iterative Heuristic Allocator Allocation order: a, b, c, d Cost: a 0 b 4 c 0 d -2 2 Total: 2 Edges to/from memory cost 3
12
School of Computer Science 11 Simultaneous Heuristic Allocator XX Current cost:-3-2 Edges to/from memory cost 3
13
School of Computer Science 12 Evaluation Implemented in gcc 3.4.3 targeting x86 code size Optimize for code size –perfect static evaluation –important metric in its own right MediaBench, MiBench, Spec95, Spec2000 –over 10,000 functions
14
School of Computer Science 13 Progressiveness CPLEX default allocator: 1121 graph allocator:1422
15
School of Computer Science 14 Progressiveness graph allocator default allocator CPLEX
16
School of Computer Science 15 Code Size Progressive!
17
School of Computer Science 16 Optimality Proven optimality Proven maximum distance from optimal
18
School of Computer Science 17 10x slower Compile Time Slowdown :-(
19
School of Computer Science 18 A 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 reg alloc machine description
20
School of Computer Science 19 Questions? ?
21
School of Computer Science 20
22
School of Computer Science 21 Accuracy of the Model Global MCNF model correctly predicts costs of register allocation within 2% for 71% of functions compiled
23
School of Computer Science 22 Code Size
24
School of Computer Science 23 Compile Time Asymptotic Complexity one iteration: O(nv)
25
School of Computer Science 24 Code Performance
26
School of Computer Science 25 Compile Time Slowdown :-( 10x slower
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.