Top Banner
Static Single Assignment Form in the COINS Compiler Infrastructure Masataka Sassa, Toshiharu Nak aya, Masaki Kohama, Takeaki F ukuoka and Masahito Takahashi (Tokyo Institute of Technolog y)
27

Static Single Assignment Form in the COINS Compiler Infrastructure

Feb 25, 2016

Download

Documents

chuong

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. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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)

Page 2: Static Single Assignment Form  in the COINS Compiler Infrastructure

0. COINS infrastructure and the SSA form1. Current status of optimization using SSA form in

COINS infrastructure2. A comparison of two major algorithms for translating

from normal form into SSA form3. 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.

Page 3: Static Single Assignment Form  in the COINS Compiler Infrastructure

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

Page 4: Static Single Assignment Form  in the COINS Compiler Infrastructure

COINS compiler infrastructure

• Multiple source languages• Retargetable• Two intermediate form, HI

R and LIR• Optimizations• Parallelization• C generation, source-to- source translation• Written in Java• 2000~ developed by Japa

nese institutions under Grant of the Ministry

High Level Intermediate Representation (HIR)

Basic analyzer &optimizer

HIRto

LIR

Low Level Intermediate Representation (LIR) SSA

optimizerCode

generator

Cfrontend

Advanced optimizer

Basicparallelizer

frontend C generation

SPARC

SIMD parallelizer

x86 Newmachine

FortranC New language C OpenMP

Fortran frontend

C generation

C

Page 5: Static Single Assignment Form  in the COINS Compiler Infrastructure

1: a = x + y2: a = a + 33: b = x + y       

Static Single Assignment (SSA) Form

(a) Normal (conventional) form (source program or internal form)

1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = x0 + y0

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

Page 6: Static Single Assignment Form  in the COINS Compiler Infrastructure

1: a = x + y2: a = a + 33: b = x + y       

Optimization in Static Single Assignment (SSA) Form

(a) Normal form

1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = x0 + y0

       (b) SSA form

1: a1 = x0 + y0 2: a2 = a1 + 3 3: b1 = a1

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

Page 7: Static Single Assignment Form  in the COINS Compiler Infrastructure

x1 = 1 x2 = 2

x3 = (x1;L1, x2:L2)… = x3

x = 1 x = 2

… = xL3

L2L1 L1 L2

L3

(b) SSA form(a) Normal form

Translating into SSA form (SSA translation)

Page 8: Static Single Assignment Form  in the COINS Compiler Infrastructure

x1=…   = x1y1=…z1=…

x2=…   = x2y2=…z2=…

   = y1    = y2

x3= (x1,x2)y3= (y1,y2)z3= (z1,z2)   = z3

x1=…   = x1y1=…z1=…

x2=…   = x2y2=…z2=…

   = y1    = y2

y3= (y1,y2)z3= (z1,z2)   = z3

x1=…   = x1y1=…z1=…

x2=…   = x2y2=…z2=…

   = y1    = y2

z3= (z1,z2)   = z3

x =…  = xy =…z =…

x =…   = xy =…z =…

   = y    = y

   = z

Minimal SSA form Semi-pruned SSA form Pruned SSA form

Normal form

Translating into SSA form (SSA translation)

Page 9: Static Single Assignment Form  in the COINS Compiler Infrastructure

x1 = 1 x2 = 2

x3 = (x1;L1, x2:L2)… = x3

x1 = 1x3 = x1

x2 = 2x3 = x2

… = x3L3

L2L1L1 L2

L3

(a) SSA form (b) Normal form

Translating back from SSA form (SSA back translation)

Page 10: Static Single Assignment Form  in the COINS Compiler Infrastructure

1. SSA form module in the COINS compiler infrastructure

Page 11: Static Single Assignment Form  in the COINS Compiler Infrastructure

High Level Intermediate Representation (HIR)

Basic analyzer &optimizer

HIRto

LIR

Low Level Intermediate Representation (LIR) SSA

optimizerCode

generator

Cfrontend

Advanced optimizer

Basicparallelizer

frontend C generation

SPARC

SIMD parallelizer

x86 Newmachine

FortranC New language C OpenMP

Fortran frontend

COINS compiler infrastructure

C generation

C

Page 12: Static Single Assignment Form  in the COINS Compiler Infrastructure

Low level Intermediate Representation (LIR)

SSA optimization module

Code generation

Source program

object code

LIR to SSAtranslation

