A system and method for reorganizing source code using frequency based
instruction loop replication are provided. Code is reorganized based on
the frequency of execution of blocks of the code so as to favor
frequently executed blocks of code over rarely executed code with regard
to subsequent optimizations. Frequently executed blocks of instructions
are maintained within loop/switch statements and rarely executed blocks
of instructions are removed from the loop/switch statements. The rarely
executed blocks of instructions may be replicated after the loop/switch
statement with a reference back to the loop/switch statement. In this
way, when subsequent loop/switch statement optimizations are applied, the
frequently executed blocks of instructions within the loop are more
likely to benefit from such optimizations since the negative influence of
the rarely executed blocks of instructions has been removed.