SSA Destruction after Register Allocation - Florent Bouchez Tichadou

Properties of an RTG: • Maximum in-degree equals 1. • 3 types of RTG (tree, cycle,. ) F. Bouchez (IISc – India). How to get the hell out of SSA? LCPC '09. 16 / 30 ...
1MB taille 4 téléchargements 390 vues
Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

SSA Destruction after Register Allocation Tutorial on Register Allocation under SSA ; Part 5

Florent Bouchez

[email protected] Indian Institute of Science Bangalore

LCPC ’09 — University of Delaware

1 / 30 F. Bouchez (IISc – India)

SSA Destruction after Register Allocation

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

How to get the hell out of SSA? Tutorial on Register Allocation under SSA ; Part 5

Florent Bouchez

[email protected] Indian Institute of Science Bangalore

LCPC ’09 — University of Delaware

2 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Outline Background: classical out-of-SSA Differences with out-of-SSA after register allocation under SSA Statement of the problem Moving parallel copies out of edges Experiments

3 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Outline Background: classical out-of-SSA Differences with out-of-SSA after register allocation under SSA Statement of the problem Moving parallel copies out of edges Experiments

4 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Cytron et al.’s out-of-SSA Cytron, Ferrante, Rosen, Wegman, Zadeck (1991) Efficiently computing static single assignment form and the control dependence graph. Na¨ıvely, a k -input φ-function at entrance to a node X can be replaced by k ordinary assignments, one at the end of each control flow predecessor of X . This is always correct.

5 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Cytron et al.’s out-of-SSA Cytron, Ferrante, Rosen, Wegman, Zadeck (1991) Efficiently computing static single assignment form and the control dependence graph.

Example a ← ...

b ← ...

c ← φ(a , b )

5 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Cytron et al.’s out-of-SSA Cytron, Ferrante, Rosen, Wegman, Zadeck (1991) Efficiently computing static single assignment form and the control dependence graph.

Example a ← ...

b ← ...

a ← ... c←a

b ← ... c←b

c ← φ(a , b )

5 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Briggs’s, Cooper’s out-of-SSA Briggs, Cooper, Harvey, Simpson (1998) Practical improvements to the construction and destruction of static single assignment form. Cytron et al.’s out-of-SSA works after some optimizations: • constant propagation • dead code elimination

6 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Briggs’s, Cooper’s out-of-SSA Briggs, Cooper, Harvey, Simpson (1998) Practical improvements to the construction and destruction of static single assignment form. Cytron et al.’s out-of-SSA works after some optimizations: • constant propagation • dead code elimination

But NOT if done after more aggressive ones: • copy folding • value numbering 6 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Lost copy problem Example a←1

c ← φ(a , b ) b ←c+1

··· ← c

7 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Lost copy problem Example a←1 c←a

a←1

c ← φ(a , b ) b ←c+1

b ←c+1 c←b

··· ← c

··· ← c

7 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Lost copy problem Example a←1 c←a

a←1

c ← φ(a , b ) b ←c+1

b ←c+1 c←b

··· ← c

··· ← c This is due to the critical edge.

7 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Swap problem Example

a ← φ(a , b ) b ← φ(b , a )

8 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Swap problem Example a←a b←b

a←b b←a

a ← φ(a , b ) b ← φ(b , a )

8 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Swap problem Example a←a b←b

a←b b←a

a ← φ(a , b ) b ← φ(b , a ) Copies induced by φ-functions must be executed in parallel. We call them ∥copies . 8 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sreedhar et al.’s out-of-SSA Sreedhar, Ju, Gillies, Santhanam (1999) Translating out of Static Single Assignment form.

Example a ← ...

b ← ...

c ← φ(a , b )

9 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sreedhar et al.’s out-of-SSA Sreedhar, Ju, Gillies, Santhanam (1999) Translating out of Static Single Assignment form.

Example a ← ...

b ← ...

a ← ... a0 ← a

b ← ... b0 ← b

c 0 ← φ(a 0 , b 0 ) c ← c0

c ← φ(a , b )

Adding primed variables à conventional SSA.

9 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sreedhar et al.’s out-of-SSA Sreedhar, Ju, Gillies, Santhanam (1999) Translating out of Static Single Assignment form.

