After some effort I built a PGOed Clang. When a new Clang version is released, can I reuse the profdata.prof file I used to build the current version?
You should generate a new version of the profile whenever the code changes significantly. A new major version qualifies while a minor version is probably fine.
In short, if you’re changing to a different version of LLVM, you need to make a new profile. If the amount of differences is small (e.g. going from 20.1.5 to 20.1.6) your existing profile may apply to some extent so you’d still get most of the benefit from the profile. But if switching between major versions (e.g. from 19.1.x to 20.1.x) you definitely need a new profile.
See PGO for cross compilation - #3 by mstorsjo for some similar concerns about reusing profiles for not-exactly-matching cases, for reusing profiles when compiling the same source, either for different targets, or with slightly differing host compilers. In short, if compiling with LLVM_BUILD_INSTRUMENTED=Frontend
, the profiles can be reused quite well, but if compiling with LLVM_BUILD_INSTRUMENTED=IR
, the profile mostly only works for exactly the same build configuration.
I really do this: I reuse profdata to build trunk clang and refresh the profdata only once per month, but I usually do not observe any compile speed drop when compiling sqlite3.c and harfbuzz.cc.
However, the other case is completely different: I build mpv and ffmpeg locally and generate profdata for PGO.
This works very well for local builds, but once I upload the profdata to GitHub for Action auto builds, it does not work. I found the reason: the source file paths in profdata cannot be relocated. -ffile-prefix-map does not work for PGO at all, and although -ffile-compilation-dir works, it still cannot achieve true relocation.