SlideShare a Scribd company logo
1 of 16
Download to read offline
Static Single Assignment Form

Last Time
 – Lattice theoretic frameworks for data-flow analysis

Today
 – Program representations
 – Static single assignment (SSA) form
     – Program representation for sparse data-flow
 – Conversion to and from SSA

Next Time
 – Reuse optimizations




CIS570 Lecture 7           Static Single Assignment Form                    2




Data Dependence

Definition
 – Data dependences are constraints on the order in which statements may be
    executed

Types of dependences
 – Flow (true) dependence:    s1 writes memory that s2 later reads (RAW)
 – Anti-dependence:           s1 reads memory that s2 later writes (WAR)
 – Output dependences:        s1 writes memory that s2 later writes (WAW)
 – Input dependences:         s1 reads memory that s2 later reads (RAR)

True dependences
 – Flow dependences represent actual flow of data
False dependences
 – Anti- and output dependences reflect reuse of memory, not actual data
    flow; can often be eliminated
CIS570 Lecture 7           Static Single Assignment Form                    3




                                                                                1
Example




                          s1            a = b;
                                                                  flow
                          s2            b = c + d;
                                                                  anti
                          s3            e = a + d;                output

                          s4            b = 3;                    input

                          s5            f = b * 2;




CIS570 Lecture 7               Static Single Assignment Form               4




Representing Data Dependences

Implicitly
  – Use variable defs and uses
  – Pros: simple
  – Cons: hides data dependence (analyses must find this info)

Def-use chains (du chains)
 – Link each def to its uses
 – Pros: explicit; therefore fast
 – Cons: must be computed and updated, consumes space

Alternate representations
 – e.g., Static single assignment form (SSA), dependence flow graphs
    (DFG), value dependence graphs (VDG)


CIS570 Lecture 7               Static Single Assignment Form               5




                                                                               2
DU Chains

Definition
 – du chains link each def to its uses

Example

                          s1            a = b;

                          s2            b = c + d;             du chain

                          s3            e = a + d;

                          s4            b = 3;

                          s5            f = b * 2;

CIS570 Lecture 7               Static Single Assignment Form          6




UD Chains

Definition
 – ud chains link each use to its defs

Example

                          s1            a = b;

                          s2            b = c + d;             ud chain

                          s3            e = a + d;

                          s4            b = 3;

                          s5            f = b * 2;

CIS570 Lecture 7               Static Single Assignment Form          7




                                                                          3
Role of Alternate Program Representations

Process
     Original Code (RTL)                          Optimized Code (RTL)


                     T1                            T2
        SSA Code1             SSA Code2                     SSA Code3


Advantage
 – Allow analyses and transformations to be simpler & more efficient/effective

Disadvantage
 – May not be “executable” (requires extra translations to and from)
 – May be expensive (in terms of time or space)


CIS570 Lecture 7            Static Single Assignment Form                   8




Static Single Assignment (SSA) Form

Idea
  – Each variable has only one static definition
  – Makes it easier to reason about values instead of variables
  – Similar to the notion of functional programming
Transformation to SSA
   – Rename each definition
   – Rename all uses reached by that assignment
Example
          v := ...                                        v0   := ...
      ... := ... v ...                                ... :=   ... v0 ...
          v := ...                                        v1   := ...
      ... := ... v ...                                ... :=   ... v1 ...
What do we do when there’s control flow?
CIS570 Lecture 7            Static Single Assignment Form                   9




                                                                                 4
SSA and Control Flow

    Problem
     – A use may be reached by several definitions

                1



2    v := ...                  3   v := ...

                                                                         1
                4      ...v...

                                                        2    v0 :=...             3   v1 :=...


                                                                         4   ...v?...


    CIS570 Lecture 7                     Static Single Assignment Form                           10




    SSA and Control Flow (cont)

    Merging Definitions
     – φ-functions merge multiple reaching definitions

    Example

                                          1



                           2   v0 :=...                  3   v1 :=...


                                     4
                                          v2 := φ(v0,v1)
                                          ...v2...




    CIS570 Lecture 7                     Static Single Assignment Form                           11




                                                                                                      5
Another Example




         1     v := 1                        1         v0 := 1



         2   v := v+1                            v1 := φ(v0,v2)
                                             2
                                                 v2 := v1+1




CIS570 Lecture 7           Static Single Assignment Form                    12




SSA vs. ud/du Chains

SSA form is more constrained

Advantages of SSA
 – More compact
 – Some analyses become simpler when each use has only one def
 – Value merging is explicit
 – Easier to update and manipulate?

