From 7041ef3cf437acd39262eed4cec0d4aa3c1ff1f9 Mon Sep 17 00:00:00 2001 From: andjo403 Date: Wed, 14 Feb 2018 21:08:21 +0100 Subject: [PATCH] lookup exported symbols only when needed. reduces the time to emit dep-info and metadata. --- src/librustc_trans/back/lto.rs | 9 ++++++--- src/librustc_trans/back/write.rs | 25 ++++++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index 9ff5bcf7a33ca..c440393a25f0a 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -122,8 +122,9 @@ pub(crate) fn run(cgcx: &CodegenContext, None } }; - - let mut symbol_white_list = cgcx.exported_symbols[&LOCAL_CRATE] + let exported_symbols = cgcx.exported_symbols + .as_ref().expect("needs exported symbols for LTO"); + let mut symbol_white_list = exported_symbols[&LOCAL_CRATE] .iter() .filter_map(symbol_filter) .collect::>(); @@ -156,8 +157,10 @@ pub(crate) fn run(cgcx: &CodegenContext, } for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() { + let exported_symbols = cgcx.exported_symbols + .as_ref().expect("needs exported symbols for LTO"); symbol_white_list.extend( - cgcx.exported_symbols[&cnum] + exported_symbols[&cnum] .iter() .filter_map(symbol_filter)); diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index ded9a296817b3..af5178eb565db 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -333,7 +333,7 @@ pub struct CodegenContext { pub no_landing_pads: bool, pub save_temps: bool, pub fewer_names: bool, - pub exported_symbols: Arc, + pub exported_symbols: Option>, pub opts: Arc, pub crate_types: Vec, pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>, @@ -1394,14 +1394,25 @@ fn start_executing_work(tcx: TyCtxt, allocator_config: Arc) -> thread::JoinHandle> { let coordinator_send = tcx.tx_to_llvm_workers.clone(); - let mut exported_symbols = FxHashMap(); - exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE)); - for &cnum in tcx.crates().iter() { - exported_symbols.insert(cnum, tcx.exported_symbols(cnum)); - } - let exported_symbols = Arc::new(exported_symbols); let sess = tcx.sess; + let exported_symbols = match sess.lto() { + Lto::No => None, + Lto::ThinLocal => { + let mut exported_symbols = FxHashMap(); + exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE)); + Some(Arc::new(exported_symbols)) + } + Lto::Yes | Lto::Fat | Lto::Thin => { + let mut exported_symbols = FxHashMap(); + exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE)); + for &cnum in tcx.crates().iter() { + exported_symbols.insert(cnum, tcx.exported_symbols(cnum)); + } + Some(Arc::new(exported_symbols)) + } + }; + // First up, convert our jobserver into a helper thread so we can use normal // mpsc channels to manage our messages and such. // After we've requested tokens then we'll, when we can,