Some Properties of SSA - PowerPoint PPT Presentation

About This Presentation
Title:

Some Properties of SSA

Description:

{ FRUIT snack; VARIETY t1; SHAPE t2; COLOR t3; t1 = APPLE; t2 = ROUND; switch (t1) { case APPLE: t3= Red; break; case BANANA: t3=Yellow; break; case ORANGE: t3=Orange; ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 19
Provided by: thoma423
Category:
Tags: ssa | apple | fruit | properties

less

Transcript and Presenter's Notes

Title: Some Properties of SSA


1
Some Properties of SSA
  • Mooly Sagiv

2
Outline
  • Why is it called Static Single Assignment form
  • What does it buy us?
  • How much does it cost us?
  • Open questions

3
Static Single Assignment
  • Every variable is assigned once
  • But in loops a variable will be assigned many
    times

4
An Acyclic Example
x ? x 2 x gt 0
x ? x 1
x ? x 4 x gt 0
x ? x 3
x ? x 6
x ? x 5
5
A Cyclic Example
i 1 j 1 k 0 while (k lt 0) if (j lt 0)
j i k k 1 else j k k
k 2 return j
6
What does it buy us?
  • Compact representation of DU chains
  • Convert imperative into functional style
  • Extended basic blocks
  • Allows flow-insensitive analysis

7
How much does it cost
  • Code size
  • Worst case the extra number of assignments is
    quadratic
  • For programs with while-do and if-then-else
    linear
  • In practice linear
  • Construction of SSA

8
Open Questions
  • Dealing with pointers
  • When is it useful?
  • Is it really needed?
  • Can we choose an appropriate data structure in
    the iterative data flow algorithm instead

9
Conditional Constant Propagation
  • Conditions with constant values can be
    interpreted to improve precision
  • A more precise solution is obtained
    optimistically

10
char Red red char Yellow
yellow char Orange orange main()
FRUIT snack VARIETY t1 SHAPE t2 COLOR
t3 t1 APPLE t2 ROUND switch (t1)
case APPLE t3 Red
break
case BANANA t3Yellow
break case
ORANGE t3Orange printf(s\n, t3
)
main() printf(s\n, red)
red
11
char Red red char Yellow
yellow char Orange orange main()
FRUIT snack VARIETY t1 SHAPE t2 COLOR
t3 t1 APPLE t2 ROUND switch (t1)
case APPLE t3 Red
break
case BANANA t3Yellow
break case
ORANGE t3Orange printf(s\n, t3)
12
Iterative Data-Flow Algorithm
Input a flow graph G(N,E,r) An
init value Init A montonic function
FB for every B in N Output For every N
in(N) Initializatio in(Entry) Init
for each node B in N-Entry do
in(B) ? WL N -
Entry Iteration while WL ! do
Select and remove an B from WL
out FB(in(B))
For all B in succ(B) such that in(B) ! in(B)
?out do
in(B) in(B) ? out
WL WL ?B
13
Iterative Data-Flow Algorithm
Input a flow graph G(N,E,r) An
init value Init A montonic function
FB for every B in N Output For every N
in(N) Initializatio in(Entry) Init
for each node B in N-Entry do
in(B) ? WL
Entry Iteration while WL ! do
Select and remove an B from WL
out FB(in(B))
For all B in succ(B) such that
in(B) ! in(B) ?out do
in(B) in(B) ? out
WL
WL ?B
14
char Red red char Yellow
yellow char Orange orange main()
FRUIT snack VARIETY t1 SHAPE t2 COLOR
t3 t1 APPLE t2 ROUND switch (t1)
case APPLE t3 Red
break
case BANANA t3Yellow
break case
ORANGE t3Orange printf(s\n, t3)
15
Conditional Constant Propagation
  • initialize the worklist to the entry node
  • mark all edges as not executable
  • repeat until the worklist is empty
  • select and remove a node from the worklist
  • if it is an assignment then mark the successor
    edge as executable
  • if it is a test then symbolically evaluate the
    test and mark the enabled successor edges as
    executable
  • if test evaluates to true or ? mark true edge
    executable
  • if test evaluates to false or ? mark false edge
    executable
  • update the value of all the variables at the
    entry and exit of this node
  • if there are changes then add all successors
    reachable from the node with edges marked
    executable to the worklist

16
Sparse Conditional Constant
  • bring the program in SSA form
  • initialize the analysis information
  • all variables are mapped to ?
  • all flow edges are marked as not executable
  • initialize the two worklists
  • Flow-Worklist contains all edges of the flow
    graph with the entry node as source
  • SSA-Worklist is empty

17
  • repeat until both worklists are empty
  • select and remove an edge from one of the
    worklists
  • if it is a flow edge then
  • if the edge is not marked executable then
  • mark it executable
  • if the target of the edge is a f-node then call
    visit-f
  • if it is the first time the node is visited (only
    one incoming flow edge is marked executable) and
    it is a normal node then call visit-instr
  • if it is an SSA edge then
  • if the target of the edge is a f-node then call
    visit-f
  • if it is a normal node and at least one of the
    flow edges entering the node are marked
    executable then call visit-instr

18
  • visit-f (the node is a f-node)
  • the assigned variable is given a value that is
    the join the values of the arguments with
    incoming edges marked executable
  • visit-instr (the node is a normal
    node)
  • determine the value of the expression of the node
    and update the variable in case of an assignment
  • if there are changes then
  • if the node is an assignment then add all SSA
    edges with source at the target of the current
    edge to the SSA-worklist
  • if the node is a test then add all relevant flow
    edges to the Flow-worklist and mark them
    executable
  • if test evaluates to true or ? add true edge
  • if test evaluates to false or ? add false edge
Write a Comment
User Comments (0)
About PowerShow.com