(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

Page 13: Static Single Assignment Form  in the COINS Compiler Infrastructure

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 propag

ation, common subexpression elimination, conditional constant propagation• Useful transformation as an infrastructure for SSA form optimizati

on‐ Copy folding at SSA translation time, critical edge removal on c

ontrol 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

Page 14: Static Single Assignment Form  in the COINS Compiler Infrastructure

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

Page 15: Static Single Assignment Form  in the COINS Compiler Infrastructure

x1 = 1 x2 = 2

x3 = (x1;L1, x2:L2)… = x3

x = 1 x = 2

… = xL3

L2L1 L1 L2

L3

(b) SSA form(a) Normal form

Translating into SSA form (SSA translation)

Page 16: Static Single Assignment Form  in the COINS Compiler Infrastructure

0100200300400500600700800900

0 1000 2000 3000 4000No. of nodes of control flow graph

Tra

nsla

tion

time

(mill

i sec

)

CytronSreedhar

Usual programs

(The gap is due to the garbage collection)

Page 17: Static Single Assignment Form  in the COINS Compiler Infrastructure

(b) ladder graph(a) nested loop

Peculiar programs

Page 18: Static Single Assignment Form  in the COINS Compiler Infrastructure

0100020003000400050006000700080009000

0 1000 2000 3000 4000No. of nodes of control flow graph

Tra

nsla

tion

time

(mill

i se

c)

CytronSreedhar

Nested loop programs

Page 19: Static Single Assignment Form  in the COINS Compiler Infrastructure

0500

100015002000250030003500

0 1000 2000 3000 4000No. of nodes of control flow graph

Tra

nsla

tion

time

(mill

i sec

)

CytronSreedhar

Ladder graph programs

Page 20: Static Single Assignment Form  in the COINS Compiler Infrastructure

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 comparisonComparison made on COINS

Page 21: Static Single Assignment Form  in the COINS Compiler Infrastructure

x1 = 1 x2 = 2

x3 = (x1;L1, x2:L2)… = x3

x1 = 1x3 = x1

x2 = 2x3 = x2

… = x3L3

L2L1L1 L2

L3

(a) SSA form (b) Normal form

Translating back from SSA form (SSA back translation)

Page 22: Static Single Assignment Form  in the COINS Compiler Infrastructure

x0 = 1

x1 =  (x0, x2)y = x1x2 = 2

return y

x0 = 1

x1 =  (x0, x2)

x2 = 2

return x1

x0 = 1x1 = 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)

Page 23: Static Single Assignment Form  in the COINS Compiler Infrastructure

x0 = 1

x1 = (x0, x2)

x2 = 2

return x1

x0 = 1x1 = x0

x2 = 2x1 = x2

return temp

block1

block3

block2

block1

block3

block2

temp = x1

(a) SSA form (b) normal form after back translation

liverangeof x1

liverangeof temp

To remedy these problems...(i) SSA back translation algorithm by Briggs

Page 24: Static Single Assignment Form  in the COINS Compiler Infrastructure

x0 = 1

x1 = (x0, x2)

x2 = 2

return x1

live range ofx0 x1 x2

x0 = 1

x1’ = (x0, x2)x1 = x1’x2 = 2

return x1

{x0, x1’, x2} A

x1 = AA = 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 ofx0 x1' x2

block1

block3

block2

(ii) SSA back translation algorithm by Sreedhar

Page 25: Static Single Assignment Form  in the COINS Compiler Infrastructure

SSA form

Briggs Briggs +Coalescing

Sreedhar

Lost copy 0 3 1 (1) 1 (1)Simple ordering 0 5 2 (2) 2 (2)

Swap 0 7 5 (5) 3 (3)Swap-lost 0 10 7 (7) 4 (4)

do 0 9 6 (4) 4 (2)fib 0 4 0 (0) 0 (0)

GCD 0 9 5 (2) 5 (2)Selection Sort 0 9 0 (0) 0 (0)

Hige Swap 0 8 3 (3) 4 (4)

No. of copies (no. of copies in loops)

Empirical comparison of SSA back translation

Page 26: Static Single Assignment Form  in the COINS Compiler Infrastructure

Previous work: SSA form in compiler infrastructure

SUIF (Stanford Univ.): no SSA formmachine SUIF (Harvard Univ.): only one optimization

in SSA formScale (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

Page 27: Static Single Assignment Form  in the COINS Compiler Infrastructure

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