Title: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs
1An Optimistic and Conservative Register
Assignment Heuristic for Chordal Graphs
Philip Brisk
Ajay K. Verma
Paolo Ienne
International Conference on Compilers,
Architecture, and Synthesis for Embedded
Systems October 3, 2007. Salzburg, Austria
2Outline
- Coalescing Problem
- Biased Coloring
- Chordal Graphs
- Optimistic Chordal Coloring Heuristic
- Experimental Results
- Conclusion
3Coalescing Problem
- Given
- k-colorable interference graph G (V, E)
- Spilling already performed
- Set of copy operations y ? x
- x and y do not interfere
- Runtime profiling gives execution count
- Objective
- Find legal k-coloring of G
- Minimize the number of dynamic copies executed
4Example
Interference Edge
Copy Instruction
5Coalescing Problem Complexity
- SSA Form
- Theorem SSA interference graphs are chordal
- Bouchez et al., MS Thesis, ENS-Lyon, 2005
- Brisk et al., IWLS 2005, TCAD 2006
- Hack et al., Tech. Report, U. Karlsruhe, 2005
IPL, 2006 - Coalescing is NP-Complete, even for chordal
graphs - Bouchez et al., CGO 2007, Best Paper Award
6Contribution
- Coloring heuristic for chordal graphs
- Conservative
- Stronger guarantees than Conservative
Coalescing - Optimistic
- Retains the benefits of Optimistic Coalescing
- Bottom Line
- Near-optimal solutions for set of benchmarks
studied - 1 extra copy, across all benchmarks
7Coalescing via Node Merging
- Chaitin et al., Comp. Languages 1981 SCC 1982
8Negative Side Effects of Coalescing
- Vertex degree increases
- Briggs et al., TOPLAS 1994
- George and Appel, TOPLAS 1996
- Hailperin, TOPLAS 2005
9Negative Side Effects of Coalescing
- Chromatic number increases
- Briggs et al., TOPLAS 1994
- George and Appel, TOPLAS 1996
Triangles form Kaluskar, MS Thesis, GA Tech.,
2003
10Positive Effects of Coalescing
Deg(Z) 2
Deg(Z) 1
XY
- Reduce the degree of neighboring vertices
- Park and Moon, PACT 1998, TOPLAS 2004
- Vegdahl, PLDI 1999
11Coalescing Strategies
- Conservative
- Coalesce if you can prove that the resulting
graph is still k-colorable - Optimistic
- Aggressively coalesce as many moves as possible
- De-coalesce, when necessary, to avoid spilling
- Coalesce non-move-related nodes to exploit
positive benefit - Complexity
- Conservative, aggressive, optimistic coalescing
are all NP-Complete - Bouchez et al., CGO 2007
12Biased Coloring
- Introduced by Briggs et al., TOPLAS 1994
- For whatever reason, we couldnt coalesce X and Y
- Assume X gets a color before Y
- If Color(X) is available when we assign a color
to Y - Then assign Color(X) to Y
13Chordal Graphs
- No chordless cycles of length 4 or more
14Coalescing and Chordal Graphs
- Coalescing does not preserve chordality
15Pseudo-coalescing
- Find independent sets of move-related vertices,
but dont merge them - Try to assign the same color to the vertices
Chordal (After pseudo-coalescing)
Chordal (Before pseudo-coalescing)
16Simpicial Vertices
- v is a Simplicial Vertex if the neighbors of v
form a clique. - Theorems
- Every chordal graph has at least one simplicial
vertex Lekkerkerker and Boland, Fund.
Math 1964 - Every induced subgraph of a chordal graph is
chordal
17Perfect Elimination Order
- Undirected graph G (V, E)
- Elimination Order
- One-to-one and onto function s V ? 0, , V -
1 - Rename vertices vi satisfies s(vi) i
- Vi v1, , vi
- Gi (Vi, Ei) is the subgraph of G induced by Vi
- Perfect Elimination Order (PEO)
- vi is a simplicial vertex in Gi, for i 1 to n
- G is chordal iff G has a PEO
18Coloring Chordal Graphs
- Optimal, O(V E)-time Algorithm
- Gavril, Siam J. Comp, 1972
- Process vertices in PEO order
- Give vi the smallest color not assigned to its
neighbors - Works because vi is simplicial in Gi
- Extensions for copy elimination (this paper)
- Pseudo-coalescing
- Bias color assignment
19Correctness Argument
- Invariant
- When we assign a color to vi, Gi is legally
colored - Optimistic extensions for copy elimination
- Examples given in the next 3 slides
- Invariant above is always maintained
- Color assignment is conservative
- The chromatic number is known, and never changes
20Simple Color Assignment Rules
3
2
Thats a really bad idea
No harm done
But that isnt how it really happens
Lets assume nodes 1 and 3 are pseudo-coalesced
21Undo Pseudo-coalescing
2
3
4
5
Assign color
Propagate color
Pre-assigned color is legal
Pre-assigned color is illegal
Undo pseudo-coalescing
Legal coloring invariant still holds
Cannot stay pseudo-coalesced with node 2
Pseudo-coalesce with nodes 3 and 4 instead
I cant pseudo-coalesce all the nodes
22Negative Biasing (Same Example)
2
3
4
5
Select a Color for Node 2
Node 2 is pseuo-coalesced with Node 5
Node 5 interferes with Node 1, which has Color RED
So bias Node 1, AWAY FROM Color RED
Assign Color BLUE to Node 1 instead
23Maximum Cardinality Search
- Compute PEO order in O(V E) time
- Tarjan and Yannakakis, Siam J. Comput, 1984
- Color move-related nodes early
- A legal color is always found for each node
- So coloring non-move-related node
- Constrains the move-related-nodes
- Biased MCS
- Push move-related vertices toward the front of
the PEO
24Simplification
- If Deg(v) lt k, remove v from G
- Kempe, American J. Math. 1876
- A color can always be found for v later
- Dont do this for move-related nodes
- Removing them doesnt help to eliminate moves
- Repeat until all remaining nodes v
- Have Deg(v) gt k, or
- Are move-related
- Justification
- Fewer coloring constraints on move-related
vertices - Hack and Grund, CC 2007
- In the context of chordal coloring
25Refinement
Sometimes heuristics just dont do the right
thing
Cant hurt, right?
26Optimistic Chordal Coloring Heuristic
- Simplification
- (Biased) Maximum Cardinality Search
- Aggressive Pseudo-Coalescing
- Optimistic Chordal Color Assignment
- Refinement
- Unsimplify
27Register Allocation for ASIPs
Proc1
Proc2
Procm
Input Data
- Profile, Convert to Pruned SSA, Build
Interference Graph
G1
G2
Gm
Chordal Color Gavril, Siam J. Comp. 1972
?(G1)
?(G2)
?(Gm)
MAX
?max Number of registers to allocate (only
spill at procedure calls)
28Experiments
- Benchmarks
- MediaBench, MiBench in SSA Form
- Color Assignment
- Optimal Coalescing via ILP (OPT)
- Hack and Grund CC, 2007
- Iterated Register Coalescing (IRC)
- George and Appel, TOPLAS 1996
- Optimistic Chordal Coloring (OCC)
- OCC (Not in the paper)
- Illegal pseudo-coalescing
- More aggressive color propagation
- Enhanced refinement stage
29Results
Benchmark Dynamically Executed Copies Dynamically Executed Copies Dynamically Executed Copies Dynamically Executed Copies
Benchmark OPT IRC OCC OCC
adpcm_rawcaudio adpcm_rawdaudio blowfish crc32 dijkstra fft g721_decode g721_encode gsm jpeg_cjpeg jpeg_djpeg mpeg2dec mpeg2enc patricia pegwit sha susan 6995016 6995016 0 53322406 0 8209 0 0 1909187 541326 272636 2115 95197 1820 48 442 2 - - - - - - - - 2990 - 6283 - - - 24 - - - - - - - - - - 2990 - 6283 - - - 1 - - - - - - - - - - - - - - - - - - 1
4 graphs were solved sub-optimally by OCC -gt
motivated OCC
30Conclusion
- OCC Heuristic for chordal graphs
- Optimistic
- Pseudo-coalescing instead of node merging
- Preserves the chordal graph property
- Conservative
- Stronger guarantees than conservative coalescing
- Chromatic number is easy to compute for chordal
graphs - Same correctness invariant as chordal graph
coloring - Choice of color assignment/color propagation
- Shares principal similarities to biased coloring
31sym_decrypt
- Weakness in aggressive pseudo-coalescing phase
3
5
6
Color is illegal
2
4
13
10
12
1
7
Propagate
8
9
11
32Rules for Color Assignment
- If vi is move-related
- and vi is uncolored
- Be judicious when selecting a color
- Propagate the color to vertices pseudo-coalesced
with vi - or, vi has optimistically been assigned a color
already - Is this color still legal with respect to Gi?
- If not, re-color vi
- Undo/redo pseudo-coalescing
- Non-move-related nodes
- Color assignment affects move-related nodes