@@ -72,6 +72,26 @@ pub enum OptLevel {
7272 SizeMin , // -Oz
7373}
7474
75+ #[ derive( Clone , Copy , PartialEq , Hash ) ]
76+ pub enum Lto {
77+ /// Don't do any LTO whatsoever
78+ No ,
79+
80+ /// Do a full crate graph LTO. The flavor is determined by the compiler
81+ /// (currently the default is "fat").
82+ Yes ,
83+
84+ /// Do a full crate graph LTO with ThinLTO
85+ Thin ,
86+
87+ /// Do a local graph LTO with ThinLTO (only relevant for multiple codegen
88+ /// units).
89+ ThinLocal ,
90+
91+ /// Do a full crate graph LTO with "fat" LTO
92+ Fat ,
93+ }
94+
7595#[ derive( Clone , Copy , PartialEq , Hash ) ]
7696pub enum DebugInfoLevel {
7797 NoDebugInfo ,
@@ -389,7 +409,7 @@ top_level_options!(
389409 // commands like `--emit llvm-ir` which they're often incompatible with
390410 // if we otherwise use the defaults of rustc.
391411 cli_forced_codegen_units: Option <usize > [ UNTRACKED ] ,
392- cli_forced_thinlto : Option < bool > [ UNTRACKED ] ,
412+ cli_forced_thinlto_off : bool [ UNTRACKED ] ,
393413 }
394414) ;
395415
@@ -590,7 +610,7 @@ pub fn basic_options() -> Options {
590610 debug_assertions : true ,
591611 actually_rustdoc : false ,
592612 cli_forced_codegen_units : None ,
593- cli_forced_thinlto : None ,
613+ cli_forced_thinlto_off : false ,
594614 }
595615}
596616
@@ -780,11 +800,13 @@ macro_rules! options {
780800 Some ( "crate=integer" ) ;
781801 pub const parse_unpretty: Option <& ' static str > =
782802 Some ( "`string` or `string=string`" ) ;
803+ pub const parse_lto: Option <& ' static str > =
804+ Some ( "one of `thin`, `fat`, or omitted" ) ;
783805 }
784806
785807 #[ allow( dead_code) ]
786808 mod $mod_set {
787- use super :: { $struct_name, Passes , SomePasses , AllPasses , Sanitizer } ;
809+ use super :: { $struct_name, Passes , SomePasses , AllPasses , Sanitizer , Lto } ;
788810 use rustc_back:: { LinkerFlavor , PanicStrategy , RelroLevel } ;
789811 use std:: path:: PathBuf ;
790812
@@ -978,6 +1000,16 @@ macro_rules! options {
9781000 _ => false ,
9791001 }
9801002 }
1003+
1004+ fn parse_lto( slot: & mut Lto , v: Option <& str >) -> bool {
1005+ * slot = match v {
1006+ None => Lto :: Yes ,
1007+ Some ( "thin" ) => Lto :: Thin ,
1008+ Some ( "fat" ) => Lto :: Fat ,
1009+ Some ( _) => return false ,
1010+ } ;
1011+ true
1012+ }
9811013 }
9821014) }
9831015
@@ -994,7 +1026,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
9941026 "extra arguments to append to the linker invocation (space separated)" ) ,
9951027 link_dead_code: bool = ( false , parse_bool, [ UNTRACKED ] ,
9961028 "don't let linker strip dead code (turning it on can be used for code coverage)" ) ,
997- lto: bool = ( false , parse_bool , [ TRACKED ] ,
1029+ lto: Lto = ( Lto :: No , parse_lto , [ TRACKED ] ,
9981030 "perform LLVM link-time optimizations" ) ,
9991031 target_cpu: Option <String > = ( None , parse_opt_string, [ TRACKED ] ,
10001032 "select target processor (rustc --print target-cpus for details)" ) ,
@@ -1677,7 +1709,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
16771709
16781710 let mut cg = build_codegen_options ( matches, error_format) ;
16791711 let mut codegen_units = cg. codegen_units ;
1680- let mut thinlto = None ;
1712+ let mut disable_thinlto = false ;
16811713
16821714 // Issue #30063: if user requests llvm-related output to one
16831715 // particular path, disable codegen-units.
@@ -1699,12 +1731,12 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
16991731 }
17001732 early_warn ( error_format, "resetting to default -C codegen-units=1" ) ;
17011733 codegen_units = Some ( 1 ) ;
1702- thinlto = Some ( false ) ;
1734+ disable_thinlto = true ;
17031735 }
17041736 }
17051737 _ => {
17061738 codegen_units = Some ( 1 ) ;
1707- thinlto = Some ( false ) ;
1739+ disable_thinlto = true ;
17081740 }
17091741 }
17101742 }
@@ -1734,7 +1766,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17341766 ( & None , & None ) => None ,
17351767 } . map ( |m| PathBuf :: from ( m) ) ;
17361768
1737- if cg. lto && incremental. is_some ( ) {
1769+ if cg. lto != Lto :: No && incremental. is_some ( ) {
17381770 early_error ( error_format, "can't perform LTO when compiling incrementally" ) ;
17391771 }
17401772
@@ -1934,7 +1966,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
19341966 debug_assertions,
19351967 actually_rustdoc : false ,
19361968 cli_forced_codegen_units : codegen_units,
1937- cli_forced_thinlto : thinlto ,
1969+ cli_forced_thinlto_off : disable_thinlto ,
19381970 } ,
19391971 cfg)
19401972}
@@ -2052,7 +2084,7 @@ mod dep_tracking {
20522084 use std:: hash:: Hash ;
20532085 use std:: path:: PathBuf ;
20542086 use std:: collections:: hash_map:: DefaultHasher ;
2055- use super :: { Passes , CrateType , OptLevel , DebugInfoLevel ,
2087+ use super :: { Passes , CrateType , OptLevel , DebugInfoLevel , Lto ,
20562088 OutputTypes , Externs , ErrorOutputType , Sanitizer } ;
20572089 use syntax:: feature_gate:: UnstableFeatures ;
20582090 use rustc_back:: { PanicStrategy , RelroLevel } ;
@@ -2107,6 +2139,7 @@ mod dep_tracking {
21072139 impl_dep_tracking_hash_via_hash ! ( RelroLevel ) ;
21082140 impl_dep_tracking_hash_via_hash ! ( Passes ) ;
21092141 impl_dep_tracking_hash_via_hash ! ( OptLevel ) ;
2142+ impl_dep_tracking_hash_via_hash ! ( Lto ) ;
21102143 impl_dep_tracking_hash_via_hash ! ( DebugInfoLevel ) ;
21112144 impl_dep_tracking_hash_via_hash ! ( UnstableFeatures ) ;
21122145 impl_dep_tracking_hash_via_hash ! ( Externs ) ;
@@ -2180,6 +2213,7 @@ mod tests {
21802213 use lint;
21812214 use middle:: cstore;
21822215 use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
2216+ use session:: config:: Lto ;
21832217 use session:: build_session;
21842218 use std:: collections:: { BTreeMap , BTreeSet } ;
21852219 use std:: iter:: FromIterator ;
@@ -2656,7 +2690,7 @@ mod tests {
26562690
26572691 // Make sure changing a [TRACKED] option changes the hash
26582692 opts = reference. clone ( ) ;
2659- opts. cg . lto = true ;
2693+ opts. cg . lto = Lto :: Fat ;
26602694 assert ! ( reference. dep_tracking_hash( ) != opts. dep_tracking_hash( ) ) ;
26612695
26622696 opts = reference. clone ( ) ;
0 commit comments