@@ -113,6 +113,21 @@ impl LinkerPluginLto {
113113 }
114114}
115115
116+ #[ derive( Clone , PartialEq , Hash ) ]
117+ pub enum PgoGenerate {
118+ Enabled ( Option < PathBuf > ) ,
119+ Disabled ,
120+ }
121+
122+ impl PgoGenerate {
123+ pub fn enabled ( & self ) -> bool {
124+ match * self {
125+ PgoGenerate :: Enabled ( _) => true ,
126+ PgoGenerate :: Disabled => false ,
127+ }
128+ }
129+ }
130+
116131#[ derive( Clone , Copy , PartialEq , Hash ) ]
117132pub enum DebugInfo {
118133 None ,
@@ -826,13 +841,15 @@ macro_rules! options {
826841 pub const parse_linker_plugin_lto: Option <& str > =
827842 Some ( "either a boolean (`yes`, `no`, `on`, `off`, etc), \
828843 or the path to the linker plugin") ;
844+ pub const parse_pgo_generate: Option <& str > =
845+ Some ( "an optional path to the profiling data output directory" ) ;
829846 pub const parse_merge_functions: Option <& str > =
830847 Some ( "one of: `disabled`, `trampolines`, or `aliases`" ) ;
831848 }
832849
833850 #[ allow( dead_code) ]
834851 mod $mod_set {
835- use super :: { $struct_name, Passes , Sanitizer , LtoCli , LinkerPluginLto } ;
852+ use super :: { $struct_name, Passes , Sanitizer , LtoCli , LinkerPluginLto , PgoGenerate } ;
836853 use rustc_target:: spec:: { LinkerFlavor , MergeFunctions , PanicStrategy , RelroLevel } ;
837854 use std:: path:: PathBuf ;
838855 use std:: str :: FromStr ;
@@ -1087,6 +1104,14 @@ macro_rules! options {
10871104 true
10881105 }
10891106
1107+ fn parse_pgo_generate( slot: & mut PgoGenerate , v: Option <& str >) -> bool {
1108+ * slot = match v {
1109+ None => PgoGenerate :: Enabled ( None ) ,
1110+ Some ( path) => PgoGenerate :: Enabled ( Some ( PathBuf :: from( path) ) ) ,
1111+ } ;
1112+ true
1113+ }
1114+
10901115 fn parse_merge_functions( slot: & mut Option <MergeFunctions >, v: Option <& str >) -> bool {
10911116 match v. and_then( |s| MergeFunctions :: from_str( s) . ok( ) ) {
10921117 Some ( mergefunc) => * slot = Some ( mergefunc) ,
@@ -1363,7 +1388,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13631388 "extra arguments to prepend to the linker invocation (space separated)" ) ,
13641389 profile: bool = ( false , parse_bool, [ TRACKED ] ,
13651390 "insert profiling code" ) ,
1366- pgo_gen: Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
1391+ pgo_gen: PgoGenerate = ( PgoGenerate :: Disabled , parse_pgo_generate , [ TRACKED ] ,
13671392 "Generate PGO profile data, to a given file, or to the default location if it's empty." ) ,
13681393 pgo_use: String = ( String :: new( ) , parse_string, [ TRACKED ] ,
13691394 "Use PGO profile data from the given profile file." ) ,
@@ -1980,7 +2005,7 @@ pub fn build_session_options_and_crate_config(
19802005 ) ;
19812006 }
19822007
1983- if debugging_opts. pgo_gen . is_some ( ) && !debugging_opts. pgo_use . is_empty ( ) {
2008+ if debugging_opts. pgo_gen . enabled ( ) && !debugging_opts. pgo_use . is_empty ( ) {
19842009 early_error (
19852010 error_format,
19862011 "options `-Z pgo-gen` and `-Z pgo-use` are exclusive" ,
@@ -2490,7 +2515,7 @@ mod dep_tracking {
24902515 use std:: path:: PathBuf ;
24912516 use std:: collections:: hash_map:: DefaultHasher ;
24922517 use super :: { CrateType , DebugInfo , ErrorOutputType , OptLevel , OutputTypes ,
2493- Passes , Sanitizer , LtoCli , LinkerPluginLto } ;
2518+ Passes , Sanitizer , LtoCli , LinkerPluginLto , PgoGenerate } ;
24942519 use syntax:: feature_gate:: UnstableFeatures ;
24952520 use rustc_target:: spec:: { MergeFunctions , PanicStrategy , RelroLevel , TargetTriple } ;
24962521 use syntax:: edition:: Edition ;
@@ -2558,6 +2583,7 @@ mod dep_tracking {
25582583 impl_dep_tracking_hash_via_hash ! ( TargetTriple ) ;
25592584 impl_dep_tracking_hash_via_hash ! ( Edition ) ;
25602585 impl_dep_tracking_hash_via_hash ! ( LinkerPluginLto ) ;
2586+ impl_dep_tracking_hash_via_hash ! ( PgoGenerate ) ;
25612587
25622588 impl_dep_tracking_hash_for_sortable_vec_of ! ( String ) ;
25632589 impl_dep_tracking_hash_for_sortable_vec_of ! ( PathBuf ) ;
@@ -2625,7 +2651,7 @@ mod tests {
26252651 build_session_options_and_crate_config,
26262652 to_crate_config
26272653 } ;
2628- use crate :: session:: config:: { LtoCli , LinkerPluginLto } ;
2654+ use crate :: session:: config:: { LtoCli , LinkerPluginLto , PgoGenerate } ;
26292655 use crate :: session:: build_session;
26302656 use crate :: session:: search_paths:: SearchPath ;
26312657 use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -3124,7 +3150,7 @@ mod tests {
31243150 assert ! ( reference. dep_tracking_hash( ) != opts. dep_tracking_hash( ) ) ;
31253151
31263152 opts = reference. clone ( ) ;
3127- opts. debugging_opts . pgo_gen = Some ( String :: from ( "abc" ) ) ;
3153+ opts. debugging_opts . pgo_gen = PgoGenerate :: Enabled ( None ) ;
31283154 assert_ne ! ( reference. dep_tracking_hash( ) , opts. dep_tracking_hash( ) ) ;
31293155
31303156 opts = reference. clone ( ) ;
0 commit comments