-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support caching Clang invocations with -fprofile-use and -fprofile-instr-use. #952
Support caching Clang invocations with -fprofile-use and -fprofile-instr-use. #952
Conversation
3c5d320
to
1465cec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. Just two small things I would change.
271b823
to
8ba25dd
Compare
Thanks for the review, @luser! I think I addressed your comments. @glandium, would you maybe be able to spare some time for merging/reviewing this PR? The new functionality is a necessary prerequisite for distributing PGOed versions of rustc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also rebase on top of #971 after it's merged? Thank you. (BTW, did you intend your user email not to contain a TLD?)
src/compiler/gcc.rs
Outdated
@@ -169,7 +176,7 @@ counted_array!(pub static ARGS: [ArgInfo<ArgData>; _] = [ | |||
flag!("-fplugin=libcc1plugin", TooHardFlag), | |||
flag!("-fprofile-arcs", ProfileGenerate), | |||
flag!("-fprofile-generate", ProfileGenerate), | |||
take_arg!("-fprofile-use", OsString, Concatenated, TooHard), | |||
take_arg!("-fprofile-use", PathBuf, Concatenated('='), ProfileUse), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-fprofile-use
can also be used without a value associated with it. It looks like that's true of -fprofile-instr-use
too, and you don't handle those cases. There's also -fno-profile-instr-use
, which you might as well add support for while you're here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-fprofile-use can also be used without a value associated with it.
Indeed. But the documentation does not seem to state what the semantics of that are. I'll have to dig into the source code...
There's also -fno-profile-instr-use, which you might as well add support for while you're here.
I'll look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like -fprofile-use
without argument will try to read from ./default.profdata
-- and that the implementation here already handles this correctly. I'll add a unit test for that.
src/compiler/gcc.rs
Outdated
@@ -275,6 +283,21 @@ where | |||
OsString::from(arg.flag_str().expect("Compilation flag expected")); | |||
} | |||
Some(ProfileGenerate) => profile_generate = true, | |||
Some(ProfileUse(path)) => { | |||
if compiler_kind != CCompilerKind::Clang { | |||
cannot_cache!("-fprofile(-instr)-use caching only supported for Clang"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the (-instr)
part.
src/compiler/gcc.rs
Outdated
@@ -275,6 +283,21 @@ where | |||
OsString::from(arg.flag_str().expect("Compilation flag expected")); | |||
} | |||
Some(ProfileGenerate) => profile_generate = true, | |||
Some(ProfileUse(path)) => { | |||
if compiler_kind != CCompilerKind::Clang { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way you could do this, without adding the compiler kind, is to simply add -fprofile-use to the clang list of arguments (see args::test_multi_search
), in which case it would probably be more appropriate to call this ClangProfileUse
rather than ProfileUse
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you can "override" arguments that way? That does sound like the better approach for this case.
src/compiler/msvc.rs
Outdated
@@ -587,7 +587,7 @@ pub fn parse_arguments( | |||
let mut args = match arg.get_data() { | |||
Some(SplitDwarf) | Some(TestCoverage) | Some(Coverage) | Some(DoCompilation) | |||
| Some(Language(_)) | Some(Output(_)) | Some(TooHardFlag) | Some(XClang(_)) | |||
| Some(TooHard(_)) => cannot_cache!(arg | |||
| Some(TooHard(_)) | Some(ProfileUse(_)) => cannot_cache!(arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't be too hard to add support for clang-cl here.
Thanks for the review, @glandium!
Will do.
That was a halfhearted (and probably ineffective) attempt to keep my email address somewhat protected from spammers. It set up git like that years ago and it seems to have stuck |
8ba25dd
to
adc9b39
Compare
OK, I think the version I just pushed addresses your comments, @glandium. And it does look cleaner than the previous version Note: I added "support" for the I was a bit surprised to find that |
@glandium, do you have an estimate on when this can be merged? Is there anything I can do to help? |
Hi, would love to see these changes upstreamed, tracking this PR for a while. Thanks for the work, and lets rebase and merge it already. 🙂 From what i see currently it's about this:
#952 (review) (@michaelwoerister has done that) |
@glandium Any idea of when/if this pull request can be merged? |
Hey @michaelwoerister, thanks for the PR, and sorry for the review delay here 😅 |
adc9b39
to
dc28e0e
Compare
I rebased the PR and tests are passing locally for me. |
Codecov Report
@@ Coverage Diff @@
## main #952 +/- ##
=======================================
Coverage 57.81% 57.82%
=======================================
Files 47 47
Lines 12055 12107 +52
Branches 2178 2184 +6
=======================================
+ Hits 6970 7001 +31
Misses 3727 3727
- Partials 1358 1379 +21
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Michael, and sorry about the review delay.
Let's get this landed 😎
Well, that was quick :) Thanks for the review! |
bump sccache for linux x86_64 to allow caching while PGO'd This bumps sccache for linux-only jobs to allow sccache work with PGO mozilla/sccache#952 This is improvement: 2h05m -> 1h44m (from 1 run) for `dist-x86_64-linux` rust-lang#133033 (comment) Why still use old release? Commit with improvement was old, so i used some release around. In future, more recent versions can be tested to see if there any improvements, while this one already gives one. aarch64 update shouldn't change much, as there no PGO used. For other OSes i will create separate PRs later. r? infra
bump sccache for linux x86_64 to allow caching while PGO'd This bumps sccache for linux-only jobs to allow sccache work with PGO mozilla/sccache#952 This is improvement: 2h05m -> 1h44m (from 1 run) for `dist-x86_64-linux` rust-lang#133033 (comment) Why still use old release? Commit with improvement was old, so i used some release around. In future, more recent versions can be tested to see if there any improvements, while this one already gives one. aarch64 update shouldn't change much, as there no PGO used. For other OSes i will create separate PRs later. r? infra
sccache supports `-fprofile-use` since mozilla/sccache#952, released as part of sccache v0.3.0, which is available in Ubuntu since 23.04 release. Bug: 40188007 Change-Id: I5bca8350113ee1940096cd53be543abf4eaf03f7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6013745 Reviewed-by: Nico Weber <thakis@chromium.org> Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com> Cr-Commit-Position: refs/heads/main@{#1384244}
This PR adds support for caching Clang invocations with
-fprofile-use
and-fprofile-instr-use
, something that will be required for supporting PGOed Rust compiler builds.The PR only implements support for Clang. I have not had time to look into how GCC works (although from a superficial glance it looks like it might be harder to find out which files to hash exactly). Adding support for Rust should be straightforward though.
I added some unit tests and verified that things work locally, but found it hard to write end-to-end tests because of Clang's PGO setup which requires the external
llvm-profdata
tool to generate the.profdata
file. Let me know if this is something that is required.In #941 I expressed the concern that hashing these rather big
.profdata
files would take a long time. In practice this does not seem to be true. In my local tests compiling LLVM with a full cache took about 50 seconds. Caching the file hashes (so that most of the hashing work could be skipped) only reduced the total build time by a couple of seconds or so.r? @luser