Skip to content

Commit 804f959

Browse files
committed
session: Add two tracked, exclusive codegen options for PGO profile usage and generation.
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
1 parent e8a1575 commit 804f959

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/librustc/session/config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
10271027
"`-C save-temps` might not produce all requested temporary products \
10281028
when incremental compilation is enabled.")],
10291029
"save all temporary output files during compilation"),
1030+
pgo_gen: Option<String> = (None, parse_opt_string, [TRACKED],
1031+
"Generate PGO profile data, to a given file, or to the default \
1032+
location if it's empty."),
1033+
pgo_use: String = (String::new(), parse_string, [TRACKED],
1034+
"Use PGO profile data from the given profile file."),
10301035
rpath: bool = (false, parse_bool, [UNTRACKED],
10311036
"set rpath values in libs/exes"),
10321037
overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
@@ -1801,6 +1806,13 @@ pub fn build_session_options_and_crate_config(
18011806
let mut codegen_units = cg.codegen_units;
18021807
let mut disable_thinlto = false;
18031808

1809+
if cg.pgo_gen.is_some() && !cg.pgo_use.is_empty() {
1810+
early_error(
1811+
error_format,
1812+
"options `-C pgo-gen` and `-C pgo-use` are exclussive",
1813+
);
1814+
}
1815+
18041816
// Issue #30063: if user requests llvm-related output to one
18051817
// particular path, disable codegen-units.
18061818
let incompatible: Vec<_> = output_types
@@ -2824,6 +2836,14 @@ mod tests {
28242836
opts.cg.lto = Lto::Fat;
28252837
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
28262838

2839+
opts = reference.clone();
2840+
opts.cg.pgo_gen = Some(String::from("abc"));
2841+
assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2842+
2843+
opts = reference.clone();
2844+
opts.cg.pgo_use = String::from("abc");
2845+
assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
2846+
28272847
opts = reference.clone();
28282848
opts.cg.target_cpu = Some(String::from("abc"));
28292849
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());

0 commit comments

Comments
 (0)