One embodiment of the present invention provides a system that facilitates
optimizing computer program performance by using steered execution. The
system operates by first receiving source code for a computer program,
and then compiling a portion of this source code with a first set of
optimizations to generate a first compiled portion. The system also
compiles the same portion of the source code with a second set of
optimizations to generate a second compiled portion. Remaining source
code is compiled to generate a third compiled portion. Additionally, a
rule is generated for selecting between the first compiled portion and
the second compiled portion. Finally, the first compiled portion, the
second compiled portion, the third compiled portion, and the rule are
combined into an executable output file.