Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

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

3 Static Single-Assignment For Structured Languages

4 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 ?

5 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 ?

6 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. ?

7 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 ?

8 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) ?

9 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

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

11 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 ?

12 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 ?

13 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 !! ?

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

15 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. ?

16 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 ?

17 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 ?

18 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 ?

19 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

20 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

21 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

22 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.

23 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

24 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

25 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

26 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 ?

27 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 ?

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

29 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

30 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.

31 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. ?

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

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

34 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

35 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

36 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.

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

38 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

39 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.

40 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)

41 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.

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

43 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)

44 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

45 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 ?

46 Static Single-Assignment Compiling WHILE and REPEAT Statements

47 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.

48 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 ?

49 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.

50 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

51 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)

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

53 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.

54 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

55 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

56 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

57 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

58 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.

59 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


Ads by Google