Data-Flow Analysis: Proving Theorems and Reaching Definitions, Slides of Compilers

An introduction to data-flow analysis, focusing on proving theorems, reaching definitions, and major examples. It covers concepts such as data-flow equations, major examples, and the importance of being conservative in optimization. The document also introduces the concepts of available expressions and live variable analysis.

Typology: Slides

2012/2013

Uploaded on 04/29/2013

aalok
aalok 🇮🇳

4.4

(15)

97 documents

1 / 40

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data-Flow Analysis
Proving Little Theorems
Data-Flow Equations
Major Examples
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download Data-Flow Analysis: Proving Theorems and Reaching Definitions and more Slides Compilers in PDF only on Docsity!

Data-Flow Analysis

Proving Little Theorems Data-Flow Equations Major Examples

An Obvious Theorem

boolean x = true;

while (x) {

... // no change to x

}

  • Doesn’t terminate.
  • Proof: only assignment to x is at top, so x is always true.

Formulation: Reaching Definitions

  • Each place some variable x is assigned is a definition.
  • Ask: for this use of x, where could x last have been defined.
  • In our example: only at x=true.

Example: Reaching Definitions

5

d1: x = true

if x == true

d2 : a = 10

d (^2)

d (^1)

d (^1) d 2 d (^1)

Not Always That Easy

int i = 2; int j = 3;

while (i != j) {

if (i < j) i += 2; else j += 2;

}

  • We’ll develop techniques for this problem, but later …

The Flow Graph

8

d1: i = 2 d2: j = 3

if i != j

if i < j

d3: i = i+2 d4: j = j+

d 1 , d 2 , d 3 , d (^4)

d (^1) d 3 d (^4)

d (^2)

d 2 , d 3 , d (^4)

d d^1 , d^3 , d^4 d 1 , d 2 , d 3 , d 4 1 , d 2 , d 3 , d (^4)

Be Conservative!

  • (Code optimization only)
  • It’s OK to discover a subset of the opportunities to make some code-improving transformation.
  • It’s not OK to think you have an opportunity that you don’t really have.

Example: Be Conservative

boolean x = true;

while (x) {

... *p = false;...

}

  • Is it possible that p points to x?

Possible Resolution

  • Just as data-flow analysis of “reaching definitions” can tell what definitions of x might reach a point, another DFA can eliminate cases where p definitely does not point to x.
  • Example: the only definition of p is p = &y and there is no possibility that y is an alias of x.

Reaching Definitions Formalized

  • A definition d of a variable x is said to reach a point p in a flow graph if:
  1. Every path from the entry of the flow graph to p has d on the path, and
  2. After the last occurrence of d there is no possibility that x is redefined.

Data-Flow Equations --- (2)

  • Variables:
    1. IN(B) = set of definitions reaching the beginning of block B.
    2. OUT(B) = set of definitions reaching the end of B.

Data-Flow Equations --- (3)

  • Two kinds of equations:
    1. Confluence equations : IN(B) in terms of outs of predecessors of B.
    2. Transfer equations : OUT(B) in terms of of IN(B) and what goes on in block B.

Transfer Equations

  • Generate a definition in the block if its variable is not definitely rewritten later in the basic block.
  • Kill a definition if its variable is definitely rewritten in the block.
  • An internal definition may be both killed and generated.

Example: Gen and Kill

20

d 1 : y = 3 d 2 : x = y+z d 3 : *p = 10 d 4 : y = 5

IN = {d 2 (x), d 3 (y), d 3 (z), d 5 (y), d 6 (y), d 7 (z)}

Kill includes {d 1 (x), d 2 (x), d 3 (y), d 5 (y), d 6 (y),…}

Gen = {d 2 (x), d 3 (x), d 3 (z),…, d 4 (y)}

OUT = {d 2 (x), d 3 (x), d 3 (z),…, d 4 (y), d 7 (z)}