+ All Categories
Home > Documents > An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs Philip BriskAjay K....

An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs Philip BriskAjay K....

Date post: 30-Dec-2015
Category:
Upload: dustin-paul
View: 219 times
Download: 3 times
Share this document with a friend
32
An Optimistic and An Optimistic and Conservative Register Conservative Register Assignment Heuristic for Assignment Heuristic for Chordal Graphs Chordal Graphs Philip Brisk Ajay K. Verma Paolo Ienne International Conference on Compilers, Architecture, and Synthesis for Embedded Systems October 3, 2007. Salzburg, Austria
Transcript

An Optimistic and Conservative An Optimistic and Conservative Register Assignment Heuristic for Register Assignment Heuristic for

Chordal GraphsChordal Graphs

Philip Brisk

Ajay K. Verma

Paolo Ienne

International Conference on Compilers, Architecture, and Synthesis for Embedded Systems

October 3, 2007. Salzburg, Austria

OutlineOutline

Coalescing Problem

Biased Coloring

Chordal Graphs

Optimistic Chordal Coloring Heuristic

Experimental Results

Conclusion

Coalescing ProblemCoalescing Problem

Given: k-colorable interference graph G = (V, E)

Spilling already performed

Set of copy operations y xx and y do not interfereRuntime profiling gives execution count

Objective:Find legal k-coloring of GMinimize the number of dynamic copies

executed

ExampleExample

K = 4 RegistersInterference Edge

Copy Instruction

A

BC

DE

F

G

HI

JK

ML

A

BC

DE

F

G

HI

JK

L M

7 copies

A

BC

DE

F

G

HI

JK

ML

5 copies

Coalescing Problem: ComplexityCoalescing Problem: Complexity

SSA FormTheorem: 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]

ContributionContribution

Coloring heuristic for chordal graphs

ConservativeStronger guarantees than “Conservative

Coalescing”

OptimisticRetains the benefits of “Optimistic Coalescing”

Bottom LineNear-optimal solutions for set of benchmarks

studied+1 extra copy, across all benchmarks

Coalescing via Node MergingCoalescing via Node Merging

YXXY

[Chaitin et al., Comp. Languages 1981; SCC 1982]

Negative Side Effects of Negative Side Effects of CoalescingCoalescing

Vertex degree increases [Briggs et al., TOPLAS 1994]

[George and Appel, TOPLAS 1996]

[Hailperin, TOPLAS 2005]

YX

Deg(X) = 3Deg(Y) = 4

XY

Deg(XY) = 6

Negative Side Effects of Negative Side Effects of CoalescingCoalescing

XY

Chromatic number increases

[Briggs et al., TOPLAS 1994]

[George and Appel, TOPLAS 1996]

Triangles form

[Kaluskar, MS Thesis, GA Tech., 2003]

YX

Positive Effects of CoalescingPositive Effects of Coalescing

YXXY

Reduce the degree of neighboring vertices

[Park and Moon, PACT 1998, TOPLAS 2004]

[Vegdahl, PLDI 1999]

Z ZDeg(Z) = 2 Deg(Z) = 1

Coalescing StrategiesCoalescing 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]

Biased ColoringBiased Coloring

YXX Y

Introduced by [Briggs et al., TOPLAS 1994] For whatever reason, we couldn’t 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

Chordal GraphsChordal Graphs

No chordless cycles of length 4 or more

Non-chordal Chordal

Non-chordal Still Non-chordal Chordal ChordalNon-Chordal

Coalescing and Chordal GraphsCoalescing and Chordal Graphs

Coalescing does not preserve chordality

Non-chordal

(After coalescing)

Chordal

(Before coalescing)

Pseudo-coalescingPseudo-coalescing

Find independent sets of move-related vertices, but don’t merge themTry to assign the same color to the vertices

Chordal

(After pseudo-coalescing)

Chordal

(Before pseudo-coalescing)

Simpicial VerticesSimpicial Vertices

v is a Simplicial Vertex if the neighbors of v form a clique.

Theorems:1. Every chordal graph has at

least one simplicial vertex [Lekkerkerker and Boland, Fund. Math 1964]