Furthermore
 – Eliminates false dependences (simplifying context)

         for (i=0; i<n; i++)
              A[i] = i;                     Unrelated uses of i are given
         for (i=0; i<n; i++)                different variable names
              print(foo(i));

CIS570 Lecture 7           Static Single Assignment Form                    13




                                                                                 6
SSA vs. ud/du Chains (cont)

Worst case du-chains?

           switch (c1)   {
           case 1:       x = 1; break;
           case 2:       x = 2; break;
           case 3:       x = 3; break;
           }
           x4 = φ(x1, x2, x3)
           switch (c2)   {
           case 1:       y1   =   x;   break;
           case 2:       y2   =   x;   break;
           case 3:       y3   =   x;   break;
           case 4:       y4   =   x;   break;
           }
                               m defs and n uses leads to m×n du chains

CIS570 Lecture 7              Static Single Assignment Form               14




Transformation to SSA Form

Two steps
 – Insert φ-functions
 – Rename variables




CIS570 Lecture 7              Static Single Assignment Form               15




                                                                               7
Where Do We Place φ-Functions?

Basic Rule
 – If two distinct (non-null) paths x→z and y→z converge at node z, and
    nodes x and y contain definitions of variable v, then a
    φ-function for v is inserted at z


                     x   v1 :=...               y   v2 :=...




                             z    v3 := φ(v1,v2)
                                  ...v3...




CIS570 Lecture 7              Static Single Assignment Form                             16




Approaches to Placing φ-Functions

Minimal
 – As few as possible subject to the basic rule

Briggs-Minimal
 – Same as minimal, except v must be live across some edge of the CFG


      v =                   v =                     Briggs Minimal will not place a
        = v                   = v
                                                    φ function in this case because v
                                                    is not live across any CFG edge

                   no uses of v




CIS570 Lecture 7              Static Single Assignment Form                             17




                                                                                             8
Approaches to Placing φ-Functions (cont)

Briggs-Minimal
 – Same as minimal, except v must be live across some edge of the CFG

Pruned
 – Same as minimal, except dead φ-functions are not inserted


      v =                   v =                    Will Pruned place a φ function at
        = v                   = v                  this merge?


                   no uses of v


What’s the difference between Briggs Minimal and Pruned SSA?

CIS570 Lecture 7              Static Single Assignment Form                       18




Briggs Minimal vs. Pruned

      v =                   v =
        = v                   = v


          v2= φ(v0,v1)
            = v2                                   Briggs Minimal will add a
                                                   φ function because v is live
                                                   across the blue edge, but Pruned
                   = φ(v2,v3)                      SSA will not because the φ
                                                   function is dead




     Why would we ever use Briggs Minimal instead of Pruned SSA?
CIS570 Lecture 7              Static Single Assignment Form                       19




                                                                                       9
Machinery for Placing φ-Functions
                                                                         entry
Recall Dominators
 – d dom i if all paths from entry to node i include d
                                                                          d      d dom i
 – d sdom i if d dom i and d≠i

Dominance Frontiers                                                i
 – The dominance frontier of a node d is the set of nodes that are “just
   barely” not dominated by d; i.e., the set of nodes n, such that
     – d dominates a predecessor p of n, and
     – d does not strictly dominate n
 – DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n}

Notational Convenience
  – DF(S) = ∪s∈S DF(s)

CIS570 Lecture 7               Static Single Assignment Form                         20




Dominance Frontier Example

 DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n}
                                                Nodes in Dom(5)
 Dom(5) = {5, 6, 7, 8}
                                     1
DF(5) =       {4, 5, 12, 13}

                     2               5                         9

                     3         6            7           10          11

                     4               8                         12


                                    13

What’s significant about the Dominance Frontier?
In SSA form, definitions must dominate uses
CIS570 Lecture 7               Static Single Assignment Form                         21




                                                                                           10
Dominance Frontier Example II

 DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n}
                                                   Nodes in Dom(5)
 Dom(5) = {5, 6, 7, 8}
                                        1
DF(5) =         {4, 5, 13}

                       2                5


                       3          6            7

                       4                8


                                       13

 In this new graph, node 4 is the first point of convergence between the entry
 and node 5, so do we need a φ- function at node 13?
CIS570 Lecture 7                  Static Single Assignment Form                       22




SSA Exercise
                                  1


            2      v3 :=...                                 7


3                      4                       8   v1 := ...          9   v2 := ...

           5                                             10       v4:=φ(v1,v2)

                                  6 v5:=φ(v3,v4)
 DF(8) =                   {10}
 DF(9) =                   {10}
 DF(2) =                   {6} DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n}
 DF({8,9}) =               {10}
 DF(10) =                  {6}
 DF({2,6,8,9,10}) =        {6,10}
