Download presentation
Presentation is loading. Please wait.
Published byKelly Rodgers Modified over 8 years ago
1
Compiler Principles Fall 2015-2016 Compiler Principles Lecture 9: Dataflow & Optimizations 2 Roman Manevich Ben-Gurion University of the Negev
2
Tentative syllabus Front End Scanning Top-down Parsing (LL) Bottom-up Parsing (LR) Intermediate Representation Lowering Operational Semantics Lowering Correctness Optimizations Dataflow Analysis Loop Optimizations Code Generation Register Allocation 2
3
Previously Extending While/IL syntax with procedures Introduction to optimizations Formalisms for program analysis – Basic blocks – Control flow graphs Dataflow analyses and optimizations – Live variables dead code elimination – In recitation: Available expressions common sub-expression elimination + copy propagation 3
4
Theory to the rescue Building up all of the machinery to design the liveness analysis was tricky The key ideas, however, are mostly independent of the analysis: – We need to be able to compute functions describing the behavior of each statement – We need to be able to merge several subcomputations together – We need an initial value for all of the basic blocks There is a beautiful formalism that captures many of these properties: dataflow framework 4
5
agenda Dataflow analysis framework – Join semilattices – Chaotic iteration – Monotone transformers More optimizations – Reminder: Available expressions common sub- expression elimination + copy propagation – Constant propagation constant folding – Reaching definition loop invariant code motion 5
6
6 Lattice theory
7
Partial order A partial order is a pair (V, ) V is a set of abstract elements called domain : V V is a binary relation that is – Reflexive: x x – Antisymmetric: if x y and y x, then x = y – Transitive: if x y and y z, then x z 7
8
Liveness partial order An IL program P induces the partial order (2 Vars(P), ) – is reflexive: X X – is antisymmetric : X Y and Y X implies X=Y – is transitive : X Y and Y Z implies X Z 8
9
Partial order for liveness (Hasse diagram) 9 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c} Greater Lower Vars(P)={a,b,c} bottom element top element
10
Partial order for liveness (Hasse diagram) 10 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c} Least precise Most precise Vars(P)={a,b,c}
11
Join operation Let (V, ) be a partial order An operation : V V V is a join if it is – commutative: x y = y x – associative: (x y) z = x (y z) – idempotent: x x = x If x y = z, we say that z is the join or (Least Upper Bound) of x and y Intuitively the join of two elements represents combining information from two elements by an overapproximation 11
12
Join semilattices A join semilattice is a partial order equipped with a join operation and a bottom element (V, , , ) There is a unique bottom element , which is smaller than all other elements – The bottom element represents “no information yet” or “most precise value” There is also usually a top element , which is greater than all other elements – “Most conservative value” 12
13
Join semilattices in program analysis The elements of a join semilattice represent (infinite) sets of states – We compute one element per program location Join approximates the information from two different paths The bottom element usually stands for an empty set of states The top element stands for the set of all possible states 13
14
What is the join of {b} and {c}? 14 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c}
15
What is the join of {b} and {c}? 15 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c}
16
What is the join of {b} and {a,c}? 16 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c}
17
What is the join of {b} and {a,c}? 17 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c}
18
What is the join of {a} and {a,b}? 18 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c}
19
What is the join of {a} and {a,b}? 19 {} {a}{b}{c} {a, b}{a, c}{b, c} {a, b, c}
20
A join semilattice for liveness Sets of live variables and the set union operation Idempotent: – x x = x Commutative: – x y = y x Associative: – (x y) z = x (y z) Bottom element: – The empty set: Ø x = x What is the ordering over these elements? 20
21
Join semilattices and orderings Every join semilattice (V, ) induces an ordering relationship over its elements Define x y iff x y = y Exercise: prove – Reflexivity: x x – Antisymmetry: If x y and y x, then x = y – Transitivity: If x y and y z, then x z 21
22
22 Dataflow framework
23
Semilattices and program analysis Semilattices naturally solve many of the problems we encounter in global analysis How do we combine information from multiple basic blocks? – …? What value do we give to basic blocks we haven't seen yet? – …? How do we know that the algorithm always terminates? – …? 23
24
Semilattices and program analysis Semilattices naturally solve many of the problems we encounter in global analysis How do we combine information from multiple basic blocks? – Take the join of all information from those blocks What value do we give to basic blocks we haven't seen yet? – Use the bottom element How do we know that the algorithm always terminates? – Actually, we still don't! More on that later 24
25
A general framework A global analysis is a tuple ( D, V, , F, I ) –D is a direction (forward or backward) The order to visit statements within a basic block, not the order in which to visit the basic blocks –V is a set of values (domain) – is a join operator over those values –F = {F[c] : V V | c P} is a set of transfer functions, one per command c –I is an initial value If D=forward then we set I in the start node, otherwise we set I in the end node 25
26
Liveness as a dataflow problem For a program P, define a dataflow problem as DataflowProblem = ( D, V, , F, I ) Liveness = ( backward, 2 Vars(P), , { v. (v\DEF(c)) USE(c) | c P}, {} ) 26
27
Running global analyses Let P be an IL program Assume that (D, V, , F, I) is a forward analysis Set OUT[c] = for all commands c P Set OUT[start] = I Repeat until no values change: For each statement c with predecessors p 1, p 2, …, p n : – Set IN[c] = OUT[p 1 ] OUT[p 2 ] … OUT[p n ] – Set OUT[c] = F[c] (IN[c]) The order of this iteration does not matter: Chaotic iteration 27
28
For comparison Set OUT[c] = for all statements c Set OUT[start] = I Repeat until no values change: For each c P with predecessors p 1,…,p n : Set IN[c] = OUT[p 1 ] … OUT[p n ] Set OUT[c] = F[c] (IN[c]) Set IN[c] = {} for all statements c Set OUT[end] = {} Repeat until no values change: For each c P with successors s 1,…,s n : Set OUT[c] = IN[s 1 ] … IN[s n ] Set IN[c] = (OUT[c]\DEF(c)) USE(c) 28
29
What is this framework good for? This form of analysis is called the dataflow framework Can be used to easily prove an analysis is sound With certain restrictions, can be used to prove that an analysis eventually terminates – Again, more on that later 29
30
30 Termination conditions
31
Height of a lattice An increasing chain is a sequence of elements a 1 a 2 … a k – The length of such a chain is k The height of a lattice is the length of the maximal increasing chain For liveness with n program variables: – {} {v 1 } {v 1,v 2 } … {v 1,…,v n } 31
32
Monotone transfer functions A transfer function f is monotone iff if x y, then f(x) f(y) Intuitively, if you know less information about a program point, you can't “gain back” more information about that program point Many transfer functions are monotone, including those for liveness and constant propagation Note: Monotonicity does not mean that x f(x) – (This is a different property called extensivity) 32
33
Liveness and monotonicity A transfer function f is monotone iff if x y, then f(x) f(y) Recall our transfer function for a:=b+c is – F[a:=b+c](X) = (X \ {a}) {b, c} Recall that our join operator is set union and induces an ordering relationship X Y iff X Y Is this monotone? 33
34
Termination theorem Theorem 1: A dataflow analysis with a finite- height join semilattice and family of monotone transfer functions always terminates Proof sketch: – The join operator can only bring values up – Transfer functions can never lower values back down below where they were in the past (monotonicity) – Values cannot increase indefinitely (finite height) 34
35
Soundness and optimality theorem Theorem 2: A dataflow analysis with a finite- height join semilattice and family of monotone transfer functions always yields a unique solution – the least fixed point in the lattice 35
36
36 distributivity
37
An “optimality” result A transfer function f is distributive if f(a b) = f(a) f(b) for every domain elements a and b If all transfer functions are distributive then the fixed-point solution is equal to the solution computed by joining results from all (potentially infinite) control-flow paths – Join over all paths Optimal if we ignore program conditions – Pretend all control-flow paths can be executed by the program Which analyses use distributive functions? 37
38
An “optimality” result A transfer function f is distributive if f(a b) = f(a) f(b) for every domain elements a and b If all transfer functions are distributive then the fixed-point solution is equal to the solution computed by joining results from all (potentially infinite) control-flow paths – Join over all paths Optimal if we ignore program conditions – Pretend all control-flow paths can be executed by the program Which analyses use distributive functions? 38
39
39 Common Subexpression elimination
40
CSE Example 40 b := a * a; c := a * a; d := b + c; e := b + b;
41
CSE Example 41 b := a * a; c := a * a; d := b + c; e := b + b;
42
CSE Example 42 b := a * a; c := b; d := b + c; e := b + b; Common sub-expression elimination
43
Common Subexpression Elimination If we have two variable assignments v1 := a op b … v2 := a op b and the values of v1, a, and b have not changed between the assignments, rewrite the code as v1 := a op b … v2 := v1 Eliminates useless recalculation Paves the way for later optimizations 43
44
44 copy propagation
45
CP Example 45 b := a * a; c := b; d := b + c; e := b + b;
46
CP Example 46 b := a * a; c := b; d := b + b; e := b + b; Copy propagation
47
Copy Propagation If we have a variable assignment v1 := v2 then as long as v1 and v2 are not reassigned, we can rewrite expressions of the form a := … v1 … as a := … v2 … 47
48
48 Available expressions
49
Both common subexpression elimination and copy propagation depend on an analysis of the available expressions in a program An expression a := b op c is called available at program location L if variable a holds the value of b op c at that location – Similarly for a := b In common subexpression elimination, we replace an available expression (b op c) by the variable holding its value (a) In copy propagation, we replace the use of a variable (a) by the available expression it holds (b) 49
50
Finding available expressions Compute for each program location L a set of expressions AE of the forms a := b op c and a := b that are definitely available there Whenever we execute a statement a := b op c: – Any expression holding a is invalidated – The expression a := b op c becomes available 50
51
Available expressions step 51 a := b + c Output Value AE out Input Value AE in AE out = ( AE in \ {e | e contains a }) { a : =b+c } Expressions of the forms a =… and x=… a … Provided that a and b and a and c are different pairs of variables
52
Available expressions example 52 a := b; c := b; d := a + b; e := a + b; d := b; f := a + b; { a:=b, c:=b, d:=b, e:=a+b } { a:=b, c:=b, d:=a+b, e:=a+b } { a:=b, c:=b, d:=a+b } { a:=b, c:=b } { a:=b } { } { a:=b, c:=b, d:=b, e:=a+b, f:=a+b }
53
Available expressions problem For a program P, define a dataflow problem as DataflowProblem = ( D, V, , F, I ) AvailExprs(P) = { x := R P | R is not Call foo(…)} AvailableExpressions = ( forward, 2 AvailExprs(P), , {F AE [c] | c P}, {} ) 53
54
Available expressions transformer AE out = F AE [C]( AE in ) 54 Command Type AE out skip AE in x := R ( AE in \ {ae | x appears in ae}) { x := R | x R } Goto l’ AE in IfZ x Goto l’ AE in IfNZ x Goto l’ AE in Call f( x 1,…, x n ) AE in Ret x AE in Avoid adding expressions like x:=x, x:=x+1
55
Optimizing via available expressions Common sub-expression elimination – If {… t := y op z … } x := y op z – Can transform statement into x := t Copy propagation – If {… y := t … } x := y op z – Can transform statement into x := t op z Note: same for x=y 55
56
56 Constant propagation
57
Constant folding is an optimization that replaces each variable that is known to be a constant value with that constant Statically evaluate expressions and replace with result – Right-hand side of assignments – Conditions 57
58
Constant propagation analysis In order to do a constant propagation, we need to track what values might be assigned to a variable at each program point Every variable will either – Never have a value assigned to it, – Have a single constant value assigned to it, – Have two or more constant values assigned to it, or – Have a known non-constant value – Our analysis will propagate this information throughout a CFG to identify locations where a value is constant 58
59
Properties of constant propagation For now, consider just some single variable x At each point in the program, we know one of three things about the value of x: – We have never seen a value for x – x is definitely a constant and has value k – x is not a constant, since it's been assigned two values or assigned a value that we know isn't a constant Note that the first and last of these are not the same! – The last one means that there may be a way for x to have multiple values – The first one means that x never had a value at all 59
60
Defining a join operator The join of any two different constants is Not-a-Constant – (If the variable might have two different values on entry to a statement, it cannot be a constant) The join of Not a Constant and any other value is Not-a-Constant – (If on some path the value is known not to be a constant, then on entry to a statement its value can't possibly be a constant) The join of Undefined and any other value is that other value – (If x has no value on some path and does have a value on some other path, we can just pretend it always had the assigned value) 60
61
A semilattice for constant propagation One possible semilattice for this analysis is shown here (for each variable): 61 Undefined 0-212... Not-a-constant The lattice is infinitely wide
62
A semilattice for constant propagation One possible semilattice for this analysis is shown here (for each variable): 62 Undefined 0-212... Not-a-constant Note: The join of any two different constants is Not-a-Constant The join of Not a Constant and any other value is Not-a-Constant The join of Undefined and any other value is that other value
63
A semilattice for constant propagation One possible semilattice for this analysis is shown here (for each variable): 63 0-212... Note: The join of any two different constants is The join of and any other value is The join of and any other value is that other value
64
Constant propagation problem For a program P, define a dataflow problem as DataflowProblem = (D, V, , F, I) ConstExprs(P) = Vars(P) (Z { , }) ConstantPropagation = (forward, ConstExprs(P), CP, {F CP [c] | c P}, x. ) 64
65
What is the join operator? For a program P, define a dataflow problem as DataflowProblem = (D, V, , F, I) ConstExprs(P) = Vars(P) (Z { , }) ConstantPropagation = (forward, ConstExprs(P), CP, {F CP [c] | c P}, x. ) 65 [x 1, y 2, z , w 5] CP [x 1, y 3, z 4, w ] = ?
66
Constant propagation transformer CP out = F CP [c]( CP in ) 66 Command Type AE out skip CP in x := R if R=n then CP in [x n] else CP in [x ] Goto l’ CP in IfZ x Goto l’ CP in IfNZ x Goto l’ CP in Call f( x 1,…, x n ) CP in Ret x CP in
67
A more precise transformer CP out = F CP *[c]( CP in ) 67 Command Type AE out skip CP in x := R CP in [x eval(R, CP in )] Goto l’ CP in IfZ x Goto l’ CP in IfNZ x Goto l’ CP in Call f( x 1,…, x n ) CP in Ret x CP in Conservatively evaluate expression under known values
68
eval(R, CP in ) eval(a+b, CP in ) = n+k if CP in (a)=n and CP in (b)=k … 68
69
69 Running global constant propagation example
70
Input CFG 70 exit x := 4; z := x; w := x; y := x;z := y; x := 6; entry
71
Setting initial values 71 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= y := x; x=y=z=w= z := y; x=y=z=w= x := 6; x=y=z=w= entry x=y=z=w=
72
Iteration 1 72 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= y := x; x=y=z=w= z := y; x=y=z=w= x := 6; x=y=z=w= entry x=y=z=w=
73
Iteration 1 73 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= y := x; x=y=z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=y=z=w= entry x=y=z=w=
74
Iteration 1 74 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= y := x; x=y=z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
75
Iteration 2 75 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= y := x; x=y=z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
76
Iteration 2 76 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
77
Iteration 2 77 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=6 z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
78
Iteration 3 78 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=6 z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
79
Iteration 3 79 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
80
Iteration 3 80 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
81
Iteration 4 81 exit x := 4; x=y=z=w= z := x; x=y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w= y=6 y= gives what?
82
Iteration 4 82 exit x := 4; x=y=z=w= z := x; x=y=z=w= x=6 y=z=w= w := x; x=y=z=w= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
83
Iteration 4 83 exit x := 4; x=y=z=w= z := x; x=y=z=w= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
84
Iteration 5 84 exit x := 4; x=y=z=w= z := x; x=y=z=w= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w= x=6 x= gives what? Y= y= gives what?
85
Iteration 5 85 exit x := 4; x=y=z=w= x=w=6 y=z= z := x; x=y=z=w= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
86
Iteration 5 86 exit x := 4; x=y=z=w= x=w=6 y=z= z := x; x=w=z=6 y= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
87
Iteration 6 87 exit x=w=z=6 y= x := 4; x=y=z=w= x=w=6 y=z= z := x; x=w=z=6 y= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
88
Iteration 6 88 exit x=w=z=6 y= x := 4; x=4 w=z=6 y= x=w=6 y=z= z := x; x=w=z=6 y= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
89
Iteration 7 89 exit x=w=z=6 y= x := 4; x=4 w=z=6 y= x=w=6 y=z= z := x; x=w=z=6 y= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
90
Iteration 7 90 exit x=w=z=6 y= x := 4; x=4 w=z=6 y= w=6 x=y=z= z := x; x=w=z=6 y= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
91
Iteration 7 91 exit x=w=z=6 y= x := 4; x=4 w=z=6 y= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
92
Iteration 8 92 exit x=w=z=6 y= x := 4; x=4 w=z=6 y= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
93
Iteration 8 93 exit w=6 x=y=z= x := 4; x=4 w=z=6 y= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
94
Iteration 8 94 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
95
Iteration 9 – no change 95 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
96
Iteration 10 – no change 96 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
97
Iteration 11 – no change 97 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
98
Iteration 12 – no change 98 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
99
Iteration 13 – no change 99 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
100
Iteration 14 – no change 100 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
101
Analysis fixed point 101 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
102
Transformation opportunities 102 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := x; x=w=6 y=z= x=6 y=z=w= y := x; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
103
Transformed CFG 103 exit w=6 x=y=z= x := 4; x=4 w=6 y=z= w=6 x=y=z= z := x; w=6 x=y=z= x=6 y=z=w= w := 6; x=w=6 y=z= x=6 y=z=w= y := 6; x=y=6 z=w= x=6 y=z=w= z := y; x=6 y=z=w= x=y=z=w= x := 6; x=6 y=z=w= entry x=y=z=w=
104
Next lecture: Loop Optimizations
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.