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

Code Generation Questions and Answers

11.

Assertion (A): Dynamic programming can find the least cost tiling of an expression tree.
Reason (R): The optimal cost of a node depends only on the optimal costs of its subtrees.

Answer: C

Both are true and the reason gives the mechanism, and the property is exactly what dynamic programming requires. Optimality no longer follows once the intermediate form is a graph rather than a tree, since a shared node has more than one parent.

Please log in or register to report this question.

Answer: D

Correct answer: computationally hard, so heuristics are used in practice

A tree can be tiled optimally in linear time because each subtree has one parent and can be solved independently. A directed acyclic graph has shared subexpressions with several parents, so the choices interact and the problem becomes NP-hard - which is why the graph is usually split into trees and each tiled separately.

Please log in or register to report this question.

Answer: A

Allocation chooses what to keep in registers and assignment chooses which register. The two are often performed together, though the distinction matters when discussing algorithms. Machine constraints on particular registers make the second decision non trivial.

Please log in or register to report this question.

Answer: B

Assignment matters because instructions may restrict which register a particular operand may use. Register pairs for multiplication and division are the classic constraint. Such constraints are expressed as pre-coloured nodes in the interference graph.

Please log in or register to report this question.

Answer: C

Each colour stands for one physical register, so a graph needing more colours than the machine has registers cannot be coloured as it stands. Removing a node by spilling its value to memory is what makes the remaining graph colourable.

Please log in or register to report this question.

Answer: D

Simultaneous liveness means they cannot share storage. Building the interference graph therefore depends on a liveness analysis over the flow graph. An inaccurate liveness result produces either wrong code or wasted registers.

Please log in or register to report this question.

Answer: A

Spilling removes a node from the graph, which may make the rest colourable. The spilled value is stored and reloaded around its uses, which costs memory traffic but always succeeds. Spilling therefore guarantees that allocation eventually terminates.

Please log in or register to report this question.

Answer: B

A store after the definition and a load before each use replace the register. Allocators choose to spill the value whose uses are fewest or least frequently executed. A value used only outside loops is nearly always the better candidate.

Please log in or register to report this question.

Answer: C

A constant or a simple address computation often costs less to recompute than to load from memory. The allocator marks such values as candidates before it starts spilling. The decision depends on the relative cost of a load on the target machine.

Please log in or register to report this question.

20.

Assertion (A): A constant is usually rematerialised rather than spilled.
Reason (R): Recomputing a constant costs a single instruction while reloading it costs a memory access.

Answer: D

Both are true and the reason gives the mechanism, and the same reasoning extends to simple address computations. Anything whose operands are still available and whose cost is below a load is worth recomputing rather than storing.

Please log in or register to report this question.

Loading…

Other Subjects

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