Presentation is loading. Please wait.

Presentation is loading. Please wait.

Static Single Assignment Form in the COINS Compiler Infrastructure Masataka Sassa, Toshiharu Nakaya, Masaki Kohama, Takeaki Fukuoka and Masahito Takahashi.

Similar presentations


Presentation on theme: "Static Single Assignment Form in the COINS Compiler Infrastructure Masataka Sassa, Toshiharu Nakaya, Masaki Kohama, Takeaki Fukuoka and Masahito Takahashi."— Presentation transcript:

1 Static Single Assignment Form in the COINS Compiler Infrastructure Masataka Sassa, Toshiharu Nakaya, Masaki Kohama, Takeaki Fukuoka and Masahito Takahashi (Tokyo Institute of Technology)

2 0. COINS infrastructure and the SSA form 1. Current status of optimization using SSA form in COINS infrastructure 2. A comparison of two major algorithms for translating from normal form into SSA form 3. A comparison of two major algorithms for translating back from SSA form into normal form Outline Background Static single assignment (SSA) form facilitates compiler optimizations. Compiler infrastructure facilitates compiler development.

3 0. COINS infrastructure and Static Single Assignment Form (SSA Form)

4 COINS compiler infrastructure Multiple source languages Retargetable Two intermediate form, HIR and LIR Optimizations Parallelization C generation, source-to- source translation Written in Java 2000~ developed by Japanese institutions under Grant of the Ministry High Level Intermediate Representation (HIR) Basic analyzer & optimizer HIR to LIR Low Level Intermediate Representation (LIR) SSA optimizer Code generator C frontend Advanced optimizer Basic parallelizer frontend C generation SPARC SIMD parallelizer x86 New machine Fortran C New language COpenMP Fortran frontend C generation C

5 1: a = x + y 2: a = a + 3 3: b = x + y Static Single Assignment (SSA) Form (a)Normal (conventional) form (source program or internal form) 1: a 1 = x 0 + y 0 2: a 2 = a 1 + 3 3: b 1 = x 0 + y 0 (b) SSA form SSA form is a recently proposed internal representation where each use of a variable has a single definition point. Indices are attached to variables so that their definitions become unique.

6 1: a = x + y 2: a = a + 3 3: b = x + y Optimization in Static Single Assignment (SSA) Form (a) Normal form 1: a 1 = x 0 + y 0 2: a 2 = a 1 + 3 3: b 1 = x 0 + y 0 (b) SSA form 1: a 1 = x 0 + y 0 2: a 2 = a 1 + 3 3: b 1 = a 1 (c) After SSA form optimization 1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = a1 (d) Optimized normal form SSA translation Optimization in SSA form (common subexpression elimination) SSA back translation SSA form is becoming increasingly popular in compilers, since it is suited for clear handling of dataflow analysis and optimization.

7 x1 = 1x2 = 2 x3 =   (x1;L1, x2:L2) … = x3 x = 1x = 2 … = x L3 L2L1 L2 L3 (b) SSA form(a) Normal form Translating into SSA form (SSA translation)

8 x1=… = x1 y1=… z1=… x2=… = x2 y2=… z2=… = y1 = y2 x3=  (x1,x2) y3=  (y1,y2) z3=  (z1,z2) = z3 x1=… = x1 y1=… z1=… x2=… = x2 y2=… z2=… = y1 = y2 y3=  (y1,y2) z3=  (z1,z2) = z3 x1=… = x1 y1=… z1=… x2=… = x2 y2=… z2=… = y1 = y2 z3=  (z1,z2) = z3 x =… = x y =… z =… x =… = x y =… z =… = y = z Minimal SSA form Semi-pruned SSA formPruned SSA form Normal form Translating into SSA form (SSA translation)

9 x1 = 1x2 = 2 x3 =   (x1;L1, x2:L2) … = x3 x1 = 1 x3 = x1 x2 = 2 x3 = x2 … = x3 L3 L2L1 L2 L3 (a) SSA form(b) Normal form Translating back from SSA form (SSA back translation)

10 1. SSA form module in the COINS compiler infrastructure

11 High Level Intermediate Representation (HIR) Basic analyzer & optimizer HIR to LIR Low Level Intermediate Representation (LIR) SSA optimizer Code generator C frontend Advanced optimizer Basic parallelizer frontend C generation SPARC SIMD parallelizer x86 New machine Fortran C New language COpenMP Fortran frontend COINS compiler infrastructure C generation C

12 Low level Intermediate Representation (LIR) SSA optimization module Code generation Source program object code LIR to SSA translation (3 variations) LIR in SSA SSA basic optimization com subexp elimination copy propagation cond const propagation dead code elimination Optimized LIR in SSA SSA to LIR back translation (2 variations) + 2 coalescing 12,000 lines transformation on SSA copy folding dead phi elim edge splitting SSA optimization module in COINS