Example a ← ...

b ← ...

a ← ... X ←a

b ← ... X ←b

c ← φ(a , b ) c←X Adding primed variables à conventional SSA. Then, all variables of the same φ-congruence class can be replaced by a common name. 9 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Outline Background: classical out-of-SSA Differences with out-of-SSA after register allocation under SSA Statement of the problem Moving parallel copies out of edges Experiments

10 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Flow of SSA vs. classical register allocation Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

SSA destruction

post SSA IR

Register allocation

Assembly

11 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Flow of SSA vs. classical register allocation Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

SSA destruction

post SSA IR

Register allocation

Assembly

Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

Assembly

11 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Flow of SSA vs. classical register allocation Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

SSA destruction

post SSA IR

Register allocation

Assembly

Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

Register allocation

Assembly

11 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Flow of SSA vs. classical register allocation Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

SSA destruction

post SSA IR

Register allocation

Assembly

SSA destruction

Assembly

Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

Register allocation

11 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Flow of SSA vs. classical register allocation Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

SSA destruction

post SSA IR

Register allocation

Assembly

Register allocation

Colored SSA form

SSA destruction

Assembly

Prog. optim. Interm. repr. (IR)

SSA conversion

SSA form IR

Only registers remains when translating out-of-SSA! à not possible to add new variables. F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

11 / 30

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Deal with the differences Without temporary variables: • Imitate Sreedhar using available registers as new variables.

But what if there are not enough registers? spill? à bad idea.

12 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Deal with the differences Without temporary variables: • Imitate Sreedhar using available registers as new variables.

But what if there are not enough registers? spill? à bad idea. • Problems are back: • ”swap problem” since copies order is important • critical edge poses the problem of where to put copies

12 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Deal with the differences Without temporary variables: • Imitate Sreedhar using available registers as new variables.

But what if there are not enough registers? spill? à bad idea. • Problems are back: • ”swap problem” since copies order is important • critical edge poses the problem of where to put copies

Back to semantics of φ-function: depends on the flow à split all incoming edges to place ∥copies, but performance problem!

12 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Splitting edges can be bad

Folk assumption that splitting edges is a bad thing to do: • adds a jump instruction • prevents mapping on hardware accelerator • code cannot be scheduled

13 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Splitting edges can be bad

Folk assumption that splitting edges is a bad thing to do: • adds a jump instruction • prevents mapping on hardware accelerator • code cannot be scheduled

We would like to have a way to not split (at least some) edges. Is it possible and how to do it?

13 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Outline Background: classical out-of-SSA Differences with out-of-SSA after register allocation under SSA Statement of the problem Moving parallel copies out of edges Experiments

14 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Problem statement

Goal: reduce the overhead due to the added copies and edge splitting during SSA destruction. We suppose there still remains ∥copies on edges after coalescing.

Problems • “parallel” problem: ∥copies must be sequentialized

à how to find a correct ordering? • if a ∥copy is placed on an edge, it must be split

à possible to move ∥copies out of edges?

15 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Modeling of ∥copies Simplifying fact: register allocation is done. ∥copies involves registers, not variables. à register transfer graphs (RTG), a graphical representation: R1 R1

R3

R2

R1

R2

R2

16 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Modeling of ∥copies Simplifying fact: register allocation is done. ∥copies involves registers, not variables. à register transfer graphs (RTG), a graphical representation: R1 R1

R3

R2

R1

R2

R2

Properties of an RTG: • Maximum in-degree equals 1 • 3 types of RTG (tree, cycle, F. Bouchez (IISc – India)

How to get the hell out of SSA?

) LCPC ’09

16 / 30

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Modeling of ∥copies Simplifying fact: register allocation is done. ∥copies involves registers, not variables. à register transfer graphs (RTG), a graphical representation:

R8 R9

R1

R7

R2 R10

R5

R6

R3 R4 Properties of an RTG: • Maximum in-degree equals 1 • 3 types of RTG (tree, cycle, windmill(general case)) F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

16 / 30

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Modeling of ∥copies Simplifying fact: register allocation is done. ∥copies involves registers, not variables. à register transfer graphs (RTG), a graphical representation: duplications R8 R9

R1

R7

R2 R10

R5

R6

