Static Single Assignment Form (SSA) - PowerPoint PPT Presentation

About This Presentation
Title:

Static Single Assignment Form (SSA)

Description:

Construction First, decide what variables need ... Improving Compiler Efficiency Static Single Assignment -Functions Dominance What it buys us More ... – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 15
Provided by: andr1438
Learn more at: http://flint.cs.yale.edu
Category:

less

Transcript and Presenter's Notes

Title: Static Single Assignment Form (SSA)


1
Static Single Assignment Form (SSA)
  • Andrew McCreight
  • (based on Prof. Shaos slides)
  • CS421
  • 11/18/05

2
Improving Compiler Efficiency
  • Many optimization passes
  • Lots of time spent optimizing
  • Worth it to have new IR for opt.
  • translation to/from new IR (cost)
  • easier/faster opt. (benefit)
  • so lets extend the basic CFG

3
Static Single Assignment
  • Main idea each assignment has a unique name

v 4 z v 5 v 6 y v 7 if P then v
4 else v 6 u v y
v1 4 z v1 5 v2 6 y v2 7 if
P then v3 4 else v4 6 v5 F(v3,v4) u
v5 y
SSA transformation
4
F-Functions
  • To support this special F-functions are added to
    each branch join point
  • F(v1, v2, ) is equal to vi, if we take the i-th
    predecessor to get to it

if P then v3 4 else v4 6 v5
F(v3,v4) u v5 y
if P then v 4 else v 6 u v y
SSA transformation
5
Dominance
  • Also a def must dominate all of its uses
  • Statement a dominates statement b if along all
    valid paths from the entry to the exit, you reach
    a before you reach b.

v1 4 z v1 5 v2 6 y v2 7 if P then
v3 4 else v4 6 v5 F(v3,v4) u v5 y
6
What it buys us
  • Easy to determine def of each use theres only
    one!
  • Less need for data flow analysis

v 4 z v 5 v 6 y v 7 if P then v
4 else v 6 u v y
v1 4 z v1 5 v2 6 y v2 7 if
P then v3 4 else v4 6 v5 F(v3,v4) u
v5 y
SSA transformation
use-def chains are much simpler
7
More efficiency
  • Weve basically pre-computed some dataflow
    information, which allows us to avoid redoing it
    with multiple passes
  • Before, there were a quadratic number of use-def
    chains (in terms of edges)
  • Now, there are a linear number of them
  • Asymptotic efficiency improvement

8
Whats the catch?
  • More variables
  • Increase in code size due to F-functions
  • But only linearly (in practice, SSA is 0.6-2.4
    times larger)
  • Some optimizations are more annoying (things that
    copy blocks)
  • But on the whole, a win for compilers

9
Sparse Analysis
  • Some properties are global
  • v1 is always 4, everywhere in the program
  • Dont have to track the value of v at each point
  • This means it is sparse

v1 4 z v1 5 v2 6 y v2 7 if
P then v3 4 else v4 6 v5 F(v3,v4) u
v5 y
10
Sparse Constant Prop
  • Keep a global table of things that are const
  • At each instruction, check each use to see if it
    is constant.
  • If you dont know yet, find out, save the answer.
  • Only have to examine each def once.
  • At phi, only const if all args are same const

v1 4 z v1 5 v2 6 y v2 7 if
P then v3 4 else v4 6 v5 F(v3,v4) u
v5 y
11
Sparse conditional const prop
  • We can be more clever, by evaluating branches.
    Track which blocks are run.
  • First, assume only first block is run
  • Ignore vals from unrun blocks
  • If ends with a jump, add next block, check it
  • If ends with a branch, see if we can figure out
    result of test.
  • If we can, only do taken branch next.
  • If we cant, do both branches
  • Repeat, until no more blocks to examine.

12
Construction
  • First, decide what variables need F-functions,
    and where
  • Next, rename the variables
  • First step is harder
  • For second, just give each assignment a unique
    name, do a reaching definitions kind of analysis

13
Placing F Functions
  • Need a F function at every join point where two
    different defs of the same variable reach
  • Want to minimize the number of them
  • Can be computed efficiently (see Appel ch. 19)

14
De-SSA
  • Eventually, we want to leave SSA
  • Drop all subscripts
  • Simplest way convert all phi statements to move
    instructions (in predecessor block)
  • Many of these moves can be eliminated if you are
    more clever, or through later optimization
Write a Comment
User Comments (0)
About PowerShow.com