Machine-translated by Google. Questions are authored in English.
Top

Code Generation Questions and Answers

Answer: A

The compiler tries to fill the slot with useful work rather than a no operation. Finding a suitable instruction is a small but real scheduling problem. Modern processors have largely removed the need by handling branches in hardware.

Please log in or register to report this question.

Answer: B

A window slides over the instructions and recognised patterns are replaced. It is cheap and catches redundancies that arise from generating each construct independently. Running it after every other pass costs very little and usually finds something.

Please log in or register to report this question.

Answer: C

Selection, allocation and scheduling each work on their own concerns and each leaves behind small local inefficiencies. The window is short enough that the pass costs almost nothing, so running it once more usually finds something worth removing.

Please log in or register to report this question.

Answer: D

The value is already in the register, so the load achieves nothing. Care is needed when a label sits between the two, since control may then arrive without the store having executed. Confining the window to a single basic block avoids the problem entirely.

Please log in or register to report this question.

45.

Assertion (A): A peephole optimiser must not remove a redundant load if a label lies between the store and the load.
Reason (R): Control may reach the load from elsewhere, in which case the store never executed and the register does not hold the value.

Answer: A

Correct answer: Both A and R are true, and R is the correct explanation of A

Both are true and the reason gives the mechanism. A label means control can arrive from somewhere else, on a path where the store never ran, so the register cannot be assumed to hold the value. This is why a peephole optimiser must respect basic block boundaries rather than looking only at adjacent instructions.

Please log in or register to report this question.

Answer: B

The convention fixes where arguments and the return value go and which registers the callee may destroy. Departing from it breaks interoperability with code compiled elsewhere. Library calls in particular depend entirely on the convention being honoured.

Please log in or register to report this question.

Answer: C

The convention divides the register set so that neither side saves more than necessary. A value not live across the call costs nothing in a caller saved register. The split is fixed by the platform and cannot be chosen by the compiler.

Please log in or register to report this question.

Answer: D

Correct answer: are live across many calls within a procedure

A callee saved register survives a call, since whoever uses it must preserve it, so it suits a value needed before and after several calls - saved once on entry and restored once on exit. A value used only between two calls belongs in a caller saved register instead, saved only where it is actually at risk.

Please log in or register to report this question.

Answer: A

Its layout is fixed by the calling convention and the compiler. Locals are addressed as offsets from a frame pointer or from the stack pointer directly. Recursion is exactly why a local cannot be given a fixed address.

Please log in or register to report this question.

Answer: B

Recursion means a local has no fixed address, so the address must be relative to the current activation. Only globals can be given an address fixed when the program is compiled. Each recursive call creates a fresh activation with its own locals.

Please log in or register to report this question.

Loading…
Tags: Code Generation Questions and Answers || Code Generation MCQ Questions and Answers || Code Generation GK Questions and Answers || Code Generation GK MCQ Questions || Code Generation Multiple Choice Questions and Answers || Code Generation GK || GK on Code Generation || Compiler Design Questions and Answers || Compiler Design MCQ Questions and Answers || Compiler Design GK Questions and Answers || GK on Compiler Design