50 likes | 196 Views
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)
E N D
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) • Read (used)
Live Variables – Basic Block • For each block, BB, compute • Written, read, readB4written, for BB • Initialize each BB • Live-in = readB4written, Live-out = Ø • 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)
Whole Algorithm • Traverse each statement, S, in function • Compute S->written, S->read • 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 • Live = Live ∨ S->read