-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Update logic around PGO staging #101744
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
Update logic around PGO staging #101744
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -666,8 +666,10 @@ impl Step for Rustc { | |
cargo.rustflag("-Clink-args=-Wl,--icf=all"); | ||
} | ||
|
||
let is_collecting = if let Some(path) = &builder.config.rust_profile_generate { | ||
if compiler.stage == 1 { | ||
let use_relative_paths = if let Some(path) = &builder.config.rust_profile_generate { | ||
if compiler.stage >= 1 | ||
|| (builder.config.llvm_profile_generate.is_some() && !builder.llvm_link_shared()) | ||
{ | ||
cargo.rustflag(&format!("-Cprofile-generate={}", path)); | ||
// Apparently necessary to avoid overflowing the counters during | ||
// a Cargo build profile | ||
|
@@ -676,18 +678,28 @@ impl Step for Rustc { | |
} else { | ||
false | ||
} | ||
} else if let Some(path) = &builder.config.rust_profile_use { | ||
if compiler.stage == 1 { | ||
cargo.rustflag(&format!("-Cprofile-use={}", path)); | ||
cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function"); | ||
} else if let Some(path) = &builder.config.llvm_profile_generate { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding this function is only responsible for building Rust crates, not the LLVM libraries. If This code now makes the original check to see if Rust instrumentation was requested. If not, it will still instrument the Rust crates if the LLVM libraries are instrumented and linkage is set to |
||
// If libLLVM.a is instrumented it will need to be linked against | ||
// the profiler's runtime environment. The only way to ensure that | ||
// occurs is to tell rustc to profile the compilation unit. | ||
if !builder.llvm_link_shared() { | ||
cargo.rustflag(&format!("-Cprofile-generate={}", path)); | ||
// Apparently necessary to avoid overflowing the counters during | ||
// a Cargo build profile | ||
cargo.rustflag("-Cllvm-args=-vp-counters-per-site=4"); | ||
true | ||
} else { | ||
false | ||
} | ||
} else if let Some(path) = &builder.config.rust_profile_use { | ||
cargo.rustflag(&format!("-Cprofile-use={}", path)); | ||
cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function"); | ||
true | ||
} else { | ||
false | ||
}; | ||
if is_collecting { | ||
|
||
if use_relative_paths { | ||
// Ensure paths to Rust sources are relative, not absolute. | ||
cargo.rustflag(&format!( | ||
"-Cllvm-args=-static-func-strip-dirname-prefix={}", | ||
|
@@ -821,7 +833,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS | |
// found. This is to avoid the linker errors about undefined references to | ||
// `__llvm_profile_instrument_memop` when linking `rustc_driver`. | ||
let mut llvm_linker_flags = String::new(); | ||
if builder.config.llvm_profile_generate && target.contains("msvc") { | ||
if builder.config.llvm_profile_generate.is_some() && target.contains("msvc") { | ||
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl { | ||
// Add clang's runtime library directory to the search path | ||
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this condition removed? Shouldn't it be the same as above,
!link_shared() || stage >= 2
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a profile is provided there is no harm in using it. If there are checksum missmatches or missing functions then we have the same result as not using one, but if there are signature matches then the Stage1 compiler will be faster and the total build should complete sooner.