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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.