GATE Computer ScienceHardGATE CS (PYQ pattern)

A web of a variable is a maximal union of def-use chains that share a definition or a use; a register allocator gives each web its own live range. How many webs does x have in 1: x = a; 2: if p > 0 goto L1; 3: x = b; 4: L1: y = x + 1; 5: x = y * 2; 6: if q > 0 goto L2; 7: x = 0; 8: L2: z = x + y; 9: x = z; 10: return x?

  1. A. 3
  2. B. 5
  3. C. 2
  4. D. 4

Correct answer: A. 3

x is defined at 1, 3, 5, 7, 9 and used at 4, 8, 10. The use at 4 is reached by 1 and 3, so {1, 3, 4} is one web; the use at 8 is reached by 5 and 7: {5, 7, 8}; the use at 10 only by 9: {9, 10}. Five definitions but only three webs.

More Compiler Design questions

Exams that ask this topic