Data Flow Analysis Applications II
Definition:
- Live variables analysis tells whether the value of variable v at program point p could be used along some path in CFG starting at p. If so, v is live at p; otherwise, v is dead at p.
One application:
- Information of live variables can be used for register allocations.
Understanding Live Variables Analysis
graph TD;
1[v = 3]
2[B. ?]
3[p1. ... = v]
4[p2. ... ...]
1-->2
2-->3
2-->4
Considering Back Analysis:
- May analysis
$$
OUT[B] = \cup \space IN[p]
$$
- OUT[B] = {v}, how we can get IN[B]
-
Tip: determine whether the variable v in some register R is live, or should we delete the value 3 of v in R, at the point of IN[B]?
- Yes: IN[B] = {v}
- No: IN[B] = {}
-
- B.? : k=n –> IN[B]={v}
- B.? : k=v –> IN[B]={v}
- B.? : v=2 –> IN[B]={}
- B.? : v=v+1 –> IN[B]={v}
-
Thus
$$
IN[B] = use_B \cup (OUT[B]-def_B)
$$
Method:
- IN[exit] = empty set
- for each basic block B\exit
- while changes to any IN occur
- for each basic block B\exit
- End for
- End while
May analysis: initialize to empty ; Must analysis: initialize to full