CIS570 Lecture 7                  Static Single Assignment Form                       23




                                                                                           11
Dominance Frontiers Revisited

 Suppose that node 3 defines variable x
                                              x ∈ Def(3)
 DF(3) =      {5}                  1

                             2            3          4


                                   5

                                          6

Do we need to insert a φ- function for x anywhere else?
 Yes. At node 6. Why?




CIS570 Lecture 7             Static Single Assignment Form                       24




Dominance Frontiers and SSA

Let
 – DF1(S) = DF(S)
 – DFi+1(S) = DF(S ∪ DFi(S))

Iterated Dominance Frontier
  – DF∞(S)

Theorem
 – If S is the set of CFG nodes that define variable v, then DF∞(S) is the set
   of nodes that require φ-functions for v




CIS570 Lecture 7             Static Single Assignment Form                       25




                                                                                      12
Algorithm for Inserting φ-Functions

for each variable v
    WorkList ← ∅
    EverOnWorkList ← ∅
    AlreadyHasPhiFunc ← ∅
    for each node n containing an assignment to v Put all defs of v on the worklist
        WorkList ← WorkList ∪ {n}
    EverOnWorkList ← WorkList
    while WorkList ≠ ∅
        Remove some node n from WorkList
        for each d ∈ DF(n)
            if d ∉ AlreadyHasPhiFunc              Insert at most one φ function per node
                Insert a φ-function for v at d
                AlreadyHasPhiFunc ← AlreadyHasPhiFunc ∪ {d}
                if d ∉ EverOnWorkList             Process each node at most once
                    WorkList ← WorkList ∪ {d}
                    EverOnWorkList ← EverOnWorkList ∪ {d}
CIS570 Lecture 7               Static Single Assignment Form                       26




Variable Renaming

Basic idea
 – When we see a variable on the LHS, create a new name for it
 – When we see a variable on the RHS, use appropriate subscript
Easy for straightline code
               x=                          x0 =
                =x                           = x0
               x=                          x1 =
                =x                           = x1

Use a stack when there’s control flow
 – For each use of x, find the definition of x that dominates it
                   x=                      x0 =          Traverse the dominance tree

                        =x                      = x0
CIS570 Lecture 7               Static Single Assignment Form                       27




                                                                                           13
Dominance Tree Example

 The dominance tree shows the dominance relation

                        1
                                                                                      1

      2                 5                       9
                                                                         2       4    5      13    9   12

      3            6         7          10                 11
                                                                         3       6    8      7    10 11

      4                 8                      12                            Dominance Tree


                       13
                       CFG


CIS570 Lecture 7                 Static Single Assignment Form                                            28




Variable Renaming (cont)

Data Structures
 – Stacks[v] ∀v
   Holds the subscript of most recent definition of variable v, initially empty
 – Counters[v] ∀v
   Holds the current number of assignments to variable v; initially 0

                                                      p
Auxiliary Routine                                   po
                                                            sh       1
  procedure GenName(variable v)                           pu
     i := Counters[v]                                2       4       5       13       9   12
     push i onto Stacks[v]
     Counters[v] := i + 1
                                                     3           6   8       7       10 11

                                 Use the Dominance Tree to remember the most
                                        recent definition of each variable

CIS570 Lecture 7                 Static Single Assignment Form                                            29




                                                                                                               14
Variable Renaming Algorithm

procedure Rename(block b)                          Call Rename(entry-node)
   for each φ-function p in b
      GenName(LHS(p)) and replace v with vi, where i=Top(Stack[v])
   for each statement s in b (in order)
      for each variable v ∈ RHS(s)
         replace v by vi, where i = Top(Stacks[v])
      for each variable v ∈ LHS(s)
         GenName(v) and replace v with vi, where i=Top(Stack[v])
   for each s ∈ succ(b) (in CFG)
      j ← position in s’s φ-function corresponding to block b
      for each φ-function p in s                                              Φ( , , )
         replace the j th operand of RHS(p) by v , where i = Top(Stack[v])
                                                i
   for each s ∈ child(b) (in DT)
      Rename(s)                              Recurse using Depth First Search
   for each φ-function or statement t in b
      for each vi ∈ LHS(t)                   Unwind stack when done with this node
         Pop(Stack[v])


CIS570 Lecture 7              Static Single Assignment Form                       30




Transformation from SSA Form

Proposal
 – Restore original variable names (i.e., drop subscripts)
 – Delete all φ-functions

Complications
                                                 x0 =
 − What if versions get out of order?
                                                 x1 =
   (simultaneously live ranges)
                                                         = x0
                                                         = x1
Alternative
  − Perform dead code elimination (to prune φ-functions)
  − Replace φ-functions with copies in predecessors
  − Rely on register allocation coalescing to remove unnecessary copies



