CS 201 Compiler Construction - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

CS 201 Compiler Construction

Description:

CS 201 Compiler Construction Data Flow Framework * – PowerPoint PPT presentation

Number of Views:64
Avg rating:3.0/5.0
Slides: 22
Provided by: defau1463
Learn more at: http://www.cs.ucr.edu
Category:

less

Transcript and Presenter's Notes

Title: CS 201 Compiler Construction


1
CS 201Compiler Construction
Data Flow Framework
2
Data Flow Framework
  • The various problems considered have things in
    common
  • Transfer functions
  • Confluence Operator
  • Direction of Propagation
  • These problems can be treated in a unified way ?
    data flow framework is an algebraic structure
    used to encode and solve data flow problems.

3
Monotone Data Flow Framework
  • Components of the framework
  • Information Set L
  • Effect of joining paths ? (meet operator)
  • Effect of basic blocks fn (monotone
    transfer func.)
  • Iterative Solution can be shown to terminate
  • (L,?) is a semilattice st ? a,b,c eL
  • a ? a a (idempotent)
  • a ? b b ? a (commutative)
  • a ? (b ? c) (a ? b) ? c (assocative)
  • Bottom Element st ? a e L, a ?
  • Top Element ? st ? a e L, a ? ? a
  • Top Bottom elements are unique.

4
Contd..
  • Relation is a partial order on L
  • a b ? a ? b a
  • Similarly relation gt can be defined.
  • A semilattice is bounded iff
  • ? a eL there exists a constant ca
  • st length of chain beginning at a is at
  • most ca.

Max ca
5
Monotonic Functions
Effect of each basic block is modeled by a
transfer function f L ? L. Function f must be
monotonic. A total function f L?L is monotonic
iff ? a,b e L f(a?b) f(a) ?
f(b) Distributive function f(a?b) f(a) ?
f(b) For monotonic functions a b gt f(a)
f(b)
6
Contd..
For monotonic functions a b gt f(a)
f(b) Proof f(a?b) f(a) ? f(b) Defn.
of Monotonicity f(a?b)?f(a)?f(b) f(a?b)
Defn. of (a?ba) f(a)?f(a)?f(b) f(a)
Given a b a ? b a f(a) ? f(b) f(a)
f(a)?f(a) f(a) idempotence f(a) f(b)
Defn. of
7
Fixpoint
A fixpoint of a monotonic function f L ? L is a
value a e L such that f(a) a ? gt f (?) gt f ( f
(?) ) gt f ( f ( f (?) ) ) .. There exists t
such that f ( ft (?) ) ft (?) ft (?) is the
greatest fixpoint of f.
8
Monotone Function Space
  • A monotone function space for a semilattice is a
    set F of monotonic functions which
  • Contains the identity function (id)
  • -- basic blocks may not modify information
  • Is closed under function composition
  • -- to model the effects of paths
  • For each a e L, there exists feF st f( )
    a
  • -- to model gen functions
  • A distributive function space is a monotone
    function space in which all functions are
    distributive.

9
A Monotone Data Flow System
  • A monotone data flow system is a tuple
  • lt L, ?, F, G, FM gt
  • (L,?) is a bounded semilattice with ?
  • F is the monotone function space
  • G (N, E, s) is the program flow graph
  • FM N ? F is a total function that associates
    a function from F with each basic block.

10
Meet Over All Paths Solution
Meet over all paths solution (MOP) of a data flow
system MOP N ? L MOP(s) NULL (NULL is the
element in L which represents no information)
F fp is composition of functions from nodes
along path p excluding node n.
n1?n2?n3?.?nk-1?nk ?
fnk o fnk-1 o.o fn2 o fn1
11
MOP Solution
Finding MOP solution is undecidable, i.e. there
does not exist a general algorithm that computes
MOP solution for all monotone data flow
systems. Let X N ? L denote a total function
that associates nodes with lattice elements. X is
conservative or safe iff ?n eN, X(n) MOP(n)
Iterative algorithm computes conservative
approximation of MOP. For distributive data flow
systems, it computes solution that is identical
to MOP solution.
12
Iterative Algorithm
13
Reaching Definitions
14
Contd
15
Dominators
16
Constant Propagation
f (X)(a,2),(b,3),(c,5) f (Y)(a,3),(b,2),(c,5)
f (X) ? f (Y) (a,not-const), (b, not-const),
(c,5) X ? Y (a,not-const),(b,not-const),(c,un
def) f (X? Y) (a,not-const),(b,not-const),(c,n
ot-const) f (X ? Y) f(X) ? f(Y)
17
Sample Problems Data Flow Framework
18
Data Flow Framework
  • For each of the given problems provide the
    following
  • Lattice values
  • Meet operator
  • Top and bottom elements
  • The partial order relation, including its
    pictorial representation
  • The transfer function
  • Data flow equations.

19
  • Reachable uses -- for each definition identify
    the set of uses reachable by the definition. This
    information is used for computing def-use chains.
  • 2. Reaching uses -- given a definition of
    variable x, identify the set of uses of x that
    are encountered prior to reaching the definition
    and there is no other definitions of x that
    intervene the use and the definition. This
    information is used for computing
    antidependences.

20
  • 3. Classify Variable Values -- classify the value
    of each program variable at each program point
    into one of the following categories (a) the
    value is a unique constant -- you must also
    identify this constant value (b) the value is
    one-of-many constants you do not have to
    compute the identities of these constants as part
    of your solution and (c) the value is
    not-a-constant, that is, it is neither a unique
    constant nor a one-of-many constants. This is a
    generalization of constant propagation.

21
  • 4. Postdominators -- postdominator set of a node
    is the set of nodes that are encountered along
    all paths from the node to the end node of the
    control flow graph. This information is used for
    computing control dependence.
Write a Comment
User Comments (0)
About PowerShow.com