rewrite pgo-use to rmake

This commit is contained in:
Oneirical 2024-06-25 13:46:20 -04:00
parent 1e4d821136
commit a1555eb0d6
3 changed files with 54 additions and 44 deletions

View File

@ -110,7 +110,6 @@ run-make/pdb-buildinfo-cl-cmd/Makefile
run-make/pgo-gen-lto/Makefile run-make/pgo-gen-lto/Makefile
run-make/pgo-gen-no-imp-symbols/Makefile run-make/pgo-gen-no-imp-symbols/Makefile
run-make/pgo-indirect-call-promotion/Makefile run-make/pgo-indirect-call-promotion/Makefile
run-make/pgo-use/Makefile
run-make/pointer-auth-link-with-c/Makefile run-make/pointer-auth-link-with-c/Makefile
run-make/print-calling-conventions/Makefile run-make/print-calling-conventions/Makefile
run-make/print-target-list/Makefile run-make/print-target-list/Makefile

View File

@ -1,43 +0,0 @@
# needs-profiler-support
# ignore-cross-compile
include ../tools.mk
# This test makes sure that PGO profiling data leads to cold functions being
# marked as `cold` and hot functions with `inlinehint`.
# The test program contains an `if` were actual execution only ever takes the
# `else` branch. Accordingly, we expect the function that is never called to
# be marked as cold.
#
# Disable the pre-inlining pass (i.e. a pass that does some inlining before
# it adds the profiling instrumentation). Disabling this pass leads to
# rather predictable IR which we need for this test to be stable.
COMMON_FLAGS=-Copt-level=2 -Ccodegen-units=1 -Cllvm-args=-disable-preinline
ifeq ($(UNAME),Darwin)
# macOS does not have the `tac` command, but `tail -r` does the same thing
TAC := tail -r
else
# some other platforms don't support the `-r` flag for `tail`, so use `tac`
TAC := tac
endif
all:
# Compile the test program with instrumentation
$(RUSTC) $(COMMON_FLAGS) -Cprofile-generate="$(TMPDIR)" main.rs
# Run it in order to generate some profiling data
$(call RUN,main some-argument) || exit 1
# Postprocess the profiling data so it can be used by the compiler
"$(LLVM_BIN_DIR)"/llvm-profdata merge \
-o "$(TMPDIR)"/merged.profdata \
"$(TMPDIR)"/default_*.profraw
# Compile the test program again, making use of the profiling data
$(RUSTC) $(COMMON_FLAGS) -Cprofile-use="$(TMPDIR)"/merged.profdata --emit=llvm-ir main.rs
# Check that the generate IR contains some things that we expect
#
# We feed the file into LLVM FileCheck tool *in reverse* so that we see the
# line with the function name before the line with the function attributes.
# FileCheck only supports checking that something matches on the next line,
# but not if something matches on the previous line.
$(TAC) "$(TMPDIR)"/main.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt

View File

@ -0,0 +1,54 @@
// This test makes sure that PGO profiling data leads to cold functions being
// marked as `cold` and hot functions with `inlinehint`.
// The test program contains an `if` where actual execution only ever takes the
// `else` branch. Accordingly, we expect the function that is never called to
// be marked as cold.
// See https://github.com/rust-lang/rust/pull/60262
//@ needs-profiler-support
//@ ignore-cross-compile
use run_make_support::{
cwd, find_files_by_prefix_and_extension, fs_wrapper, llvm_filecheck, llvm_profdata,
run_with_args, rustc,
};
fn main() {
// Compile the test program with instrumentation
// Disable the pre-inlining pass (i.e. a pass that does some inlining before
// it adds the profiling instrumentation). Disabling this pass leads to
// rather predictable IR which we need for this test to be stable.
rustc()
.opt_level("2")
.codegen_units(1)
.arg("-Cllvm-args=-disable-preinline")
.profile_generate(cwd())
.input("main.rs")
.run();
// Run it in order to generate some profiling data
run_with_args("main", &["some-argument"]);
// Postprocess the profiling data so it can be used by the compiler
llvm_profdata()
.merge()
.output("merged.profdata")
.input(find_files_by_prefix_and_extension(cwd(), "default", "profraw").get(0).unwrap())
.run();
// Compile the test program again, making use of the profiling data
rustc()
.opt_level("2")
.codegen_units(1)
.arg("-Cllvm-args=-disable-preinline")
.profile_use("merged.profdata")
.emit("llvm-ir")
.input("main.rs")
.run();
// Check that the generate IR contains some things that we expect
//
// We feed the file into LLVM FileCheck tool *in reverse* so that we see the
// line with the function name before the line with the function attributes.
// FileCheck only supports checking that something matches on the next line,
// but not if something matches on the previous line.
let mut bytes = fs_wrapper::read("interesting.ll");
bytes.reverse();
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(bytes).run();
}