GateAI
Data Flow Analyses

GATE CSE 2023 · Q37

MCQ2 marksMedium

Time

Consider the control flow graph shown. Which one of the following choices correctly lists the set of live\textit{live} variables at the exit point of each basic block?

GATE CSE 2023 Q37 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: D) B1: {a, i, j}, B2: {a, j}, B3: {a, j}, B4: {a, i, j}

Data Flow Analyses

A variable vv is live at a point pp if there exists a directed path from pp to a use of vv along which vv is not redefined (killed).

The data-flow equations for liveness analysis (backward analysis) are:

In[B]=use[B]∪(Out[B]∖def[B])\text{In}[B] = \text{use}[B] \cup (\text{Out}[B] \setminus \text{def}[B])
Out[B]=⋃S∈succ(B)In[S]\text{Out}[B] = \bigcup_{S \in \text{succ}(B)} \text{In}[S]

### Step 1: Identify use\text{use} and def\text{def} sets for each basic block

  • B1: def[B1]={a,i,j}\text{def}[B1] = \{a, i, j\}, use[B1]={m,n}\text{use}[B1] = \{m, n\}

  • B2: def[B2]={i,j}\text{def}[B2] = \{i, j\}, use[B2]={i,j}\text{use}[B2] = \{i, j\}

  • B3: def[B3]={a}\text{def}[B3] = \{a\}, use[B3]=∅\text{use}[B3] = \emptyset

  • B4: def[B4]={i}\text{def}[B4] = \{i\}, use[B4]={a}\text{use}[B4] = \{a\}

### Step 2: Successor relations

  • succ(B1)={B2}\text{succ}(B1) = \{B2\}

  • succ(B2)={B3,B4}\text{succ}(B2) = \{B3, B4\}

  • succ(B3)={B4}\text{succ}(B3) = \{B4\}

  • succ(B4)={B2,EXIT}\text{succ}(B4) = \{B2, \text{EXIT}\}

### Step 3: Iterative Computation of In\text{In} and Out\text{Out}

Iteration 1:

  • Out[B4]=In[B2]=∅  ⟹  In[B4]={a}∪(∅∖{i})={a}\text{Out}[B4] = \text{In}[B2] = \emptyset \implies \text{In}[B4] = \{a\} \cup (\emptyset \setminus \{i\}) = \{a\}

  • Out[B3]=In[B4]={a}  ⟹  In[B3]=∅∪({a}∖{a})=∅\text{Out}[B3] = \text{In}[B4] = \{a\} \implies \text{In}[B3] = \emptyset \cup (\{a\} \setminus \{a\}) = \emptyset

  • Out[B2]=In[B3]∪In[B4]=∅∪{a}={a}  ⟹  In[B2]={i,j}∪({a}∖{i,j})={a,i,j}\text{Out}[B2] = \text{In}[B3] \cup \text{In}[B4] = \emptyset \cup \{a\} = \{a\} \implies \text{In}[B2] = \{i, j\} \cup (\{a\} \setminus \{i, j\}) = \{a, i, j\}

  • Out[B1]=In[B2]={a,i,j}\text{Out}[B1] = \text{In}[B2] = \{a, i, j\}

Iteration 2:

  • Out[B4]=In[B2]={a,i,j}  ⟹  In[B4]={a}∪({a,i,j}∖{i})={a,j}\text{Out}[B4] = \text{In}[B2] = \{a, i, j\} \implies \text{In}[B4] = \{a\} \cup (\{a, i, j\} \setminus \{i\}) = \{a, j\}

  • Out[B3]=In[B4]={a,j}  ⟹  In[B3]=∅∪({a,j}∖{a})={j}\text{Out}[B3] = \text{In}[B4] = \{a, j\} \implies \text{In}[B3] = \emptyset \cup (\{a, j\} \setminus \{a\}) = \{j\}

  • Out[B2]=In[B3]∪In[B4]={j}∪{a,j}={a,j}  ⟹  In[B2]={i,j}∪({a,j}∖{i,j})={a,i,j}\text{Out}[B2] = \text{In}[B3] \cup \text{In}[B4] = \{j\} \cup \{a, j\} = \{a, j\} \implies \text{In}[B2] = \{i, j\} \cup (\{a, j\} \setminus \{i, j\}) = \{a, i, j\}

  • Out[B1]=In[B2]={a,i,j}\text{Out}[B1] = \text{In}[B2] = \{a, i, j\}

Iteration 3 (Fixed Point Reached):

  • Out[B4]={a,i,j}  ⟹  In[B4]={a,j}\text{Out}[B4] = \{a, i, j\} \implies \text{In}[B4] = \{a, j\}

  • Out[B3]={a,j}  ⟹  In[B3]={j}\text{Out}[B3] = \{a, j\} \implies \text{In}[B3] = \{j\}

  • Out[B2]={a,j}  ⟹  In[B2]={a,i,j}\text{Out}[B2] = \{a, j\} \implies \text{In}[B2] = \{a, i, j\}

  • Out[B1]={a,i,j}\text{Out}[B1] = \{a, i, j\}

Thus, the live variable sets at the exit of each block are:

  • B1: {a,i,j}\{a, i, j\}

  • B2: {a,j}\{a, j\}

  • B3: {a,j}\{a, j\}

  • B4: {a,i,j}\{a, i, j\}

This matches (D).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Data Flow Analyses previous year question is Q37 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Data Flow Analyses in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Data Flow Analyses PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Data Flow Analyses in GATE CSE

Data Flow Analyses has 8 GATE CSE PYQs across 8 papers from 2014 to 2026. 5 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2023.

How GATE tests Data Flow Analyses

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q37 · MCQ

Consider the control flow graph shown. Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.