Fix pgo tests

This commit is contained in:
ywxt
2025-08-13 09:23:41 +08:00
parent 075ce31bd3
commit bc8a521619
4 changed files with 27 additions and 5 deletions

View File

@@ -405,6 +405,12 @@ impl Rustc {
};
self
}
/// Make that the generated LLVM IR is in source order.
pub fn codegen_source_order(&mut self) -> &mut Self {
self.cmd.arg("-Zcodegen-source-order");
self
}
}
/// Query the sysroot path corresponding `rustc --print=sysroot`.

View File

@@ -17,15 +17,21 @@ use run_make_support::{llvm_filecheck, llvm_profdata, rfs, run_with_args, rustc}
fn main() {
let path_prof_data_dir = Path::new("prof_data_dir");
let path_merged_profdata = path_prof_data_dir.join("merged.profdata");
rustc().input("opaque.rs").run();
rustc().input("opaque.rs").codegen_source_order().run();
rfs::create_dir_all(&path_prof_data_dir);
rustc()
.input("interesting.rs")
.profile_generate(&path_prof_data_dir)
.opt()
.codegen_units(1)
.codegen_source_order()
.run();
rustc()
.input("main.rs")
.profile_generate(&path_prof_data_dir)
.opt()
.codegen_source_order()
.run();
rustc().input("main.rs").profile_generate(&path_prof_data_dir).opt().run();
run_with_args("main", &["aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc"]);
llvm_profdata().merge().output(&path_merged_profdata).input(path_prof_data_dir).run();
rustc()
@@ -34,6 +40,7 @@ fn main() {
.opt()
.codegen_units(1)
.emit("llvm-ir")
.codegen_source_order()
.run();
llvm_filecheck()
.patterns("filecheck-patterns.txt")

View File

@@ -14,11 +14,17 @@ 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();
rustc().input("opaque.rs").codegen_source_order().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();
rustc()
.input("interesting.rs")
.profile_generate("prof_data_dir")
.opt()
.codegen_units(1)
.codegen_source_order()
.run();
rustc().input("main.rs").profile_generate("prof_data_dir").opt().codegen_source_order().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();
@@ -28,6 +34,7 @@ fn main() {
.opt()
.codegen_units(1)
.emit("llvm-ir")
.codegen_source_order()
.run();
llvm_filecheck()
.patterns("filecheck-patterns.txt")

View File

@@ -22,6 +22,7 @@ fn main() {
.opt_level("2")
.codegen_units(1)
.arg("-Cllvm-args=-disable-preinline")
.codegen_source_order()
.profile_generate(cwd())
.input("main.rs")
.run();
@@ -40,6 +41,7 @@ fn main() {
.arg("-Cllvm-args=-disable-preinline")
.profile_use("merged.profdata")
.emit("llvm-ir")
.codegen_source_order()
.input("main.rs")
.run();
// Check that the generate IR contains some things that we expect.