-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #125165 - Oneirical:pgo-branch-weights, r=<try>
Migrate `run-make/pgo-branch-weights` to `rmake` Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). This is a scary one and I expect things to break. Set as draft, because this isn't ready. - [x] There is this comment here, which suggests the test is excluded from the testing process due to a platform specific issue? I can't see anything here that would cause this test to not run... > // FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works // properly. Since we only have GCC on the CI ignore the test for now." EDIT: This is specific to Windows-gnu. - [x] The Makefile has this line: ``` ifneq (,$(findstring x86,$(TARGET))) COMMON_FLAGS=-Clink-args=-fuse-ld=gold ``` I honestly can't tell whether this is checking if the target IS x86, or IS NOT. EDIT: It's checking if it IS x86. - [x] I don't know why the Makefile was trying to pass an argument directly in the Makefile instead of setting that "aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc" input as a variable in the Rust program directly. I changed that, let me know if that was wrong. - [x] Trying to rewrite `cat "$(TMPDIR)/interesting.ll" | "$(LLVM_FILECHECK)" filecheck-patterns.txt` resulted in some butchery. For starters, in `tools.mk`, LLVM_FILECHECK corrects its own backslashes on Windows distributions, but there is no further mention of it, so I assume this is a preset environment variable... but is it really? Then, the command itself uses a Standard Input and a passed input file as an argument simultaneously, according to the [documentation](https://llvm.org/docs/CommandGuide/FileCheck.html#synopsis). try-job: aarch64-gnu
- Loading branch information
Showing
7 changed files
with
211 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::{env_var, Command}; | ||
|
||
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available | ||
/// at `$LLVM_BIN_DIR/llvm-readobj`. | ||
pub fn llvm_readobj() -> LlvmReadobj { | ||
LlvmReadobj::new() | ||
} | ||
|
||
/// Construct a new `llvm-profdata` invocation. This assumes that `llvm-profdata` is available | ||
/// at `$LLVM_BIN_DIR/llvm-profdata`. | ||
pub fn llvm_profdata() -> LlvmProfdata { | ||
LlvmProfdata::new() | ||
} | ||
|
||
/// Construct a new `llvm-filecheck` invocation. This assumes that `llvm-filecheck` is available | ||
/// at `$LLVM_FILECHECK`. | ||
pub fn llvm_filecheck() -> LlvmFilecheck { | ||
LlvmFilecheck::new() | ||
} | ||
|
||
/// A `llvm-readobj` invocation builder. | ||
#[derive(Debug)] | ||
pub struct LlvmReadobj { | ||
cmd: Command, | ||
} | ||
|
||
/// A `llvm-profdata` invocation builder. | ||
#[derive(Debug)] | ||
pub struct LlvmProfdata { | ||
cmd: Command, | ||
} | ||
|
||
/// A `llvm-filecheck` invocation builder. | ||
#[derive(Debug)] | ||
pub struct LlvmFilecheck { | ||
cmd: Command, | ||
} | ||
|
||
crate::impl_common_helpers!(LlvmReadobj); | ||
crate::impl_common_helpers!(LlvmProfdata); | ||
crate::impl_common_helpers!(LlvmFilecheck); | ||
|
||
/// Generate the path to the bin directory of LLVM. | ||
pub fn llvm_bin_dir() -> PathBuf { | ||
let llvm_bin_dir = env_var("LLVM_BIN_DIR"); | ||
PathBuf::from(llvm_bin_dir) | ||
} | ||
|
||
impl LlvmReadobj { | ||
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available | ||
/// at `$LLVM_BIN_DIR/llvm-readobj`. | ||
pub fn new() -> Self { | ||
let llvm_readobj = llvm_bin_dir().join("llvm-readobj"); | ||
let cmd = Command::new(llvm_readobj); | ||
Self { cmd } | ||
} | ||
|
||
/// Provide an input file. | ||
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { | ||
self.cmd.arg(path.as_ref()); | ||
self | ||
} | ||
|
||
/// Pass `--file-header` to display file headers. | ||
pub fn file_header(&mut self) -> &mut Self { | ||
self.cmd.arg("--file-header"); | ||
self | ||
} | ||
} | ||
|
||
impl LlvmProfdata { | ||
/// Construct a new `llvm-profdata` invocation. This assumes that `llvm-profdata` is available | ||
/// at `$LLVM_BIN_DIR/llvm-profdata`. | ||
pub fn new() -> Self { | ||
let llvm_profdata = llvm_bin_dir().join("llvm-profdata"); | ||
let cmd = Command::new(llvm_profdata); | ||
Self { cmd } | ||
} | ||
|
||
/// Provide an input file. | ||
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { | ||
self.cmd.arg(path.as_ref()); | ||
self | ||
} | ||
|
||
/// Specify the output file path. | ||
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { | ||
self.cmd.arg("-o"); | ||
self.cmd.arg(path.as_ref()); | ||
self | ||
} | ||
|
||
/// Take several profile data files generated by PGO instrumentation and merge them | ||
/// together into a single indexed profile data file. | ||
pub fn merge(&mut self) -> &mut Self { | ||
self.cmd.arg("merge"); | ||
self | ||
} | ||
} | ||
|
||
impl LlvmFilecheck { | ||
/// Construct a new `llvm-filecheck` invocation. This assumes that `llvm-filecheck` is available | ||
/// at `$LLVM_FILECHECK`. | ||
pub fn new() -> Self { | ||
let llvm_filecheck = env_var("LLVM_FILECHECK"); | ||
let cmd = Command::new(llvm_filecheck); | ||
Self { cmd } | ||
} | ||
|
||
/// Pipe a read file into standard input containing patterns that will be matched against the .patterns(path) call. | ||
pub fn stdin<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self { | ||
self.cmd.set_stdin(input.as_ref().to_vec().into_boxed_slice()); | ||
self | ||
} | ||
|
||
/// Provide the patterns that need to be matched. | ||
pub fn patterns<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { | ||
self.cmd.arg(path.as_ref()); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// This test generates an instrumented binary - a program which | ||
// will keep track of how many times it calls each function, a useful | ||
// feature for optimization. Then, an argument (aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc) | ||
// is passed into the instrumented binary, which should react with a number of function calls | ||
// fully known in advance. (For example, the letter 'a' results in calling f1()) | ||
|
||
// If the test passes, the expected function call count was added to the use-phase LLVM-IR. | ||
// See https://github.com/rust-lang/rust/pull/66631 | ||
|
||
//@ needs-profiler-support | ||
//@ ignore-cross-compile | ||
|
||
// (This test has problems generating profdata on mingw. This could use further investigation.) | ||
//@ ignore-windows-gnu | ||
|
||
use run_make_support::{fs_wrapper, llvm_filecheck, llvm_profdata, run_with_args, rustc}; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
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(); | ||
fs_wrapper::create_dir_all(&path_prof_data_dir); | ||
rustc() | ||
.input("interesting.rs") | ||
.profile_generate(&path_prof_data_dir) | ||
.opt() | ||
.codegen_units(1) | ||
.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() | ||
.input("interesting.rs") | ||
.profile_use(path_merged_profdata) | ||
.opt() | ||
.codegen_units(1) | ||
.emit("llvm-ir") | ||
.run(); | ||
llvm_filecheck() | ||
.patterns("filecheck-patterns.txt") | ||
.stdin(fs_wrapper::read("interesting.ll")) | ||
.run(); | ||
} |