9.8 Machine-dependent Optimization

The naïve code generator that we have demonstrated several times does generate code which will execute (after assembly and linker steps) but the code quality is rather poor, in the following respect:

  • Program size is big because the generated instruction sequences are quite long.
  • Program execution time is long because there are redundant instructions and/or memory transfers.
  • There is an inadequate use of CPU registers.
  • The code generator does not make good use of the facilities of the machine, in the form of power of the instruction set.

An example: with the E compilation scheme, the statement:

total = total + count * count;

compiles to:

movl total, %eax pushl %eax movl count, %eax pushl %eax movl count, %eax ...

Get Compilers: Principles and Practice now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.