@@ -72,6 +72,26 @@ pub enum OptLevel {
72
72
SizeMin , // -Oz
73
73
}
74
74
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
+
75
95
#[ derive( Clone , Copy , PartialEq , Hash ) ]
76
96
pub enum DebugInfoLevel {
77
97
NoDebugInfo ,
@@ -389,7 +409,7 @@ top_level_options!(
389
409
// commands like `--emit llvm-ir` which they're often incompatible with
390
410
// if we otherwise use the defaults of rustc.
391
411
cli_forced_codegen_units: Option <usize > [ UNTRACKED ] ,
392
- cli_forced_thinlto : Option < bool > [ UNTRACKED ] ,
412
+ cli_forced_thinlto_off : bool [ UNTRACKED ] ,
393
413
}
394
414
) ;
395
415
@@ -590,7 +610,7 @@ pub fn basic_options() -> Options {
590
610
debug_assertions : true ,
591
611
actually_rustdoc : false ,
592
612
cli_forced_codegen_units : None ,
593
- cli_forced_thinlto : None ,
613
+ cli_forced_thinlto_off : false ,
594
614
}
595
615
}
596
616
@@ -780,11 +800,13 @@ macro_rules! options {
780
800
Some ( "crate=integer" ) ;
781
801
pub const parse_unpretty: Option <& ' static str > =
782
802
Some ( "`string` or `string=string`" ) ;
803
+ pub const parse_lto: Option <& ' static str > =
804
+ Some ( "one of `thin`, `fat`, or omitted" ) ;
783
805
}
784
806
785
807
#[ allow( dead_code) ]
786
808
mod $mod_set {
787
- use super :: { $struct_name, Passes , SomePasses , AllPasses , Sanitizer } ;
809
+ use super :: { $struct_name, Passes , SomePasses , AllPasses , Sanitizer , Lto } ;
788
810
use rustc_back:: { LinkerFlavor , PanicStrategy , RelroLevel } ;
789
811
use std:: path:: PathBuf ;
790
812
@@ -978,6 +1000,16 @@ macro_rules! options {
978
1000
_ => false ,
979
1001
}
980
1002
}
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
+ }
981
1013
}
982
1014
) }
983
1015
@@ -994,7 +1026,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
994
1026
"extra arguments to append to the linker invocation (space separated)" ) ,
995
1027
link_dead_code: bool = ( false , parse_bool, [ UNTRACKED ] ,
996
1028
"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 ] ,
998
1030
"perform LLVM link-time optimizations" ) ,
999
1031
target_cpu: Option <String > = ( None , parse_opt_string, [ TRACKED ] ,
1000
1032
"select target processor (rustc --print target-cpus for details)" ) ,
@@ -1677,7 +1709,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1677
1709
1678
1710
let mut cg = build_codegen_options ( matches, error_format) ;
1679
1711
let mut codegen_units = cg. codegen_units ;
1680
- let mut thinlto = None ;
1712
+ let mut disable_thinlto = false ;
1681
1713
1682
1714
// Issue #30063: if user requests llvm-related output to one
1683
1715
// particular path, disable codegen-units.
@@ -1699,12 +1731,12 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1699
1731
}
1700
1732
early_warn ( error_format, "resetting to default -C codegen-units=1" ) ;
1701
1733
codegen_units = Some ( 1 ) ;
1702
- thinlto = Some ( false ) ;
1734
+ disable_thinlto = true ;
1703
1735
}
1704
1736
}
1705
1737
_ => {
1706
1738
codegen_units = Some ( 1 ) ;
1707
- thinlto = Some ( false ) ;
1739
+ disable_thinlto = true ;
1708
1740
}
1709
1741
}
1710
1742
}
@@ -1734,7 +1766,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1734
1766
( & None , & None ) => None ,
1735
1767
} . map ( |m| PathBuf :: from ( m) ) ;
1736
1768
1737
- if cg. lto && incremental. is_some ( ) {
1769
+ if cg. lto != Lto :: No && incremental. is_some ( ) {
1738
1770
early_error ( error_format, "can't perform LTO when compiling incrementally" ) ;
1739
1771
}
1740
1772
@@ -1934,7 +1966,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1934
1966
debug_assertions,
1935
1967
actually_rustdoc : false ,
1936
1968
cli_forced_codegen_units : codegen_units,
1937
- cli_forced_thinlto : thinlto ,
1969
+ cli_forced_thinlto_off : disable_thinlto ,
1938
1970
} ,
1939
1971
cfg)
1940
1972
}
@@ -2052,7 +2084,7 @@ mod dep_tracking {
2052
2084
use std:: hash:: Hash ;
2053
2085
use std:: path:: PathBuf ;
2054
2086
use std:: collections:: hash_map:: DefaultHasher ;
2055
- use super :: { Passes , CrateType , OptLevel , DebugInfoLevel ,
2087
+ use super :: { Passes , CrateType , OptLevel , DebugInfoLevel , Lto ,
2056
2088
OutputTypes , Externs , ErrorOutputType , Sanitizer } ;
2057
2089
use syntax:: feature_gate:: UnstableFeatures ;
2058
2090
use rustc_back:: { PanicStrategy , RelroLevel } ;
@@ -2107,6 +2139,7 @@ mod dep_tracking {
2107
2139
impl_dep_tracking_hash_via_hash ! ( RelroLevel ) ;
2108
2140
impl_dep_tracking_hash_via_hash ! ( Passes ) ;
2109
2141
impl_dep_tracking_hash_via_hash ! ( OptLevel ) ;
2142
+ impl_dep_tracking_hash_via_hash ! ( Lto ) ;
2110
2143
impl_dep_tracking_hash_via_hash ! ( DebugInfoLevel ) ;
2111
2144
impl_dep_tracking_hash_via_hash ! ( UnstableFeatures ) ;
2112
2145
impl_dep_tracking_hash_via_hash ! ( Externs ) ;
@@ -2180,6 +2213,7 @@ mod tests {
2180
2213
use lint;
2181
2214
use middle:: cstore;
2182
2215
use session:: config:: { build_configuration, build_session_options_and_crate_config} ;
2216
+ use session:: config:: Lto ;
2183
2217
use session:: build_session;
2184
2218
use std:: collections:: { BTreeMap , BTreeSet } ;
2185
2219
use std:: iter:: FromIterator ;
@@ -2656,7 +2690,7 @@ mod tests {
2656
2690
2657
2691
// Make sure changing a [TRACKED] option changes the hash
2658
2692
opts = reference. clone ( ) ;
2659
- opts. cg . lto = true ;
2693
+ opts. cg . lto = Lto :: Fat ;
2660
2694
assert ! ( reference. dep_tracking_hash( ) != opts. dep_tracking_hash( ) ) ;
2661
2695
2662
2696
opts = reference. clone ( ) ;
0 commit comments