+ All Categories
Home > Documents > A Study of Spilling and Coalescing in Register Allocation as...

A Study of Spilling and Coalescing in Register Allocation as...

Date post: 20-Jan-2021
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
205
Introduction Difficulty of register allocation The coalescing problem Conclusion A Study of Spilling and Coalescing in Register Allocation as Two Separate Phases Ph.D. Defense Florent Bouchez [email protected] Compsys LIP UMR CNRS — Inria — ENS Lyon — UCBL France April 30th 2009 BU 1 / 39
Transcript
Page 1: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

A Study of Spilling and Coalescing in RegisterAllocation as Two Separate Phases

Ph.D. Defense

Florent [email protected]

CompsysLIP UMR CNRS — Inria — ENS Lyon — UCBL

France

April 30th 2009

BU

1 / 39

Page 2: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Compilation

foo.c foo.bin

Our interest

Register allocation, one of the latest steps.

ZO

2 / 39

Page 3: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

French folklore: Les Shadoks

MEU

3 / 39

Page 4: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Shadoks have a very small brain

BU GA

4 / 39

Page 5: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Shadoks have a very small brain

BU GA

4 / 39

Page 6: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Shadoks have a very small brain

BU GA

4 / 39

Page 7: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Shadoks have a very small brain

BU GA

4 / 39

Page 8: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Shadoks have a very small brain

BU GA

4 / 39

Page 9: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Shadoks have a very small brain

BU GA

4 / 39

Page 10: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 11: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 12: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 13: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 14: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 15: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 16: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 17: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 18: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 19: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 20: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 21: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 22: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 23: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 24: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 25: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 26: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 27: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 28: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 29: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 30: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 31: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 32: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 33: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 34: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 35: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 36: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 37: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 38: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 39: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 40: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 41: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 42: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 43: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The shadoks at the library

BU BU

5 / 39

Page 44: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is register allocation?

Assign variables to memorylocations

Registers: , , , . . .

Memory: infinite

Rules of the game

two interfering variablesà different registers

not enough registersà spill to memory

a← 3425n← 0

a 6= 1 ?

n← n + 1a even ?

a← a/2 a← 3× a + 1

print nBU ZO

6 / 39

Page 45: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is register allocation?

Assign variables to memorylocations

Registers: , , , . . .

Memory: infinite

Rules of the game

two interfering variablesà different registers

not enough registersà spill to memory

Plus constraints:

register constraints

pre-colored variables

register pairing,aliasing,. . .

BU ZO

6 / 39

Page 46: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin et al. model

Live-in: k jg := mem[j+12]h := k-1f := g+he := mem[j+8]m := mem[j+16]b := mem[f]c := e+8d := ck := m+4j := b

Live-out: d k j

Live-rangesg

h

f

e

m

b

c

d

g

h

f

e

m

b

c

d

kj

jk

BU MEU

7 / 39

Page 47: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin et al. model

Interference graph

k

j

g

h

f

e

mb c

d

Live-rangesg

h

f

e

m

b

c

d

g

h

f

e

m

b

c

d

kj

jk

BU MEU

7 / 39

Page 48: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin et al. model

Interference graph

k

j

g

h

f

e

mb c

d

Live-rangesg

h

f

e

m

b

c

d

g

h

f

e

m

b

c

d

kj

jk

BU MEU

7 / 39

Page 49: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.

Problem

Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)

à register allocation is NP-complete in this model.

A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme

If coloring fails, usually spill.Disadvantages:

The scheme might fail even when there is a solution.

à need to spill more than necessary

A variable is supposed to be in exactly one register.

à restriction on the coloring

ZO GA

8 / 39

Page 50: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.

Problem

Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)

à register allocation is NP-complete in this model.

A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme

If coloring fails, usually spill.

Disadvantages: The scheme might fail even when there is a solution.

à need to spill more than necessary

A variable is supposed to be in exactly one register.

à restriction on the coloring

ZO GA

8 / 39

Page 51: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.

Problem

Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)

à register allocation is NP-complete in this model.

A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme

If coloring fails, usually spill.Disadvantages:

The scheme might fail even when there is a solution.

à need to spill more than necessary

A variable is supposed to be in exactly one register.

à restriction on the coloring

ZO GA

8 / 39

