Description
One of the first steps in bringing PGO to rustc is adding support for it to the compiler's build system. Concretely this means
- support building an instrumented compiler (
-Cprofile-generate
phase), and - support building a compiler that makes use of profile data (
-Cprofile-use
phase)
Optionally, the build system could also
- support profile data collection (by running the instrumented compiler through a standard set of workloads)
In rust-lang/cargo#7618 (comment), @luser suggests that the three phases should be operable separately. I think that makes a lot of sense since on CI we'll probably want to either only run the "profile-use" phase with downloaded profile data, or only the "profile-generate" phase that uploads the profile data.
I suggest adding the following new config.toml
settings:
llvm.profile-generate = ( "<path>" | "default-path" )
llvm.profile-use = ( "<path>" | "default-path" | "download-profdata" )
rust.profile-generate = ( "<path>" | "default-path" )
rust.profile-use = ( "<path>" | "default-path" | "download-profdata" )
rust.profile-collect = (true | false)
The paths specify the argument to the -Cprofile-generate
and -Cprofile-use
flags. default-path
means some known location within the build directory. download-profdata
means that the build system will try to find and download the most recent profile data available for the given commit. If rust.profile-collect
is true, the build system will run a standard data collection scenario with the instrumented compiler (or will error if none of profile-generate
flags is set).
Note that this setup has the following implications:
- One can turn PGO on or off independently for LLVM and Rust.
- There is no single command that runs all three phases at once. If one wants to build a PGOed compiler completely locally, one has to run something like:
./configure --llvm.profile-generate=default-path --rust.profile-generate=default-path --llvm.profile-collect=true ./x.py build ./x.py clean # including LLVM? ./configure --llvm.profile-use=default-path --rust.profile-use=default-path ./x.py build
- The "default" scenario where "generate" and "use" phases are not run on the same machine can be done with a single
./configure && ./x.py build
though.
I'd like to hear if somebody can come up with a different, better setup. Maybe something that allows the entire three-phase build with a single ./x.py pgo-build
command?