2. Every induced subgraph of a chordal graph is chordal

Perfect Elimination OrderPerfect Elimination Order

Undirected graph: G = (V, E)

Elimination Order One-to-one and onto function: σ: V {0, …, |V| - 1} Rename vertices: vi satisfies σ(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

Coloring Chordal GraphsColoring 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

Correctness ArgumentCorrectness Argument

Invariant:When we assign a color to vi, Gi is legally

colored

Optimistic extensions for copy eliminationExamples given in the next 3 slides Invariant above is always maintained

Color assignment is conservativeThe chromatic number is known, and never

changes

Simple Color Assignment RulesSimple Color Assignment Rules

PEO order: 1 2 3

That’s a really bad ideaNo harm doneBut that isn’t how it really happens…Let’s assume nodes 1 and 3 are pseudo-coalesced

Propagate color RED to node 3Try to respect the fact that node 3 has been optimistically colored

Only choose RED if no other color is available

If RED is the only option… then we’ll re-color node 3 later

Undo Pseudo-coalescingUndo Pseudo-coalescing

PEO order:

1

2 3

45

I can’t pseudo-coalesce all the nodes…

Assign colorPropagate colorLegal coloring invariant still holds

Pre-assigned color is legalPre-assigned color is illegalCannot stay pseudo-coalesced with node 2Undo pseudo-coalescingPseudo-coalesce with nodes 3 and 4 instead

Negative Biasing (Same Example)Negative Biasing (Same Example)

PEO order:

1

2 3

45

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 REDAssign Color BLUE to Node 1 instead

Maximum Cardinality SearchMaximum Cardinality Search

Compute PEO order in O(|V| + |E|) time[Tarjan and Yannakakis, Siam J. Comput, 1984]

Color move-related nodes earlyA legal color is always found for each node…So coloring non-move-related node …

Constrains the move-related-nodes

Biased MCSPush move-related vertices toward the front of the

PEO

SimplificationSimplification If Deg(v) < k, remove v from G

[Kempe, American J. Math. 1876] A color can always be found for v later Don’t do this for move-related nodes

Removing them doesn’t help to eliminate moves

Repeat until all remaining nodes v… Have Deg(v) > k, or Are move-related

Justification Fewer coloring constraints on move-related vertices [Hack and Grund, CC 2007]

In the context of chordal coloring

RefinementRefinement

Sometimes heuristics just don’t do the right thing…Can’t hurt, right?

Optimistic Chordal Coloring Optimistic Chordal Coloring HeuristicHeuristic

1. Simplification

2. (Biased) Maximum Cardinality Search

3. Aggressive Pseudo-Coalescing

4. Optimistic Chordal Color Assignment

5. Refinement

6. Unsimplify

Register Allocation for ASIPsRegister Allocation for ASIPs

Proc1 Proc2 Procm…

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)

Input Data

ExperimentsExperiments

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

ResultsResults

 Benchmark

Dynamically Executed Copies

OPT IRC OCC OCC++

adpcm_rawcaudioadpcm_rawdaudioblowfishcrc32dijkstrafftg721_decodeg721_encodegsmjpeg_cjpegjpeg_djpegmpeg2decmpeg2encpatriciapegwitshasusan

69950166995016

053322406

08209

00

1909187541326272636

211595197

182048

4422

--------

+ 2990-

+ 6283---

+ 24--

--------

+ 2990-

+ 6283---

+ 1--

----------------

+ 1

4 graphs were solved sub-optimally by OCC -> motivated OCC++

ConclusionConclusion OCC Heuristic for chordal graphs

OptimisticPseudo-coalescing instead of node mergingPreserves the chordal graph property

ConservativeStronger 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 propagationShares principal similarities to biased coloring

sym_decryptsym_decrypt

1

2

3

4

56

89

10

11

12

7 Propagate

Color is illegal

13

Weakness in aggressive pseudo-coalescing phase

Rules for Color AssignmentRules for Color Assignment

If vi is move-related…and vi is uncolored

Be judicious when selecting a colorPropagate 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 nodesColor assignment affects move-related nodes


Recommended