Page 52: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Coloring the interference graph: the greedy wayRegister allocation is modeled as coloring the interference graph of theprogram.

Problem

Graph-k-coloring is NP-complete (for k ≥ 3), and any interference graphcan arise in programs. (Chaitin et al.’s proof)

à register allocation is NP-complete in this model.

A greedy coloring heuristic is used: Chaitin et al.’s greedy scheme.Greedy scheme

If coloring fails, usually spill.Disadvantages:

The scheme might fail even when there is a solution.à need to spill more than necessary

A variable is supposed to be in exactly one register.à restriction on the coloring

ZO GA

8 / 39

Page 53: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Outline

1 IntroductionLes ShadoksRegister allocation

2 Difficulty of register allocationStrict SSA graphs are chordalQuestions with register allocation in two phases

3 The coalescing problemIntroduction to coalescingIncremental coalescing

ZO BU

9 / 39

Page 54: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Outline

1 IntroductionLes ShadoksRegister allocation

2 Difficulty of register allocationStrict SSA graphs are chordalQuestions with register allocation in two phases

3 The coalescing problemIntroduction to coalescingIncremental coalescing

ZO ZO

10 / 39

Page 55: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

SSA interference graphs are chordal

In 2002, Darte realized that the interference graph of programs understrict SSA are chordal.(The same discovery was made independently by Brisk and Hack in 2004-2005.)

à Starting point of this thesis

Theorem

The interference graph of a program under strict SSA form is chordal.

ZO MEU

11 / 39

Page 56: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

SSA interference graphs are chordal

In 2002, Darte realized that the interference graph of programs understrict SSA are chordal.(The same discovery was made independently by Brisk and Hack in 2004-2005.)

à Starting point of this thesis

Theorem

The interference graph of a program under strict SSA form is chordal.

ZO MEU

11 / 39

Page 57: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a b c

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 58: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 59: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

d

e

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 60: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

d

e

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 61: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

d

e

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 62: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

d

e

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 63: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

d

e

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 64: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs

Definition (Chordal graph)

A graph is chordal iff every cycle of size ≥ 4 has a chord.

a

b

c

d

e

Chordal graphs are perfect and easy to color.

MEU GA

12 / 39

Page 65: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Static Single AssignmentSSA : exactly one textual definition per variable

strictness : SSA where the definition always dominates its uses

MEU BU

13 / 39

Page 66: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Static Single AssignmentSSA : exactly one textual definition per variable

strictness : SSA where the definition always dominates its uses

Example (Straight code converted to SSA form)

a← . . ....

. . .← a...

a← . . ....

. . .← a

a1 ← . . ....

. . .← a1...

a2 ← . . ....

. . .← a2

MEU BU

13 / 39

Page 67: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Static Single AssignmentSSA : exactly one textual definition per variable

strictness : SSA where the definition always dominates its uses

Example (Conditional code converted to SSA form)

if (. . . )

a← 1 a← 2

. . .← a

if (. . . )

a1 ← 1 a2 ← 2

a3 ← φ(a1, a2). . .← a3

MEU BU

13 / 39

Page 68: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Static Single AssignmentSSA : exactly one textual definition per variable

strictness : SSA where the definition always dominates its uses

Example (strict SSA or SSA with dominance property)

if (. . . )

a1 ← 1 . . .

. . .← a1

if (. . . )

a1 ← 1 . . .

a2 ← φ(a1,⊥). . .← a2

MEU BU

13 / 39

Page 69: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Proof that strict SSA interference graphs are chordal

Theorem

The interference graph of a program under strict SSA form is chordal.

Proof.

a

b

c

d

e

dominance property

a and b interfere ⇒ def (a) dominates def (b)(or the converse)

direct each edge with dominance

def (d) is dominated by def (c) and def (e)

c and e are live at def (d)

MEU ZO

14 / 39

Page 70: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Proof that strict SSA interference graphs are chordal

Theorem

The interference graph of a program under strict SSA form is chordal.

Proof.

a

b

c

d

e

dominance property

a and b interfere ⇒ def (a) dominates def (b)(or the converse)

direct each edge with dominance

def (d) is dominated by def (c) and def (e)

c and e are live at def (d)

MEU ZO

14 / 39

Page 71: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Proof that strict SSA interference graphs are chordal

Theorem

The interference graph of a program under strict SSA form is chordal.

Proof.

a

b

c

d

e

dominance property

a and b interfere ⇒ def (a) dominates def (b)(or the converse)

direct each edge with dominance

def (d) is dominated by def (c) and def (e)

c and e are live at def (d)

MEU ZO

14 / 39

Page 72: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Proof that strict SSA interference graphs are chordal

Theorem

The interference graph of a program under strict SSA form is chordal.

Proof.

a

b

c

d

e

dominance property

a and b interfere ⇒ def (a) dominates def (b)(or the converse)

direct each edge with dominance

def (d) is dominated by def (c) and def (e)

c and e are live at def (d)

MEU ZO

14 / 39

Page 73: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Proof that strict SSA interference graphs are chordal

Theorem

The interference graph of a program under strict SSA form is chordal.

Proof.

a

b

c

d

e

dominance property

a and b interfere ⇒ def (a) dominates def (b)(or the converse)

direct each edge with dominance

def (d) is dominated by def (c) and def (e)

c and e are live at def (d)

MEU ZO

14 / 39

Page 74: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Proof that strict SSA interference graphs are chordal

Theorem

The interference graph of a program under strict SSA form is chordal.

Proof.

a

b

c

d

e

dominance property

a and b interfere ⇒ def (a) dominates def (b)(or the converse)

direct each edge with dominance

def (d) is dominated by def (c) and def (e)

c and e are live at def (d)

MEU ZO

14 / 39

Page 75: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Strict SSA programs are easy to colorChordal graphs are perfect graphs, hence easy to color. We proved more:

Theorem

Chordal graphs are colorable using Chaitin et al. greedy scheme.They are greedy-k-colorable.

General program:NP-complete

strict SSA program:greedy-k-colorable

Under strict SSA, Maxlive, the maximum number of simultaneously livevariables, is the coloring indicator:

Maxlive ≤ R

MEU MEU

15 / 39

Page 76: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Strict SSA programs are easy to colorChordal graphs are perfect graphs, hence easy to color. We proved more:

Theorem

Chordal graphs are colorable using Chaitin et al. greedy scheme.They are greedy-k-colorable.

General program:NP-complete

strict SSA program:greedy-k-colorable

Under strict SSA, Maxlive, the maximum number of simultaneously livevariables, is the coloring indicator:

Maxlive ≤ R

MEU MEU

15 / 39

Page 77: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Register allocation in two phases

Using Maxlive, it seems possible to use a very simple register allocationscheme:

1 spill variables until Maxlive ≤ R

2 transform program into strict SSA form

3 allocate variables using R registers

4 go out of colored SSA form

Questions

SSA seems to transform an NP-complete problem into polynomial one. . .Where is the complexity now? What else is simplified?

BU GA GA

16 / 39

Page 78: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Register allocation in two phases

Using Maxlive, it seems possible to use a very simple register allocationscheme:

1 spill variables until Maxlive ≤ R

2 transform program into strict SSA form

3 allocate variables using R registers

4 go out of colored SSA form

Questions

SSA seems to transform an NP-complete problem into polynomial one. . .Where is the complexity now? What else is simplified?

BU GA GA

16 / 39

Page 79: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

BU GA BU

17 / 39

Page 80: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

revisitChaitin’s

proof

criticalflow-edgesplitting

swapproblem

# simult.defs

BU GA BU

17 / 39

Page 81: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin’s proof revisited

No Yes

* on basic block borders only

Proofcriti

cal edges

variable

splitting

complexity

Chaitin et al.NP-complete

Thm. 3.1NP-complete

Sec. 3.2.1 (SSA) *polynomial

Thm. 3.2 *NP-complete

Thm. 3.4 (Col. prop.)polynomial

Thm. 3.3NP-complete

BU GA ZO

18 / 39

Page 82: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin’s proof revisited

No Yes

* on basic block borders only

Proofcriti

cal edges

variable

splitting

complexity

Chaitin et al.NP-complete

Thm. 3.1NP-complete

Sec. 3.2.1 (SSA) *polynomial

Thm. 3.2 *NP-complete

Thm. 3.4 (Col. prop.)polynomial

Thm. 3.3NP-complete

BU GA ZO

18 / 39

Page 83: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin’s proof revisited

