# Static Single-Assignment ? ? Introduction: Over last few years [1991] SSA has been Stablished as… Intermediate program representation.

## Presentation on theme: "Static Single-Assignment ? ? Introduction: Over last few years [1991] SSA has been Stablished as… Intermediate program representation."— Presentation transcript:

Static Single-Assignment ? ? Introduction: Over last few years [1991] SSA has been Stablished as… Intermediate program representation

? ALLOWS 1.New powerful optimizations 2. Simplifies other programs considerably

Static Single-Assignment For Structured Languages

Static Single-Assignment ? ? The essential property of SSA form is that there is only one assignment to each variable in the whole program text. ¿ one assignment to each variable = program text more easy ?

Static Single-Assignment YES!! Because if two variables have the same name they also contain the same value. Variable with same name for all program = Same value for all program ?

Static Single-Assignment YES!! Because if two variables have the same name they also contain the same value. Variable with same name for all program = Same value for all program A variable that is not been using make free space in memory. ?

Static Single-Assignment V:=0; X:=v+1; V:=2; Y:=v+3 ABITUAL FORM V1:=0; X1:=v1+1; V2:=2; Y1:=v2+3 SSA FORM We can explain the construction of SSA informally with as simple sequence of assignments ?

Static Single-Assignment V:=0; X:=v+1; V:=2; Y:=v+3 ABITUAL FORM V1:=0; X1:=v1+1; V2:=2; Y1:=v2+3 SSA FORM The original name about this new subscripts variable unique are Value instances (Or simple values for short) ?

Static Single-Assignment V:=0; X:=v+1; V:=2; Y:=v+3 ABITUAL FORM V1:=0; X1:=v1+1; V2:=2; Y1:=v2+3 SSA FORM The original name about this new subscripts variable unique are Value instances (Or simple values for short) If two expressions are textually the same, they are sure to evaluate the same result. Subscripts to make variable name Unique. 3 variables 4 variables

Static Single-Assignment But, normally in a program we find complicated programs.Because contains… branches & join nodes ?

Static Single-Assignment IF cond THEN V:=1 ELSE v:=2 END; X:=v+l Cond V1:= 1V2 := 1 V3:= (V1,V2) X1=V3+1 1:=0; WHILE cond DO  1:=i+1  END,  X=i i1:=0 i3:=(i1,i2) cond i2:=i3+1 x1:=i3 Values have to be merged into UNIQUE value ?

Static Single-Assignment IF cond THEN V:=1 ELSE v:=2 END; X:=v+l Cond V1:= 1V2 := 1 V3:= O(V1,V2) X1=V3+1 1:=0; WHILE cond DO  1:=i+1  END,  X=i i1:=0 i3:=O(i1,i2) cond i2:=i3+1 x1:=i3 Values v1 and v2 have to be merged into a unique value v3 ?

Static Single-Assignment Values v1 and v2 have to be merged into a unique value v3 V3 DEPENDS FROM V1 AND V2 So, we need a function to decide which variable are we going to asign !! ?

Static Single-Assignment Function Name:O-function Right hand: as many operands as there are branchs into the join name. ?

Static Single-Assignment IF cond THEN V:=1 ELSE v:=2 END; X:=v+l Cond V1:= 1V2 := 1 V3:= O(V1,V2) X1=V3+1 Right hand: as many operands as there are branchs into the join name. ?

Static Single-Assignment CONTROL FLOW GRAPHS IF cond THEN V:=1 ELSE v:=2 END; X:=v+l Cond V1:= 1V2 := 1 V3:= O(V1,V2) X1=V3+1 1:=0; WHILE cond DO  1:=i+1  END,  X=i i1:=0 i3:=O(i1,i2) cond i2:=i3+1 x1:=i3 Control flow graphs of an IF and a WHILE statement with instructions in SSA form. Ogni nodo=basic block ?

Static Single-Assignment Algorithms for Generating SSA Form: presented by Cytron et al. [1986] Their algorithm computes the DOMINANCE FRONTIERS in the graph Fino adesso Aviamo visto la forma”informal” At join nodes ?

