






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







CMSC 631 2
Compiler Structure
Source Code
Abstract Syntax Tree
Control Flow Graph
Object Code
CMSC 631 3
Abstract Syntax Tree (AST)
Abstract Syntax Tree Example
•x := a + b; •y := a * b; •while (y > a) {
Program
While
Block
x a b
y a
a
a (^) + 1
CMSC 631 5
ASTs
CMSC 631 6
Disadvantages of ASTs
CMSC 631 7
Control-Flow Graph (CFG)
CMSC 631 8
•x := a + b; •y := a * b; •while (y > a) {
Control-Flow Graph Example
x := a + b
y := a * b
y > a
a := a + 1
x := a + b
CMSC 631 9
Variations on CFGs
CMSC 631 10
Control-Flow Graph w/Basic Blocks
x := a + b; y := a * b; while (y > a + b) { a := a + 1; x := a + b }
x := a + b y := a * b y > a
a := a + 1 x := a + b
CMSC 631 11
CFG vs. AST
CMSC 631 12
Data Flow Analysis
CMSC 631 19
Liveness Analysis
CMSC 631 20
In(s')
Data Flow Equations
CMSC 631 21
Gen and Kill
Stmt Gen Kill
x := a + b a, b x
y := a * b a, b y
y > a a, y
a := a + 1 a a
x := a + b
y := a * b
y > a
a := a + 1
x := a + b
CMSC 631 22
Computing Live Variables
{x}
{x, y, a}
{x, y, a}
{y, a, b}
{y, a, b}
{x, a, b}
{a, b} x := a + b
y := a * b
y > a
a := a + 1
x := a + b
{x, y, a, b}
{x, y, a, b}
CMSC 631 23
•An expression e is very busy at point p if
•Optimization
•What kind of problem?
Very Busy Expressions
CMSC 631 24
Reaching Definitions
CMSC 631 25
Space of Data Flow Analyses
May Must
Forward (^) definitionsReaching expressionsAvailable
Backward (^) variablesLive expressionsVery busy
CMSC 631 26
Data Flow Facts and Lattices
a+b, a*b, a+
a+b, ab ab, a+ a+b, a+
(none)
a*b a+
a+b
CMSC 631 27
Partial Orders
CMSC 631 28
Meet and Join Operations
CMSC 631 29
Lattices
•A partial order is a lattice if meet and join exist for every pair of elements in P
•A lattice has unique elements and such that
¦ ¦
•In a lattice,
•A partial order is a complete lattice if meet and join are defined on any set S P CMSC 631 30
Useful Lattices
, ) forms a lattice for any set S
CMSC 631 37
Lattices (P, <= ), cont’d
CMSC 631 38
Forward vs. Backward
temp := f s
s' succ(s) In(s'))
CMSC 631 39
Termination Revisited
s' pred(s) Out(s')) ¦ if (temp != Out(s)) { ... }
CMSC 631 40
Termination Revisited (cont’d)
•A descending chain in a lattice is a sequence
•The height of a lattice is the length of the longest descending chain in the lattice
•Then, dataflow must terminate in O(nk) time
CMSC 631 41
Least vs. Greatest Fixpoints
CMSC 631 42
Distributive Data Flow Problems
CMSC 631 43
Benefit of Distributivity
f
h
k
g
CMSC 631 44
Accuracy of Data Flow Analysis
CMSC 631 45
What Problems are Distributive?
CMSC 631 46
A Non-Distributive Example
x := 1 x := 2
y := 2 y := 1
z := x + y
CMSC 631 47
Practical Implementation
CMSC 631 48
Basic Blocks
CMSC 631 55
Elimination Methods: Conditionals
CMSC 631 56
Elimination Methods: Loops
CMSC 631 57
Elimination Methods: Loops (cont’d)
CMSC 631 58
Height of Function Lattice
CMSC 631 59
Non-Reducible Flow Graphs
CMSC 631 60
Comments
CMSC 631 61
Data Flow Analysis and Functions
CMSC 631 62
More Terminology
CMSC 631 63
Data Flow Analysis and The Heap
CMSC 631 64
Data Flow Analysis and Optimization