Skip to content

Commit ff479b1

Browse files
committed
Auto merge of #100801 - Kobzol:track-pgo-profile-paths, r=michaelwoerister
Track PGO profiles in depinfo This PR makes sure that PGO profiles (`-Cprofile-use` and `-Cprofile-sample-use`) are tracked in depinfo, so that when they change, the compilation session will be invalidated. This approach was discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Tracking.20PGO.20profile.20files.20in.20cargo). I tried it locally and it seems that the code is recompiled just with this change, and #100413 is not even needed. But it's possible that not everything required is recompiled, so we will probably want to land both changes. Another approach to implement this could be to store the PGO profiles in `sess.parse_sess.file_depinfo` when the session is being created, but then the paths would have to be converted to a string and then to a symbol, which seemed unnecessarily complicated. CC `@michaelwoerister` r? `@Eh2406`
2 parents 8c41305 + 925644e commit ff479b1

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

compiler/rustc_interface/src/passes.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,24 @@ fn write_out_deps(
573573
// Account for explicitly marked-to-track files
574574
// (e.g. accessed in proc macros).
575575
let file_depinfo = sess.parse_sess.file_depinfo.borrow();
576-
let extra_tracked_files = file_depinfo.iter().map(|path_sym| {
577-
let path = PathBuf::from(path_sym.as_str());
576+
577+
let normalize_path = |path: PathBuf| {
578578
let file = FileName::from(path);
579579
escape_dep_filename(&file.prefer_local().to_string())
580-
});
580+
};
581+
582+
let extra_tracked_files =
583+
file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str())));
581584
files.extend(extra_tracked_files);
582585

586+
// We also need to track used PGO profile files
587+
if let Some(ref profile_instr) = sess.opts.cg.profile_use {
588+
files.push(normalize_path(profile_instr.as_path().to_path_buf()));
589+
}
590+
if let Some(ref profile_sample) = sess.opts.unstable_opts.profile_sample_use {
591+
files.push(normalize_path(profile_sample.as_path().to_path_buf()));
592+
}
593+
583594
if sess.binary_dep_depinfo() {
584595
if let Some(ref backend) = sess.opts.unstable_opts.codegen_backend {
585596
if backend.contains('.') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# needs-profiler-support
2+
# ignore-windows-gnu
3+
4+
-include ../../run-make-fulldeps/tools.mk
5+
6+
# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
7+
# instead of hardcoding them everywhere they're needed.
8+
ifeq ($(IS_MUSL_HOST),1)
9+
ADDITIONAL_ARGS := $(RUSTFLAGS)
10+
endif
11+
12+
all:
13+
# Generate PGO profiles
14+
$(BARE_RUSTC) $(ADDITIONAL_ARGS) -Cprofile-generate=$(TMPDIR)/profiles --out-dir $(TMPDIR) main.rs
15+
$(TMPDIR)/main
16+
17+
# Merge profiles
18+
"$(LLVM_BIN_DIR)/llvm-profdata" merge \
19+
-o "$(TMPDIR)/merged.profdata" \
20+
"$(TMPDIR)/profiles" || exit 1
21+
22+
# Use the profile
23+
$(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata --emit dep-info main.rs
24+
25+
# Check that profile file is in depinfo
26+
$(CGREP) "merged.profdata" < $(TMPDIR)/main.d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

0 commit comments

Comments
 (0)