GATE CS 2024 Set 1 — Question 39
MCQ+2 / -0.67MediumBasic Blocks & Flow GraphsCode OptimizationCompiler Design
Compiler Design → Code Optimization → Basic Blocks & Flow Graphs
Last updated
Question
Consider the following pseudo-code.Which one of the following options CORRECTLY specifies the number of basic blocks and the number of instructions in the largest basic block, respectively ?
L1: t1 = -1
L2: t2 = 0
L3: t3 = 0
L4: t4 = 4 * t3
L5: t5 = 4 * t2
L6: t6 = t5 * M
L7: t7 = t4 + t6
L8: t8 = a[t7]
L9: if t8 <= max goto L11
L10: t1 = t8
L11: t3 = t3 + 1
L12: if t3 < M goto L4
L13: t2 = t2 + 1
L14: if t2 < N goto L3
L15: max = t1
A.
6 and 6
B.
6 and 7
C.
7 and 7
D.
7 and 6
Correct answer
(D) 7 and 6
Solution
To find the number of basic blocks, we first identify the leaders in the code:
The largest basic block is Block 3, which contains 6 instructions.
Therefore, the correct option is (D).
1.The first instruction is a leader: L1.
2.Any instruction that is the target of a conditional or unconditional jump is a leader: L3 (target of L14), L4 (target of L12), and L11 (target of L9).
3.Any instruction that immediately follows a conditional or unconditional jump is a leader: L10 (follows L9), L13 (follows L12), and L15 (follows L14).
The set of leaders is .Now, we form the basic blocks starting from each leader until the next leader or the end of the program:- Block 1: (2 instructions)
- Block 2: (1 instruction)
- Block 3: (6 instructions)
- Block 4: (1 instruction)
- Block 5: (2 instructions)
- Block 6: (2 instructions)
- Block 7: (1 instruction)
The largest basic block is Block 3, which contains 6 instructions.
Therefore, the correct option is (D).
More questions on Code Optimization
2024 Set 2 Q21Consider the following two sets: | Set X | Set Y | | :--- | :--- | | P. Lexical Analyzer | 1.…2024 Set 1 Q26Which of the following is/are Bottom-Up Parser(s)?2024 Set 2 Q29Which of the following statements is/are FALSE?2024 Set 1 Q37Consider the following syntax-directed definition (SDD). | Production | Semantic Rules | | ------ |…2024 Set 1 Q38Consider the following grammar , with as the start symbol. The grammar has three…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free