SUBJECT CODE
TYPE THE SUBJECT NAME HERE
UNIT NO 5
CODE OPTIMIZATION
5.5 Global Data Flow Analysis
III VI
20CSPC602
COMPILER DESIGN
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
Data- flow information can be collected by setting up and solving systems of equations of the
form :
out [S] = gen [S] U ( in [S] – kill [S] )
This equation can be read as ― the information at the end of a statement is either generated within the statement ,
or enters at the beginning and is not killed as control flows through the statement.ǁ
The details of how data-flow equations are set and solved depend on three factors.
· The notions of generating and killing depend on the desired information, i.e., on the data flow
analysis problem to be solved. Moreover, for some problems, instead of proceeding along with flow of control
and defining out[s] in terms of in[s], we need to proceed backwards and define in[s] in terms of out[s].
· Since data flows along control paths, data-flow analysis is affected by the constructs in a program. In fact,
when we write out[s] we implicitly assume that there is unique end point where control leaves the statement; in
general, equations are set up at the level of basic blocks rather than statements, because blocks do have unique end
points.
· There are subtleties that go along with such statements as procedure calls, assignments through pointer
variables, and even assignments to array variables.
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
Points and Paths:
Within a basic block, we talk of the point between two adjacent statements, as well as the point before the first
statement and after the last. Thus, block B1 has four points: one before any of the assignments and one after each of the
three assignments.
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
Now let us take a global view and consider all the points in all the blocks. A path from p1 to pn is a
sequence of points p1, p2,….,pn such that for each i between 1 and n-1, either
· Pi is the point immediately preceding a statement and pi+1 is the point immediately
following that statement in the same block, or
· Pi is the end of some block and pi+1 is the beginning of a successor block.
Data-flow analysis of structured programs:
Flow graphs for control flow constructs such as do-while statements have a useful property: there is a single
beginning point at which control enters and a single end point that control leaves from when execution of the statement is over.
We exploit this property when we talk of the definitions reaching the beginning and the end of statements with the following
syntax.
S id: = E| S; S | if E then S else S | do S while E E id + id|
id
Expressions in this language are similar to those in the intermediate code, but the flow graphs for statements have
restricted forms
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
gen[S]=gen[S1]Ugen[S2]
kill[S]=kill[S1]∩kill[S2]
in [S1] = in [S]
in [S2]= in [S] out [S] =
out[S1]
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
gen[S]=gen[S1] kill[S]=kill[S1]
in[S1]=in[S]Ugen[S1]
out[S]=out[S1]
20CSPC602
COMPILER DESIGN
Global Data Flow Analysis
Computation of in and out:
· Many data-flow problems can be solved by synthesized translations similar to those used to
compute gen and kill. It can be used, for example, to determine loop-invariant computations.
The set out[S] is defined similarly for the end of s. it is important to note the distinction between
out[S] and gen[S]. The latter is the set of definitions that reach the end of S without following
paths outside S.
· Assuming we know in[S] we compute out by equation, that is
· Out[S] = gen[S] U (in[S] - kill[S])
· Considering cascade of two statements S1; S2, as in the second case. We start by
observingin[S 1]=in[S]. Then, we recursively compute out[S1], which gives us in[S2], since a
definition reaches the beginning of S2 if and only if it reaches the end of S1. Now we can compute
out[S2], and this set is equal to out[S].
· Considering if-statement we have conservatively assumed that control can follow either
branch, a definition reaches the beginning of S1 or S2 exactly when it reaches the beginning of S.
· In[S1] = in[S2] = in[S]
· If a definition reaches the end of S if and only if it reaches the end of one or both sub
statements; i.e,
· Out[S]=out[S 1] U out[S2]
20CSPC602
COMPILER DESIGN
Video Link
https://youtu.be/NHK3M945WDQ
20CSPC602
COMPILER DESIGN
Thank You