Top Banner
P423/P523 Compilers Single Static Assignment Based on material from Static Single Assignment Book Deyaaeldeen Almahallawi 1 1 [email protected] Indiana University April 23, 2015 Deyaaeldeen Almahallawi P423/P523 1/ 36
65

P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Jun 05, 2018

Download

Documents

LêHạnh
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: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

P423/P523 CompilersSingle Static Assignment

Based on material from Static Single Assignment Book

Deyaaeldeen Almahallawi1

[email protected] University

April 23, 2015

Deyaaeldeen Almahallawi P423/P523 1/ 36

Page 2: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

History

• Developed by Wegman, Zadeck, Alpern, and Rosen in 1988.

• First used for for efficient computation of dataflow problemssuch as global value numbering, congruence of variables,aggressive deadcode removal, and constant propagation withconditional branches

• Currently used by GCC, Suns HotSpot JVM, IBMsRVM,Chromium V8, Mono, and LLVM

Deyaaeldeen Almahallawi P423/P523 2/ 36

Page 3: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

Definition

A program is defined to be in SSA form if each variable is a targetof exactly one assignment statement in the program text.

Deyaaeldeen Almahallawi P423/P523 3/ 36

Page 4: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

Consider the following code:

x = 1 ;y = x +1;x = 2 ;z = x +1;

x1 = 1 ;y = x1 +1;x2 = 2 ;z = x2 +1;

Deyaaeldeen Almahallawi P423/P523 4/ 36

Page 5: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

Consider the following code:

x = 1 ;y = x +1;x = 2 ;z = x +1;

x1 = 1 ;y = x1 +1;x2 = 2 ;z = x2 +1;

Deyaaeldeen Almahallawi P423/P523 4/ 36

Page 6: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

What about this code?

x = i n p u t ( ) ;i f ( x == 42)theny = 1 ;e l s ey = x + 2 ;endp r i n t ( y ) ;

Deyaaeldeen Almahallawi P423/P523 5/ 36

Page 7: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

x = i n p u t ( ) ;i f ( x == 42)theny1 = 1 ;e l s ey2 = x +2;endy3 = φ ( y1 , y2 ) ;p r i n t ( y3 ) ;

Deyaaeldeen Almahallawi P423/P523 6/ 36

Page 8: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

x = 0 ;y = 0 ;

w h i l e ( x < 10){y = y + x ;x = x + 1 ;

}

p r i n t ( y )

Deyaaeldeen Almahallawi P423/P523 7/ 36

Page 9: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

Deyaaeldeen Almahallawi P423/P523 8/ 36

Page 10: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

Deyaaeldeen Almahallawi P423/P523 8/ 36

Page 11: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Introduction

x1 = 0 ;y1 = 0 ;

x2 = φ( x1 , x3 )y2 = φ( y1 , y3 )w h i l e ( x2 < 10){

y3 = y2 + x2 ;x3 = x2 + 1 ;

}

p r i n t ( y2 )

Deyaaeldeen Almahallawi P423/P523 9/ 36

Page 12: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Properties

• Since there is only a single definition for each variable in theprogram text, a variables value is independent of its positionin the program.

• Almost free use-def chains.

• Simplifies def-use chains.

Deyaaeldeen Almahallawi P423/P523 10/ 36

Page 13: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Properties (Def-use)

Deyaaeldeen Almahallawi P423/P523 11/ 36

Page 14: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Properties (Def-use)

Deyaaeldeen Almahallawi P423/P523 11/ 36

Page 15: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Properties

• Since there is only a single definition for each variable in theprogram text, a variables value is independent of its positionin the program.

• Almost free use-def chains.

• Simplifies def-use chains.

• No program point can be reached by two definitions of thesame variable (First phase).

Deyaaeldeen Almahallawi P423/P523 12/ 36

Page 16: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Properties

Single reaching-definition property

A definition D of variable v reaches a point p in the CFG if there ex-ists a path from D to p that does not pass through another definitionof v