R3 R4 Properties of an RTG: • Maximum in-degree equals 1 • 3 types of RTG (tree, cycle, windmill(general case)) F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

16 / 30

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Outline Background: classical out-of-SSA Differences with out-of-SSA after register allocation under SSA Statement of the problem Moving parallel copies out of edges Experiments

17 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Is it possible to move ∥copies out of edges? On a simple edge (i.e., non-critical): code can be placed on predecessor or successor basic block.

Example Bs

∥copy Bd

18 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Is it possible to move ∥copies out of edges? On a simple edge (i.e., non-critical): code can be placed on predecessor or successor basic block.

Example Bs

Bs

∥copy

∥copy

move up Bd

Bd

18 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Is it possible to move ∥copies out of edges? On a simple edge (i.e., non-critical): code can be placed on predecessor or successor basic block.

Example Bs

Bs

∥copy

move down

Bd

Bd

∥copy

18 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Is it possible to move ∥copies out of edges? On a simple edge (i.e., non-critical): code can be placed on predecessor or successor basic block.

Example Bs

Bs

∥copy

move down

Bd

Bd

∥copy

But what if Bs has more than one successor? Bd has more than one predecessor? 18 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

∥copies are hard to move out of critical edges Example B

A

D

C

19 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

∥copies are hard to move out of critical edges Example B

A

D

C x ← φ(y , z )

19 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

∥copies are hard to move out of critical edges Example B

A

D

C R1 ← φ(R2 , R3 )

19 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

∥copies are hard to move out of critical edges Example B

D R1 ← R3

R1 R3 R2

A

C

19 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

∥copies are hard to move out of critical edges Example D R1 ← R3

B

A

C R1 ← R2

Moving down erases R1 if path comes from D. 19 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

∥copies are hard to move out of critical edges Example B

R1 ← . . . R1 ← R2

A · · · ← R1

C

D R1 ← R3

Moving up might erase a live variable in R1 . 19 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Reversing the effect of parallel copies Idea: a ∥copy can be moved if its effects are cancelled on the other edges.

20 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Reversing the effect of parallel copies Idea: a ∥copy can be moved if its effects are cancelled on the other edges.

Example (Cancelling R1 ← R2 ) R1 ← . . . B R3 ← R1 R1 ← R2

A R1 ← R3

C

D R1 ← R3

R1 ← φ(R2 , R3 ) 20 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Reversing the effect of parallel copies Idea: a ∥copy can be moved if its effects are cancelled on the other edges.

Example (Cancelling R1 ← R2 ) B R1 ← . . .

A

C

D

R1 ← R3 R2 ← R1

R1 ← R2 R1 ← φ(R2 , R3 ) 20 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Reversing the effect of parallel copies Idea: a ∥copy can be moved if its effects are cancelled on the other edges.

Example (Duplication problem) B

D R1

A

C

R1 ← R2 R2 ← R3

R2

R1 ← φ(R1 , R2 ) R2 ← φ(R1 , R3 ) 20 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Reversing the effect of parallel copies Idea: a ∥copy can be moved if its effects are cancelled on the other edges. • Effects must be reversed if moving up. • Effects must be pre-reversed if moving down.

Problems • ∥copies involving overwriting of existing value must be carefully moved. à ∥copy motion is highly dependent on the liveness. • ∥copies with duplications cannot be pre-reversed.

20 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Extracting duplications from ∥copies Duplications can only be moved up. We want to extract them to ∥copies to get rid of them. This can be done using free registers.

Example R1

R1 R3

=

R1 R3

R2

R2

F. Bouchez (IISc – India)

How to get the hell out of SSA?



R3 R2

21 / 30 LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Extracting duplications from ∥copies Duplications can only be moved up. We want to extract them to ∥copies to get rid of them. This can be done using free registers.

Example B

D

R1 ← R2 R2 ← R3

R1 R3 A

R2 R1 ← φ(R1 , R2 ) C R2 ← φ(R1 , R3 ) 21 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Extracting duplications from ∥copies Duplications can only be moved up. We want to extract them to ∥copies to get rid of them. This can be done using free registers.

Example R1 R3

B R2

D

R1 ← R2 R2 ← R3

R1 R3

A

R2 R1 ← φ(R1 , R2 ) C R2 ← φ(R1 , R3 ) 21 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Extracting duplications from ∥copies Duplications can only be moved up. We want to extract them to ∥copies to get rid of them. This can be done using free registers. • Extracted duplications are moved up. • If preceding basic block has not enough free registers, one

needs to split or spill.

21 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Extracting duplications from ∥copies Duplications can only be moved up. We want to extract them to ∥copies to get rid of them. This can be done using free registers. • Extracted duplications are moved up. • If preceding basic block has not enough free registers, one

needs to split or spill. • There remains a reversible ∥copy: max out-degree = 1.

Example R1

R1 R3

reverse

R2

R3 R2 21 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Permutations to easily deal with liveness Liveness is important when moving ∥copies. Registers holding live variables must not be overwritten. We convert reversible ∥copies to permutations: à just close the open cycles in the RTG.

22 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Permutations to easily deal with liveness Liveness is important when moving ∥copies. Registers holding live variables must not be overwritten. We convert reversible ∥copies to permutations: à just close the open cycles in the RTG.

Example R1

R4 R3

R2

R6 R5

22 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Permutations to easily deal with liveness Liveness is important when moving ∥copies. Registers holding live variables must not be overwritten. We convert reversible ∥copies to permutations: à just close the open cycles in the RTG.

Example R1

R4 R3

R2

R6 R5

22 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion out of critical edges Example

B

A

D

C

23 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion out of critical edges Example

B

D

R1 R3 R2

A

C

23 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion out of critical edges Example

B

D

R1 R3 R2

A

C

23 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion out of critical edges Example R1 R3

B

D

R2 R1 R3

A

C

R2

23 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion out of critical edges Example R1 B

R3

D R2 R1

A

R3

C R2

This critical edge is weak: its adjacent edges are not critical. 23 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion follows weak critical edges

Example

Weakness is a property propagated along connected edges.

24 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion follows weak critical edges

wn do

do wn

Example

dow n

Weakness is a property propagated along connected edges.

24 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion follows weak critical edges

Example

wn do

do wn

up

up

up

dow n

Weakness is a property propagated along connected edges.

24 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

π-motion follows weak critical edges

Example up

wn do

wn do

do wn

up

up

dow n

Weakness is a property propagated along connected edges.

24 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong.

Example

25 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong.

Example

25 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong. • π-motion is not possible on strong critical edges

25 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong. • π-motion is not possible on strong critical edges • removing the ∥copies on such a multiplexing region is

NP-complete

25 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong. • π-motion is not possible on strong critical edges • removing the ∥copies on such a multiplexing region is

NP-complete

Example Broot

d c Ba ,b

b

d

switch Ba ,c a←0 b←1 x ←a+b

a

Ba

Bb ,d a←3 c←3 x ←a+c

Bb return a + x

Bc return b + x

c←9 d←9 x ←c+d

b←6 d←6 x ←b +d

x

b

Bc ,d

c

a

Bd return c + x

return d + x 25 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong. • π-motion is not possible on strong critical edges • removing the ∥copies on such a multiplexing region is

NP-complete

Example Broot

d c Ba ,b

b

d

switch Ba ,c a←0 b←1 x ←a+b

a

Ba

Bb ,d a←3 c←3 x ←a+c

Bb return a + x

Bc return b + x

c←9 d←9 x ←c+d

b←6 d←6 x ←b +d

x

b

Bc ,d

c

a

Bd return c + x

return d + x 25 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Intrinsic difficulty strong critical edges Connected critical edges forming a cycle are strong. • π-motion is not possible on strong critical edges • removing the ∥copies on such a multiplexing region is

NP-complete

Example Broot

d c Ba ,b

b

d

switch Ba ,c a←0 b←1 x←a+b

a

Ba

Bb ,d a←3 c←3 x←a+c

Bb return a + x

Bc return b + x

c←9 d←9 x←c+d

b←6 d←6 x←b+d

x

b

Bc ,d

c

a

Bd return c + x

return d + x 25 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 1. Liveness projection R8 R9

Non Live = {R5 , R7 }

R1

R7

R2 R10

R5

R6

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 2. Sequentialize chains R8 R9

R1

R7

