On the Complexity of Spill Everywhere under SSA Form

The rules of the game. 2. How SSA simplifies Register Allocation. Assignment part. The optimization problem (rough version). 3. Spill Everywhere easy under ...
641KB taille 3 téléchargements 296 vues
On the Complexity of Spill Everywhere under SSA Form F. Bouchez? , A. Darte? and F. Rastello? ? LIP

Compsys UMR CNRS - Inria - ENS Lyon - UCBL France LCTES, june 2007

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

1 / 21

Outline 1

The rules of the game

2

How SSA simplifies Register Allocation Assignment part The optimization problem (rough version)

3

Spill Everywhere easy under SSA?

4

Refining the model

5

Results and conclusion

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

2 / 21

Outline 1

The rules of the game

2

How SSA simplifies Register Allocation Assignment part The optimization problem (rough version)

3

Spill Everywhere easy under SSA?

4

Refining the model

5

Results and conclusion

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

3 / 21

What is Register Allocation? Assign variables to Registers (

) & Memory (infinite)

Architectural subtleties Specific registers (sp, fp, r0), Variable affinities (auto-inc), register pairing (64 bits ops), Distributed register banks, etc.

Rules of the game Fixed instruction schedule Spill: insert LOADS and STORES Split: add register-to-register MOVES Coalesce: delete MOVES

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

4 / 21

What is Register Allocation? Assign variables to Registers (

) & Memory (infinite)

Architectural subtleties Specific registers (sp, fp, r0), Variable affinities (auto-inc), register pairing (64 bits ops), Distributed register banks, etc.

Rules of the game Fixed instruction schedule Spill: insert LOADS and STORES Split: add register-to-register MOVES Coalesce: delete MOVES

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

4 / 21

What is Register Allocation (cont)?

Allocation vs Assignment Allocation: which variables are allocated to memory (spilled), which ones are allocated to registers? Assignment: assign non spilled variables to registers

Allocation pb Is spilling necessary (assignment feasible)? What to spill and where to insert loads & stores?

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

5 / 21

Outline 1

The rules of the game

2

How SSA simplifies Register Allocation Assignment part The optimization problem (rough version)

3

Spill Everywhere easy under SSA?

4

Refining the model

5

Results and conclusion

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

6 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d Live−out: k’ j’

SSA code Live−in: k1 j1

General CFG Live−in: k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block kj Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g h

SSA code

f e

Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block j Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g h

SSA code

f e

Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g h

SSA code

f e

Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

h

SSA code

f e

Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

SSA code

f e

Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

SSA code

e

Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

SSA code Live−in: k1 j1

General CFG Live−in: k j

m b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

SSA code Live−in: k1 j1

General CFG Live−in: k j

b c d k’ j’

Live−out: k’ j’

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

SSA code Live−in: k1 j1

c d j’

Live−out: k’ j’

General CFG Live−in: k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

SSA code Live−in: k1 j1

d j’

Live−out: k’ j’

General CFG Live−in: k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d Live−out: k’ j’

SSA code Live−in: k1 j1

General CFG Live−in: k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d Live−out: k’ j’

SSA code Live−in: k1 j1

General CFG Live−in: k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” Basic block

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d Live−out: k’ j’

SSA code Live−in: k1 j1

General CFG Live−in: k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

g h f e m b c d k j

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test Linear scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

7 / 21

“Spilling easier on a BB than on a general CFG” General control flow graph Live−in: k j

BB

g h f e m b c d k j

SSA

Live−in: k1 j1

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

Live−out: k’ j’

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

COLORING test Gready coloring

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

8 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Static Single Assignment form Live−in: k1 j1

BB Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

CFG

Live−in: k j

g h f e m b c d k j

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2)

Live−out: k j

MAXLIVE test Tree scan

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

9 / 21

“Under SSA: the dominance tree” Basic block

SSA form Live−in: k1 j1

General CFG Live−in: k j

Live−in: k j g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

m b c d k’ j’

g h f e m b c d k j

g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k2 := m+4 j2 := b+d

Live−out: k’ j’

:= := := := := := := := := :=

mem[j+12] k−1 g+h mem[j+8] mem[j+16] mem[f] e+8 c m+4 b+d

k

g h j e

f m b

c d

k := phi(k1,k2) j := phi(j1,j2) Live−out: k j

MAXLIVE test

MAXLIVE test

COLORING test

