Skip to content

Commit a1555eb

Browse files
committed
rewrite pgo-use to rmake
1 parent 1e4d821 commit a1555eb

File tree

3 files changed

+54
-44
lines changed

3 files changed

+54
-44
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ run-make/pdb-buildinfo-cl-cmd/Makefile
110110
run-make/pgo-gen-lto/Makefile
111111
run-make/pgo-gen-no-imp-symbols/Makefile
112112
run-make/pgo-indirect-call-promotion/Makefile
113-
run-make/pgo-use/Makefile
114113
run-make/pointer-auth-link-with-c/Makefile
115114
run-make/print-calling-conventions/Makefile
116115
run-make/print-target-list/Makefile

tests/run-make/pgo-use/Makefile

-43
This file was deleted.

tests/run-make/pgo-use/rmake.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This test makes sure that PGO profiling data leads to cold functions being
2+
// marked as `cold` and hot functions with `inlinehint`.
3+
// The test program contains an `if` where actual execution only ever takes the
4+
// `else` branch. Accordingly, we expect the function that is never called to
5+
// be marked as cold.
6+
// See https://github.com/rust-lang/rust/pull/60262
7+
8+
//@ needs-profiler-support
9+
//@ ignore-cross-compile
10+
11+
use run_make_support::{
12+
cwd, find_files_by_prefix_and_extension, fs_wrapper, llvm_filecheck, llvm_profdata,
13+
run_with_args, rustc,
14+
};
15+
16+
fn main() {
17+
// Compile the test program with instrumentation
18+
// Disable the pre-inlining pass (i.e. a pass that does some inlining before
19+
// it adds the profiling instrumentation). Disabling this pass leads to
20+
// rather predictable IR which we need for this test to be stable.
21+
rustc()
22+
.opt_level("2")
23+
.codegen_units(1)
24+
.arg("-Cllvm-args=-disable-preinline")
25+
.profile_generate(cwd())
26+
.input("main.rs")
27+
.run();
28+
// Run it in order to generate some profiling data
29+
run_with_args("main", &["some-argument"]);
30+
// Postprocess the profiling data so it can be used by the compiler
31+
llvm_profdata()
32+
.merge()
33+
.output("merged.profdata")
34+
.input(find_files_by_prefix_and_extension(cwd(), "default", "profraw").get(0).unwrap())
35+
.run();
36+
// Compile the test program again, making use of the profiling data
37+
rustc()
38+
.opt_level("2")
39+
.codegen_units(1)
40+
.arg("-Cllvm-args=-disable-preinline")
41+
.profile_use("merged.profdata")
42+
.emit("llvm-ir")
43+
.input("main.rs")
44+
.run();
45+
// Check that the generate IR contains some things that we expect
46+
//
47+
// We feed the file into LLVM FileCheck tool *in reverse* so that we see the
48+
// line with the function name before the line with the function attributes.
49+
// FileCheck only supports checking that something matches on the next line,
50+
// but not if something matches on the previous line.
51+
let mut bytes = fs_wrapper::read("interesting.ll");
52+
bytes.reverse();
53+
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(bytes).run();
54+
}

0 commit comments

Comments
 (0)