A method and apparatus for generating an optimized intermediate
representation of source code for a computer program are described. An
initial intermediate representation is extracted from the source code by
organizing it as a plurality of basic blocks that each contain at least
one program instruction ordered according to respective estimated profit
values. A goal function that measures the degree of optimization of the
program is calculated in accordance with its intermediate representation.
The effect on the goal function of modifying the intermediate
representation by moving an instruction from one of the basic blocks to
each of its predecessors is tested iteratively and adopting the modified
intermediate representation if it causes a reduction in the goal function.