Download presentation

Presentation is loading. Please wait.

Published byNikhil Bossom Modified about 1 year ago

1
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

2
2 Translating Out of SSA Form Introduction Basic Keywords Algorithm for going out of SSA form Experimental Results Conclusion References

3
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

4
4 Introduction Static Single Assignment form is an intermediate representation that compilers use to facilitate program analysis and optimization. OriginalOptimized Intermediate Code Intermediate Code P 0 P 1 P 2 …………………………………… P n Role of SSA form in a compiler Algorithm for going out of SSA form. Algorithm for eliminating redundant copies.

5
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

6
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

7
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

8
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

9
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

10
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 L2 An example program in TSSA form

11
11 Translating the TSSA form to a CSSA form x3=phi(x1:L1, x2:L2) Z=x3 x2= x1= x2’=x2 x3’=phi(x1’:L1, x2’:L2) x3=x3’ Z=x3 L1 L2 L1 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

12
12 Translating the TSSA form to a CSSA form x3=phi(x1:L1, x2:L2) Z=x3 x2= x1= x2’=x2 x3=phi(x1’:L1, x2’:L2) Z=x3 L1 L2 L1 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

13
13 Translating the TSSA form to a CSSA form x3=phi(x1:L1, x2:L2) Z=x3 x2= x1= x2’=x2 x3=phi(x1:L1, x2’:L2) Z=x3 L1 L2 L1 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=

14
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.

15
15 CASE 1. The intersection of phiCongruenceClass[xi] and LiveOut[Lj] is not 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] is empty and the intersection of phiCongruenceClass[xj] and LiveOut[Li] is not empty. A new copy, xj’=xj, is needed in Lj. CASE 3. The intersection of phiCongruenceClass[xi] and LiveOut[Lj] is not 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] is empty, and the intersection of phiCongruenceClass[xj] and LiveOut[Li] is empty. Either a copy, xi’=xi in Li, or a copy, xj’=xj in Lj, is sufficient to eliminate 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.

16
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.

17
17 An example to illustrate the algorithm of Method III X3= X1= X2= X2’=x2 X1= 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.

18
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.

19
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 L1 L3 L2 L3 L2 X2 and x3 interfere LiveOut[L2] = {x2,x3} LiveIn[L2] = {x2}

20
20 Eliminating Redundant Copies CASE 1: phiCongruenceClass[x]=={} and phiCongruenceClass[y]=={}. This means that x and y are not referenced in any phi instruction. The copy 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.

21
21 Example of Copy Elimination Y1=30 X1=y1 Y2=10X2=20 Y3=phi(y1,y2) Foo(y3) x3=phi(x1,x2) Goo(x3) Y=30 Y=10X=20 Goo(x3) Foo(y3) PhiCongruenceClass[x1] = {x1,x2,x3} PhiCongruenceClass[y1] = {y1,y2,y3}

22
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=x x=x2+1 =x2 L1 L3 L2 L1 L3 L2 Replace x1,x2’ and x3 by x

23
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

24
24 Experimental Results Procedure Name BTMeth ods ATAT-BTACDF/IG (secs) TT (secs) TC (secs) Total (secs) Yylex (gcc) 1573I II III Ttin (o/s code) 539I II III % Improvem ent I II III ****** * * ****** ****** ****** *

25
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

26
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

27
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”

28
28 Questions ?

29
29 What is the need of translation? To eliminate the phi instruction. Phi instructions are only conceptual tool

30
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

31
31 Algorithm for method III

32
32 vise versa.

33
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.

34
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 = 1 Z > 2 Y = X + 1 X = 2 Z = X – 3 X = 4 Z = X + 7 exit B1 B3 B2 B6 B5 B4

35
35 Control Dependency Definition - Let G be a CFG, with X and Y nodes in G. Y is control-dependent on X iff 1.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 = 1 Z > 2 Y = X + 1 X = 2 Z = X – 3 X = 4 Z = X + 7 exit B1 B3 B2 B6 B5 B4 T F F T

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google