This Request for Comments (RFC) proposes a set of the CMake cache files and surrounding changes required for improving the compilation time of the Flang compiler by using the PGO and BOLT optimizations.
Motivation and Background
The indented beneficiaries of this change are the LLVM-based toolchain publishers. With this change they would be able to incorporate the Flang optimization routine into the toolchain building process. As for today, the toolchain publishers already do the same thing with the Clang compiler. The change proposed in this document is mostly reusing the same two-stage methodology as used for optimizing Clang, intentionally combining optimization of Clang and Flang into one building process. The motivation behind this choice was to avoid addition of unnecessary burden of re-running mostly the same steps in order to obtain both Clang and Flang optimized.
Proposed extension
Following the Clang’s suit, a set of CMake cache files is being proposed:
-
flang/cmake/caches/PGO.cmake, which can be used to generate a multi-stage instrumented compiler; the instrumented compiler is being profiled on the training set of programs to compile, and the final optimized compiler is being built using the profile obtained during the training. -
flang/cmake/caches/BOLT.cmake, which can be used to initiate the post-link binaries optimization using runtime profiling. -
flang/cmake/caches/BOLT-PGO.cmake, which combines both BOLT and PGO for better optimization.
Other CMake cache files (flang/cmake/caches/PGO-stage2.cmake and flang/cmake/caches/PGO-stage2-instrumented.cmake) are the auxiliaries included by the flang/cmake/caches/PGO.cmake cache file.
As a proof of concept, two pull requests were opened ([1] and [2]), with most comments and evaluations added under [1] (see the comment [3]).
The two pull requests represent the use of a two different selections of the PGO training codes. The first one ([1]) proposes a simple set of hello world and alike Fortran programs, the other one ([2]) proposes the reuse of the flang test suite already present in the flang directory tree.
As the evaluation presented in the comment [3] showed, the first approach gives the most of the improvement on compiling a set of randomly picked Fortran applications (dbcsr, polyhedron pb11, netlib’s lapack), while the second approach gives even more improvement, yet at cost of the longer preparation time and significantly bigger storage occupancy (200GB at least) needed for storing the performance profiling data.
The benefits of improving the compilation time of the flang compiler are undeniable. Compiling larger projects with flang is known to be time consuming, which results in a degradation of the user experience.