0% found this document useful (0 votes)
2 views18 pages

Unit 5 Part 3

Data Flow Analysis is a set of techniques used to derive information about the flow of data along program execution paths, which helps in optimizing code by eliminating dead code and implementing constant folding. The analysis involves understanding the transformations of program states and identifying reaching definitions, live variables, and available expressions. Key concepts include transfer functions, control flow constraints, and the ability to determine the availability of expressions at specific program points.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Unit 5 Part 3

Data Flow Analysis is a set of techniques used to derive information about the flow of data along program execution paths, which helps in optimizing code by eliminating dead code and implementing constant folding. The analysis involves understanding the transformations of program states and identifying reaching definitions, live variables, and available expressions. Key concepts include transfer functions, control flow constraints, and the ability to determine the availability of expressions at specific program points.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

CS 3501 COMPILER DESIGN

What is Data Flow Analysis?

● set of techniques that derive information about the flow of data along program
execution paths.
● one way to implement global common subexpression elimination requires us
to determine whether two textually identical expressions evaluate to the same
value along any possible execution path of the program.
● If the result of an assignment is not used along any subsequent execution
path, then we can eliminate the assignment as dead code
Data Flow Abstraction
● the execution of a program can be viewed as a series of transformations of
the program state, which consists of the values of all the variables in the
program, including those associated with stack frames below the top of the
run-time stack. Each execution of an intermediate-code statement transforms
an input state to a new output state.

a= 5
I/P State
a=a*5
O/P State

● The input state is associated with the program point before the statement and
the output state is associated with the program point after the statement.
Find Path From Flow Graphs
Path Example

● To aid program debugging, we aim to identify all potential


values of a variable at a given program point and pinpoint
their possible sources. For example, at point (5), we may
state that variable "a" can be in {1, 243}, with potential
definitions from {d1, d3}. These influencing definitions
are known as reaching definitions.

● Suppose we want to implement constant folding. If a


variable x is influenced by only one definition at a given
program point, and that definition assigns a constant to
x, we can replace x with that constant.

● However, if multiple definitions of x may reach the same


program point, constant folding is not feasible for x.
Therefore, for constant folding, we aim to identify unique
definitions of a variable that reach a specific program
point, regardless of the execution path taken.
Data Flow Analysis Schema
The data-flow problem is to find a solution to a set of constraints on the IN[s] and
OUT[s], for all statements s.
IN[s] - Data flow value before statement s
OUT[s] - Data flow value after statement s
Constraint - Transfer Function , Control Function
1. Transfer Function

a=5 a = a*5

b=a
Data Flow Analysis Schema
Constraint - Transfer Function , Control Function

2. Control Flow Constraints


Data Flow Schema on Basics Blocks

Forward flow problem Backward flow problem


Reaching Definitions
● By knowing where in a program each variable x may have been defined when
control reaches each point p, we can determine many things about x.
● We say a definition d reaches a point p if there is a path from the point
immediately following d to p, such that d is not killed" along that path. We kill a
definition of a variable x if there is any other definition of x anywhere along the
path.

a=5 a=5
b = a+10 b = a+10
c = c*a a=a+1
c = c*a
Live Variable Analysis

● In live-variable analysis we wish to know for variable x and point p whether


the value of x at p could be used along some path in the graph starting at p. If
so, we say x is live at p; otherwise, x is dead at p.
● Use=>register allocation for basic blocks.
Available Expressions
● An expression x + y is available at a point p if every path from the entry node to p evaluates x +
y, and after the last such evaluation prior to reaching p, there are no subsequent assignments to
x or y.
● For the available-expressions data-flow schema we say that a block kills expression x + y if it
assigns x or y and does not subsequently recompute x + y.
● A block generates expression x + y if it definitely evaluates x + y and does not subsequently
define x or y
● use of available-expression information is for detecting global common subexpressions

You might also like