Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl ModuleConfig {
),
pgo_use: if_regular!(sess.opts.cg.profile_use.clone(), None),
pgo_sample_use: if_regular!(sess.opts.unstable_opts.profile_sample_use.clone(), None),
debug_info_for_profiling: sess.opts.unstable_opts.debug_info_for_profiling,
debug_info_for_profiling: sess.opts.unstable_opts.debuginfo_for_profiling,
instrument_coverage: if_regular!(sess.instrument_coverage(), false),

sanitizer: if_regular!(sess.sanitizers(), SanitizerSet::empty()),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ fn test_unstable_options_tracking_hash() {
);
tracked!(crate_attr, vec!["abc".to_string()]);
tracked!(cross_crate_inline_threshold, InliningThreshold::Always);
tracked!(debug_info_for_profiling, true);
tracked!(debug_info_type_line_numbers, true);
tracked!(debuginfo_for_profiling, true);
tracked!(default_visibility, Some(rustc_target::spec::SymbolVisibility::Hidden));
tracked!(dep_info_omit_d_target, true);
tracked!(direct_access_external_data, Some(true));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2252,12 +2252,12 @@ options! {
"inject the given attribute in the crate"),
cross_crate_inline_threshold: InliningThreshold = (InliningThreshold::Sometimes(100), parse_inlining_threshold, [TRACKED],
"threshold to allow cross crate inlining of functions"),
debug_info_for_profiling: bool = (false, parse_bool, [TRACKED],
"emit discriminators and other data necessary for AutoFDO"),
debug_info_type_line_numbers: bool = (false, parse_bool, [TRACKED],
"emit type and line information for additional data types (default: no)"),
debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED],
"compress debug info sections (none, zlib, zstd, default: none)"),
debuginfo_for_profiling: bool = (false, parse_bool, [TRACKED],
"emit discriminators and other data necessary for AutoFDO"),
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
"deduplicate identical diagnostics (default: yes)"),
default_visibility: Option<SymbolVisibility> = (None, parse_opt_symbol_visibility, [TRACKED],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `debug-info-for-profiling`
# `debuginfo-for-profiling`

---

Expand All @@ -22,7 +22,7 @@ external tool `create_llvm_prof` from [this repository] must be used.
Given a Rust file `main.rs`, we can produce an optimized binary as follows:

```shell
rustc -O -Zdebug-info-for-profiling main.rs -o main
rustc -O -Zdebuginfo-for-profiling main.rs -o main
perf record -b ./main
create_llvm_prof --binary=main --out=code.prof
rustc -O -Zprofile-sample-use=code.prof main.rs -o main2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`-Zprofile-sample-use=code.prof` directs `rustc` to use the profile
`code.prof` as a source for Automatic Feedback Directed Optimization (AFDO).
See the documentation of [`-Zdebug-info-for-profiling`] for more information
See the documentation of [`-Zdebuginfo-for-profiling`] for more information
on using AFDO.

[`-Zdebug-info-for-profiling`]: debug_info_for_profiling.html
[`-Zdebuginfo-for-profiling`]: debuginfo_for_profiling.html
30 changes: 30 additions & 0 deletions tests/assembly-llvm/debuginfo-for-profiling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Verify that additional discriminators are emitted for profiling with `-Zdebuginfo-for-profiling`:
// - 0 discriminators are emitted without the flag in the test below
// - 2 discriminators are emitted with the flag in the test below
//
//
//@ revisions: DEFAULT DEBUGINFO_FOR_PROFILING
//@ assembly-output: emit-asm
//@ compile-flags: -Copt-level=2 -Cdebuginfo=line-tables-only
//@ [DEBUGINFO_FOR_PROFILING] compile-flags: -Zdebuginfo-for-profiling
// DEFAULT-NOT: discriminator
// DEBUGINFO_FOR_PROFILING-COUNT-2: discriminator
// DEBUGINFO_FOR_PROFILING-NOT: discriminator

fn main() {
let mut sum = 0;

for i in 1..=20 {
if i % 2 == 0 {
sum += compute(i);
} else {
sum += compute(i) * 2;
}
}

println!("The total sum is: {}", sum);
}

fn compute(x: i32) -> i32 {
if x < 10 { x * x } else { x + 5 }
}
30 changes: 30 additions & 0 deletions tests/codegen-llvm/debuginfo-for-profiling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Verify that additional discriminators are emitted for profiling with `-Zdebuginfo-for-profiling`:
// - 2 discriminators are emitted without the flag in the test below
// - 5 discriminators are emitted with the flag in the test below
//
//
//@ revisions: DEFAULT DEBUGINFO_FOR_PROFILING
//@ compile-flags: -Copt-level=2 -Cdebuginfo=line-tables-only
//@ [DEBUGINFO_FOR_PROFILING] compile-flags: -Zdebuginfo-for-profiling
// DEFAULT-COUNT-2: discriminator:
// DEFAULT-NOT: discriminator:
// DEBUGINFO_FOR_PROFILING-COUNT-5: discriminator:
// DEBUGINFO_FOR_PROFILING-NOT: discriminator:

fn main() {
let mut sum = 0;

for i in 1..=20 {
if i % 2 == 0 {
sum += compute(i);
} else {
sum += compute(i) * 2;
}
}

println!("The total sum is: {}", sum);
}

fn compute(x: i32) -> i32 {
if x < 10 { x * x } else { x + 5 }
}
Loading