Static Single-Assignment Cytron Agorithm is the most efficient algorithm currently known for a general flow graph but … present the problem that requires several passes over instructions of the graph. Problem:MULTIPASS ?

Static Single-Assignment How resolve multipass problem ? 1988  Rosen: sketch a single-pass algoritm for generating SSA form. Problem: this algorithm requires a topologically sorted control flow graph generates many unnecessary o-assignments of dependece graphs

Static Single-Assignment How resolve multipass problem ? 1988  Rosen sketch asingle-pass algoritm forgenerating SSA form. Problem: this algorithm requires atopologically sorted control flow graph generates many unnecessary o-assignments A similar idea was exploited next year by Horwitz in the construction of dependence graphs

Static Single-Assignment How resolve multipass problem ? 1988  Rosen sketch asingle-pass algoritm forgenerating SSA form. They identify single-entry/single exit regions To place merge nodes….but the main difference or problem is that make use of structured control flow 1993 Johnson and Pingali where near to resolve this problem It means MULTIPASS

Static Single-Assignment How resolve multipass problem ? Finally M.Brenadis and H.Mössenböck presented a technique for generating SSA form in a single pass direcctly from the source text program.

Static Single-Assignment How resolve multipass problem ? Finally M.Brandis and H.Mössenböck presented a technique for generating SSA form in a single pass direcctly from the source text program. THIS TECNIQUE CAN BE APPLIED TO Structured programs Programs that contain assignments Structured statements If,case,while,repeat or for goto

Static Single-Assignment How resolve multipass problem ? The technique for generating SSA form in a single pass is possible creating o-assignments on-the-fly during the parsing

Static Single-Assignment o-assignments on-the-fly during the parsing ADVANTAGE: Saves an intermediate step. Save time and memory. Directly Generate machine-specific Instructions in SSA form ready for optimizations

Static Single-Assignment o-assignments on-the-fly during the parsing ADVANTAGE:Saves an intermediate step Problems caused by  assignments to array Elements  to parameters passed by reference, And  to variables that are referenced via pointers We can not control dynamic assignment ?

Static Single-Assignment o-assignments on-the-fly during the parsing ADVANTAGE:Saves an intermediate step Problems caused by  assignments to array Elements  to parameters passed by reference, and  to variables that are referenced via pointers Can be dealt as described CYTRON Using dominator tree In subsequent optimization In a single pass too ?

Static Single-Assignment algorithm for generating SSA form ¿Cuestions?

Static Single-Assignment algorithm for generating SSA form At this point… we are going to see first. Algorithm to generate SSA form (single pass) How to build the dominator tree during parsing

Static Single-Assignment Naming of Values: Every Asignment to a variable “v” generates a new value “vi”. ” i ” is the unique number for this variable.

Static Single-Assignment Naming of Values: Every Asignment to a variable “v” generates a new value “vi”. ” i ” is the unique number for this variable. ?

Static Single-Assignment Join Nodes In the flow graph of a procedure is normal find Control structures as Like,while and repeat

Static Single-Assignment Join Nodes Control structures as Like,while and repeat Introduce branches into the flow graph

Static Single-Assignment Join Nodes IF cond THEN V:=1 ELSE v:=2 END; X:=v+l Cond V1:= 1V2 := 1 V3:= O(V1,V2) X1=V3+1 1:=0; WHILE cond DO  1:=i+1  END,  X=i i1:=0 i3:=O(i1,i2) cond i2:=i3+1 x1:=i3 A node where two branches join is called a join node

Static Single-Assignment Join Nodes A node where two branches join is called a join node Control structures and their join nodes on the flow graph

Static Single-Assignment Join Nodes To the flow graph of every procedure we ad a virtual start node ENTER and a virtual end node EXIT.

Static Single-Assignment Only introduce additional join nodes is when Repeat statements are nested ?

Static Single-Assignment This is necessary for later optimizations. For example, if the join nodes of the two loops were merged one could not move loop-invariant calculations out of the innermost loop. Additional join nodes may be inserted for nested REPEAT statements

Static Single-Assignment Where to place o-assignments Every assignment to a variable v adds or modifies a o-assignment for v in the current join node.

