-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Migrate pgo-gen
, pgo-use
and profile
run-make
tests to rmake.rs
#126957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,18 @@ | ||
// -C profile-generate, when used with rustc, is supposed to output | ||
// profile files (.profraw) after running a binary to analyze how the compiler | ||
// optimizes code. This test checks that these files are generated. | ||
// See https://github.com/rust-lang/rust/pull/48346 | ||
|
||
//@ needs-profiler-support | ||
//@ ignore-cross-compile | ||
|
||
use run_make_support::{cwd, has_extension, has_prefix, run, rustc, shallow_find_files}; | ||
|
||
fn main() { | ||
rustc().arg("-g").profile_generate(cwd()).input("test.rs").run(); | ||
run("test"); | ||
let profraw_files = shallow_find_files(cwd(), |path| { | ||
has_prefix(path, "default") && has_extension(path, "profraw") | ||
}); | ||
assert!(!profraw_files.is_empty(), "no .profraw file generated"); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,55 @@ | ||
// 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, fs_wrapper, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args, | ||
rustc, shallow_find_files, | ||
}; | ||
|
||
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 | ||
let profraw_files = shallow_find_files(cwd(), |path| { | ||
has_prefix(path, "default") && has_extension(path, "profraw") | ||
}); | ||
let profraw_file = profraw_files.get(0).unwrap(); | ||
llvm_profdata().merge().output("merged.profdata").input(profraw_file).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 *with its lines reversed* 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 ir = fs_wrapper::read_to_string("main.ll"); | ||
let lines: Vec<_> = ir.lines().rev().collect(); | ||
let mut reversed_ir = lines.join("\n"); | ||
reversed_ir.push('\n'); | ||
llvm_filecheck().patterns("filecheck-patterns.txt").stdin(reversed_ir.as_bytes()).run(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,22 @@ | ||
// This test revolves around the rustc flag -Z profile, which should | ||
// generate a .gcno file (initial profiling information) as well | ||
// as a .gcda file (branch counters). The path where these are emitted | ||
// should also be configurable with -Z profile-emit. This test checks | ||
// that the files are produced, and then that the latter flag is respected. | ||
// See https://github.com/rust-lang/rust/pull/42433 | ||
|
||
//@ ignore-cross-compile | ||
//@ needs-profiler-support | ||
|
||
use run_make_support::{run, rustc}; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
rustc().arg("-g").arg("-Zprofile").input("test.rs").run(); | ||
run("test"); | ||
assert!(Path::new("test.gcno").exists(), "no .gcno file"); | ||
assert!(Path::new("test.gcda").exists(), "no .gcda file"); | ||
rustc().arg("-g").arg("-Zprofile").arg("-Zprofile-emit=abc/abc.gcda").input("test.rs").run(); | ||
run("test"); | ||
assert!(Path::new("abc/abc.gcda").exists(), "gcda file not emitted to defined path"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.