CIS570 Lecture 7              Static Single Assignment Form                       31




                                                                                         15
Concepts

Data dependences
 – Three kinds of data dependences
 – du-chains
Alternate representations
SSA form
Conversion to SSA form
 – φ-function placement
      – Dominance frontiers
 – Variable renaming
      – Dominance trees
Conversion from SSA form




CIS570 Lecture 7           Static Single Assignment Form   32




Next Time

Assignments
 – Project proposals due

Lecture
 – Reuse optimizations




CIS570 Lecture 7           Static Single Assignment Form   33




                                                                16

More Related Content

Viewers also liked

Indian Semiconductors Industry Presentation 060109
Indian Semiconductors Industry Presentation 060109Indian Semiconductors Industry Presentation 060109
Indian Semiconductors Industry Presentation 060109Workosaur.com
 
Digital logic and computer design
Digital logic and computer design Digital logic and computer design
Digital logic and computer design Hareem Aslam
 
Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...
Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...
Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...DVClub
 
System-on-Chip Design, Embedded System Design Challenges
System-on-Chip Design, Embedded System Design ChallengesSystem-on-Chip Design, Embedded System Design Challenges
System-on-Chip Design, Embedded System Design Challengespboulet
 
It all starts here
It all starts hereIt all starts here
It all starts hereSIAAmerica
 
IP Reuse Impact on Design Verification Management Across the Enterprise
IP Reuse Impact on Design Verification Management Across the EnterpriseIP Reuse Impact on Design Verification Management Across the Enterprise
IP Reuse Impact on Design Verification Management Across the EnterpriseDVClub
 
The worldwide semiconductor industry: Trends and opportunities 2016
The worldwide semiconductor industry: Trends and opportunities 2016 The worldwide semiconductor industry: Trends and opportunities 2016
The worldwide semiconductor industry: Trends and opportunities 2016 The Broker Forum
 
System On Chip (SOC)
System On Chip (SOC)System On Chip (SOC)
System On Chip (SOC)Shivam Gupta
 
System On Chip
System On ChipSystem On Chip
System On Chipanishgoel
 
System on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phonesSystem on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phonesJeffrey Funk
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 

Viewers also liked (16)

Indian Semiconductors Industry Presentation 060109
Indian Semiconductors Industry Presentation 060109Indian Semiconductors Industry Presentation 060109
Indian Semiconductors Industry Presentation 060109
 
System-on-Chip
System-on-ChipSystem-on-Chip
System-on-Chip
 
System on Chip (SoC)
System on Chip (SoC)System on Chip (SoC)
System on Chip (SoC)
 
Digital logic and computer design
Digital logic and computer design Digital logic and computer design
Digital logic and computer design
 
Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...
Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...
Efficient Migration of Verilog Testbenches to 'UVM' Keeping the Functionality...
 
System-on-Chip Design, Embedded System Design Challenges
System-on-Chip Design, Embedded System Design ChallengesSystem-on-Chip Design, Embedded System Design Challenges
System-on-Chip Design, Embedded System Design Challenges
 
SoC: System On Chip
SoC: System On ChipSoC: System On Chip
SoC: System On Chip
 
It all starts here
It all starts hereIt all starts here
It all starts here
 
IP Reuse Impact on Design Verification Management Across the Enterprise
IP Reuse Impact on Design Verification Management Across the EnterpriseIP Reuse Impact on Design Verification Management Across the Enterprise
IP Reuse Impact on Design Verification Management Across the Enterprise
 
SOC Design Challenges and Practices
SOC Design Challenges and PracticesSOC Design Challenges and Practices
SOC Design Challenges and Practices
 
The worldwide semiconductor industry: Trends and opportunities 2016
The worldwide semiconductor industry: Trends and opportunities 2016 The worldwide semiconductor industry: Trends and opportunities 2016
The worldwide semiconductor industry: Trends and opportunities 2016
 
Semiconductor industry 2016
Semiconductor industry 2016Semiconductor industry 2016
Semiconductor industry 2016
 
System On Chip (SOC)
System On Chip (SOC)System On Chip (SOC)
System On Chip (SOC)
 
System On Chip
System On ChipSystem On Chip
System On Chip
 
System on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phonesSystem on Chip (SoC) for mobile phones
System on Chip (SoC) for mobile phones
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 

Similar to Lecture07

Cs718min1 2008soln View
Cs718min1 2008soln ViewCs718min1 2008soln View
Cs718min1 2008soln ViewRavi Soni
 
