Contents    Page-10    Prev    Next    Page+10    Index   

Heuristic for Expressions

The likelihood of running out of registers can be reduced by using a heuristic in generating code for expressions:

Generate code for the most complicated operand first.
The ``most complicated'' operand can be found by determining the size of each subtree. However, simply generating code for a subtree that is an operation before a subtree that is a simple operand is usually sufficient.

With this simple heuristic, on a machine with 8 or more registers, the compiler will never[Well, hardly ever.] run out.

If a machine allows arithmetic instructions to be used with a full address, the operation may be combined with the last load.