Skip to content
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

Track PGO profiles in depinfo #100801

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,24 @@ fn write_out_deps(
// Account for explicitly marked-to-track files
// (e.g. accessed in proc macros).
let file_depinfo = sess.parse_sess.file_depinfo.borrow();
let extra_tracked_files = file_depinfo.iter().map(|path_sym| {
let path = PathBuf::from(path_sym.as_str());

let normalize_path = |path: PathBuf| {
let file = FileName::from(path);
escape_dep_filename(&file.prefer_local().to_string())
});
};

let extra_tracked_files =
file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str())));
files.extend(extra_tracked_files);

// We also need to track used PGO profile files
if let Some(ref profile_instr) = sess.opts.cg.profile_use {
files.push(normalize_path(profile_instr.as_path().to_path_buf()));
}
if let Some(ref profile_sample) = sess.opts.unstable_opts.profile_sample_use {
files.push(normalize_path(profile_sample.as_path().to_path_buf()));
}

if sess.binary_dep_depinfo() {
if let Some(ref backend) = sess.opts.unstable_opts.codegen_backend {
if backend.contains('.') {
Expand Down
26 changes: 26 additions & 0 deletions src/test/run-make/track-pgo-dep-info/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# needs-profiler-support
# ignore-windows-gnu

-include ../../run-make-fulldeps/tools.mk

# FIXME(eddyb) provide `HOST_RUSTC` and `TARGET_RUSTC`
# instead of hardcoding them everywhere they're needed.
ifeq ($(IS_MUSL_HOST),1)
ADDITIONAL_ARGS := $(RUSTFLAGS)
endif

all:
# Generate PGO profiles
$(BARE_RUSTC) $(ADDITIONAL_ARGS) -Cprofile-generate=$(TMPDIR)/profiles --out-dir $(TMPDIR) main.rs
$(TMPDIR)/main

# Merge profiles
"$(LLVM_BIN_DIR)/llvm-profdata" merge \
-o "$(TMPDIR)/merged.profdata" \
"$(TMPDIR)/profiles" || exit 1

# Use the profile
$(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata --emit dep-info main.rs

# Check that profile file is in depinfo
$(CGREP) "merged.profdata" < $(TMPDIR)/main.d
1 change: 1 addition & 0 deletions src/test/run-make/track-pgo-dep-info/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}