Enable AutoFDO.
This largely involves implementing the options debug-info-for-profiling and profile-sample-use and forwarding them on to LLVM. AutoFDO can be used on x86-64 Linux like this: rustc -O -Cdebug-info-for-profiling main.rs -o main perf record -b ./main create_llvm_prof --binary=main --out=code.prof rustc -O -Cprofile-sample-use=code.prof main.rs -o main2 Now `main2` will have feedback directed optimization applied to it. The create_llvm_prof tool can be obtained from this github repository: https://github.com/google/autofdo Fixes #64892.
This commit is contained in:
parent
d7539a6af0
commit
a17193dbb9
12 changed files with 120 additions and 9 deletions
|
@ -2009,6 +2009,15 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||
);
|
||||
}
|
||||
|
||||
if debugging_opts.profile_sample_use.is_some()
|
||||
&& (cg.profile_generate.enabled() || cg.profile_use.is_some())
|
||||
{
|
||||
early_error(
|
||||
error_format,
|
||||
"option `-Z profile-sample-use` cannot be used with `-C profile-generate` or `-C profile-use`",
|
||||
);
|
||||
}
|
||||
|
||||
if debugging_opts.instrument_coverage.is_some()
|
||||
&& debugging_opts.instrument_coverage != Some(InstrumentCoverage::Off)
|
||||
{
|
||||
|
|
|
@ -1040,6 +1040,8 @@ options! {
|
|||
"combine CGUs into a single one"),
|
||||
crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
|
||||
"inject the given attribute in the crate"),
|
||||
debug_info_for_profiling: bool = (false, parse_bool, [TRACKED],
|
||||
"emit discriminators and other data necessary for AutoFDO"),
|
||||
debug_macros: bool = (false, parse_bool, [TRACKED],
|
||||
"emit line numbers debug info inside macros (default: no)"),
|
||||
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
|
||||
|
@ -1242,6 +1244,8 @@ options! {
|
|||
(default based on relative source path)"),
|
||||
profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
|
||||
"name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
|
||||
profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
|
||||
"use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
|
||||
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
|
||||
"enable queries of the dependency graph for regression testing (default: no)"),
|
||||
query_stats: bool = (false, parse_bool, [UNTRACKED],
|
||||
|
|
|
@ -1353,6 +1353,16 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
|
|||
}
|
||||
}
|
||||
|
||||
// Do the same for sample profile data.
|
||||
if let Some(ref path) = sess.opts.debugging_opts.profile_sample_use {
|
||||
if !path.exists() {
|
||||
sess.err(&format!(
|
||||
"File `{}` passed to `-C profile-sample-use` does not exist.",
|
||||
path.display()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Unwind tables cannot be disabled if the target requires them.
|
||||
if let Some(include_uwtables) = sess.opts.cg.force_unwind_tables {
|
||||
if sess.target.requires_uwtable && !include_uwtables {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue