reader: pushpinder kaur chouhan

35
1 Authors: Vugranam C. Sreedhar, Roy Dz- Ching Ju, David M. Gilles and Vatsa Santhanam Reader: Pushpinder Kaur Chouhan Translating Out of Static Single Assignment Form

Upload: darin

Post on 06-Feb-2016

53 views

Category:

Documents


0 download

DESCRIPTION

Translating Out of Static Single Assignment Form. Authors: Vugranam C. Sreedhar, Roy Dz-Ching Ju, David M. Gilles and Vatsa Santhanam. Reader: Pushpinder Kaur Chouhan. Translating Out of SSA Form. Introduction Basic Keywords Algorithm for going out of SSA form - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Reader:  Pushpinder Kaur Chouhan

1

Authors: Vugranam C. Sreedhar, Roy Dz-Ching Ju, David M. Gilles and Vatsa

Santhanam

Reader: Pushpinder Kaur Chouhan

Translating Out of Static Single Assignment Form

Page 2: Reader:  Pushpinder Kaur Chouhan

2

Translating Out of SSA Form

Introduction Basic Keywords Algorithm for going out of SSA form Experimental Results Conclusion References

Page 3: Reader:  Pushpinder Kaur Chouhan

3

Translating Out of SSA Form Introduction

Definition of SSA form Role of SSA form in Compiler A new framework for leaving SSA form A new CSSA-based coalescing algorithm

Basic Keywords Algorithm for going out of SSA form Experimental Results Conclusion References

Page 4: Reader:  Pushpinder Kaur Chouhan

4

Introduction

Static Single Assignment form is an intermediate representation that compilers use to facilitate program analysis and optimization.

Original Optimized

Intermediate Code Intermediate Code

P0 P1 P2 …………………………………… Pn

Role of SSA form in a compiler

Algorithm for going out of SSA form.

Algorithm for eliminating redundant copies.

Page 5: Reader:  Pushpinder Kaur Chouhan

5

Translating Out of SSA Form Introduction Basic Keywords

Phi Congruence Class Phi Congruence Property Liveness and Interference

Algorithm for going out of SSA form Experimental Results Conclusion References

Page 6: Reader:  Pushpinder Kaur Chouhan

6

Phi Congruence Class[x] is the reflexive and transitive closure of phiConnectedResource(x), where phiConnectedResource(x) = {y | x and y are referenced in the same phi instruction} .

Phi Congruence Property states that the occurrences of all resources which belong to the same phi congruence class in a program can be replaced by representative resource.

Basic Keywords

Page 7: Reader:  Pushpinder Kaur Chouhan

7

Liveness and Interference – A variable is live at a program

point P if there exists a path from P to a use of x that contains no definition of x.

Two variables in a program are said to interferer if their live ranges overlap at any program point.

LiveIn[L]: The set of resources that are live at the beginning of the basic block L.

LiveOut[L]: The set of resources that are live at the end of the basic block L.

Basic Keywords

Page 8: Reader:  Pushpinder Kaur Chouhan

8

Translating Out of SSA Form

Introduction Basic Keywords Algorithm for going out of SSA form

Translating the TSSA form to a CSSA form Eliminating redundant copies Eliminating phi instructions and leaving the CSSA form

Experimental Results Conclusion References

Page 9: Reader:  Pushpinder Kaur Chouhan

9

Translating the TSSA form to a CSSA form Naïve Translation Translation based on Interference Graph Translation based on Data Flow and Interference Graph

Eliminating redundant copies CSSA-based coalescing algorithm

Eliminating phi instruction and leaving the CSSA form Eliminate the phi instruction by replacing all references in the phi

instruction by a representative resource.

Algorithm for going out of SSA form

Page 10: Reader:  Pushpinder Kaur Chouhan

10

TSSA form – The SSA form transformed to a state in which there are phi resource interference.

CSSA form – The SSA from that has the phi congruence property.

Translating the TSSA form to a CSSA form

Y=X1=

x3=phi(x1:L1, x2:L2)Z=x3

X2=y

An example program in SSA form

x2=X1=