13 Outline of SSA module in COINS Translation into and back from SSA form on Low Level Intermediate Representation (LIR) ‐ SSA translation: Use dominance frontier [Cytron et al. 91] ‐ SSA back translation: [Sreedhar et al. 99] ‐ Basic optimization on SSA form: dead code elimination, copy propagation, common subexpression elimination, conditional constant propagation Useful transformation as an infrastructure for SSA form optimization ‐ Copy folding at SSA translation time, critical edge removal on control flow graph … ‐ Each variation and transformation can be made selectively Preliminary result ‐ 1.43 times faster than COINS w/o optimization ‐ 1.25 times faster than gcc w/o optimization

14 2. A comparison of two major algorithms for SSA translation Algorithm by Cytron [1991] Dominance frontier Algorithm by Sreedhar [1995] DJ-graph Comparison made to decide the algorithm to be included in COINS

15 x1 = 1x2 = 2 x3 =   (x1;L1, x2:L2) … = x3 x = 1x = 2 … = x L3 L2L1 L2 L3 (b) SSA form(a) Normal form Translating into SSA form (SSA translation)

16 0 100 200 300 400 500 600 700 800 900 01000200030004000 No. of nodes of control flow graph Translation time (milli sec) Cytron Sreedhar Usual programs (The gap is due to the garbage collection)

17 (b) ladder graph(a) nested loop Peculiar programs

18 0 1000 2000 3000 4000 5000 6000 7000 8000 9000 01000200030004000 No. of nodes of control flow graph Translation time (milli sec) Cytron Sreedhar Nested loop programs

19 0 500 1000 1500 2000 2500 3000 3500 01000200030004000 No. of nodes of control flow graph Translation time (milli sec) Cytron Sreedhar Ladder graph programs

20 3. A comparison of two major algorithms for SSA back translation Algorithm by Briggs [1998] Insert copy statements Algorithm by Sreedhar [1999] Eliminate interference There have been no studies of comparison Comparison made on COINS

21 x1 = 1x2 = 2 x3 =   (x1;L1, x2:L2) … = x3 x1 = 1 x3 = x1 x2 = 2 x3 = x2 … = x3 L3 L2L1 L2 L3 (a) SSA form(b) Normal form Translating back from SSA form (SSA back translation)

22 x0 = 1 x1 =  (x0, x2) y = x1 x2 = 2 return y x0 = 1 x1 =  (x0, x2) x2 = 2 return x1 x0 = 1 x1 = x0 x2 = 2 x1 = x2 return x1 not correct block1 block3 block2 block1 block3 block2 block1 block3 block2 Copy propagation Back translation by na ï ve method Problems of naïve SSA back translation (lost copy problem)

23 x0 = 1 x1 =  (x0, x2) x2 = 2 return x1 x0 = 1 x1 = x0 x2 = 2 x1 = x2 return temp block1 block3 block2 block1 block3 block2 temp = x1 (a) SSA form(b) normal form after back translation live range of x1 live range of temp To remedy these problems... (i) SSA back translation algorithm by Briggs

24 x0 = 1 x1 =  (x0, x2) x2 = 2 return x1 live range of x0 x1 x2 x0 = 1 x1’ =  (x0, x2) x1 = x1’ x2 = 2 return x1 {x0, x1 ’, x2}  A x1 = A A = 2 A = 1 block1 block3 block2 block1 block3 block2 return x1 (a) SSA form(b) eliminating interference (c) normal form after back translation live range of x0 x1' x2 block1 block3 block2 (ii) SSA back translation algorithm by Sreedhar

25 SSA form BriggsBriggs + Coalescing Sreedhar Lost copy031 (1) Simple ordering052 (2) Swap075 (5)3 (3) Swap-lost0107 (7)4 (4) do096 (4)4 (2) fib040 (0) GCD095 (2) Selection Sort090 (0) Hige Swap083 (3)4 (4) No. of copies (no. of copies in loops) Empirical comparison of SSA back translation

26 Previous work: SSA form in compiler infrastructure SUIF (Stanford Univ.): no SSA form machine SUIF (Harvard Univ.): only one optimization in SSA form Scale (Univ. Massachusetts): a couple of SSA form optimizations. But it generates only C programs, and cannot generate machine code like in COINS. GCC: some attempts but experimental Only COINS will have full support of SSA form as a compiler infrastructure

27 Summary SSA form module of the COINS infrastructure Empirical comparison of algorithms for SSA translation gave criterion to make a good choice Empirical comparison of algorithms for SSA back translation clarified there is no single algorithm which gives optimal result Hope COINS and its SSA module help the compiler writer to compare/evaluate/add optimization methods


Download ppt "Static Single Assignment Form in the COINS Compiler Infrastructure Masataka Sassa, Toshiharu Nakaya, Masaki Kohama, Takeaki Fukuoka and Masahito Takahashi."

Similar presentations


Ads by Google