R2 R10

R5

R6

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 2. Sequentialize chains R8 R9

R7 ← R6

R1

R7

R2 R10

R5

R6

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 2. Sequentialize chains R8 R9

R1

R7

R2 R10

R5

R7 ← R6 R5 ← R4

R6

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 2. Sequentialize chains R8 R9

R1

R7

R2 R10

R5

R7 ← R6 R5 ← R4 R4 ← R3

R6

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 2. Sequentialize chains R8 R9

R1

R7

R2 R10

R5

R6

R7 R5 R4 R3

← R6 ← R4 ← R3 ← R2

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies.

R8 R9

R1

R7

R2 R10

R5

R6

R7 R5 R4 R3 R2

← R6 ← R4 ← R3 ← R2 ← R1

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 3. Mark root of chain as “free” R8 R9

R1

R7

R2 R10

R5

R6

R7 R5 R4 R3 R2

← R6 ← R4 ← R3 ← R2 ← R1

R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4. Use free register for cycles R8 R9

R1

R7

R2 R10

R5

R6

R3 R4

R7 R5 R4 R3 R2 R1

← R6 ← R4 ← R3 ← R2 ← R1 ← R10

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4. Use free register for cycles R8 R9

R1

R7

R2 R10

R5

R6

R3 R4

R7 ← R6 R5 ← R4 R4 ← R3 R3 ← R2 R2 ← R1 R1 ← R10 R10 ← R9

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4. Use free register for cycles R8 R9

R1

R7

R2 R10

R5

R6

R3 R4

R7 ← R6 R5 ← R4 R4 ← R3 R3 ← R2 R2 ← R1 R1 ← R10 R10 ← R9 R9 ← R8

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4. Use free register for cycles R8 R9

R1

R7

R2 R10

R5

R6

R3 R4

R7 ← R6 R5 ← R4 R4 ← R3 R3 ← R2 R2 ← R1 R1 ← R10 R10 ← R9 R9 ← R8 R8 ← R1 26 / 30

F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4’. (only cycles) No free register à swap R1 R2 R5 R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4’. (only cycles) No free register à swap swap(R1 , R5 )

R1 R2 R5 R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4’. (only cycles) No free register à swap swap(R1 , R5 ) swap(R2 , R5 )

R1 R2 R5 R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4’. (only cycles) No free register à swap swap(R1 , R5 ) swap(R2 , R5 ) swap(R3 , R5 )

R1 R2 R5 R3 R4

26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Sequentialize permutations Permutations must eventually be converted to actual copies. Step 4’. (only cycles) No free register à swap swap(R1 , R5 ) swap(R2 , R5 ) swap(R3 , R5 ) swap(R4 , R5 )

R1 R2 R5 R3

Swaps can be hardware or emulated (by using 3 XOR).

R4

If swapping is impossible, spilling is required. 26 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Outline Background: classical out-of-SSA Differences with out-of-SSA after register allocation under SSA Statement of the problem Moving parallel copies out of edges Experiments

27 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Experiments Different approaches to deal with ∥copies on edges: • split: edges are split by default • π-motion: ∥copies are moved out of edges whenever possible • done after coalescing (IRC1 ) or not

Number of split edges in SPEC2000

Average per bench Total number of edges

After coalescing split π-motion 257 45.5 2829 499

No coalescing split π-motion 1338 51.5 14725 567

For about 180 000 total edges.

1

Iterated Register Coalescing of Appel&George

F. Bouchez (IISc – India)

How to get the hell out of SSA?

28 / 30 LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

Conclusion SSA destruction after register allocation means: • new variable creation not possible • reappearance of “swap problem” and “critical edge problem”

Emergency instructions to get out-of-SSA 1. φ-functions are replaced by ∥copies on incoming edges 2. ∥copies are decomposed into duplications (moved up) and reversible ∥copies 3. ∥copies are converted to permutations for easier handling 4. permutations can be moved out of weak critical edges 5. permutations are converted back to ∥copies and sequentialized in a working order. 29 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09

Background

out-of-SSA after RA

The problem

Moving ∥copies

Experiments

Conclusion

That’s all for today

30 / 30 F. Bouchez (IISc – India)

How to get the hell out of SSA?

LCPC ’09