No Yes* on basic block borders only

Proofcriti

cal edges

variable

splitting

Swap instructio

n

complexity

Chaitin et al.NP-complete

Thm. 3.1NP-complete

Sec. 3.2.1 (SSA) *polynomial

Thm. 3.2 *NP-complete

Thm. 3.4 (Col. prop.)polynomial

Thm. 3.3NP-complete

BU GA ZO

18 / 39

Page 84: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin’s proof revisited

No Yes* on basic block borders only

Proofcriti

cal edges

variable

splitting

Swap instructio

n

complexity

Chaitin et al.NP-complete

Thm. 3.1NP-complete

Sec. 3.2.1 (SSA) *polynomial

Thm. 3.2 *NP-complete

Thm. 3.4 (Col. prop.)polynomial

Thm. 3.3NP-complete

BU GA ZO

18 / 39

Page 85: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chaitin’s proof revisited

No Yes* on basic block borders only

Proofcriti

cal edges

variable

splitting

Swap instructio

n

2 simult.

def.

complexity

Chaitin et al.NP-complete

Thm. 3.1NP-complete

Sec. 3.2.1 (SSA) *polynomial

Thm. 3.2 *NP-complete

Thm. 3.4 (Col. prop.)polynomial

Thm. 3.3NP-complete

BU GA ZO

18 / 39

Page 86: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

revisitChaitin’s

proof

criticalflow-edgesplitting

swapproblem

# simult.defs

BU GA MEU

19 / 39

Page 87: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

revisitChaitin’s

proof

criticalflow-edgesplitting

swapproblem

# simult.defs

criticalflow-edgesplitting

π-motion

BU GA MEU

19 / 39

Page 88: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not.

Short answer: No

BU BU GA

20 / 39

Page 89: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No

BU BU GA

20 / 39

Page 90: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No

Longer answer:

Chordal graph= SSA case

Interval graph= basic block

weighted

no

yes

no

yes

Ω′ ≤ C

dyn. prog.

Ω′ ≤ R

furthest use

ILP

Ω′ ≤ Ω− 1

X3C

dyn. prog.

polynomial NP-complete new result

Previous studies by Belady, Yannakakis&Gavril, and Liberatore.

BU BU GA

20 / 39

Page 91: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No

Longer answer:

Chordal graph= SSA case

Interval graph= basic block

weighted

no

yes

no

yes

Ω′ ≤ C

dyn. prog.

Ω′ ≤ R

furthest use

ILP

Ω′ ≤ Ω− 1

X3C

dyn. prog.

polynomial NP-complete new result

Previous studies by Belady, Yannakakis&Gavril, and Liberatore.

BU BU GA

20 / 39

Page 92: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No

The problem of “holes.”

On RISC architectures, spilled variables leave small intervals behind.

a← . . ..... . .← a.... . .← a

spill a

a1 ← . . .store a1...a2 ← load. . .← a2...a3 ← load. . .← a3

BU BU GA

20 / 39

Page 93: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Spilling under SSA is still a difficult problemIn this thesis, we studied the complexity of spill everywhere under SSA toknow whether it would simplify the problem or not. Short answer: No

With “holes,” it becomes harder even on a basic block:

h = 1

h ≥ 2

h notbounded

weight

no

yes

no

yes

no

yes

Ω′ ≤ C

dyn. prog.

Ω′ ≤ R

?

stable set

stable set

Ω′ ≤ Ω− C

dyn. prog.

Ω′ ≤ Ω− 1

set cover

polynomial NP-complete new result

BU BU GA

20 / 39

Page 94: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

revisitChaitin’s

proof

criticalflow-edgesplitting

swapproblem

# simult.defs

criticalflow-edgesplitting

π-motion

spilling NOTsimplifiedby SSA

BU BU BU

21 / 39

Page 95: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

revisitChaitin’s

proof

criticalflow-edgesplitting

swapproblem

# simult.defs

criticalflow-edgesplitting

π-motion

spilling NOTsimplifiedby SSA

Coalescing(out-of-SSA)

edgesplitting

π-motion

heuristicscomplexity

BU BU BU

21 / 39

Page 96: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Outline

1 IntroductionLes ShadoksRegister allocation

2 Difficulty of register allocationStrict SSA graphs are chordalQuestions with register allocation in two phases

