Data Flow Analysis – Program Analysis and Understanding | CMSC 631, Study notes of Computer Science

Material Type: Notes; Class: PROG ANLYS&UNDERSTANDING; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-yib
koofers-user-yib 🇺🇸

9 documents

1 / 121

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Flow Analysis
CMSC 631 — Program Analysis and
Understanding
Fall 2007
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
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Data Flow Analysis – Program Analysis and Understanding | CMSC 631 and more Study notes Computer Science in PDF only on Docsity!

Data Flow Analysis

CMSC 631 — Program Analysis and

Understanding

Fall 2007

CMSC 631

• Source code parsed to produce AST

• AST transformed to CFG

• Data flow analysis operates on control flow graph

(and other intermediate representations)

Compiler Structure

Source Code Abstract Syntax Tree Control Flow Graph Object Code

CMSC 631

  • • • • • •

Control-Flow Graph Example

x := a + b y := a * b y > a a := a + 1 x := a + b

CMSC 631

Variations on CFGs

• Usually don’t include declarations (e.g., int x;)

■ But there’s usually something in the implementation

• Useful to have a unique entry and exit node

■ Treat them differently during dataflow analysis

• May group statements into basic blocks

■ A sequence of instructions with no branches into or

out of the block

CMSC 631

  • • • • • • • •

Graph Example with Entry and Exit

x := a + b y := a * b y > a a := a + 1 x := a + b

exit

entry

CMSC 631

CFG vs. AST

• CFGs are much simpler than ASTs

■ Fewer forms, less redundancy, simple expressions

• But...AST is a more faithful representation

■ CFGs introduce temporaries

■ Lose block structure of program

• So for AST,

■ Easier to report error + other messages

■ Easier to explain to programmer

■ Easier to unparse to produce readable code

CMSC 631

Available Expressions

CMSC 631

• Expression^ e^ is^ available^ at program point^ p^ if

■ e is computed on every path to p, and

■ the value of e has not changed since the last time e is

computed on p

• Optimization

■ If an expression is available, need not be recomputed

- (At least, if it’s still in a register somewhere)

Available Expressions

CMSC 631

• What is the effect of each

statement on the set of facts?

Gen and Kill

Stmt Gen Kill x := a + b a + b y := a * b a * b a := a + 1 a + 1, a + b, a * b x := a + b y := a * b y > a a := a + 1 x := a + b

exit

entry

CMSC 631

Computing Available Expressions

x := a + b y := a * b y > a a := a + 1 x := a + b

entry

exit

CMSC 631

Computing Available Expressions

{a + b}

x := a + b y := a * b y > a a := a + 1 x := a + b

entry

exit

CMSC 631

Computing Available Expressions

{a + b}

x := a + b y := a * b y > a a := a + 1 x := a + b

entry

exit

CMSC 631

Computing Available Expressions

{a + b}

{a + b, a * b}

x := a + b y := a * b y > a a := a + 1 x := a + b

entry

exit

CMSC 631

Computing Available Expressions

{a + b}

{a + b, a * b}

{a + b, a * b}

x := a + b y := a * b y > a a := a + 1 x := a + b

entry

exit