Compilers

Which describes instruction selection, one stage of code generation?

  1. ADeciding which of the target CPU's instructions implement each IR operation
  2. BDeciding the order in which the OS picks processes to run
  3. CExtracting instructions written as comments in the source code
Show answer and explanation

Answer: A. Deciding which of the target CPU's instructions implement each IR operation

Instruction selection maps sequences of IR operations to concrete instructions of the target CPU. Available instructions differ by CPU; a * b + c, for example, becomes one instruction if the CPU has a fused multiply-add (FMA) and two (multiply and add) otherwise. Making good use of the CPU's instructions, such as folding address calculations into addressing modes, yields faster code. It has nothing to do with OS scheduling or comments.

  • A. Correct. It maps IR operations to CPU instructions.
  • B. Process order is decided by the OS scheduler.
  • C. Comments are removed during lexical analysis.
Practice this topic Back to topic

More Compilers questions

  1. Which describes a cross compiler?
  2. When debugging a program compiled with optimization, some variables may show as "unavailable." What is the main reason?
  3. After thoroughly applying constant propagation, constant folding and dead-code elimination to the function above, what does it return and what code remains?
  4. What is the role of lexical analysis in a compiler?
  5. What is done during syntax analysis (parsing) in a compiler?