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

Code Generation Questions and Answers

61.

Assertion (A): Register allocators weight uses inside loops more heavily than uses outside them.
Reason (R): An instruction inside a loop executes many times, so keeping its operands in registers saves proportionately more.

Answer: C

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 use inside a loop costs whatever it costs multiplied by the trip count, so the allocator weights it accordingly - commonly by ten per level of nesting. That weighting is what makes the allocator spill the outer values and keep the inner ones.

Please log in or register to report this question.

62.

A use inside a loop nested two deep is weighted by a factor of ten per level. What weight does a single use there receive?

Answer: D

Two levels of nesting give ten times ten, that is one hundred. The heuristic is crude but reflects the fact that inner loop code dominates execution time in most programs. Profile data replaces the heuristic with a measurement when it is available.

Please log in or register to report this question.

Answer: A

Increment and decrement instructions, multiply and accumulate, and address computation instructions are typical examples. Recognising them is part of instruction selection. A machine description lists the idioms the generator should look for.

Please log in or register to report this question.

Answer: B

Correct answer: correct but longer and slower than necessary

Machine idioms - an increment instruction, an add with shift, a multiply-accumulate - do in one instruction what would otherwise take several. Ignoring them costs performance and code size but not correctness, since the longer sequence computes the same result.

Please log in or register to report this question.

Answer: C

Everything that depends on the machine lives in the back end. The front end depends on the source language and should not need to change at all. That separation is precisely what an intermediate representation exists to provide.

Please log in or register to report this question.

Answer: D

Machine description languages let a new target be supported by writing a specification rather than code. The approach trades some code quality for much faster retargeting. A hand written back end still wins where the last few per cent matter.

Please log in or register to report this question.

Answer: A

Correct answer: needs no register allocation, since operands are on a stack

A stack machine takes its operands from the top of the stack implicitly, so there are no registers to allocate and code generation reduces to a postorder walk of the expression tree. That simplicity is why stack code is used for portable intermediate forms - and why it is slower than register code on real hardware.

Please log in or register to report this question.

Answer: B

Each leaf becomes a push and each interior node an operator that consumes the values pushed by its children. The result is exactly reverse Polish order. No register allocation is required, which is what makes the model so simple.

Please log in or register to report this question.

Answer: C

Explicit registers avoid the traffic that a stack discipline forces. Stack code is more compact, which is why it remains attractive for a portable distribution format. Just in time compilers translate such code into register code before running it.

Please log in or register to report this question.

Answer: D

Correct answer: find the storage location and type of each name

The generator needs to know where each name lives - a register, a frame offset, a static address - and what type it has, since the type determines which instructions apply. Both come from the symbol table, which is why it survives long after the parse.

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