SVD and Lifting Wavelet Based Fragile Image Watermarking
SVD and Lifting Wavelet Based Fragile Image WatermarkingSVD and Lifting Wavelet Based Fragile Image Watermarking
SVD and Lifting Wavelet Based Fragile Image WatermarkingIDES Editor
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Igalia
 
Relational Model
Relational ModelRelational Model
Relational ModelSiti Ismail
 
W ee network_theory_10-06-17_ls2-sol
W ee network_theory_10-06-17_ls2-solW ee network_theory_10-06-17_ls2-sol
W ee network_theory_10-06-17_ls2-solAnkit Chaurasia
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonAMD Developer Central
 
20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilersComputer Science Club
 
ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...
ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...
ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...Deepak Malani
 
Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"Ciklum Minsk
 
Scalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving GraphsScalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving GraphsNicolas Kourtellis
 
Epsrcws08 campbell isvm_01
Epsrcws08 campbell isvm_01Epsrcws08 campbell isvm_01
Epsrcws08 campbell isvm_01Cheng Feng
 
Spring 2003
Spring 2003Spring 2003
Spring 2003butest
 
A novel estimation based backoff algorithm in the ieee
A novel estimation based backoff algorithm in the ieeeA novel estimation based backoff algorithm in the ieee
A novel estimation based backoff algorithm in the ieeeambitlick
 

Similar to Lecture07 (20)

Lecture03
Lecture03Lecture03
Lecture03
 
Cs718min1 2008soln View
Cs718min1 2008soln ViewCs718min1 2008soln View
Cs718min1 2008soln View
 
SVD and Lifting Wavelet Based Fragile Image Watermarking
SVD and Lifting Wavelet Based Fragile Image WatermarkingSVD and Lifting Wavelet Based Fragile Image Watermarking
SVD and Lifting Wavelet Based Fragile Image Watermarking
 
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
Good news, everybody! Guile 2.2 performance notes (FOSDEM 2016)
 
Ass5
Ass5Ass5
Ass5
 
Relational Model
Relational ModelRelational Model
Relational Model
 
Unit 05 dbms
Unit 05 dbmsUnit 05 dbms
Unit 05 dbms
 
W ee network_theory_10-06-17_ls2-sol
W ee network_theory_10-06-17_ls2-solW ee network_theory_10-06-17_ls2-sol
W ee network_theory_10-06-17_ls2-sol
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
 
20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers
 
ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...
ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...
ILP Based Approach for Input Vector Controlled (IVC) Toggle Maximization in C...
 
Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"Николай Папирный Тема: "Java memory model для простых смертных"
Николай Папирный Тема: "Java memory model для простых смертных"
 
Scalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving GraphsScalable Online Betweenness Centrality in Evolving Graphs
Scalable Online Betweenness Centrality in Evolving Graphs
 
Epsrcws08 campbell isvm_01
Epsrcws08 campbell isvm_01Epsrcws08 campbell isvm_01
Epsrcws08 campbell isvm_01
 
Backpropagation for Deep Learning
Backpropagation for Deep LearningBackpropagation for Deep Learning
Backpropagation for Deep Learning
 
Chp1
Chp1Chp1
Chp1
 
Spring 2003
Spring 2003Spring 2003
Spring 2003
 
C++ references
C++ referencesC++ references
C++ references
 
A novel estimation based backoff algorithm in the ieee
A novel estimation based backoff algorithm in the ieeeA novel estimation based backoff algorithm in the ieee
A novel estimation based backoff algorithm in the ieee
 
Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)
 

More from sean chen

Uvm presentation dac2011_final
Uvm presentation dac2011_finalUvm presentation dac2011_final
Uvm presentation dac2011_finalsean chen
 
Uvm dcon2013
Uvm dcon2013Uvm dcon2013
Uvm dcon2013sean chen
 
Example my hdl
Example my hdlExample my hdl
Example my hdlsean chen
 
0021.system partitioning
0021.system partitioning0021.system partitioning
0021.system partitioningsean chen
 
0015.register allocation-graph-coloring
0015.register allocation-graph-coloring0015.register allocation-graph-coloring
0015.register allocation-graph-coloringsean chen
 
0006.scheduling not-ilp-not-force
0006.scheduling not-ilp-not-force0006.scheduling not-ilp-not-force
0006.scheduling not-ilp-not-forcesean chen
 
Dominator tree
Dominator treeDominator tree
Dominator treesean chen
 
Lect.10.arm soc.4 neon
Lect.10.arm soc.4 neonLect.10.arm soc.4 neon
Lect.10.arm soc.4 neonsean chen
 
Image scalar hw_algorithm
Image scalar hw_algorithmImage scalar hw_algorithm
Image scalar hw_algorithmsean chen
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 

More from sean chen (20)