x3=phi(x1:L1, x2:L2)Z=x3

L1

L2

L1

L3 L3

L2

An example program in TSSA form

Page 11: Reader:  Pushpinder Kaur Chouhan

11

Translating the TSSA form to a CSSA form

x3=phi(x1:L1, x2:L2)Z=x3

x2=

x2=x1=

x2’=x2

x3’=phi(x1’:L1, x2’:L2)x3=x3’Z=x3

L1

L2

L1

L3 L3

L2

An example program in TSSA form

Naïve Translation method Insert the copies for all resources referenced in a phi instruction.

CSSA form

x2=X1=

x1’=x1

Page 12: Reader:  Pushpinder Kaur Chouhan

12

Translating the TSSA form to a CSSA form

x3=phi(x1:L1, x2:L2)Z=x3

x2=

x2=x1=

x2’=x2

x3=phi(x1’:L1, x2’:L2)Z=x3

L1

L2

L1

L3 L3

L2

An example program in TSSA form

Translation based on Interference Graph Insert the copies only if resources of phi instruction interfere.

CSSA form

x2=X1=

x1’=x1

Page 13: Reader:  Pushpinder Kaur Chouhan

13

Translating the TSSA form to a CSSA form

x3=phi(x1:L1, x2:L2)Z=x3

x2=

x2=x1=

x2’=x2

x3=phi(x1:L1, x2’:L2)Z=x3

L1

L2

L1

L3 L3

L2

An example program in TSSA form

Translation based on Data Flow and Interference Graph Use LiveOut sets to eliminate the interference among phi source resources. Use LiveIn and LiveOut sets to eliminate interferences between the target

resource and a source resource.

CSSA form

x2=X1=

Page 14: Reader:  Pushpinder Kaur Chouhan

14

Main Feature of Algorithm

First check whether for any pair of resources, xi:Li and xj:Lj in a phi instruction, where 0<=i, j<=n and xi =! xj, there exists resource yi in phiCongruenceClass[xi], yj in phiCongruenceClass[xj] and yi and yj interfere.

If so we will insert copies to ensure that xi and xj will not be put in the same phi congruence class. Consider the case in which both xi and xj are source resources in the phi instruction.

There are four cases to consider to insert copies instructions for resources in the phi instruction.

Page 15: Reader:  Pushpinder Kaur Chouhan

15

CASE 1. The intersection of phiCongruenceClass[xi] and LiveOut[Lj] isnot empty and the intersection of phiCongruenceClass[xj] and LiveOut[Li] is empty. A new copy, xi’=xi, is needed in Li.

CASE 2. The intersection of phiCongruenceClass[xi] and LiveOut[Lj] isempty and the intersection of phiCongruenceClass[xj] and LiveOut[Li] isnot empty. A new copy, xj’=xj, is needed in Lj.

CASE 3. The intersection of phiCongruenceClass[xi] and LiveOut[Lj] isnot empty, and the intersection of phiCongruenceClass[xj] and LiveOut[Li] is not empty. Two new copies, xi’=xi in Li and xj’=xj in Lj, are needed to ensure that xi and xj are put in different phi congruence classes.

CASE 4. The intersection of phiCongruenceClass[xi] and LiveOut[Lj] isempty, and the intersection of phiCongruenceClass[xj] and LiveOut[Li] isempty. Either a copy, xi’=xi in Li, or a copy, xj’=xj in Lj, is sufficient toeliminate the interference between xi and xj. However, the final decision of which copy to insert is deferred until all pairs of interfering resources in the phi instruction are processed.

Page 16: Reader:  Pushpinder Kaur Chouhan

16

An example to illustrate the algorithm of Method III

X3=X1=

X2=X1=

X0=phi(X1:L1,X2:L2, X3:L3)

L2

L3

L1

L0

L4

phiCongruenceClass[xi]={xi}

LiveOut sets:

L1={x1}

L2={x2}

L3={x1,x3}

Use LiveOut sets to eliminate the interference among phi source resources.

Page 17: Reader:  Pushpinder Kaur Chouhan

17

