1 / 27

Static Single Assignment Form in the COINS Compiler Infrastructure

Static Single Assignment Form in the COINS Compiler Infrastructure. Masataka Sassa, Toshiharu Nakaya, Masaki Kohama, Takeaki Fukuoka and Masahito Takahashi (Tokyo Institute of Technology). Background. Static single assignment (SSA) form facilitates compiler optimizations.

chuong
Télécharger la présentation

Static Single Assignment Form in the COINS Compiler Infrastructure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Background Static single assignment (SSA) form facilitates compiler optimizations. Compiler infrastructure facilitates compiler development. Outline 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

  3. 0. COINS infrastructure andStatic Single Assignment Form (SSA Form)

  4. Fortran New language C C OpenMP C frontend Fortran frontend C generation frontend High Level Intermediate Representation (HIR) HIR to LIR Basic analyzer & optimizer Basic parallelizer Advanced optimizer Low Level Intermediate Representation (LIR) SSA optimizer Code generator SIMD parallelizer C generation New machine C x86 SPARC 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

  5. Static Single Assignment (SSA) Form 1: a = x + y 2: a = a + 3 3: b = x + y 1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = x0 + y0 (b) SSA form Normal (conventional) form (source program or internal 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. Optimization in Static Single Assignment (SSA) Form 1: a = x + y 2: a = a + 3 3: b = x + y 1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = x0 + y0 SSA translation (b) SSA form (a) Normal form Optimization in SSA form (common subexpression elimination) 1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = a1 1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = a1 SSA back translation (c) After SSA form optimization (d) Optimized normal form SSA form is becoming increasingly popular in compilers, since it is suited for clear handling of dataflow analysis and optimization.

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

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

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

  10. 1. SSA form module in the COINS compiler infrastructure

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

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

  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. Translating into SSA form (SSA translation) x = 1 x = 2 L1 x1 = 1 L2 x2 = 2 L1 L2 L3 x3 = (x1;L1, x2:L2) … = x3 … = x L3 (a) Normal form (b) SSA form

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

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

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

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

  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. Translating back from SSA form (SSA back translation) x1 = 1 x3 = x1 x2 = 2 x3 = x2 L1 x1 = 1 L2 x2 = 2 L1 L2 x3 = (x1;L1, x2:L2) … = x3 L3 … = x3 L3 (a) SSA form (b) Normal form

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

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

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

  25. Empirical comparison of SSA back translation No. of copies (no. of copies in loops)

  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

More Related