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

An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

Date post: 02-Feb-2016
Category:
Upload: pancho
View: 22 times
Download: 0 times
Share this document with a friend
Description:
An 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. Outline. Coalescing Problem Biased Coloring - PowerPoint PPT Presentation
Popular Tags:
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
Page 1: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 2: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

OutlineOutline

Coalescing Problem

Biased Coloring

Chordal Graphs

Optimistic Chordal Coloring Heuristic

Experimental Results

Conclusion

Page 3: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 4: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 5: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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]

Page 6: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 7: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

Coalescing via Node MergingCoalescing via Node Merging

YXXY

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

Page 8: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 9: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 10: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 11: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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]

Page 12: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 13: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

Chordal GraphsChordal Graphs

No chordless cycles of length 4 or more

Non-chordal Chordal

Non-chordal Still Non-chordal Chordal ChordalNon-Chordal

Page 14: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

Coalescing and Chordal GraphsCoalescing and Chordal Graphs

Coalescing does not preserve chordality

Non-chordal

(After coalescing)

Chordal

(Before coalescing)

Page 15: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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)

Page 16: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 17: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 18: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 19: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 20: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 21: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 22: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 23: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 24: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 25: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

RefinementRefinement

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

Page 26: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 27: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 28: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 29: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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++

Page 30: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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

Page 31: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

sym_decryptsym_decrypt

1

2

3

4

56

89

10

11

12

7 Propagate

Color is illegal

13

Weakness in aggressive pseudo-coalescing phase

Page 32: An Optimistic and Conservative Register Assignment Heuristic for Chordal Graphs

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