An example to illustrate the algorithm of Method III

X3=X1=

X2=X2’=x2X1=

X0=phi(X1:L1,X2:L2, X3:L3)

L2

L3

L1

L0

L4

phiCongruenceClass[x1]={x1}

phiCongruenceClass[x2]={x2}

LiveOut[1]={x1}

LiveOut[2]={x2}

According to Case 4.

Use LiveOut sets to eliminate the interference among phi source resources.

Page 18: Reader:  Pushpinder Kaur Chouhan

18

An example to illustrate the algorithm of Method III

X3=X1=

X2=X2’=x2

X1=X1’=x1

X0=phi(X1:L1,X2:L2, X3:L3)

L2

L3

L1

L0

L4

phiCongruenceClass[x1]={x1}

phiCongruenceClass[x3]={x3}

LiveOut[1] = {x1}

LiveOut[3] = {x1,x3}

According to Case 1.

Use LiveOut sets to eliminate the interference among phi source resources.

Page 19: Reader:  Pushpinder Kaur Chouhan

19

An example to illustrate the algorithm of Method III

Use LiveIn and LiveOut sets to eliminate interferences between the target resource and a source resource.

x1=

x2=phi(x1:L1,x3:L2)x3=x2+1

=x2

x1=

x2’=phi(x1:L1,x3:L2)x2=x2’

x3=x2+1

=x2

L1L1

L3

L2

L3

L2

X2 and x3 interfere

LiveOut[L2] = {x2,x3}

LiveIn[L2] = {x2}

Page 20: Reader:  Pushpinder Kaur Chouhan

20

Eliminating Redundant Copies

CASE 1: phiCongruenceClass[x]=={} and phiCongruenceClass[y]=={}.This means that x and y are not referenced in any phi instruction. Thecopy can be removed even if x and y interfere.CASE 2: phiCongruenceClass[x]=={} and phiCongruenceClass[y]=! {}. If x interferes with any resource in (phiCongruenceClass[y]-y) then the copy can not be removed, otherwise it can be removed.CASE 3: phiCongruenceClass[x] =! {}and phiCongruenceClass[y]== {}. If y interferes with any resource in (phiCongruenceClass[x]- x) then the copy can not be removed, otherwise it can be removed.CASE 4: phiCongruenceClass[x] =! {} and phiCongruenceClass[y]=! {}. The copy cannot be removed if any resource in phiCongruenceClass[x] interferes with any resource in (phiCongruenceClass[y]-y) or if any resource in phiCongruenceClass[y] interferes with any resource in (phiCongruenceClass[x]-x), otherwise it can be removed.

For eliminating redundant copies, CSSA-based coalescing algorithm can be used, as it can eliminate copies even when their live ranges interfere, so long as the coalesced live range does not introduced any phi resource interference.

Page 21: Reader:  Pushpinder Kaur Chouhan

21

Example of Copy Elimination

Y1=30X1=y1

Y2=10 X2=20

Y3=phi(y1,y2)Foo(y3)

x3=phi(x1,x2)Goo(x3)

Y=30 Y=10 X=20

Goo(x3)Foo(y3)

PhiCongruenceClass[x1] = {x1,x2,x3}

PhiCongruenceClass[y1] = {y1,y2,y3}

Page 22: Reader:  Pushpinder Kaur Chouhan

22

Eliminating phi instructions and leaving the CSSA form

Eliminate the phi instruction by replacing all references in the phi instruction (belonging to the same phi congruence class) by a representative resource.

x1=

x2’=phi(x1:L1,x3:L2)x2=x2’

x3=x2+1

=x2

x=

x2=xx=x2+1

=x2

L1

L3

L2

L1

L3

L2

Replace x1,x2’ and x3 by x

Page 23: Reader:  Pushpinder Kaur Chouhan

23

Translating Out of SSA Form

Introduction

Basic Keywords

Algorithm for going out of SSA form

Experimental Results Based on compilation time

Based on space usage

Conclusion

References

Page 24: Reader:  Pushpinder Kaur Chouhan

24

Experimental Results

Procedure Name

BT Methods

