Patent ID: 8490071

Claim:
A method, in a data processing system, for optimizing code to perform prefetching of data into a shared memory of a computing device that is shared by a plurality of threads that execute on the computing device, comprising: identifying, by a compiler executing on at least one processor of the data processing system, a memory stream, of a portion of code, that is shared by the plurality of threads, each thread in the plurality of threads having an associated instruction sequence; distributing, by the compiler, a set of prefetch instructions across the plurality of threads; inserting, by the compiler, prefetch instructions, of the set of prefetch instructions, into the instruction sequences of the plurality of threads such that each instruction sequence has a separate sub-portion of the set of prefetch instructions, thereby generating optimized code; generating executable code based on the optimized code; and storing the executable code in a storage device of the data processing system, wherein the executable code, when executed, performs the prefetches associated with the distributed set of prefetch instructions in a shared manner across the plurality of threads.