More Datafow Analysis
Monday, November 14, 2011
Recall steps to building analysis
•
Step 1: Choose lattice
•
Step 2: Choose direction oF datafow (Forward or
backward)
•
Step 3: Create monotonic transFer Function
•
Step 4: Choose
confuence
operator (
i.e.
, what to do at
merges)
•
Either join or meet in the lattice
•
Let’s walk through these steps For a new analysis
Monday, November 14, 2011
Liveness analysis
•
Which variables are live at a particular program point?
•
Used all over the place in compilers
•
Register allocation
•
Loop optimizations
Monday, November 14, 2011
Choose lattice
•
What do we want to know?
•
At each program point,
want to maintain the set
oF variables that are live
•
Lattice elements: sets oF
variables
•
Natural choice For lattice:
powerset oF variables!
{ }
{a}
{b}
{c}
{a,b}
{a,c}
{b,c}
{a,b,c}
Monday, November 14, 2011
Choose datafow direction
•
A variable is
live
iF it is used later in the program without
being rede±ned
•
At a given program point, we want to know inFormation
about what happens later in the program
•
This means that liveness is a
backwards
analysis
•
Recall that we did liveness backwards when we
looked at single basic blocks
Monday, November 14, 2011
Create x-Fer Functions
•
What do we do For a statement like:
x = y + z
•
IF x was live “beFore” (i.e., live aFter the statement), it isn’t
now (i.e., is not live beFore the statement)
•
IF y and z were not live “beFore,” they are now
•
What about:
x = x
Monday, November 14, 2011