The present invention provides for a method for computer program code
optimization for a software managed cache in either a uni-processor or a
multi-processor system. A single source file comprising a plurality of
array references is received. The plurality of array references is
analyzed to identify predictable accesses. The plurality of array
references is analyzed to identify secondary predictable accesses. One or
more of the plurality of array references is aggregated based on
identified predictable accesses and identified secondary predictable
accesses to generate aggregated references. The single source file is
restructured based on the aggregated references to generate restructured
code. Prefetch code is inserted in the restructured code based on the
aggregated references. Software cache update code is inserted in the
restructured code based on the aggregated references. Explicit cache
lookup code is inserted for the remaining unpredictable accesses. Calls
to a miss handler for misses in the explicit cache lookup code are
inserted. A miss handler is included in the generated code for the
program. In the miss handler, a line to evict is chosen based on recent
usage and predictability. In the miss handler, appropriate DMA commands
are issued for the evicted line and the missing line.