Skip to content

Commit 925644e

Browse files
committed
Track PGO profiles in depinfo
1 parent 6c943ba commit 925644e

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
@@ -593,13 +593,24 @@ fn write_out_deps(
593593
// Account for explicitly marked-to-track files
594594
// (e.g. accessed in proc macros).
595595
let file_depinfo = sess.parse_sess.file_depinfo.borrow();
596-
let extra_tracked_files = file_depinfo.iter().map(|path_sym| {
597-
let path = PathBuf::from(path_sym.as_str());
596+
597+
let normalize_path = |path: PathBuf| {
598598
let file = FileName::from(path);
599599
escape_dep_filename(&file.prefer_local().to_string())
600-
});
600+
};
601+
602+
let extra_tracked_files =
603+
file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str())));
601604
files.extend(extra_tracked_files);
602605

606+
// We also need to track used PGO profile files
607+
if let Some(ref profile_instr) = sess.opts.cg.profile_use {
608+
files.push(normalize_path(profile_instr.as_path().to_path_buf()));
609+
}
610+
if let Some(ref profile_sample) = sess.opts.unstable_opts.profile_sample_use {
611+
files.push(normalize_path(profile_sample.as_path().to_path_buf()));
612+
}
613+
603614
if sess.binary_dep_depinfo() {
604615
if let Some(ref backend) = sess.opts.unstable_opts.codegen_backend {
605616
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)