Abstract:
Source-to-source translation is an important way to make analysis and optimization in a compiler retargetable. It is widely used to support various parallel programming language extensions and platform independent optimizations, and it can help programmers to validate the program correctness and to tune the performance. In the multi-core and many-core times, users are more eagerly demanded to get involved in program analysis and optimization. Source-to-source code generation, which is platform independent and user friendly, is increasingly welcomed. Source-to-source is easy to implement in a simple compiler, but difficult to implement in a compiler with complex program analysis and aggressive optimizations. Therefore few production quality compilers provided robust source-to-source translation. It is found that transformation produced by optimization is the leading cause of the difficulty. The problems are analyzed in the source-to-source translation based on a lot of error cases, and a translation technique with type restoration is provided to solve the problem. Then the authors implement the technique in the Open64 compiler, evaluate it via supertest and spec2000 benchmarks and prove that it greatly improves the robustness of the source-to-source translation. The method in the paper is integrated in the source-to-source translator module and separated from various optimizations, so it is easy to be used in other compilers.