3 The coalescing problemIntroduction to coalescingIncremental coalescing

BU BU ZO

22 / 39

Page 97: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is coalescing?

Goal of coalescing

Removing the register-to-register copies [move a← b]

Numerous move due to:

live-range splitting toavoid spilling

register constraints

SSA destruction

Not a new problem, butnever studied not intermixedwith spilling.

BU BU MEU

23 / 39

Page 98: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is coalescing?

Goal of coalescing

Removing the register-to-register copies [move a← b]

Numerous move due to:

live-range splitting toavoid spilling

register constraints

SSA destruction

Not a new problem, butnever studied not intermixedwith spilling.

a← . . .b← . . .c← f(a, b)

a← . . .b← . . .move R0,amove R1,bcall fmove c,R0

BU BU MEU

23 / 39

Page 99: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is coalescing?

Goal of coalescing

Removing the register-to-register copies [move a← b]

Numerous move due to:

live-range splitting toavoid spilling

register constraints

SSA destruction

Not a new problem, butnever studied not intermixedwith spilling.

if (. . . )

a1 ← 1 a2 ← 2

a3 ← φ(a1, a2)· · · ← a3

BU BU MEU

23 / 39

Page 100: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is coalescing?

Goal of coalescing

Removing the register-to-register copies [move a← b]

Numerous move due to:

live-range splitting toavoid spilling

register constraints

SSA destruction

Not a new problem, butnever studied not intermixedwith spilling.

if (. . . )

a1 ← 1 a2 ← 2

a3 ← φ(a1, a2)· · · ← a3

move a3 ← a1 move a3 ← a2

BU BU MEU

23 / 39

Page 101: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

What is coalescing?

Goal of coalescing

Removing the register-to-register copies [move a← b]

Numerous move due to:

live-range splitting toavoid spilling

register constraints

SSA destruction

Not a new problem, butnever studied not intermixedwith spilling.

if (. . . )

a1 ← 1 a2 ← 2

a3 ← φ(a1, a2)· · · ← a3

move a3 ← a1 move a3 ← a2

BU BU MEU

23 / 39

Page 102: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Traditional modeling of the coalescing problem

Given an instruction [move a← b]

Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.

Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.

a

b c

d

Merge a and bab

c

d

We work on graphs instead of programs.

BU ZO GA

24 / 39

Page 103: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Traditional modeling of the coalescing problem

Given an instruction [move a← b]

Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.

Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.

a

b c

d

Merge a and bab

c

d

We work on graphs instead of programs.

BU ZO GA

24 / 39

Page 104: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Traditional modeling of the coalescing problem

Given an instruction [move a← b]

Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.

Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.

a

b c

d

Merge a and bab

c

d

We work on graphs instead of programs.

BU ZO GA

24 / 39

Page 105: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Traditional modeling of the coalescing problem

Given an instruction [move a← b]

Fact I Giving the same color to both a and b saves the instruction.Fact II Merging nodes a and b forces them to have the same color.

Idea Express this as an “affinity” between a and b in theinterference graph to drive the algorithm.

a

b c

d

Merge a and bab

c

d

We work on graphs instead of programs.

BU ZO GA

24 / 39

Page 106: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

Incremental

Conservative

Optimistic

BU ZO BU

25 / 39

Page 107: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

Coalesce as many affinitiesas possible.

Incremental

Conservative

Optimistic

BU ZO BU

25 / 39

Page 108: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

Conservative

Optimistic

BU ZO BU

25 / 39

Page 109: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

Conservative

Coalesce as many affinities aspossible but remains k-colorable.

Optimistic

BU ZO BU

25 / 39

Page 110: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

Conservative

a

b

d

c

e

a

b

d

c

e

x〈a,c〉

y〈a,c〉x〈b,a〉

y〈b,a〉

x〈d,b〉

y〈d,b〉 x〈c,d〉

y〈c,d〉

x〈c,e〉

y〈c,e〉

graph k-coloring

Optimistic

BU ZO BU

25 / 39

Page 111: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

Conservative

a

b

d

c

e

a

b

d

c

e

x〈a,c〉

y〈a,c〉x〈b,a〉

y〈b,a〉

x〈d,b〉

y〈d,b〉 x〈c,d〉

y〈c,d〉