Demo
DemoDemo
Demo
 
Uvm presentation dac2011_final
Uvm presentation dac2011_finalUvm presentation dac2011_final
Uvm presentation dac2011_final
 
Uvm dcon2013
Uvm dcon2013Uvm dcon2013
Uvm dcon2013
 
Example my hdl
Example my hdlExample my hdl
Example my hdl
 
0021.system partitioning
0021.system partitioning0021.system partitioning
0021.system partitioning
 
0015.register allocation-graph-coloring
0015.register allocation-graph-coloring0015.register allocation-graph-coloring
0015.register allocation-graph-coloring
 
0006.scheduling not-ilp-not-force
0006.scheduling not-ilp-not-force0006.scheduling not-ilp-not-force
0006.scheduling not-ilp-not-force
 
Dominator tree
Dominator treeDominator tree
Dominator tree
 
Work items
Work itemsWork items
Work items
 
Work items
Work itemsWork items
Work items
 
ocelot
ocelotocelot
ocelot
 
Lect.10.arm soc.4 neon
Lect.10.arm soc.4 neonLect.10.arm soc.4 neon
Lect.10.arm soc.4 neon
 
Image scalar hw_algorithm
Image scalar hw_algorithmImage scalar hw_algorithm
Image scalar hw_algorithm
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Spi
SpiSpi
Spi
 
Serializer
SerializerSerializer
Serializer
 
Defense
DefenseDefense
Defense
 
Defense
DefenseDefense
Defense
 
I2 c
I2 cI2 c
I2 c
 
