Data-Flow Analysis - Part 1: Y.N. Srikant
Data-Flow Analysis - Part 1: Y.N. Srikant
Y.N. Srikant
Department of Computer Science Indian Institute of Science Bangalore 560 012
Y.N. Srikant
Data-ow Analysis
Data-ow analysis
These are techniques that derive information about the ow of data along program execution paths An execution path (or path) from point p1 to point pn is a sequence of points p1 , p2 , ..., pn such that for each i = 1, 2, ..., n 1, either
1
pi is the point immediately preceding a statement and pi +1 is the point immediately following that same statement, or pi is the end of some block and pi +1 is the beginning of a successor block
In general, there is an innite number of paths through a program and there is no bound on the length of a path Program analyses summarize all possible program states that can occur at a point in the program with a nite set of facts No analysis is necessarily a perfect representation of the state
Y.N. Srikant Data-ow Analysis
Program debugging
Which are the denitions (of variables) that may reach a program point? These are the reaching denitions
Program optimizations
Constant folding Copy propagation Common sub-expression elimination etc.
Y.N. Srikant
Data-ow Analysis
IN [s] and OUT [s]: data-ow values before and after each statement s The data-ow problem is to nd a solution to a set of constraints on IN [s] and OUT [s], for all statements s
Y.N. Srikant
Data-ow Analysis
We always compute safe estimates of data-ow values A decision or estimate is safe or conservative, if it never leads to a change in what the program computes (after the change) These safe values may be either subsets or supersets of actual values, based on the application
Y.N. Srikant Data-ow Analysis
Sets of denitions constitute the domain of data-ow values We compute supersets of denitions as safe values It is safe to assume that a denition reaches a point, even if it does not. In the following example, we assume that both a=2 and a=4 reach the point after the complete if-then-else statement, even though the statement a=4 is not reached by control ow if (a==b) a=2; else if (a==b) a=4;
Y.N. Srikant
Data-ow Analysis
OUT [B ] = GEN [B ]
IN [B ] = , for all B (initialization only ) If some denitions reach B1 (entry), then IN [B1 ] is initialized to that set Forward ow DFA problem (since OUT [B ] is expressed in terms of IN [B ]), conuence operator is GEN [B ] = set of all denitions inside B that are visible immediately after the block - downwards exposed denitions KILL[B ] = union of the denitions in all the basic blocks of the ow graph, that are killed by individual statements in B
Y.N. Srikant Data-ow Analysis
Y.N. Srikant
Data-ow Analysis
Y.N. Srikant
Data-ow Analysis
Y.N. Srikant
Data-ow Analysis
OUT [P ];
oldout
OUT [B ] = GEN [B ]
if (OUT [B ] = oldout ) change = true; } } GEN , KILL, IN , and OUT are all represented as bit vectors with one bit for each denition in the ow graph
Y.N. Srikant Data-ow Analysis
Y.N. Srikant
Data-ow Analysis