Deyaaeldeen Almahallawi P423/P523 13/ 36

Page 17: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion: performs live-range splitting to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming: assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 18: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion: performs live-range splitting to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming: assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 19: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion:

performs live-range splitting to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming: assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 20: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion: performs live-range splitting

to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming: assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 21: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion: performs live-range splitting to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming: assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 22: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion: performs live-range splitting to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming:

assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 23: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Minimality property

The minimality of the number of inserted φ-functions.

• φ-function insertion: performs live-range splitting to ensuresthat any use of a given variable v is reached by exactly onedefinition of v.

• Variable renaming: assigns a unique variable name to eachlive-range.

Deyaaeldeen Almahallawi P423/P523 14/ 36

Page 24: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Background

• Join sets: For a given set of nodes S in a CFG, the join setS (S) is the set of nodes in S that can be reached by two (ormore) distinct elements of S using disjoint paths.

• Dominance: d dom i if all paths from entry to node i include d

• Strict dominance: d sdom i if d dom i and d 6= i

• Dominance frontier: DF (n) is the border of the CFG regionthat is dominated by n, i.e. it contains all nodes x such that ndominates a predecessor of x but n does not strictly dominatex .

Deyaaeldeen Almahallawi P423/P523 15/ 36

Page 25: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Background

• Join sets: For a given set of nodes S in a CFG, the join setS (S) is the set of nodes in S that can be reached by two (ormore) distinct elements of S using disjoint paths.

• Dominance: d dom i if all paths from entry to node i include d

• Strict dominance: d sdom i if d dom i and d 6= i

• Dominance frontier: DF (n) is the border of the CFG regionthat is dominated by n, i.e. it contains all nodes x such that ndominates a predecessor of x but n does not strictly dominatex .

Deyaaeldeen Almahallawi P423/P523 15/ 36

Page 26: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Background

• Join sets: For a given set of nodes S in a CFG, the join setS (S) is the set of nodes in S that can be reached by two (ormore) distinct elements of S using disjoint paths.

• Dominance: d dom i if all paths from entry to node i include d

• Strict dominance: d sdom i if d dom i and d 6= i

• Dominance frontier: DF (n) is the border of the CFG regionthat is dominated by n, i.e. it contains all nodes x such that ndominates a predecessor of x but n does not strictly dominatex .

Deyaaeldeen Almahallawi P423/P523 15/ 36

Page 27: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Background

• Join sets: For a given set of nodes S in a CFG, the join setS (S) is the set of nodes in S that can be reached by two (ormore) distinct elements of S using disjoint paths.

• Dominance: d dom i if all paths from entry to node i include d

• Strict dominance: d sdom i if d dom i and d 6= i

• Dominance frontier: DF (n) is the border of the CFG regionthat is dominated by n, i.e. it contains all nodes x such that ndominates a predecessor of x but n does not strictly dominatex .

Deyaaeldeen Almahallawi P423/P523 15/ 36

Page 28: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Background

• Join sets: For a given set of nodes S in a CFG, the join setS (S) is the set of nodes in S that can be reached by two (ormore) distinct elements of S using disjoint paths.

• Dominance: d dom i if all paths from entry to node i include d

• Strict dominance: d sdom i if d dom i and d 6= i

• Dominance frontier: DF (n) is the border of the CFG regionthat is dominated by n,

i.e. it contains all nodes x such that ndominates a predecessor of x but n does not strictly dominatex .

Deyaaeldeen Almahallawi P423/P523 15/ 36

Page 29: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Minimal SSA Construction

Background

• Join sets: For a given set of nodes S in a CFG, the join setS (S) is the set of nodes in S that can be reached by two (ormore) distinct elements of S using disjoint paths.

• Dominance: d dom i if all paths from entry to node i include d

• Strict dominance: d sdom i if d dom i and d 6= i

