Some code optimizations are carried out on the intermediate code because
View worked solution
Answer: A
The correct option is A.
A modern compiler is typically structured into three main phases:
- Front-end: Translates the source code into an Intermediate Representation (IR).
- Optimizer: Performs machine-independent optimizations on the IR.
- Back-end (Code Generator): Translates the optimized IR into target machine code.
By performing optimizations on the intermediate code (IR) rather than the target machine code, we decouple the optimization phase from the target architecture. This design has a significant advantage:
- Portability: The same optimizer can be reused across different target processors. To support a new target processor, only the back-end (code generator) needs to be rewritten, while the front-end and the optimizer remain exactly the same.
Let's analyze the other options:
- Option B: Program analysis is not inherently more accurate on IR than on machine code. In fact, machine code contains precise details about registers and memory layouts, though IR is cleaner and easier to analyze.
- Options C and D: Dataflow analysis and front-end information can still be utilized at other stages of compilation (such as directly on the Abstract Syntax Tree or during target code generation). Thus, intermediate code is not a strict prerequisite for using this information.
Free practice · Your answers on this page are not saved.