Static Single-Assignment Where to place o-assignments Every assignment to a variable v adds or modifies a o-assignment for v in the current join node. O-assignments, like all assignments, generate new values and therefore cause the placement of other o-assignments in the next outer join node (exception of o-assignments in the Exit node for which there is no join node)

Static Single-Assignment Compiling IF Statements: When we start an IF parsing statement it’s been creating a new join node…this join node becomes the container of all o-functions generated due to assignments in both branches of the IF statements.

Static Single-Assignment Compiling IF Statements: join node becomes the container of all o-functions generated ?

Static Single-Assignment Compiling IF Statements After (3) a is reset to a0 and b to b0 then else You (voi) can note that there is No assignment to b in the else And c in then …so… see join node (per capire)

Static Single-Assignment Compiling IF Statements At same time that we are running the branch, o-functinon It’s been creating 1 2 3 4

Static Single-Assignment Compiling IF Statements When the whole IF statement has been parsed, the generated o-assignment are commited (i.e. they are processed as assignments) Values of the left hand (a2,b2,c2) become The new current values for a,b, and c. and ?

Static Single-Assignment Compiling WHILE and REPEAT Statements

Static Single-Assignment Compiling WHILE Statements Compiling WHILE: All asignments in the loop cause the placement of o-functions in this join node in the same way as it is done for IF statements.

Static Single-Assignment Compiling WHILE Statements Compiling WHILE: All asignments in the loop cause the placement of o-functions in this join node in the same way as it is done for IF statements. The compilation of CASE statements and FOR statements follows the same lines as the compilation of IF statements and WHILE statements ?

Static Single-Assignment Compiling REPEAT Statements Repeat statements are special because control dosen’t leave them via their join node. All asignments in the Repeat statement cause the placement of o-functions in the join node like while form.

Static Single-Assignment Compiling REPEAT Statements Repeat statements are special because … o-assignments are committed after the Repeat statement, the second operand of every o-function is taken a as the new current value after th Repeat statements. Repeat statements dosen’t leave them via their join node

Static Single-Assignment SSA form can be generated using a procedure… 1.To generate or modify a o-assignment (InsertPhi). 2.To commit the o-ssignments of a join mode (CommitPhi)

Static Single-Assignment computing the dominator tree SSA form dosen’t need the dominator tree…however… Many optimization algorithms require this data structure

Static Single-Assignment computing the dominator tree Many optimization algorithms require dominator tree. Is based on the dominance relation between basic blocks. Many optimization algorithms require dominator tree. Is based on the dominance relation between basic blocks. A block X dominate a block Y if…. X appears on every path from start node of the flow graph to Y.

Static Single-Assignment computing the dominator tree A block X dominate a block Y if…. X appears on every path from start node of the flow graph to Y. Single ENTRY node Single EXIT node

Static Single-Assignment computing the dominator tree For structured programs we can use a simpler technique That allows to build the dominator tree in a single pass During the parsing The ENTRY node Dominates all nodes Inside the statement

Static Single-Assignment Algorithm implemented in a compiler for a subset Oberon (whith expressions, assignments,IF,WHILE,REPEAT,and LOOP/EXIT). With o-assignments Without O-assignments

Static Single-Assignment The result show that our algorithm imposes a linear time penalty of about 10 % abd a almost linear space overhead of about 15 % to a compilation in practice. With o-assignments Without O-assignments

Static Single-Assignment SSA form and dominator tree are: IMPORTANT DATA STRUCTURES IN OPTIMIZING COMPILERS. Allow building small and efficient compilers. Make an easy understand compilers.

Static Single-Assignment Single-Pass Generation of Static Single-AssignmentForm for Structured Languages Marc M.Brandis and Hansperter MössenböckETH Zürich Efficiently Computing Static Single Assignment Form and the Control Dependence Graph. –Ron Cytron,J.Ferrente,B.Rosen and M.Wegman. Using Static Single Assignment Form in a Code Optimize- Carl Mc.Connell and Ralph E. Johnson. University Illinois.

Download ppt "Static Single-Assignment ? ? Introduction: Over last few years [1991] SSA has been Stablished as… Intermediate program representation."

Similar presentations