AT AT-BT AC DF/IG(secs)

TT(secs)

TC(secs)

Total(secs)

Yylex

(gcc)

1573 I

II

III

4632

1825

1648

3050

252

74

660

670

493

6.37

5.30

5.86

0.60

0.90

0.38

3.78

1.61

1.62

10.75

7.81

7.86

Ttin

(o/s code)

539 I

II

III

2389

1369

761

1850

830

222

826

1201

600

3.44

2.43

2.59

0.20

2.21

0.87

1.41

0.30

0.18

5.05

4.94

3.64

% Improvem

ent

I

II

III

*

*

*

*

72.1

89.9

*

-29.1

8.6

*

*

*

*

*

*

*

*

*

*

13.1

15.1

Page 25: Reader:  Pushpinder Kaur Chouhan

25

Based on space usage – Method III introduce 90% fewer copies than method I Method II introduce 72% fewer copies than method I

Based on Compilation time - Method III is 15% better than method I

CSSA-based coalescing algorithm – Most effective for method I

Experimental Results

Page 26: Reader:  Pushpinder Kaur Chouhan

26

LiveOut sets are used to eliminate interference among

phi source resources.

LiveOut and LiveIn sets are used to eliminate interference between the target resource and a source resource.

Translation based on Data Flow and Interference Graph is best among three methods for translating TSSA form to CSSA form.

CSSA-based coalescing algorithm can eliminate copies even when the source resource and destination resource

interfere, if certain constraints are satisfied.

Conclusion

Page 27: Reader:  Pushpinder Kaur Chouhan

27

References

P. Briggs, K. Cooper, T. Harvey and Taylor Simpson. ”Practical Improvements to the Construction and Destruction of Static Single Assignment Form”.

R. Cytron, J.Ferrente, B.K. Rosen, M.N. Wegman and F.K. Zadeck. ”Esiently Computing Static Single Assignment Form and the Control Dependence Graph”.

Andrew W. Appel – “Modern Compiler Implementation in ML”

Page 28: Reader:  Pushpinder Kaur Chouhan

28

Questions ?

Page 29: Reader:  Pushpinder Kaur Chouhan

29

What is the need of translation?

To eliminate the phi instruction.

Phi instructions are only conceptual tool

Page 30: Reader:  Pushpinder Kaur Chouhan

30

Why is it useful

more compact representation than def-use and use-def chains.

for most programs reduces space/time requirement

make data-flow analysis easy

representation explicitly converts definitions to their

uses and vise versa. merging of value is explicit

Page 31: Reader:  Pushpinder Kaur Chouhan

31

Algorithm for method III

Page 32: Reader:  Pushpinder Kaur Chouhan

32

vise versa. vise versa. vise versa.

Page 33: Reader:  Pushpinder Kaur Chouhan

33

DU-Chains, UD-Chains

A definition-use chain or DU-chain for a definition D of variable v connects the D to all uses of v that it can reach.

A use-definition chain or UD-chain for a use U of variable v connects U to all definitions of v that reach it.

Page 34: Reader:  Pushpinder Kaur Chouhan

34

Data-dependence Graph

A data-dependence graph has one node for every variable (basic block) and one edge representing the flow of data between the two nodes

Different types of data dependence– Flow: def to use– Anti: use to def– Out: def to def

entry

Z > 1

X = 1Z > 2

Y = X + 1

X = 2

Z = X – 3X = 4

Z = X + 7

exit

B1

B3

B2

B6

B5

B4

Page 35: Reader:  Pushpinder Kaur Chouhan

35

Control Dependency

Definition - Let G be a CFG, with X and Y nodes in G. Y is control-dependent on X iff1.There exists a directed path P from X to Y with any Z in P (excluding X and Y) postdominated by Y and

2. X is not postdominated by Y (there are two edges out of Y; traversing one edges always leads to X, the other may not lead to X)

entry

Z > 1

X = 1Z > 2

Y = X + 1

X = 2

Z = X – 3X = 4

Z = X + 7

exit

B1

B3

B2

B6

B5

B4

T

F

F

T