From 804f959507ec38f5b3e1f7593c8c3aef5a7a2c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 19 Feb 2018 01:46:39 +0100 Subject: [PATCH] session: Add two tracked, exclusive codegen options for PGO profile usage and generation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- src/librustc/session/config.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f41765b642d..e5d7a618b35 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1027,6 +1027,11 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options, "`-C save-temps` might not produce all requested temporary products \ when incremental compilation is enabled.")], "save all temporary output files during compilation"), + pgo_gen: Option = (None, parse_opt_string, [TRACKED], + "Generate PGO profile data, to a given file, or to the default \ + location if it's empty."), + pgo_use: String = (String::new(), parse_string, [TRACKED], + "Use PGO profile data from the given profile file."), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes"), overflow_checks: Option = (None, parse_opt_bool, [TRACKED], @@ -1801,6 +1806,13 @@ pub fn build_session_options_and_crate_config( let mut codegen_units = cg.codegen_units; let mut disable_thinlto = false; + if cg.pgo_gen.is_some() && !cg.pgo_use.is_empty() { + early_error( + error_format, + "options `-C pgo-gen` and `-C pgo-use` are exclussive", + ); + } + // Issue #30063: if user requests llvm-related output to one // particular path, disable codegen-units. let incompatible: Vec<_> = output_types @@ -2824,6 +2836,14 @@ mod tests { opts.cg.lto = Lto::Fat; assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); + opts = reference.clone(); + opts.cg.pgo_gen = Some(String::from("abc")); + assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); + + opts = reference.clone(); + opts.cg.pgo_use = String::from("abc"); + assert_ne!(reference.dep_tracking_hash(), opts.dep_tracking_hash()); + opts = reference.clone(); opts.cg.target_cpu = Some(String::from("abc")); assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());