Linear scan

Tree scan

Gready coloring

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

10 / 21

Spill everywhere optimization problem

“Spill everywhere” formalization Live ranges of a program: intervals for a basic block sub-trees for a CFG under SSA

Spill a variable removes its entire live-range The spill of a variable may have a cost (weight) MAXLIVE = maximum number of simultaneously live variables r = number of available registers Spill a minumum weight of variables such that MAXLIVE is lowered to r

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

11 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady).

kj g h f e m b c d k k’ j j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

kj g h f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

kj g

Possibilities at a program point.

h f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

j

Possibilities at a program point. f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

j

Possibilities at a program point. Spill j, Keep f

f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

j

Possibilities at a program point. Spill j, Keep f

f e

Keep j, Spill f

m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

j

Possibilities at a program point. Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

j

Possibilities at a program point. Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

Possibilities at a program point. j

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming.

kj g

Possibilities at a program point.

h

Spill j, Keep f

f e

Keep j, Spill f

m b

Spill j, Spill f

c d

Keep j, Keep f

k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Spill everywhere optimization problem on a Basic bloc Furthest-First algorithm (Bellady). Only if unweighted Dynamic programming. Only if r is small ILP with a totally unimodular matrix Solve the following {0, 1} lin. prog.: n o ~ .~x | C~x ≤ ~r , ~0 ≤ ~x ≤ ~1 max w

kj g h f

where:

e m

wi = cost of removing (spilling) variable vi

b c d k’ j’

C = (cp,v ) = incidence matrix of variables on program points xi = 0 iff vi is removed

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

12 / 21

Outline 1

The rules of the game

2

How SSA simplifies Register Allocation Assignment part The optimization problem (rough version)

3

Spill Everywhere easy under SSA?

4

Refining the model

5

Results and conclusion

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

13 / 21

Spill everywhere optimization problem on a general CFG under SSA Interval graph

Path graph

Chordal graph Ta

Pc

Ib

Tc

Ia

Te

Pe

Ic

Tb Tf

Pf

Id Pd

Td a

a

b

c

c b

e

d

c

d

f

e

d

f

Interval/Path/Chordal graphs are perfect and intersection graphs Interval/Path graph incidence matrices are totally unimodular What about chordal graphs incidence matrices? F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

14 / 21

Is spill everywhere optimization easy under SSA? NO: Yannakakis & Gavril (graph theory): NP-complete in the general case, even if unweighted.

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

15 / 21

Is spill everywhere optimization easy under SSA? NO: Yannakakis & Gavril (graph theory): NP-complete in the general case, even if unweighted.

K

ep

t

Dynamic programming for BB can be generalized.

0

r

Maxlive

Polynomial with fixed r = k

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

15 / 21

Is spill everywhere optimization easy under SSA? NO: Yannakakis & Gavril (graph theory): NP-complete in the general case, even if unweighted.

0

Sp

K

ill

ep

t

ed

Dynamic programming for BB can be generalized.

r

Polynomial with fixed r = k

Maxlive

0

r

Maxlive

r = MAXLIVE − k NP-complete even with unweighted version and k = 1

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

15 / 21

Is spill everywhere optimization easy under SSA? NO: Yannakakis & Gavril (graph theory): NP-complete in the general case, even if unweighted.

Sp

ill

ed

Dynamic programming for BB can be generalized.

0

r

Polynomial with fixed r = k

Maxlive

0

r

Maxlive

r = MAXLIVE − k NP-complete even with unweighted version and k = 1

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

15 / 21

Outline 1

The rules of the game

2

How SSA simplifies Register Allocation Assignment part The optimization problem (rough version)

3

Spill Everywhere easy under SSA?

4

Refining the model

5

Results and conclusion

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

16 / 21

Spilling inserts local variables

kj g

g := mem[j+12] h := k−1 f := g+h

h f e

e := mem[j+8]

m

m := mem[j+16]

b

b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj

Spill j,m,k’

g

g := mem[j+12] h := k−1 f := g+h

h f e

e := mem[j+8]

m

m := mem[j+16]

b

b := mem[f] c := e+8 d := c k’ := m+4 j’ := b+d

c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj load j g := mem[j+12] h := k−1 f := g+h load j e := mem[j+8] load j m := mem[j+16] store m b := mem[f] c := e+8 d := c load m k’ := m+4 store k’ j’ := b+d

