Some code optimizations are carried out on the intermediate code because
2008
Some code optimizations are carried out on the intermediate code because
- A.
they enhance the portability of the compiler to other target processors
- B.
program analysis is more accurate on intermediate code than on machine code
- C.
the information from dataflow analysis cannot otherwise be used for optimization
- D.
the information from the front end cannot otherwise be used for optimization
Attempted by 102 students.
Show answer & explanation
Correct answer: A
Answer: they enhance the portability of the compiler to other target processors
Explanation: Optimizing on an intermediate representation (IR) allows optimization passes to be written in a machine-independent way. The same IR-based optimizations can be reused when retargeting the compiler to different processors, which improves portability and reduces duplication of effort.
IR decouples optimizations from target-specific details, so optimizations need not be reimplemented for each backend.
IR can retain high-level information useful for many optimizations while remaining independent of machine instruction sets.
After machine-independent optimizations on the IR, backends can perform target-specific optimizations on generated machine code.
Why the other choices are not correct:
Program analysis is sometimes easier on IR, but saying analysis is always more accurate there is misleading; the main goal is portability.
Dataflow information can be used for optimization at multiple stages; the advantage of IR is convenience and reusability, not exclusivity.
Front-end information can be attached to the IR and used for optimization, so it is not true that front-end information "cannot otherwise be used".
A video solution is available for this question — log in and enroll to watch it.