@@ -113,6 +113,21 @@ impl LinkerPluginLto {
113
113
}
114
114
}
115
115
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
+
116
131
#[ derive( Clone , Copy , PartialEq , Hash ) ]
117
132
pub enum DebugInfo {
118
133
None ,
@@ -826,13 +841,15 @@ macro_rules! options {
826
841
pub const parse_linker_plugin_lto: Option <& str > =
827
842
Some ( "either a boolean (`yes`, `no`, `on`, `off`, etc), \
828
843
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" ) ;
829
846
pub const parse_merge_functions: Option <& str > =
830
847
Some ( "one of: `disabled`, `trampolines`, or `aliases`" ) ;
831
848
}
832
849
833
850
#[ allow( dead_code) ]
834
851
mod $mod_set {
835
- use super :: { $struct_name, Passes , Sanitizer , LtoCli , LinkerPluginLto } ;
852
+ use super :: { $struct_name, Passes , Sanitizer , LtoCli , LinkerPluginLto , PgoGenerate } ;
836
853
use rustc_target:: spec:: { LinkerFlavor , MergeFunctions , PanicStrategy , RelroLevel } ;
837
854
use std:: path:: PathBuf ;
838
855
use std:: str :: FromStr ;
@@ -1087,6 +1104,14 @@ macro_rules! options {
1087
1104
true
1088
1105
}
1089
1106
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
+
1090
1115
fn parse_merge_functions( slot: & mut Option <MergeFunctions >, v: Option <& str >) -> bool {
1091
1116
match v. and_then( |s| MergeFunctions :: from_str( s) . ok( ) ) {
1092
1117
Some ( mergefunc) => * slot = Some ( mergefunc) ,
@@ -1363,7 +1388,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
1363
1388
"extra arguments to prepend to the linker invocation (space separated)" ) ,
1364
1389
profile: bool = ( false , parse_bool, [ TRACKED ] ,
1365
1390
"insert profiling code" ) ,
1366
- pgo_gen: Option < String > = ( None , parse_opt_string , [ TRACKED ] ,
1391
+ pgo_gen: PgoGenerate = ( PgoGenerate :: Disabled , parse_pgo_generate , [ TRACKED ] ,
1367
1392
"Generate PGO profile data, to a given file, or to the default location if it's empty." ) ,
1368
1393
pgo_use: String = ( String :: new( ) , parse_string, [ TRACKED ] ,
1369
1394
"Use PGO profile data from the given profile file." ) ,
@@ -1980,7 +2005,7 @@ pub fn build_session_options_and_crate_config(
1980
2005
) ;
1981
2006
}
1982
2007
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 ( ) {
1984
2009
early_error (
1985
2010
error_format,
1986
2011
"options `-Z pgo-gen` and `-Z pgo-use` are exclusive" ,
@@ -2490,7 +2515,7 @@ mod dep_tracking {
2490
2515
use std:: path:: PathBuf ;
2491
2516
use std:: collections:: hash_map:: DefaultHasher ;
2492
2517
use super :: { CrateType , DebugInfo , ErrorOutputType , OptLevel , OutputTypes ,
2493
- Passes , Sanitizer , LtoCli , LinkerPluginLto } ;
2518
+ Passes , Sanitizer , LtoCli , LinkerPluginLto , PgoGenerate } ;
2494
2519
use syntax:: feature_gate:: UnstableFeatures ;
2495
2520
use rustc_target:: spec:: { MergeFunctions , PanicStrategy , RelroLevel , TargetTriple } ;
2496
2521
use syntax:: edition:: Edition ;
@@ -2558,6 +2583,7 @@ mod dep_tracking {
2558
2583
impl_dep_tracking_hash_via_hash ! ( TargetTriple ) ;
2559
2584
impl_dep_tracking_hash_via_hash ! ( Edition ) ;
2560
2585
impl_dep_tracking_hash_via_hash ! ( LinkerPluginLto ) ;
2586
+ impl_dep_tracking_hash_via_hash ! ( PgoGenerate ) ;
2561
2587
2562
2588
impl_dep_tracking_hash_for_sortable_vec_of ! ( String ) ;
2563
2589
impl_dep_tracking_hash_for_sortable_vec_of ! ( PathBuf ) ;
@@ -2625,7 +2651,7 @@ mod tests {
2625
2651
build_session_options_and_crate_config,
2626
2652
to_crate_config
2627
2653
} ;
2628
- use crate :: session:: config:: { LtoCli , LinkerPluginLto } ;
2654
+ use crate :: session:: config:: { LtoCli , LinkerPluginLto , PgoGenerate } ;
2629
2655
use crate :: session:: build_session;
2630
2656
use crate :: session:: search_paths:: SearchPath ;
2631
2657
use std:: collections:: { BTreeMap , BTreeSet } ;
@@ -3124,7 +3150,7 @@ mod tests {
3124
3150
assert ! ( reference. dep_tracking_hash( ) != opts. dep_tracking_hash( ) ) ;
3125
3151
3126
3152
opts = reference. clone ( ) ;
3127
- opts. debugging_opts . pgo_gen = Some ( String :: from ( "abc" ) ) ;
3153
+ opts. debugging_opts . pgo_gen = PgoGenerate :: Enabled ( None ) ;
3128
3154
assert_ne ! ( reference. dep_tracking_hash( ) , opts. dep_tracking_hash( ) ) ;
3129
3155
3130
3156
opts = reference. clone ( ) ;
0 commit comments