x〈c,e〉

y〈c,e〉

graph k-coloring

Optimistic

Perform aggressive coalescing, thende-coalescing to get k-colorable.

BU ZO BU

25 / 39

Page 112: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

Conservative

a

b

d

c

e

a

b

d

c

e

x〈a,c〉

y〈a,c〉x〈b,a〉

y〈b,a〉

x〈d,b〉

y〈d,b〉 x〈c,d〉

y〈c,d〉

x〈c,e〉

y〈c,e〉

graph k-coloring

Optimistic

cv

v1

v2

v3cv

c′v

v1

v2

v3

cv

v1

v2

v3

3-vertex-cover

BU ZO BU

25 / 39

Page 113: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

Coalesce one affinity while stayingk-colorable.

Conservative

a

b

d

c

e

a

b

d

c

e

x〈a,c〉

y〈a,c〉x〈b,a〉

y〈b,a〉

x〈d,b〉

y〈d,b〉 x〈c,d〉

y〈c,d〉

x〈c,e〉

y〈c,e〉

graph k-coloring

Optimistic

cv

v1

v2

v3cv

c′v

v1

v2

v3

cv

v1

v2

v3

3-vertex-cover

BU ZO BU

25 / 39

Page 114: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

T

F

R

ci,1bi,1

ai,1yi,1

ai,2yi,2

ci,2bi,2

ai,3yi,3

ai,4yi,4

3-SAT

NP-complete for general graphs.

Polynomial for chordal graphs.

Conservative

a

b

d

c

e

a

b

d

c

e

x〈a,c〉

y〈a,c〉x〈b,a〉

y〈b,a〉

x〈d,b〉

y〈d,b〉 x〈c,d〉

y〈c,d〉

x〈c,e〉

y〈c,e〉

graph k-coloring

Optimistic

cv

v1

v2

v3cv

c′v

v1

v2

v3

cv

v1

v2

v3

3-vertex-cover

BU ZO BU

25 / 39

Page 115: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Different coalescing problems

Aggressive

s1s2

s3

uw

v

edge removeds1

s2

s3

uw

v

affinity notcoalesced

multiway-cut

Incremental

T

F

R

ci,1bi,1

ai,1yi,1

ai,2yi,2

ci,2bi,2

ai,3yi,3

ai,4yi,4

3-SAT

NP-complete for general graphs.

Polynomial for chordal graphs.

Conservative

a

b

d

c

e

a

b

d

c

e

x〈a,c〉

y〈a,c〉x〈b,a〉

y〈b,a〉

x〈d,b〉

y〈d,b〉 x〈c,d〉

y〈c,d〉

x〈c,e〉

y〈c,e〉

graph k-coloring

Optimistic

cv

v1

v2

v3cv

c′v

v1

v2

v3

cv

v1

v2

v3

3-vertex-cover

BU ZO BU

25 / 39

Page 116: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

The problem of incremental coalescing

The goal of incremental is to perform conservative coalescing bycoalescing affinities one by one.

Problem (Incremental coalescing)

Given a k-colorable graph G and two nodes x and y, is it possible to colorG such that x and y have the same color?

Theorem

The incremental coalescing problem is NP-complete.

BU ZO ZO

26 / 39

Page 117: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

BU ZO MEU

27 / 39

Page 118: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

x

x

BU ZO MEU

27 / 39

Page 119: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

x

x

y

y

BU ZO MEU

27 / 39

Page 120: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

x

x

y

yzz

BU ZO MEU

27 / 39

Page 121: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

x

x

y

yzz

w

w

BU ZO MEU

27 / 39

Page 122: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

x

x

y

yzz

w

w

v

v

BU ZO MEU

27 / 39

Page 123: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

First, equivalence between graph-3-coloring and 4-SAT.

3 nodes for True, False, and X

2 nodes for each variable: v and v

. . . and a widget to forbid everyvariable of a clause to be false

X

T F

x

x

y

yzz

w

w

v

v

BU ZO MEU

27 / 39

Page 124: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

w

z

y

x

T

F

X

Need a widget that is 3-colorable only if not all 4 variables are false.

BU ZO MEU

27 / 39

Page 125: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

w

z

y

x

T

F

X

Need a widget that is 3-colorable only if not all 4 variables are false.

BU ZO MEU