Spill j,m,k’

g h f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj load j g := mem[j+12] h := k−1 f := g+h load j e := mem[j+8] load j m := mem[j+16] store m b := mem[f] c := e+8 d := c load m k’ := m+4 store k’ j’ := b+d

Spill j,m,k’

g h

New temporary variables created

f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj load j g := mem[j+12] h := k−1 f := g+h load j e := mem[j+8] load j m := mem[j+16] store m b := mem[f] c := e+8 d := c load m k’ := m+4 store k’ j’ := b+d

Spill j,m,k’

g h

New temporary variables created

f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj load j g := mem[j+12] h := k−1 f := g+h load j e := mem[j+8] load j m := mem[j+16] store m b := mem[f] c := e+8 d := c load m k’ := m+4 store k’ j’ := b+d

Spill j,m,k’

g h

New temporary variables created

f e m b c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj

Spill j,m,k’

g

g := mem[j+12] h := k−1 f := g+h

h

e

e := mem[j+8]

b

b := mem[f] c := e+8 d := c

j’ := b+d

The intervals removed contain “holes”

m

m := mem[j+16]

k’ := m+4

New temporary variables created

f

c d k’ j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

kj

Spill j,m,k’

g

g := mem[j+12] h := k−1 f := g+h

h

e

e := mem[j+8]

b

b := mem[f] c := e+8 d := c k’ := m+4

The intervals removed contain “holes”

m

m := mem[j+16]

j’ := b+d

New temporary variables created

f

c d k’

Spilling these variables leaves “chads”

j’

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

Spill j,m,k’ g := mem[j+12] h := k−1 f := g+h e := mem[j+8] m := mem[j+16] b := mem[f] c := e+8 d := c k’ := m+4

New temporary variables created The intervals removed contain “holes” Spilling these variables leaves “chads”

j’ := b+d

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Spilling inserts local variables

Spill j,m,k’ g := mem[j+12] h := k−1 f := g+h

New temporary variables created

e := mem[j+8]

The intervals removed contain “holes”

m := mem[j+16] b := mem[f] c := e+8 d := c

Spilling these variables leaves “chads”

k’ := m+4 j’ := b+d

Without holes

With holes

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

Load-store

17 / 21

Spilling inserts local variables

Spill j,m,k’ g := mem[j+12] h := k−1 f := g+h

New temporary variables created

e := mem[j+8]

The intervals removed contain “holes”

m := mem[j+16] b := mem[f] c := e+8 d := c

Spilling these variables leaves “chads”

k’ := m+4 j’ := b+d

Without holes

With holes

Load-store

Polynomial (ILP)

Complexity?

NP-C (Liberatore)

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

17 / 21

Outline 1

The rules of the game

2

How SSA simplifies Register Allocation Assignment part The optimization problem (rough version)

3

Spill Everywhere easy under SSA?

4

Refining the model

5

Results and conclusion

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

18 / 21

Complexity results

Spill everywhere without Holes Interval graph Chordal graph

few reg. P P dyn. prog.

general case P ILP NP

many reg. P dyn. prog. NP 3-exact cover

Spill everywhere with Holes on a basic block h fixed h not bounded

few reg. P P dyn. prog.

general case NP stable set NP

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

many reg. P dyn. prog. NP set cover

19 / 21

Motivations Why studying the complexity of spill everywhere? 1

Practical for JIT compilation: simple model no need to deal (using data flow) with inconsistencies on block borders

2

A global optimization problem to drive local decisions

3

Unknown complexity: a hope for polynomial results

Why considering spill everywhere with or without holes? The model without holes can be expressed as a node deletion problem (graph theory) The model with holes is more realistic but still easier than Load-store

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

20 / 21

Conclusion Main results Spill everywhere even without holes is not easy under SSA The complexity comes from: the number of registers the degree of the dominance tree 3 the number of arguments per instruction

1

2

Complexity is asymetric: adding variables iteratively is easier than removing variables iteratively

Practical implications Not surprising that optimal ILP formulations work (e.g. George et al., Hack et al., etc.) on architectures with few registers Branch & bound, with dynamic programming, can be used for architectures with few registers (even for load-store) Iterative heuristic possible for architectures with more registers or for split compilation

F. Rastello (Compsys ? LIP UMR CNRS - Inria - ENS Lyon SSA - UCBL & Spill France Complexity )

21 / 21