Skip to content

Commit

Permalink
rewrite pgo-indirect-call-promotion to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jul 31, 2024
1 parent 9fae59a commit 76c5149
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/tools/compiletest/src/command-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"only-watchos",
"only-windows",
"only-windows-gnu",
"only-windows-msvc",
"only-x86",
"only-x86_64",
"only-x86_64-fortanix-unknown-sgx",
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/no-alloc-shim/Makefile
run-make/pgo-gen-lto/Makefile
run-make/pgo-indirect-call-promotion/Makefile
run-make/print-calling-conventions/Makefile
run-make/print-target-list/Makefile
run-make/raw-dylib-alt-calling-convention/Makefile
Expand Down
28 changes: 12 additions & 16 deletions tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//@ only-windows-msvc
// Reason: pdb files are unique to this architecture

use run_make_support::{assert_contains, env_var, rfs, rustc};
use run_make_support::{assert_contains, bstr, env_var, rfs, rustc};

fn main() {
rustc()
Expand All @@ -17,19 +17,15 @@ fn main() {
.crate_type("bin")
.metadata("dc9ef878b0a48666")
.run();
assert_contains(rfs::read_to_string("my_crate_name.pdb"), env_var("RUSTC_ORIGINAL"));
let strings = [
r#""main.rs""#,
r#""-g""#,
r#""--crate-name""#,
r#""my_crate_name""#,
r#""--crate-type""#,
r#""bin""#,
r#""-C""#,
r#""metadata=dc9ef878b0a48666""#,
r#""--out-dir""#,
];
for string in strings {
assert_contains(rfs::read_to_string("my_crate_name.pdb"), string);
}
use bstr::ByteSlice;
assert!(&rfs::read("my_crate_name.pdb").find(env_var("RUSTC").as_bytes()).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""main.rs""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""-g""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""--crate-name""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""my_crate_name""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""--crate-type""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""bin""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""-C""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""metadata=dc9ef878b0a48666""#).is_some());
assert!(&rfs::read("my_crate_name.pdb").find(br#""--out-dir""#).is_some());
}
23 changes: 0 additions & 23 deletions tests/run-make/pgo-indirect-call-promotion/Makefile

This file was deleted.

33 changes: 33 additions & 0 deletions tests/run-make/pgo-indirect-call-promotion/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This test checks that indirect call promotion is performed. The test
// programs calls the same function a thousand times through a function pointer.
// Only PGO data provides the information that it actually always is the same
// function. We verify that the indirect call promotion pass inserts a check
// whether it can make a direct call instead of the indirect call.
// See https://github.com/rust-lang/rust/pull/66631

//@ needs-profiler-support
// Reason: llvm_profdata is used
//@ ignore-cross-compile
// Reason: the compiled binary is executed

use run_make_support::{llvm_filecheck, llvm_profdata, rfs, run, rustc};

fn main() {
// We don't compile `opaque` with either optimizations or instrumentation.
rustc().input("opaque.rs").run();
// Compile the test program with instrumentation
rfs::create_dir("prof_data_dir");
rustc().input("interesting.rs").profile_generate("prof_data_dir").opt().codegen_units(1).run();
rustc().input("main.rs").profile_generate("prof_data_dir").opt().run();
// The argument below generates to the expected branch weights
run("main");
llvm_profdata().merge().output("prof_data_dir/merged.profdata").input("prof_data_dir").run();
rustc()
.input("interesting.rs")
.profile_use("prof_data_dir/merged.profdata")
.opt()
.codegen_units(1)
.emit("llvm-ir")
.run();
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(rfs::read("interesting.ll")).run();
}

0 comments on commit 76c5149

Please sign in to comment.