27 / 39

Page 126: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

w

z

y

x

T

F

X

If all 4 variables are false, not 3-colorable.

BU ZO MEU

27 / 39

Page 127: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

w

z

y

x

T

F

X

If at least one variable is true

, 3-colorable.

BU ZO MEU

27 / 39

Page 128: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

w

z

y

x

T

F

X

If at least one variable is true

, 3-colorable.

BU ZO MEU

27 / 39

Page 129: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

w

z

y

x

T

F

X

If at least one variable is true, 3-colorable.

BU ZO MEU

27 / 39

Page 130: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

Now, transform 3-SAT instance into 4-SAT by adding x0 to every clause:

(y ∨ z ∨ w) ∧ · · · ∧ (z ∨ y ∨ u)

becomes

(x0 ∨ y ∨ z ∨ w) ∧ · · · ∧ (x0 ∨ z ∨ y ∨ u)

Clearly, x0 =True satisfies the equation (i.e., the graph is 3-colorable).

BU ZO MEU

27 / 39

Page 131: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

Now, transform 3-SAT instance into 4-SAT by adding x0 to every clause:

(y ∨ z ∨ w) ∧ · · · ∧ (z ∨ y ∨ u)

becomes

(x0 ∨ y ∨ z ∨ w) ∧ · · · ∧ (x0 ∨ z ∨ y ∨ u)

Clearly, x0 =True satisfies the equation (i.e., the graph is 3-colorable).

Now, ask x0 and False to be coalesced. . .

BU ZO MEU

27 / 39

Page 132: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing is NP-complete in the general caseReduction from 3-SAT. (Similar to reduction of graph-3-coloring from 3-SAT).

Example on (x ∨ y ∨ z ∨ w) ∧ · · · ∧ (x ∨ z ∨ y ∨ u).

To conclude:

3-SAT is true ⇐⇒ 4-SAT is true with x0 = False

⇐⇒ graph is 3-colorable with x0 in red/False

⇐⇒ incremental coalescing of x0 with False is possible

BU ZO MEU

27 / 39

Page 133: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Incremental coalescing for chordal graphs

Problem (Incremental coalescing for chordal graphs)

Given a k-colorable chordal graph G and two nodes x and y. Is it possibleto color G such that x and y have the same color?

This problem is polynomial!

Moreover, if the answer is yes, it is possible to modify G so that x and y are

merged and G stays chordal.

The same question with greedy-k-colorable graphs is still open.

BU MEU GA

28 / 39

Page 134: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Example on a chordal graph

Let us consider a 3-colorable chordal graph.

Demo: graph in ubigraph

BU MEU BU

29 / 39

Page 135: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs as subtrees of a tree

BU MEU ZO

30 / 39

Page 136: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs as subtrees of a tree

BU MEU ZO

30 / 39

Page 137: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Chordal graphs as subtrees of a tree

BU MEU ZO

30 / 39

Page 138: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 139: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 140: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 141: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 142: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 143: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 144: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 145: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 146: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 147: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 148: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 149: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 150: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 151: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 152: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 153: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 154: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 155: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 156: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 157: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 158: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 159: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 160: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 161: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 162: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 163: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 164: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 165: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

xy

BU MEU MEU

31 / 39

Page 166: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 167: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 168: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 169: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 170: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 171: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 172: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Finding a path on the interval graphOnce the branches are pruned, an interval graph remains.

x y

BU MEU MEU

31 / 39

Page 173: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

A simple algorithmic strategy for chordal incrementalcoalescing

Building the representation of a chordal graph as subtrees of a tree ispainful.

We have devised an algorithmic strategy that works directly on the graph,using the same ideas as in Chaitin et al.’s greedy coloring algorithm.

ZO GA GA

32 / 39

Page 174: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Demonstration of coalescingDemonstration of conservative coalescing on graph #311 of the“Coalescing Challenge.” (Appel&George)

Demo: conservative coalescing ZO GA BU

33 / 39

Page 175: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Questions raised by register allocation in two phases

SSA = chordal(2002)

spillingsimplifiedby SSA?

Coalescing(out-of-SSA)

Chaitin’sproof

revisitChaitin’s

proof

criticalflow-edgesplitting

swapproblem

# simult.defs

criticalflow-edgesplitting

