Official answer: D) B1: {a, i, j}, B2: {a, j}, B3: {a, j}, B4: {a, i, j}
Data Flow AnalysesA variable v is live at a point p if there exists a directed path from p to a use of v along which v is not redefined (killed).
The data-flow equations for liveness analysis (backward analysis) are:
In[B]=use[B]∪(Out[B]∖def[B]) Out[B]=S∈succ(B)⋃In[S] ### Step 1: Identify use and def sets for each basic block
B1: def[B1]={a,i,j}, use[B1]={m,n}
B2: def[B2]={i,j}, use[B2]={i,j}
B3: def[B3]={a}, use[B3]=∅
B4: def[B4]={i}, use[B4]={a}
### Step 2: Successor relations
succ(B1)={B2}
succ(B2)={B3,B4}
succ(B3)={B4}
succ(B4)={B2,EXIT}
### Step 3: Iterative Computation of In and Out
Iteration 1:
Out[B4]=In[B2]=∅⟹In[B4]={a}∪(∅∖{i})={a}
Out[B3]=In[B4]={a}⟹In[B3]=∅∪({a}∖{a})=∅
Out[B2]=In[B3]∪In[B4]=∅∪{a}={a}⟹In[B2]={i,j}∪({a}∖{i,j})={a,i,j}
Out[B1]=In[B2]={a,i,j}
Iteration 2:
Out[B4]=In[B2]={a,i,j}⟹In[B4]={a}∪({a,i,j}∖{i})={a,j}
Out[B3]=In[B4]={a,j}⟹In[B3]=∅∪({a,j}∖{a})={j}
Out[B2]=In[B3]∪In[B4]={j}∪{a,j}={a,j}⟹In[B2]={i,j}∪({a,j}∖{i,j})={a,i,j}
Out[B1]=In[B2]={a,i,j}
Iteration 3 (Fixed Point Reached):
Out[B4]={a,i,j}⟹In[B4]={a,j}
Out[B3]={a,j}⟹In[B3]={j}
Out[B2]={a,j}⟹In[B2]={a,i,j}
Out[B1]={a,i,j}
Thus, the live variable sets at the exit of each block are:
B1: {a,i,j}
B4: {a,i,j}
This matches (D).