+ All Categories
Home > Documents > DFA Theory 2

DFA Theory 2

Date post: 03-Apr-2018
Category:
Upload: dilip-thelip
View: 226 times
Download: 0 times
Share this document with a friend

of 17

Transcript
  • 7/28/2019 DFA Theory 2

    1/17

    Data-ow Analysis: Theoretical Foundations -Part 2

    Y.N. SrikantDepartment of Computer Science

    Indian Institute of ScienceBangalore 560 012

    NPTEL Course on Compiler Design

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/
  • 7/28/2019 DFA Theory 2

    2/17

    Foundations of Data-ow Analysis

    Basic questions to be answered1 Under what situations is the iterative DFA algorithm correct?2 How precise is the solution produced by it?3 Will the algorithm converge?4 What is the meaning of a solution?

    The above questions can be answered accurately by aDFA frameworkFurther, reusable components of the DFA algorithm can beidentied once a framework is denedA DFA framework (D , V , , F ) consists of

    D : A direction of the dataow, either forward or backward

    V : A domain of values : A meet operator (V , ) form a semi-latticeF : A family of transfer functions, V V

    F includes constant transfer functions for theENTRY/EXIT nodes as well

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/
  • 7/28/2019 DFA Theory 2

    3/17

    Properties of the Iterative DFA Algorithm

    If the iterative algorithm converges, the result is a solution

    to the DF equationsProof : If the equations are not satised by the time theloop ends, atleast one of the OUT sets changes and weiterate again

    If the framework is monotone, then the solution found is themaximum xpoint (MFP) of the DF equationsAn MFP solution is such that in any other solution, valuesof IN [B ] and OUT [B ] are the corresponding values ofthe MFP (i.e., less precise)

    Proof : We can show by induction that the values of IN [B ]and OUT [B ] only decrease (in the sense of relation) asthe algorithm iterates

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/
  • 7/28/2019 DFA Theory 2

    4/17

    Properties of the Iterative DFA Algorithm (2)

    If the semi-lattice of the framework is monotone and is ofnite height, then the algorithm is guaranteed to converge

    Proof : Dataow values decrease with each iterationMax no. of iterations = height of the lattice no. of nodesin the ow graph

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/
  • 7/28/2019 DFA Theory 2

    5/17

    Meaning of the Ideal Data-ow Solution

    Find all possible execution paths from the start node to thebeginning of B

    (Assuming forward ow) Compute the data-ow value atthe end of each path (using composition of transferfunctions) and apply the operator to these values to ndtheir glb No execution of the program can produce a smaller valuefor that program point

    IDEAL[B ] =P , a possible execution path from start node to B

    f P (v init )

    Answers greater (in the sense of ) than IDEAL areincorrect (one or more execution paths have been ignored)Any value smaller than or equal to IDEAL is conservative,i.e., safe (one or more infeasible paths have been included)Closer the value to IDEAL, more preci s e it is

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/http://goback/
  • 7/28/2019 DFA Theory 2

    6/17

    Meaning of the Meet-Over-Paths Data-ow Solution

    Since nding all execution paths is an undecidableproblem, we approximate this set to include all paths in theow graph

    MOP [B ] =P , a path from start node to B

    f P (v init )

    MOP [B ] IDEAL[B ], since we consider a superset of theset of execution paths

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/http://goback/
  • 7/28/2019 DFA Theory 2

    7/17

    Meaning of the Maximum Fixpoint Data-ow Solution

    Finding all paths in a ow graph may still be impossible, if ithas cyclesThe iterative algorithm does not try this

    It visits all basic blocks, not necessarily in execution orderIt applies the operator at each join point in the ow graphThe solution obtained is the Maximum Fixpoint solution(MFP)

    If the framework is distributive, then the MOP and MFPsolutions will be identical

    Otherwise, with just monotonicity, MFP MOP IDEAL,and the solution provided by the iterative algorithm is safe

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/
  • 7/28/2019 DFA Theory 2

    8/17

    Example to show MFP MOP

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/http://goback/
  • 7/28/2019 DFA Theory 2

    9/17

    Example to show MFP MOP (2)

    There are two paths from Start to B4:Start B 1 B 3 B 4 and Start B 2 B 3 B 4MOP [B 4] = (( f B 3 f B 1 ) (f B 3 f B 2 ))( v init )In the iterative algorithm, if we chose to visit the nodes inthe order (Start , B 1 , B 2 , B 3 , B 4), thenIN [B 4] = f B 3 (f B 1(v init ) f B 2(v init ))Note that the operator is being applied differently herethan in the MOP equationThe two values above will be equal only if the framework isdistributiveWith just monotonicity, we would have IN [B 4] MOP [B 4]

    Y.N. Srikant Theoretical Foundations of DFA

    k l

    http://find/
  • 7/28/2019 DFA Theory 2

    10/17

    Constant Propagation Framework - Data-ow Values

    The lattice for a single variable in the CP framework isshown in the next slideAn example of product of two lattices is in the next slideDF values in the RD framework can also be considered as

    values in a product of lattices of denitionsone lattice for each denition, with as and {d} as theonly other element

    The lattice of the DF values in the CP frameworkProduct of the semi-lattices of the variables (one lattice foreach variable)

    Y.N. Srikant Theoretical Foundations of DFA

    P d f T L i d L i f C

    http://find/
  • 7/28/2019 DFA Theory 2

    11/17

    Product of Two Lattices and Lattice of Constants

    Y.N. Srikant Theoretical Foundations of DFA

    CP F k Th ( ) O

    http://find/
  • 7/28/2019 DFA Theory 2

    12/17

    CP Framework - The (meet) Operator

    In a product lattice, (a 1 , b 1 ) (a 2 , b 2 ) iff a 1 A a 2 andb 1 B b 2 assuming a 1 , a 2 A and b 1 , b 2 B Each variable is associated with a map m m (v ) is the abstract value (as in the lattice) of the variablev in a map m Each element of the product lattice is a similar, but largermap m

    which is dened for all variables, andwhere m (v ) is the abstract value of the variable v

    Thus, m m (in the product lattice), iff for all variables v ,m (v ) m (v ), OR, m m = m , if m (v ) = m (v ) m (v ),for all variables v

    Y.N. Srikant Theoretical Foundations of DFA

    T f F ti f th CP F k

    http://find/
  • 7/28/2019 DFA Theory 2

    13/17

    Transfer Functions for the CP Framework

    Assume one statement per basic blockTransfer functions for basic blocks containing manystatements may be obtained by compositionm (v ) is the abstract value of the variable v in a map m .

    The set F of the framework contains transfer functionswhich accept maps and produce maps as outputsF contains an identity mapMap for the Start block is m 0(v ) = UNDEF , for allvariables v This is reasonable since all variables are undened beforea program begins

    Y.N. Srikant Theoretical Foundations of DFA

    T f F ti f th CP F k

    http://find/
  • 7/28/2019 DFA Theory 2

    14/17

    Transfer Functions for the CP Framework

    Let f s be the transfer function of the statement s If m = f s (m ), then f s is dened as follows

    1 If s is not an assignment, f s is the identity function2 If s is an assignment to a variable x , then m (v ) = m (v ), for

    all v = x , provided, one of the following conditions holds(a) If the RHS of s is a constant c , then m (x ) = c (b) If the RHS is of the form y + z , then

    m (x ) = m (y ) + m (z ) , if m (y ) and m (z ) are constants = NAC , if either m (y ) or m (z ) is NAC

    =UNDEF , otherwise

    (c) If the RHS is any other expression, then m (x ) = NAC

    Y.N. Srikant Theoretical Foundations of DFA

    Monotonicity of the CP Framework

    http://find/
  • 7/28/2019 DFA Theory 2

    15/17

    Monotonicity of the CP Framework

    It must be noted that the transfer function ( m = f s (m )) alwaysproduces a lower or same level value in the CP lattice,

    whenever there is a change in inputs

    m (y ) m (z ) m (x )

    UNDEF UNDEF

    UNDEF c 2 UNDEF

    NAC NAC

    UNDEF UNDEF

    c 1 c 2 c 1 + c 2

    NAC NAC

    UNDEF NAC

    NAC c 2 NAC

    NAC NAC

    Y.N. Srikant Theoretical Foundations of DFA

    Non distributivity of the CP Framework

    http://find/
  • 7/28/2019 DFA Theory 2

    16/17

    Non-distributivity of the CP Framework

    Y.N. Srikant Theoretical Foundations of DFA

    Non distributivity of the CF Framework Example

    http://find/
  • 7/28/2019 DFA Theory 2

    17/17

    Non-distributivity of the CF Framework - Example

    If f 1 , f 2 , f 3 are transfer functions of B 1 , B 2 , B 3 (resp.), then

    f 3(f 1 (m 0 ) f 2(m 0)) < f 3(f 1(m 0)) f 3(f 2 (m 0 ))as shown in the table, and therefore the CF framework isnon-distributive

    m m (x ) m (y ) m (z )

    m 0 UNDEF UNDEF UNDEFf 1(m 0 ) 2 3 UNDEFf 2(m 0 ) 3 2 UNDEFf 1(m 0 ) f 2(m 0) NAC NAC UNDEFf 3(f 1 (m 0) f 2(m 0)) NAC NAC NACf 3(f 1 (m 0)) 2 3 5f 3(f 2 (m 0)) 3 2 5f 3(f 1 (m 0)) f 3 (f 2(m 0)) NAC NAC 5

    Y.N. Srikant Theoretical Foundations of DFA

    http://find/

Recommended