π-motion

spilling NOTsimplifiedby SSA

Coalescing(out-of-SSA)

edgesplitting

π-motion

heuristicscomplexity

WDDD’06

LCPC’06 (ext)LCTES’07 CGO’07

(best paper) CASES’08

not published

ZO GA ZO

34 / 39

Page 176: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Conclusion: practical work going on

This work was part of a collaboration with STMicroelectronics in Grenoble.Practical experiments were made during this thesis (coalescing). But a lotmore are going on, including:

including Hack’s spilling in LAO

experimenting new coalescing strategies in LAO

experimenting the permutation motion to avoid splitting edges

ZO GA MEU

35 / 39

Page 177: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Conclusion

Why are those results important for register allocation?The idea of separating register allocation in two phases has been aroundfor a while:

spilling is the most important issue

splitting helps (Briggs, Cooper) but copies are hard to remove

greedy coloring is not a good indicator for spilling

Assuming that some copies are always better than a spill:

Maxlive is an “oracle” for spilling

spilling can be optimized first so that Maxlive ≤ R

good coalescing strategies: do not worry about splitting anymore

ZO BU GA

36 / 39

Page 178: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

Remaining problems to work on

continuing the work on permutation motion

improving the spilling as a first phase

having a better “oracle” that handles registers constraints(Pereira&Palsberg)

register allocation in two phases for JIT

Maxlive indicator can be used for better instruction scheduling

Bonus: what will be written left to the pumping shadoks in next slide?

ZO BU BU

37 / 39

Page 179: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Introduction Difficulty of register allocation The coalescing problem Conclusion

That’s all for today

Answer: ZO BU ZO

ZO BU ZO

38 / 39

Page 180: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

i

j

c ′

d ′

g ′

1

2

34

2

332

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 181: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

i

j

j

c ′

d ′

g ′ 2

24

2

332

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 182: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

g

i

j

j

c ′

d ′

g ′

13

2

332

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 183: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

g

i

i

j

j

c ′

d ′

g ′

2

2

332

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 184: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e

f

f

g

g

i

i

j

j

c ′

d ′

g ′1

232

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 185: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e

f

f

g

g

i

i

j

j

c ′

d ′

g ′g ′

132

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 186: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d

e

e

f

f

g

g

i

i

j

j

c ′

d ′

g ′g ′

22

4 4

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 187: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′

g ′g ′

2

3 3

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 188: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′2 2

3

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 189: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

b

c

c

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′1

2

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 190: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

b

b

c

c

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′

1

1

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 191: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a a

b

b

c

c

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 192: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a a

b

b

c

c

dd

e

e

f

f

g

g

i

i

j

jc ′

c ′

d ′ d ′

g ′g ′

Hi-degree nodeLow-degree node

Return

ZO BU MEU

39 / 39

Page 193: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a a

b

b

c

c

dd

e

e

f

f

g

g

i

i

j

jc ′

c ′

d ′ d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 194: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a a

b

b

c

c

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 195: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

b

b

c

c

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 196: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

b

c

c

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 197: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′ d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 198: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

dd

e

e

f

f

g

g

i

i

j

j

c ′

d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 199: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d

e

e

f

f

g

g

i

i

j

j

c ′

d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 200: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e

f

f

g

g

i

i

j

j

c ′

d ′

g ′g ′

Return

ZO BU MEU

39 / 39

Page 201: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e

f

f

g

g

i

i

j

j

c ′

d ′

g ′Return

ZO BU MEU

39 / 39

Page 202: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

g

i

i

j

j

c ′

d ′

g ′Return

ZO BU MEU

39 / 39

Page 203: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

g

i

j

j

c ′

d ′

g ′Return

ZO BU MEU

39 / 39

Page 204: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

i

j

j

c ′

d ′

g ′Return

ZO BU MEU

39 / 39

Page 205: A Study of Spilling and Coalescing in Register Allocation as ...florent.bouchez.free.fr/?download=papers/florent.bouchez...Introduction Di culty of register allocation The coalescing

Greedy coloring scheme of Chaitin et al.

Greedy-k-colorable-graphs: simplify nodes with < k neighbors.

Sta

ck

a

bc

d e f

g

i

j

c ′

d ′

g ′Return

ZO BU MEU

39 / 39


Recommended