Software code analysis and optimization is commonly performed to make a computer program work more efficiently or use fewer resources. For example, code is optimized to make a computer program run faster or use less memory or use less power.
Code optimization is often automatically performed by a compiler. Compilers are typically used to transform source code to an executable program, and they often have different phases for performing the transformation. Some of these phases perform code optimization. In many instances, the compiler transforms the source code to an intermediate representation (IR), which is then transformed to an optimized executable program in later phases. Typical transformations in the optimization phases are removal of useless or unreachable code, discovering and propagating constant values, relocation of a computation to a less frequently executed place (e.g., out of a loop), or specializing a computation based on the context.
There is a large body of techniques for analyzing and optimizing sequential code. Sequential code is code that is executed by a single thread, with no other thread simultaneously running. This is opposed to parallel code employing multithreading, which includes multiple threads in a process executed on one or more processors. In multithreading, the threads share a process' resources but are able to execute independently.
Compiler phases may use known transformations to optimize sequential code. These transformations are referred to as optimizations. Unfortunately, much of the known techniques for sequential-code optimization cannot be directly applied on parallel code, which is becoming more popular with the prevalence of multiprocessor computer systems. The inability to directly apply sequential-code optimizations on parallel code is mainly due to the asynchronous nature of parallel code. Conditions that are sufficient for applying sequential-code optimizations on sequential code may not be sufficient for applying sequential-code optimizations on asynchronous code that performs parallel accesses.
Optimizations in modern compilers are usually designed to work on an IR, as described above. Researchers have generally addressed the parallel-program optimization problem by devising analyses and transformations from the ground up, or by adapting existing sequential analyses and transformations. Many of these approaches, which are specifically tailored for parallel code, depend on specialized IRs rather than the conventional IRs commonly used for sequential code. To use these specialized IRs, existing sequential-code compiler phases may have to be re-designed. However, re-designing or modifying an existing compiler phase requires access to the phase's source code, which may not be available.