Uart
UartUart
Uart
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Lecture07

  • 1. Static Single Assignment Form Last Time – Lattice theoretic frameworks for data-flow analysis Today – Program representations – Static single assignment (SSA) form – Program representation for sparse data-flow – Conversion to and from SSA Next Time – Reuse optimizations CIS570 Lecture 7 Static Single Assignment Form 2 Data Dependence Definition – Data dependences are constraints on the order in which statements may be executed Types of dependences – Flow (true) dependence: s1 writes memory that s2 later reads (RAW) – Anti-dependence: s1 reads memory that s2 later writes (WAR) – Output dependences: s1 writes memory that s2 later writes (WAW) – Input dependences: s1 reads memory that s2 later reads (RAR) True dependences – Flow dependences represent actual flow of data False dependences – Anti- and output dependences reflect reuse of memory, not actual data flow; can often be eliminated CIS570 Lecture 7 Static Single Assignment Form 3 1
  • 2. Example s1 a = b; flow s2 b = c + d; anti s3 e = a + d; output s4 b = 3; input s5 f = b * 2; CIS570 Lecture 7 Static Single Assignment Form 4 Representing Data Dependences Implicitly – Use variable defs and uses – Pros: simple – Cons: hides data dependence (analyses must find this info) Def-use chains (du chains) – Link each def to its uses – Pros: explicit; therefore fast – Cons: must be computed and updated, consumes space Alternate representations – e.g., Static single assignment form (SSA), dependence flow graphs (DFG), value dependence graphs (VDG) CIS570 Lecture 7 Static Single Assignment Form 5 2
  • 3. DU Chains Definition – du chains link each def to its uses Example s1 a = b; s2 b = c + d; du chain s3 e = a + d; s4 b = 3; s5 f = b * 2; CIS570 Lecture 7 Static Single Assignment Form 6 UD Chains Definition – ud chains link each use to its defs Example s1 a = b; s2 b = c + d; ud chain s3 e = a + d; s4 b = 3; s5 f = b * 2; CIS570 Lecture 7 Static Single Assignment Form 7 3
  • 4. Role of Alternate Program Representations Process Original Code (RTL) Optimized Code (RTL) T1 T2 SSA Code1 SSA Code2 SSA Code3 Advantage – Allow analyses and transformations to be simpler & more efficient/effective Disadvantage – May not be “executable” (requires extra translations to and from) – May be expensive (in terms of time or space) CIS570 Lecture 7 Static Single Assignment Form 8 Static Single Assignment (SSA) Form Idea – Each variable has only one static definition – Makes it easier to reason about values instead of variables – Similar to the notion of functional programming Transformation to SSA – Rename each definition – Rename all uses reached by that assignment Example v := ... v0 := ... ... := ... v ... ... := ... v0 ... v := ... v1 := ... ... := ... v ... ... := ... v1 ... What do we do when there’s control flow? CIS570 Lecture 7 Static Single Assignment Form 9 4
  • 5. SSA and Control Flow Problem – A use may be reached by several definitions 1 2 v := ... 3 v := ... 1 4 ...v... 2 v0 :=... 3 v1 :=... 4 ...v?... CIS570 Lecture 7 Static Single Assignment Form 10 SSA and Control Flow (cont) Merging Definitions – φ-functions merge multiple reaching definitions Example 1 2 v0 :=... 3 v1 :=... 4 v2 := φ(v0,v1) ...v2... CIS570 Lecture 7 Static Single Assignment Form 11 5
  • 6. Another Example 1 v := 1 1 v0 := 1 2 v := v+1 v1 := φ(v0,v2) 2 v2 := v1+1 CIS570 Lecture 7 Static Single Assignment Form 12 SSA vs. ud/du Chains SSA form is more constrained Advantages of SSA – More compact – Some analyses become simpler when each use has only one def – Value merging is explicit – Easier to update and manipulate? Furthermore – Eliminates false dependences (simplifying context) for (i=0; i<n; i++) A[i] = i; Unrelated uses of i are given for (i=0; i<n; i++) different variable names print(foo(i)); CIS570 Lecture 7 Static Single Assignment Form 13 6
  • 7. SSA vs. ud/du Chains (cont) Worst case du-chains? switch (c1) { case 1: x = 1; break; case 2: x = 2; break; case 3: x = 3; break; } x4 = φ(x1, x2, x3) switch (c2) { case 1: y1 = x; break; case 2: y2 = x; break; case 3: y3 = x; break; case 4: y4 = x; break; } m defs and n uses leads to m×n du chains CIS570 Lecture 7 Static Single Assignment Form 14 Transformation to SSA Form Two steps – Insert φ-functions – Rename variables CIS570 Lecture 7 Static Single Assignment Form 15 7
  • 8. Where Do We Place φ-Functions? Basic Rule – If two distinct (non-null) paths x→z and y→z converge at node z, and nodes x and y contain definitions of variable v, then a φ-function for v is inserted at z x v1 :=... y v2 :=... z v3 := φ(v1,v2) ...v3... CIS570 Lecture 7 Static Single Assignment Form 16 Approaches to Placing φ-Functions Minimal – As few as possible subject to the basic rule Briggs-Minimal – Same as minimal, except v must be live across some edge of the CFG v = v = Briggs Minimal will not place a = v = v φ function in this case because v is not live across any CFG edge no uses of v CIS570 Lecture 7 Static Single Assignment Form 17 8
  • 9. Approaches to Placing φ-Functions (cont) Briggs-Minimal – Same as minimal, except v must be live across some edge of the CFG Pruned – Same as minimal, except dead φ-functions are not inserted v = v = Will Pruned place a φ function at = v = v this merge? no uses of v What’s the difference between Briggs Minimal and Pruned SSA? CIS570 Lecture 7 Static Single Assignment Form 18 Briggs Minimal vs. Pruned v = v = = v = v v2= φ(v0,v1) = v2 Briggs Minimal will add a φ function because v is live across the blue edge, but Pruned = φ(v2,v3) SSA will not because the φ function is dead Why would we ever use Briggs Minimal instead of Pruned SSA? CIS570 Lecture 7 Static Single Assignment Form 19 9
  • 10. Machinery for Placing φ-Functions entry Recall Dominators – d dom i if all paths from entry to node i include d d d dom i – d sdom i if d dom i and d≠i Dominance Frontiers i – The dominance frontier of a node d is the set of nodes that are “just barely” not dominated by d; i.e., the set of nodes n, such that – d dominates a predecessor p of n, and – d does not strictly dominate n – DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n} Notational Convenience – DF(S) = ∪s∈S DF(s) CIS570 Lecture 7 Static Single Assignment Form 20 Dominance Frontier Example DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n} Nodes in Dom(5) Dom(5) = {5, 6, 7, 8} 1 DF(5) = {4, 5, 12, 13} 2 5 9 3 6 7 10 11 4 8 12 13 What’s significant about the Dominance Frontier? In SSA form, definitions must dominate uses CIS570 Lecture 7 Static Single Assignment Form 21 10
  • 11. Dominance Frontier Example II DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n} Nodes in Dom(5) Dom(5) = {5, 6, 7, 8} 1 DF(5) = {4, 5, 13} 2 5 3 6 7 4 8 13 In this new graph, node 4 is the first point of convergence between the entry and node 5, so do we need a φ- function at node 13? CIS570 Lecture 7 Static Single Assignment Form 22 SSA Exercise 1 2 v3 :=... 7 3 4 8 v1 := ... 9 v2 := ... 5 10 v4:=φ(v1,v2) 6 v5:=φ(v3,v4) DF(8) = {10} DF(9) = {10} DF(2) = {6} DF(d) = {n | ∃p∈pred(n), d dom p and d !sdom n} DF({8,9}) = {10} DF(10) = {6} DF({2,6,8,9,10}) = {6,10} CIS570 Lecture 7 Static Single Assignment Form 23 11
  • 12. Dominance Frontiers Revisited Suppose that node 3 defines variable x x ∈ Def(3) DF(3) = {5} 1 2 3 4 5 6 Do we need to insert a φ- function for x anywhere else? Yes. At node 6. Why? CIS570 Lecture 7 Static Single Assignment Form 24 Dominance Frontiers and SSA Let – DF1(S) = DF(S) – DFi+1(S) = DF(S ∪ DFi(S)) Iterated Dominance Frontier – DF∞(S) Theorem – If S is the set of CFG nodes that define variable v, then DF∞(S) is the set of nodes that require φ-functions for v CIS570 Lecture 7 Static Single Assignment Form 25 12
  • 13. Algorithm for Inserting φ-Functions for each variable v WorkList ← ∅ EverOnWorkList ← ∅ AlreadyHasPhiFunc ← ∅ for each node n containing an assignment to v Put all defs of v on the worklist WorkList ← WorkList ∪ {n} EverOnWorkList ← WorkList while WorkList ≠ ∅ Remove some node n from WorkList for each d ∈ DF(n) if d ∉ AlreadyHasPhiFunc Insert at most one φ function per node Insert a φ-function for v at d AlreadyHasPhiFunc ← AlreadyHasPhiFunc ∪ {d} if d ∉ EverOnWorkList Process each node at most once WorkList ← WorkList ∪ {d} EverOnWorkList ← EverOnWorkList ∪ {d} CIS570 Lecture 7 Static Single Assignment Form 26 Variable Renaming Basic idea – When we see a variable on the LHS, create a new name for it – When we see a variable on the RHS, use appropriate subscript Easy for straightline code x= x0 = =x = x0 x= x1 = =x = x1 Use a stack when there’s control flow – For each use of x, find the definition of x that dominates it x= x0 = Traverse the dominance tree =x = x0 CIS570 Lecture 7 Static Single Assignment Form 27 13
  • 14. Dominance Tree Example The dominance tree shows the dominance relation 1 1 2 5 9 2 4 5 13 9 12 3 6 7 10 11 3 6 8 7 10 11 4 8 12 Dominance Tree 13 CFG CIS570 Lecture 7 Static Single Assignment Form 28 Variable Renaming (cont) Data Structures – Stacks[v] ∀v Holds the subscript of most recent definition of variable v, initially empty – Counters[v] ∀v Holds the current number of assignments to variable v; initially 0 p Auxiliary Routine po sh 1 procedure GenName(variable v) pu i := Counters[v] 2 4 5 13 9 12 push i onto Stacks[v] Counters[v] := i + 1 3 6 8 7 10 11 Use the Dominance Tree to remember the most recent definition of each variable CIS570 Lecture 7 Static Single Assignment Form 29 14
  • 15. Variable Renaming Algorithm procedure Rename(block b) Call Rename(entry-node) for each φ-function p in b GenName(LHS(p)) and replace v with vi, where i=Top(Stack[v]) for each statement s in b (in order) for each variable v ∈ RHS(s) replace v by vi, where i = Top(Stacks[v]) for each variable v ∈ LHS(s) GenName(v) and replace v with vi, where i=Top(Stack[v]) for each s ∈ succ(b) (in CFG) j ← position in s’s φ-function corresponding to block b for each φ-function p in s Φ( , , ) replace the j th operand of RHS(p) by v , where i = Top(Stack[v]) i for each s ∈ child(b) (in DT) Rename(s) Recurse using Depth First Search for each φ-function or statement t in b for each vi ∈ LHS(t) Unwind stack when done with this node Pop(Stack[v]) CIS570 Lecture 7 Static Single Assignment Form 30 Transformation from SSA Form Proposal – Restore original variable names (i.e., drop subscripts) – Delete all φ-functions Complications x0 = − What if versions get out of order? x1 = (simultaneously live ranges) = x0 = x1 Alternative − Perform dead code elimination (to prune φ-functions) − Replace φ-functions with copies in predecessors − Rely on register allocation coalescing to remove unnecessary copies CIS570 Lecture 7 Static Single Assignment Form 31 15
  • 16. Concepts Data dependences – Three kinds of data dependences – du-chains Alternate representations SSA form Conversion to SSA form – φ-function placement – Dominance frontiers – Variable renaming – Dominance trees Conversion from SSA form CIS570 Lecture 7 Static Single Assignment Form 32 Next Time Assignments – Project proposals due Lecture – Reuse optimizations CIS570 Lecture 7 Static Single Assignment Form 33 16