# Live Variable Analysis

```Live Variable Analysis
Determines for each “point” in a program
what (variable’s) values are live at that
point.
 Program “points” are defined before and
after each statement of a basic block.
 A value is “live” iff

 It
has been written (defined)
 It might be read (used) on some path later in
the control flow graph
Statement Dataflow

Consider a statement, S,
 dest
= src1 operator src2,
OR
 dest = operator(src1, src2, … srcN)

Keep two sets for each statement
 Written
(defined)
Live Variables – Basic Block

For each block, BB, compute
 Written,

Initialize each BB
 Live-in

Repeat until neither live-in, live-out change
 For
each BB
Live-out(BB) U= U Live-in(Successor)
 Live-in(BB) U= Live-out(BB) – written(BB)

Live Analysis – Statements
Lin (s )  (Lout (s )  write (s ))  read (s )

if succ (s )   



Lout (s )  
Lin (s )
otherwise 
s succ ( s )

Whole Algorithm
 Traverse

each statement, S, in function
 For
each basic block, BB, compute BB->live-in and
BB->live-out (See Live Variables – Basic Block)
 For each basic block, BB


Live = BB->live-out
Traverse each statement, S, of BB, in reverse



Live = Live – S->written
S->live = Live