Skip to main content

GATE CSE 2025Compiler Design › Code Optimization & Register AllocationVerified

GATE CSE 2025 PYQ: Refer to the given 3 3 3 -address code sequence. This code sequence is split into basic blocks. The number…

Refer to the given 3-address code sequence. This code sequence is split into basic blocks. The number of basic blocks is ________. (Answer in integer)

  1. 1001: i = 1
  2. 1002: j = 1
  3. 1003: t1 = 10*i
  4. 1004: t2 = t1+j
  5. 1005: t3 = 8*t2
  6. 1006: t4 = t3-88
  7. 1007: a[t4] = 0.0
  8. 1008: j = j+1
  9. 1009: if j <= 10 goto 1003
  10. 1010: i = i+1
  11. 1011: if i <= 10 goto 1002
  12. 1012: i = 1
  13. 1013: t5 = i-1
  14. 1014: t6 = 88*t5
  15. 1015: a[t6] = 1.0
  16. 1016: i = i+1
  17. 1017: if i <= 10 goto 1013

 

    Answer

    6

    Approach

    Use the standard leader-based partitioning rule: identify all leader statements, then group consecutive statements from each leader up to, but not including, the next leader or the end of the code.

    The number of basic blocks equals the number of leader statements. The leaders are 1001, 1002, 1003, 1010, 1012, and 1013, so the total number of basic blocks is 6.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.