• Dominance frontier: DF (n) is the border of the CFG regionthat is dominated by n, i.e. it contains all nodes x such that ndominates a predecessor of x but n does not strictly dominatex .

Deyaaeldeen Almahallawi P423/P523 15/ 36

Page 30: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Dominance Frontier

What is the border frontier of y in blocks B and C?

Deyaaeldeen Almahallawi P423/P523 16/ 36

Page 31: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion (First Phase)

Constructing minimal SSA form requires for each variable v , theinsertion of φ-functions at S (Defs (v))

, where Defs(v) is the setof nodes that have definitions of v .

Deyaaeldeen Almahallawi P423/P523 17/ 36

Page 32: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion (First Phase)

Constructing minimal SSA form requires for each variable v , theinsertion of φ-functions at S (Defs (v)) , where Defs(v) is the setof nodes that have definitions of v .

Deyaaeldeen Almahallawi P423/P523 17/ 36

Page 33: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion

Deyaaeldeen Almahallawi P423/P523 18/ 36

Page 34: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion

Notes

• Because a φ-function is itself a definition,

it may requirefurther φ-functions to be inserted.

• Dominance frontiers of distinct nodes may intersect, but oncea φ-function for a particular variable has been inserted at anode, there is no need to insert another.

Deyaaeldeen Almahallawi P423/P523 19/ 36

Page 35: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion

Notes

• Because a φ-function is itself a definition, it may requirefurther φ-functions to be inserted.

• Dominance frontiers of distinct nodes may intersect, but oncea φ-function for a particular variable has been inserted at anode, there is no need to insert another.

Deyaaeldeen Almahallawi P423/P523 19/ 36

Page 36: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion

Notes

• Because a φ-function is itself a definition, it may requirefurther φ-functions to be inserted.

• Dominance frontiers of distinct nodes may intersect,

but oncea φ-function for a particular variable has been inserted at anode, there is no need to insert another.

Deyaaeldeen Almahallawi P423/P523 19/ 36

Page 37: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

φ-function Insertion

Notes

• Because a φ-function is itself a definition, it may requirefurther φ-functions to be inserted.

• Dominance frontiers of distinct nodes may intersect, but oncea φ-function for a particular variable has been inserted at anode, there is no need to insert another.

Deyaaeldeen Almahallawi P423/P523 19/ 36

Page 38: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 20/ 36

Page 39: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 21/ 36

Page 40: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 22/ 36

Page 41: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 23/ 36

Page 42: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 24/ 36

Page 43: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 25/ 36

Page 44: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Example: x

Deyaaeldeen Almahallawi P423/P523 26/ 36

Page 45: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Computing Dominance Frontier

Deyaaeldeen Almahallawi P423/P523 27/ 36

Page 46: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Computing Dominance Frontier

Deyaaeldeen Almahallawi P423/P523 28/ 36

Page 47: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Variable Renaming (Second Phase)

Deyaaeldeen Almahallawi P423/P523 29/ 36

Page 48: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Variable Renaming

Deyaaeldeen Almahallawi P423/P523 30/ 36

Page 49: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Destruction

What’s next?

• No we have a nice code in SSA form, but

it has φ-functions allover the place that we do not know how to implement them.

• Let’s remove them!

• How? rename all φ-related variables (φ-web) to one uniquename.

Deyaaeldeen Almahallawi P423/P523 31/ 36

Page 50: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Destruction

What’s next?

• No we have a nice code in SSA form, but it has φ-functions allover the place that we do not know how to implement them.

• Let’s remove them!

• How? rename all φ-related variables (φ-web) to one uniquename.

Deyaaeldeen Almahallawi P423/P523 31/ 36

Page 51: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Destruction

What’s next?

• No we have a nice code in SSA form, but it has φ-functions allover the place that we do not know how to implement them.

• Let’s remove them!

• How? rename all φ-related variables (φ-web) to one uniquename.

