WSSE Pune Liveness Analysis: Live Variables Analysis 7/25 Data Flow Equations for Our Example IN 1 = (OUT 1 − Kill 1 ) ∪ Gen 1 w = x 1 OUT 1 = IN 2 IN 2 = (OUT 2 − Kill 2 ) ∪ Gen 2 OUT 2 = IN 3 ∪ IN 4 while (x.data < max) 2 IN 3 = (OUT 3 − Kill 3 ) ∪ Gen 3 OUT 3 = IN 2 x = x.rptr 4 y = x.lptr 3 IN 4 = (OUT 4 − Kill 4 ) ∪ Gen 4 OUT 4 = IN 5 5 z = New class of z IN 5 = (OUT 5 − Kill 5 ) ∪ Gen 5 OUT 5 = IN 6 y = y.lptr 6 IN 6 = (OUT 6 − Kill 6 ) ∪ Gen 6 OUT 6 = IN 7 z.sum = x.data + y.data 7 − Kill 7 ) ∪ Gen 7 7 IN 7 = (OUT OUT 7 = ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 7/25 Data Flow Equations for Our Example IN 1 = (OUT 1 − Kill 1 ) ∪ Gen 1 w = x 1 OUT 1 = IN 2 IN 2 = (OUT 2 − Kill 2 ) ∪ Gen 2 OUT 2 = IN 3 ∪ IN 4 while (x.data < max) 2 IN 3 = (OUT 3 − Kill 3 ) ∪ Gen 3 OUT 3 = IN 2 x = x.rptr 4 y = x.lptr 3 IN 4 = (OUT 4 − Kill 4 ) ∪ Gen 4 OUT 4 = IN 5 5 z = New class of z IN 5 = (OUT 5 − Kill 5 ) ∪ Gen 5 OUT 5 = IN 6 y = y.lptr 6 IN 6 = (OUT 6 − Kill 6 ) ∪ Gen 6 OUT 6 = IN 7 z.sum = x.data + y.data 7 − Kill 7 ) ∪ Gen 7 7 IN 7 = (OUT OUT 7 = ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 7/25 Data Flow Equations for Our Example IN 1 = (OUT 1 − Kill 1 ) ∪ Gen 1 w = x 1 OUT 1 = IN 2 IN 2 = (OUT 2 − Kill 2 ) ∪ Gen 2 OUT 2 = IN 3 ∪ IN 4 while (x.data < max) 2 IN 3 = (OUT 3 − Kill 3 ) ∪ Gen 3 OUT 3 = IN 2 x = x.rptr 4 y = x.lptr 3 IN 4 = (OUT 4 − Kill 4 ) ∪ Gen 4 OUT 4 = IN 5 5 z = New class of z IN 5 = (OUT 5 − Kill 5 ) ∪ Gen 5 OUT 5 = IN 6 y = y.lptr 6 IN 6 = (OUT 6 − Kill 6 ) ∪ Gen 6 OUT 6 = IN 7 z.sum = x.data + y.data 7 − Kill 7 ) ∪ Gen 7 7 IN 7 = (OUT OUT 7 = ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 7/25 Data Flow Equations for Our Example IN 1 = (OUT 1 − Kill 1 ) ∪ Gen 1 w = x 1 OUT 1 = IN 2 IN 2 = (OUT 2 − Kill 2 ) ∪ Gen 2 OUT 2 = IN 3 ∪ IN 4 while (x.data < max) 2 IN 3 = (OUT 3 − Kill 3 ) ∪ Gen 3 OUT 3 = IN 2 x = x.rptr 4 y = x.lptr 3 IN 4 = (OUT 4 − Kill 4 ) ∪ Gen 4 OUT 4 = IN 5 5 z = New class of z IN 5 = (OUT 5 − Kill 5 ) ∪ Gen 5 OUT 5 = IN 6 y = y.lptr 6 IN 6 = (OUT 6 − Kill 6 ) ∪ Gen 6 OUT 6 = IN 7 z.sum = x.data + y.data 7 − Kill 7 ) ∪ Gen 7 7 IN 7 = (OUT OUT 7 = ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 7/25 Data Flow Equations for Our Example IN 1 = (OUT 1 − Kill 1 ) ∪ Gen 1 w = x 1 OUT 1 = IN 2 IN 2 = (OUT 2 − Kill 2 ) ∪ Gen 2 OUT 2 = IN 3 ∪ IN 4 while (x.data < max) 2 IN 3 = (OUT 3 − Kill 3 ) ∪ Gen 3 OUT 3 = IN 2 x = x.rptr 4 y = x.lptr 3 IN 4 = (OUT 4 − Kill 4 ) ∪ Gen 4 OUT 4 = IN 5 5 z = New class of z IN 5 = (OUT 5 − Kill 5 ) ∪ Gen 5 Cyclic Dependence OUT 5 = IN 6 y = y.lptr 6 IN 6 = (OUT 6 − Kill 6 ) ∪ Gen 6 OUT 6 = IN 7 z.sum = x.data + y.data 7 − Kill 7 ) ∪ Gen 7 7 IN 7 = (OUT OUT 7 = ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis Gen = { x } , Kill = { w } w = x Gen = { x } , Kill = ∅ while (x.data < max) Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr Gen = ∅ , Kill = { z } z = New class of z Gen = { y } , Kill = { y } y = y.lptr Gen = { x , y , z } , Kill = ∅ z.sum = x.data + y.data Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis Gen = { x } , Kill = { w } w = x Gen = { x } , Kill = ∅ while (x.data < max) Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr Gen = ∅ , Kill = { z } z = New class of z Gen and Kill need not be mutually exclusive Gen = { y } , Kill = { y } y = y.lptr Gen = { x , y , z } , Kill = ∅ z.sum = x.data + y.data Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis Gen = { x } , Kill = { w } w = x Gen = { x } , Kill = ∅ while (x.data < max) Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr Gen = ∅ , Kill = { z } z = New class of z Gen = { y } , Kill = { y } y = y.lptr z is an r-value occurrence and Gen = { x , y , z } , Kill = ∅ not an l-value occurrence z.sum = x.data + y.data Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis Gen = { x } , Kill = { w } w = x Gen = { x } , Kill = ∅ while (x.data < max) Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr Gen = ∅ , Kill = { z } z = New class of z x , y , z are considered to be used based purely on local use Gen = { y } , Kill = { y } even if the value of z is not y = y.lptr used later. A different analy- sis called strongly live variables Gen = { x , y , z } , Kill = ∅ analysis improves on this. z.sum = x.data + y.data Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis ∅ Gen = { x } , Kill = { w } w = x ∅ ∅ Gen = { x } , Kill = ∅ while (x.data < max) ∅ ∅ ∅ Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr ∅ ∅ ∅ Gen = ∅ , Kill = { z } z = New class of z ∅ ∅ Gen = { y } , Kill = { y } y = y.lptr ∅ ∅ Gen = { x , y , z } , Kill = ∅ Initialization z.sum = x.data + y.data ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis Ignoring max be- { x } cause we are doing Gen = { x } , Kill = { w } analysis for pointer w = x { x } variables w, x, y, z { x } Gen = { x } , Kill = ∅ while (x.data < max) { x } { x } { x } Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr ∅ { x , y } { x , y } Gen = ∅ , Kill = { z } Traversal z = New class of z { x , y , z } { x , y , z } Gen = { y } , Kill = { y } y = y.lptr { x , y , z } { x , y , z } Gen = { x , y , z } , Kill = ∅ Iteration #1 z.sum = x.data + y.data ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 8/25 Performing Live Variables Analysis Ignoring max be- { x } { x } cause we are doing Gen = { x } , Kill = { w } analysis for pointer w = x { x } { x } variables w, x, y, z { x } { x } Gen = { x } , Kill = ∅ while (x.data < max) { x } { x } { x } { x } { x } { x } Gen = { x } , Kill = { y } Gen = { x } , Kill = { x } y = x.lptr x = x.rptr { x } ∅ { x , y } { x , y } { x , y } { x , y } Gen = ∅ , Kill = { z } Traversal z = New class of z { x , y , z } { x , y , z } { x , y , z } { x , y , z } Gen = { y } , Kill = { y } y = y.lptr { x , y , z } { x , y , z } { x , y , z } { x , y , z } Gen = { x , y , z } , Kill = ∅ Iteration #2 z.sum = x.data + y.data ∅ ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 9/25 Performing Live Variables Analysis Local data flow properties when basic blocks contain multiple statements Gen = { x } , Kill = { w } w = x Gen = { x } , Kill = ∅ while (x.data < max) Gen = { x } , Kill = { x } Gen = { x } , Kill = { y , z } x = x.rptr y = x.lptr z = New class of z y = y.lptr z.sum = x.data + y.data Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 10/25 Local Data Flow Properties for Live Variables Analysis IN n = Gen n ∪ (OUT n − Kill n ) • Gen n : Use not preceded by definition • Kill n : Definition anywhere in a block Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 10/25 Local Data Flow Properties for Live Variables Analysis IN n = Gen n ∪ (OUT n − Kill n ) • Gen n : Use not preceded by definition Upwards exposed use • Kill n : Definition anywhere in a block Stop the effect from being propagated across a block Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 11/25 Using Data Flow Information of Live Variables Analysis • Used for register allocation If variable x is live in a basic block b , it is a potential candidate for register allocation Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Live Variables Analysis 11/25 Using Data Flow Information of Live Variables Analysis • Used for register allocation If variable x is live in a basic block b , it is a potential candidate for register allocation • Used for dead code elimination If variable x is not live after an assignment x = . . . , then the assignment is redundant and can be deleted as dead code Dec 2017 IIT Bombay
Part 2 Strongly Live Variables Analysis
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 12/25 Strongly Live Variables Analysis • A variable is strongly live if ◮ it is used in a statement other than assignment statement, or (same as simple liveness) ◮ it is used in an assignment statement defining a variable that is strongly live (different from simple liveness) • Killing: An assignment statement, an input statement, or BI (this is same as killing in simple liveness) • Generation: A direct use or a use for defining values that are strongly live (this is different from generation in simple liveness) Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness y = x y = x y = x print ( x ) print ( y ) print ( z ) Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Strong Liveness y = x y = x y = x print ( x ) print ( y ) print ( z ) Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Strong Liveness y = x y = x y = x print ( x ) print ( y ) print ( z ) ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Strong Liveness y = x y = x y = x { x } print ( x ) print ( y ) print ( z ) ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Strong Liveness { x } y = x y = x y = x { x } print ( x ) print ( y ) print ( z ) ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Liveness Liveness { x } { x } y = x y = x y = x { x } { x } print ( x ) print ( y ) print ( z ) ∅ ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Liveness Liveness { x } { x } y = x y = x y = x { x } { x } print ( x ) print ( y ) print ( z ) ∅ ∅ Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Strong Liveness Liveness Liveness { x } { x } y = x y = x y = x { x } { x } print ( x ) print ( y ) print ( z ) ∅ ∅ Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Strong Liveness Liveness Liveness { x } { x } y = x y = x y = x { x } { x } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Strong Liveness Liveness Liveness { x } { x } y = x y = x y = x { x } { x } { y } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Strong Liveness Liveness Liveness { x } { x } { x } y = x y = x y = x { x } { x } { y } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Liveness Liveness Liveness Liveness { x } { x } { x } { x } y = x y = x y = x { x } { x } { y } { y } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Liveness Liveness Liveness Liveness { x } { x } { x } { x } y = x y = x y = x { x } { x } { y } { y } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ Same Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Strong Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } y = x y = x y = x { x } { x } { y } { y } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ Same Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Strong Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } y = x y = x y = x { x } { x } { y } { y } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ ∅ Same Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Strong Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } y = x y = x y = x { x } { x } { y } { y } { z } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ ∅ Same Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Strong Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } { z } y = x y = x y = x { x } { x } { y } { y } { z } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ ∅ Same Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Simple Strong Liveness Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } { z , x } { z } y = x y = x y = x { x } { x } { y } { y } { z } { z } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ ∅ ∅ Same Same Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 13/25 Understanding Strong Liveness Simple Strong Simple Strong Simple Strong Liveness Liveness Liveness Liveness Liveness Liveness { x } { x } { x } { x } { z , x } { z } y = x y = x y = x { x } { x } { y } { y } { z } { z } print ( x ) print ( y ) print ( z ) ∅ ∅ ∅ ∅ ∅ ∅ Same Same Different Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 14/25 Live Variables Analysis: Simple and Strong Liveness • A variable is live at a program point if its current value is likely to be used later Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 14/25 Live Variables Analysis: Simple and Strong Liveness • A variable is live at a program point if its current value is likely to be used later • We want to compute the smallest set of variables that are live Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 14/25 Live Variables Analysis: Simple and Strong Liveness a = 1; b = 2 B1 • A variable is live at a program c = 3; n = 6 point if its current value is likely to be used later if a ≤ n B2 • We want to compute the smallest T set of variables that are live F B3 a = a + 1 if a ≤ 11 B4 T t1 = a + b F a = t1 + c B5 print ”Hello” B6 print ”Hi” Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 14/25 Live Variables Analysis: Simple and Strong Liveness ∅ a = 1; b = 2 B1 • A variable is live at a program c = 3; n = 6 { a , b , c , n } point if its current value is likely { a , b , c , n } to be used later if a ≤ n B2 { a , b , c , n } • We want to compute the smallest T { a , , n } b , c set of variables that are live F B3 a = a + 1 • Simple liveness considers every { a , } b , c { a , , n } b , c if a ≤ 11 B4 use of a variable as useful { } a , b , c T { } a , b , c t1 = a + b F a = t1 + c B5 print ”Hello” ∅ ∅ B6 print ”Hi” ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 14/25 Live Variables Analysis: Simple and Strong Liveness ∅ a = 1; b = 2 B1 • A variable is live at a program c = 3; n = 6 { a , / b , c / / / , n } point if its current value is likely { a , / b , c / / / , n } to be used later if a ≤ n B2 { a , / b , c / / / , n } • We want to compute the smallest T { a , / / / / , n } b , c set of variables that are live F B3 a = a + 1 • Simple liveness considers every { a , } / b , c / / / { a , , n } / b , c / / / if a ≤ 11 B4 use of a variable as useful { / / / / / / / } a , b , c T • Strong liveness checks the liveness { / / // / / / } a , b , c of the result before declaring the t1 = a + b F operands to be live a = t1 + c B5 print ”Hello” ∅ ∅ B6 print ”Hi” ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 14/25 Live Variables Analysis: Simple and Strong Liveness ∅ a = 1; b = 2 B1 • A variable is live at a program c = 3; n = 6 { a , / b , c / / / , n } point if its current value is likely { a , / b , c / / / , n } to be used later if a ≤ n B2 { a , / b , c / / / , n } • We want to compute the smallest T { a , / / / / , n } b , c set of variables that are live F B3 a = a + 1 • Simple liveness considers every { a , } / b , c / / / { a , , n } / b , c / / / if a ≤ 11 B4 use of a variable as useful { / / / / / / / } a , b , c T • Strong liveness checks the liveness { / / // / / / } a , b , c of the result before declaring the t1 = a + b F operands to be live a = t1 + c B5 print ”Hello” ∅ • Strong liveness is more precise ∅ than simple liveness B6 print ”Hi” ∅ Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 15/25 Data Flow Equations for Strongly Live Variables Analysis IN n = f n (OUT n ) BI n is End � OUT = IN s otherwise n s ∈ succ ( n ) where, ( X − { y } ) ∪ ( Opd ( e ) ∩ V ar) n is y = e , e ∈ E xpr , y ∈ X X − { y } n is input ( y ) f n ( X ) = X ∪ { y } n is use ( y ) X otherwise Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Strongly Live Variables Analysis 15/25 Data Flow Equations for Strongly Live Variables Analysis IN n = f n (OUT n ) BI n is End � OUT = IN s otherwise n s ∈ succ ( n ) where, ( X − { y } ) ∪ ( Opd ( e ) ∩ V ar) n is y = e , e ∈ E xpr , y ∈ X X − { y } n is input ( y ) f n ( X ) = X ∪ { y } n is use ( y ) X otherwise If y is not strongly live, the assignment is skipped using the “otherwise” clause Dec 2017 IIT Bombay
Part 3 Some Observations
WSSE Pune Liveness Analysis: Some Observations 16/25 What Does Data Flow Analysis Involve? • Defining the analysis. • Formulating the analysis. • Performing the analysis. Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 16/25 What Does Data Flow Analysis Involve? • Defining the analysis. Define the properties of execution paths • Formulating the analysis. • Performing the analysis. Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 16/25 What Does Data Flow Analysis Involve? • Defining the analysis. Define the properties of execution paths • Formulating the analysis. Define data flow equations ◮ Linear simultaneous equations on sets rather than numbers ◮ Later we will generalize the domain of values • Performing the analysis. Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 16/25 What Does Data Flow Analysis Involve? • Defining the analysis. Define the properties of execution paths • Formulating the analysis. Define data flow equations ◮ Linear simultaneous equations on sets rather than numbers ◮ Later we will generalize the domain of values • Performing the analysis. Solve data flow equations for the given program flow graph Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 16/25 What Does Data Flow Analysis Involve? • Defining the analysis. Define the properties of execution paths • Formulating the analysis. Define data flow equations ◮ Linear simultaneous equations on sets rather than numbers ◮ Later we will generalize the domain of values • Performing the analysis. Solve data flow equations for the given program flow graph • Many unanswered questions Initial value? Termination? Complexity? Properties of Solutions? Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 17/25 Iterative Solution of Linear Simultaneous Equations • Simultaneous equations represented in the form of the product of a matrix of coefficients ( A ) with the vector of unknowns ( x ) Ax = b • Start with approximate values • Compute new values repeatedly from old values • Two classical methods ◮ Gauss-Seidel Method (Gauss: 1823, 1826), (Seidel: 1874) ◮ Jacobi Method (Jacobi: 1845) Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 18/25 Our Method of Performing Data Flow Analysis • Round robin iteration • Essentially Jacobi method • Unknowns are the data flow variables IN i and OUT i • Domain of values is not numbers • Computation in a fixed order ◮ either forward (reverse post order) traversal, or ◮ backward (post order) traversal over the control flow graph Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information • Spurious inclusion of a non-live variable x = y + 10 i OUT i = { x , y } print y j print y End Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information • Spurious inclusion of a non-live variable x = y + 10 i ◮ A dead assignment may not be eliminated ◮ Solution is sound but may be imprecise OUT i = { x , y } print y j print y End Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information • Spurious inclusion of a non-live variable x = y + 10 i ◮ A dead assignment may not be eliminated ◮ Solution is sound but may be imprecise OUT i = { x , y } print y j • Spurious exclusion of a live variable print y End x = z + 10 i OUT i = { y } print x , y j print y End Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information • Spurious inclusion of a non-live variable x = y + 10 i ◮ A dead assignment may not be eliminated ◮ Solution is sound but may be imprecise OUT i = { x , y } print y j • Spurious exclusion of a live variable ◮ A useful assignment may be eliminated print y End ◮ Solution is unsound x = z + 10 i OUT i = { y } print x , y j print y End Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information • Spurious inclusion of a non-live variable x = y + 10 i ◮ A dead assignment may not be eliminated ◮ Solution is sound but may be imprecise OUT i = { x , y } print y j • Spurious exclusion of a live variable ◮ A useful assignment may be eliminated print y End ◮ Solution is unsound • Given L 2 ⊇ L 1 representing liveness information x = z + 10 ◮ Using L 2 in place of L 1 is sound i ◮ Using L 1 in place of L 2 may not be sound OUT i = { y } print x , y j print y End Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 19/25 Soundness and Precision of Live Variables Analysis Consider dead code elimination based on liveness information • Spurious inclusion of a non-live variable x = y + 10 i ◮ A dead assignment may not be eliminated ◮ Solution is sound but may be imprecise OUT i = { x , y } print y j • Spurious exclusion of a live variable ◮ A useful assignment may be eliminated print y End ◮ Solution is unsound • Given L 2 ⊇ L 1 representing liveness information x = z + 10 ◮ Using L 2 in place of L 1 is sound i ◮ Using L 1 in place of L 2 may not be sound OUT i = { y } print x , y j • The smallest set of all live variables is most precise ◮ Since liveness sets grow (confluence is ∪ ), we print y End choose ∅ as the initial conservative value Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 20/25 Termination, Convergence, and Complexity • For live variables analysis, ◮ The set of all variables is finite, and ◮ the confluence operation (i.e. meet) is union, hence ◮ the set associated with a data flow variable can only grow ⇒ Termination is guaranteed Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 20/25 Termination, Convergence, and Complexity • For live variables analysis, ◮ The set of all variables is finite, and ◮ the confluence operation (i.e. meet) is union, hence ◮ the set associated with a data flow variable can only grow ⇒ Termination is guaranteed • Since initial value is ∅ , live variables analysis converges on the smallest set Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 20/25 Termination, Convergence, and Complexity • For live variables analysis, ◮ The set of all variables is finite, and ◮ the confluence operation (i.e. meet) is union, hence ◮ the set associated with a data flow variable can only grow ⇒ Termination is guaranteed • Since initial value is ∅ , live variables analysis converges on the smallest set • How many iterations do we need for reaching the convergence? Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 20/25 Termination, Convergence, and Complexity • For live variables analysis, ◮ The set of all variables is finite, and ◮ the confluence operation (i.e. meet) is union, hence ◮ the set associated with a data flow variable can only grow ⇒ Termination is guaranteed • Since initial value is ∅ , live variables analysis converges on the smallest set • How many iterations do we need for reaching the convergence? • Going beyond live variables analysis ◮ Do the sets always grow for other data flow frameworks? ◮ What is the complexity of round robin analysis for other analyses? Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 21/25 Conservative Nature of Analysis (1) x=abs(x) b1 if (x < 0) b2 T F x=a+y x=a+z b3 b4 x=a+z b5 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 21/25 Conservative Nature of Analysis (1) • abs(n) returns the absolute value of n x=abs(x) b1 if (x < 0) b2 T F x=a+y x=a+z b3 b4 x=a+z b5 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 21/25 Conservative Nature of Analysis (1) • abs(n) returns the absolute value of n • Is y live on entry to block b2? x=abs(x) b1 if (x < 0) b2 T F x=a+y x=a+z b3 b4 x=a+z b5 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 21/25 Conservative Nature of Analysis (1) • abs(n) returns the absolute value of n • Is y live on entry to block b2? x=abs(x) b1 • By execution semantics, NO Path b1 → b2 → b3 is an infeasible if (x < 0) b2 execution path T F x=a+y x=a+z b3 b4 x=a+z b5 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 21/25 Conservative Nature of Analysis (1) • abs(n) returns the absolute value of n • Is y live on entry to block b2? x=abs(x) b1 • By execution semantics, NO Path b1 → b2 → b3 is an infeasible if (x < 0) b2 execution path T F • A compiler makes conservative assumptions: x=a+y x=a+z b3 b4 All branch outcomes are possible ⇒ Consider every path in CFG as a po- x=a+z b5 tential execution path Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 21/25 Conservative Nature of Analysis (1) • abs(n) returns the absolute value of n • Is y live on entry to block b2? x=abs(x) b1 • By execution semantics, NO Path b1 → b2 → b3 is an infeasible if (x < 0) b2 execution path T F • A compiler makes conservative assumptions: x=a+y x=a+z b3 b4 All branch outcomes are possible ⇒ Consider every path in CFG as a po- x=a+z b5 tential execution path • Our analysis concludes that y is live on entry to block b2 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 22/25 Conservative Nature of Analysis (2) if (x < 0) b1 T F a=a+y x=a+z b2 b3 if (x < 0) b4 F T b5 x=c+1 x=b+1 b6 if (x < 0) b7 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 22/25 Conservative Nature of Analysis (2) • Is b live on entry to block b2? if (x < 0) b1 T F a=a+y x=a+z b2 b3 if (x < 0) b4 F T b5 x=c+1 x=b+1 b6 if (x < 0) b7 Dec 2017 IIT Bombay
WSSE Pune Liveness Analysis: Some Observations 22/25 Conservative Nature of Analysis (2) • Is b live on entry to block b2? • By execution semantics, NO Path b1 → b2 → b4 → b6 is an infeasible if (x < 0) b1 execution path T F a=a+y x=a+z b2 b3 if (x < 0) b4 F T b5 x=c+1 x=b+1 b6 if (x < 0) b7 Dec 2017 IIT Bombay
Recommend
More recommend