Deyaaeldeen Almahallawi P423/P523 31/ 36

Page 52: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Destruction

What’s next?

• No we have a nice code in SSA form, but it has φ-functions allover the place that we do not know how to implement them.

• Let’s remove them!

• How?

rename all φ-related variables (φ-web) to one uniquename.

Deyaaeldeen Almahallawi P423/P523 31/ 36

Page 53: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Destruction

What’s next?

• No we have a nice code in SSA form, but it has φ-functions allover the place that we do not know how to implement them.

• Let’s remove them!

• How? rename all φ-related variables (φ-web) to one uniquename.

Deyaaeldeen Almahallawi P423/P523 31/ 36

Page 54: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Destruction

Finding φ-webs

Deyaaeldeen Almahallawi P423/P523 32/ 36

Page 55: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Closer Look at Minimal SSA

Is it really minimal?

It can insert a φ-function to merge two values that are never usedafter the merge.

Solution

Construct pruned SSA that uses global data-flow analysis to decidewhere values are live, so it only inserts φ-function at those mergepoints where the analysis indicates that the value is potentially live.

Deyaaeldeen Almahallawi P423/P523 33/ 36

Page 56: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Closer Look at Minimal SSA

Is it really minimal?

It can insert a φ-function to merge two values that are never usedafter the merge.

Solution

Construct pruned SSA that uses global data-flow analysis to decidewhere values are live, so it only inserts φ-function at those mergepoints where the analysis indicates that the value is potentially live.

Deyaaeldeen Almahallawi P423/P523 33/ 36

Page 57: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Closer Look at Minimal SSA

Is it really minimal?

It can insert a φ-function to merge two values that are never usedafter the merge.

Solution

Construct pruned SSA that uses global data-flow analysis to decidewhere values are live, so it only inserts φ-function at those mergepoints where the analysis indicates that the value is potentially live.

Deyaaeldeen Almahallawi P423/P523 33/ 36

Page 58: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Closer Look at Minimal SSA

Is it really minimal?

It can insert a φ-function to merge two values that are never usedafter the merge.

Solution

Construct pruned SSA that uses global data-flow analysis to decidewhere values are live, so it only inserts φ-function at those mergepoints where the analysis indicates that the value is potentially live.

Deyaaeldeen Almahallawi P423/P523 33/ 36

Page 59: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Pruned SSA

Is it really the solution?

• Time-consuming, since computing the live ranges is not trivial.

• Space-consuming, it increases the space requirements for thebuild process.

Deyaaeldeen Almahallawi P423/P523 34/ 36

Page 60: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Pruned SSA

Is it really the solution?

• Time-consuming

, since computing the live ranges is not trivial.

• Space-consuming, it increases the space requirements for thebuild process.

Deyaaeldeen Almahallawi P423/P523 34/ 36

Page 61: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Pruned SSA

Is it really the solution?

• Time-consuming, since computing the live ranges is not trivial.

• Space-consuming, it increases the space requirements for thebuild process.

Deyaaeldeen Almahallawi P423/P523 34/ 36

Page 62: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Pruned SSA

Is it really the solution?

• Time-consuming, since computing the live ranges is not trivial.

• Space-consuming

, it increases the space requirements for thebuild process.

Deyaaeldeen Almahallawi P423/P523 34/ 36

Page 63: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Pruned SSA

Is it really the solution?

• Time-consuming, since computing the live ranges is not trivial.

• Space-consuming, it increases the space requirements for thebuild process.

Deyaaeldeen Almahallawi P423/P523 34/ 36

Page 64: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

SSA Flavors Example

Deyaaeldeen Almahallawi P423/P523 35/ 36

Page 65: P423/P523 Compilers Single Static Assignment Based …deyaaeldeen.github.io/Teaching/p423/ssa.pdf · P423/P523 Compilers Single Static Assignment Based on material from Static Single

Thank you!

Deyaaeldeen Almahallawi P423/P523 36/ 36