Skip to content

Commit 76de8a6

Browse files
committed
Remove each_linked_rlib_for_lto from CodegenContext
1 parent 41478d1 commit 76de8a6

File tree

7 files changed

+62
-23
lines changed

7 files changed

+62
-23
lines changed

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct LtoData {
4949

5050
fn prepare_lto(
5151
cgcx: &CodegenContext<GccCodegenBackend>,
52+
each_linked_rlib_for_lto: &[PathBuf],
5253
dcx: DiagCtxtHandle<'_>,
5354
) -> Result<LtoData, FatalError> {
5455
let tmp_path = match tempdir() {
@@ -67,7 +68,7 @@ fn prepare_lto(
6768
// with either fat or thin LTO
6869
let mut upstream_modules = Vec::new();
6970
if cgcx.lto != Lto::ThinLocal {
70-
for &(_cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
71+
for path in each_linked_rlib_for_lto {
7172
let archive_data = unsafe {
7273
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
7374
};
@@ -111,11 +112,12 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
111112
/// for further optimization.
112113
pub(crate) fn run_fat(
113114
cgcx: &CodegenContext<GccCodegenBackend>,
115+
each_linked_rlib_for_lto: &[PathBuf],
114116
modules: Vec<FatLtoInput<GccCodegenBackend>>,
115117
) -> Result<ModuleCodegen<GccContext>, FatalError> {
116118
let dcx = cgcx.create_dcx();
117119
let dcx = dcx.handle();
118-
let lto_data = prepare_lto(cgcx, dcx)?;
120+
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx)?;
119121
/*let symbols_below_threshold =
120122
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
121123
fat_lto(
@@ -281,12 +283,13 @@ impl ModuleBufferMethods for ModuleBuffer {
281283
/// can simply be copied over from the incr. comp. cache.
282284
pub(crate) fn run_thin(
283285
cgcx: &CodegenContext<GccCodegenBackend>,
286+
each_linked_rlib_for_lto: &[PathBuf],
284287
modules: Vec<(String, ThinBuffer)>,
285288
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
286289
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
287290
let dcx = cgcx.create_dcx();
288291
let dcx = dcx.handle();
289-
let lto_data = prepare_lto(cgcx, dcx)?;
292+
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx)?;
290293
if cgcx.opts.cg.linker_plugin_lto.enabled() {
291294
unreachable!(
292295
"We should never reach this case if the LTO step \

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ mod type_of;
8181
use std::any::Any;
8282
use std::fmt::Debug;
8383
use std::ops::Deref;
84+
use std::path::PathBuf;
8485
#[cfg(not(feature = "master"))]
8586
use std::sync::atomic::AtomicBool;
8687
#[cfg(not(feature = "master"))]
@@ -357,24 +358,26 @@ impl WriteBackendMethods for GccCodegenBackend {
357358
cgcx: &CodegenContext<Self>,
358359
// FIXME(bjorn3): Limit LTO exports to these symbols
359360
_exported_symbols_for_lto: &[String],
361+
each_linked_rlib_for_lto: &[PathBuf],
360362
modules: Vec<FatLtoInput<Self>>,
361363
diff_fncs: Vec<AutoDiffItem>,
362364
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
363365
if !diff_fncs.is_empty() {
364366
unimplemented!();
365367
}
366368

367-
back::lto::run_fat(cgcx, modules)
369+
back::lto::run_fat(cgcx, each_linked_rlib_for_lto, modules)
368370
}
369371

370372
fn run_thin_lto(
371373
cgcx: &CodegenContext<Self>,
372374
// FIXME(bjorn3): Limit LTO exports to these symbols
373375
_exported_symbols_for_lto: &[String],
376+
each_linked_rlib_for_lto: &[PathBuf],
374377
modules: Vec<(String, Self::ThinBuffer)>,
375378
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
376379
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError> {
377-
back::lto::run_thin(cgcx, modules, cached_modules)
380+
back::lto::run_thin(cgcx, each_linked_rlib_for_lto, modules, cached_modules)
378381
}
379382

380383
fn print_pass_timings(&self) {

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BTreeMap;
22
use std::ffi::{CStr, CString};
33
use std::fs::File;
4-
use std::path::Path;
4+
use std::path::{Path, PathBuf};
55
use std::ptr::NonNull;
66
use std::sync::Arc;
77
use std::{io, iter, slice};
@@ -34,6 +34,7 @@ const THIN_LTO_KEYS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-keys.bin";
3434
fn prepare_lto(
3535
cgcx: &CodegenContext<LlvmCodegenBackend>,
3636
exported_symbols_for_lto: &[String],
37+
each_linked_rlib_for_lto: &[PathBuf],
3738
dcx: DiagCtxtHandle<'_>,
3839
) -> Result<(Vec<CString>, Vec<(SerializedModule<ModuleBuffer>, CString)>), FatalError> {
3940
let mut symbols_below_threshold = exported_symbols_for_lto
@@ -54,7 +55,7 @@ fn prepare_lto(
5455
// with either fat or thin LTO
5556
let mut upstream_modules = Vec::new();
5657
if cgcx.lto != Lto::ThinLocal {
57-
for &(_cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
58+
for path in each_linked_rlib_for_lto {
5859
let archive_data = unsafe {
5960
Mmap::map(std::fs::File::open(&path).expect("couldn't open rlib"))
6061
.expect("couldn't map rlib")
@@ -136,12 +137,13 @@ fn get_bitcode_slice_from_object_data<'a>(
136137
pub(crate) fn run_fat(
137138
cgcx: &CodegenContext<LlvmCodegenBackend>,
138139
exported_symbols_for_lto: &[String],
140+
each_linked_rlib_for_lto: &[PathBuf],
139141
modules: Vec<FatLtoInput<LlvmCodegenBackend>>,
140142
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {
141143
let dcx = cgcx.create_dcx();
142144
let dcx = dcx.handle();
143145
let (symbols_below_threshold, upstream_modules) =
144-
prepare_lto(cgcx, exported_symbols_for_lto, dcx)?;
146+
prepare_lto(cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx)?;
145147
let symbols_below_threshold =
146148
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
147149
fat_lto(cgcx, dcx, modules, upstream_modules, &symbols_below_threshold)
@@ -153,13 +155,14 @@ pub(crate) fn run_fat(
153155
pub(crate) fn run_thin(
154156
cgcx: &CodegenContext<LlvmCodegenBackend>,
155157
exported_symbols_for_lto: &[String],
158+
each_linked_rlib_for_lto: &[PathBuf],
156159
modules: Vec<(String, ThinBuffer)>,
157160
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
158161
) -> Result<(Vec<ThinModule<LlvmCodegenBackend>>, Vec<WorkProduct>), FatalError> {
159162
let dcx = cgcx.create_dcx();
160163
let dcx = dcx.handle();
161164
let (symbols_below_threshold, upstream_modules) =
162-
prepare_lto(cgcx, exported_symbols_for_lto, dcx)?;
165+
prepare_lto(cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx)?;
163166
let symbols_below_threshold =
164167
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
165168
if cgcx.opts.cg.linker_plugin_lto.enabled() {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use std::any::Any;
2323
use std::ffi::CStr;
2424
use std::mem::ManuallyDrop;
25+
use std::path::PathBuf;
2526

2627
use back::owned_target_machine::OwnedTargetMachine;
2728
use back::write::{create_informational_target_machine, create_target_machine};
@@ -177,10 +178,12 @@ impl WriteBackendMethods for LlvmCodegenBackend {
177178
fn run_and_optimize_fat_lto(
178179
cgcx: &CodegenContext<Self>,
179180
exported_symbols_for_lto: &[String],
181+
each_linked_rlib_for_lto: &[PathBuf],
180182
modules: Vec<FatLtoInput<Self>>,
181183
diff_fncs: Vec<AutoDiffItem>,
182184
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
183-
let mut module = back::lto::run_fat(cgcx, exported_symbols_for_lto, modules)?;
185+
let mut module =
186+
back::lto::run_fat(cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, modules)?;
184187

185188
if !diff_fncs.is_empty() {
186189
builder::autodiff::differentiate(&module, cgcx, diff_fncs)?;
@@ -195,10 +198,17 @@ impl WriteBackendMethods for LlvmCodegenBackend {
195198
fn run_thin_lto(
196199
cgcx: &CodegenContext<Self>,
197200
exported_symbols_for_lto: &[String],
201+
each_linked_rlib_for_lto: &[PathBuf],
198202
modules: Vec<(String, Self::ThinBuffer)>,
199203
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
200204
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError> {
201-
back::lto::run_thin(cgcx, exported_symbols_for_lto, modules, cached_modules)
205+
back::lto::run_thin(
206+
cgcx,
207+
exported_symbols_for_lto,
208+
each_linked_rlib_for_lto,
209+
modules,
210+
cached_modules,
211+
)
202212
}
203213
fn optimize(
204214
cgcx: &CodegenContext<Self>,

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::ffi::CString;
2-
use std::path::PathBuf;
32
use std::sync::Arc;
43

54
use rustc_data_structures::memmap::Mmap;
@@ -75,7 +74,7 @@ fn crate_type_allows_lto(crate_type: CrateType) -> bool {
7574

7675
pub(super) fn exported_symbols_for_lto(
7776
tcx: TyCtxt<'_>,
78-
each_linked_rlib_for_lto: &[(CrateNum, PathBuf)],
77+
each_linked_rlib_for_lto: &[CrateNum],
7978
) -> Vec<String> {
8079
// FIXME move symbol filtering to cg_ssa
8180
let export_threshold = match tcx.sess.lto() {
@@ -128,7 +127,7 @@ pub(super) fn exported_symbols_for_lto(
128127
tcx.sess.dcx().emit_fatal(DynamicLinkingWithLTO);
129128
}
130129

131-
for &(cnum, ref _path) in each_linked_rlib_for_lto {
130+
for &cnum in each_linked_rlib_for_lto {
132131
{
133132
let _timer = tcx.prof.generic_activity("lto_generate_symbols_below_threshold");
134133
symbols_below_threshold.extend(copy_symbols(cnum));

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_errors::{
2020
Suggestions,
2121
};
2222
use rustc_fs_util::link_or_copy;
23-
use rustc_hir::def_id::CrateNum;
2423
use rustc_incremental::{
2524
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
2625
};
@@ -339,7 +338,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
339338
pub time_trace: bool,
340339
pub opts: Arc<config::Options>,
341340
pub crate_types: Vec<CrateType>,
342-
pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>,
343341
pub output_filenames: Arc<OutputFilenames>,
344342
pub invocation_temp: Option<String>,
345343
pub regular_module_config: Arc<ModuleConfig>,
@@ -395,14 +393,20 @@ impl<B: WriteBackendMethods> CodegenContext<B> {
395393
fn generate_thin_lto_work<B: ExtraBackendMethods>(
396394
cgcx: &CodegenContext<B>,
397395
exported_symbols_for_lto: &[String],
396+
each_linked_rlib_for_lto: &[PathBuf],
398397
needs_thin_lto: Vec<(String, B::ThinBuffer)>,
399398
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
400399
) -> Vec<(WorkItem<B>, u64)> {
401400
let _prof_timer = cgcx.prof.generic_activity("codegen_thin_generate_lto_work");
402401

403-
let (lto_modules, copy_jobs) =
404-
B::run_thin_lto(cgcx, exported_symbols_for_lto, needs_thin_lto, import_only_modules)
405-
.unwrap_or_else(|e| e.raise());
402+
let (lto_modules, copy_jobs) = B::run_thin_lto(
403+
cgcx,
404+
exported_symbols_for_lto,
405+
each_linked_rlib_for_lto,
406+
needs_thin_lto,
407+
import_only_modules,
408+
)
409+
.unwrap_or_else(|e| e.raise());
406410
lto_modules
407411
.into_iter()
408412
.map(|module| {
@@ -719,6 +723,7 @@ pub(crate) enum WorkItem<B: WriteBackendMethods> {
719723
/// Performs fat LTO on the given module.
720724
FatLto {
721725
exported_symbols_for_lto: Arc<Vec<String>>,
726+
each_linked_rlib_for_lto: Vec<PathBuf>,
722727
needs_fat_lto: Vec<FatLtoInput<B>>,
723728
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
724729
autodiff: Vec<AutoDiffItem>,
@@ -992,6 +997,7 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
992997
fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
993998
cgcx: &CodegenContext<B>,
994999
exported_symbols_for_lto: &[String],
1000+
each_linked_rlib_for_lto: &[PathBuf],
9951001
mut needs_fat_lto: Vec<FatLtoInput<B>>,
9961002
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
9971003
autodiff: Vec<AutoDiffItem>,
@@ -1001,8 +1007,13 @@ fn execute_fat_lto_work_item<B: ExtraBackendMethods>(
10011007
needs_fat_lto.push(FatLtoInput::Serialized { name: wp.cgu_name, buffer: module })
10021008
}
10031009

1004-
let module =
1005-
B::run_and_optimize_fat_lto(cgcx, exported_symbols_for_lto, needs_fat_lto, autodiff)?;
1010+
let module = B::run_and_optimize_fat_lto(
1011+
cgcx,
1012+
exported_symbols_for_lto,
1013+
each_linked_rlib_for_lto,
1014+
needs_fat_lto,
1015+
autodiff,
1016+
)?;
10061017
let module = B::codegen(cgcx, module, module_config)?;
10071018
Ok(WorkItemResult::Finished(module))
10081019
}
@@ -1118,11 +1129,13 @@ fn start_executing_work<B: ExtraBackendMethods>(
11181129
let autodiff_items = autodiff_items.to_vec();
11191130

11201131
let mut each_linked_rlib_for_lto = Vec::new();
1132+
let mut each_linked_rlib_file_for_lto = Vec::new();
11211133
drop(link::each_linked_rlib(crate_info, None, &mut |cnum, path| {
11221134
if link::ignored_for_lto(sess, crate_info, cnum) {
11231135
return;
11241136
}
1125-
each_linked_rlib_for_lto.push((cnum, path.to_path_buf()));
1137+
each_linked_rlib_for_lto.push(cnum);
1138+
each_linked_rlib_file_for_lto.push(path.to_path_buf());
11261139
}));
11271140

11281141
// Compute the set of symbols we need to retain when doing LTO (if we need to)
@@ -1162,7 +1175,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
11621175

11631176
let cgcx = CodegenContext::<B> {
11641177
crate_types: tcx.crate_types().to_vec(),
1165-
each_linked_rlib_for_lto,
11661178
lto: sess.lto(),
11671179
fewer_names: sess.fewer_names(),
11681180
save_temps: sess.opts.cg.save_temps,
@@ -1435,13 +1447,15 @@ fn start_executing_work<B: ExtraBackendMethods>(
14351447
let needs_fat_lto = mem::take(&mut needs_fat_lto);
14361448
let needs_thin_lto = mem::take(&mut needs_thin_lto);
14371449
let import_only_modules = mem::take(&mut lto_import_only_modules);
1450+
let each_linked_rlib_for_lto = mem::take(&mut each_linked_rlib_file_for_lto);
14381451

14391452
if !needs_fat_lto.is_empty() {
14401453
assert!(needs_thin_lto.is_empty());
14411454

14421455
work_items.push((
14431456
WorkItem::FatLto {
14441457
exported_symbols_for_lto: exported_symbols_for_lto.clone(),
1458+
each_linked_rlib_for_lto,
14451459
needs_fat_lto,
14461460
import_only_modules,
14471461
autodiff: autodiff_items.clone(),
@@ -1460,6 +1474,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14601474
for (work, cost) in generate_thin_lto_work(
14611475
&cgcx,
14621476
&exported_symbols_for_lto,
1477+
&each_linked_rlib_file_for_lto,
14631478
needs_thin_lto,
14641479
import_only_modules,
14651480
) {
@@ -1803,6 +1818,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
18031818
}
18041819
WorkItem::FatLto {
18051820
exported_symbols_for_lto,
1821+
each_linked_rlib_for_lto,
18061822
needs_fat_lto,
18071823
import_only_modules,
18081824
autodiff,
@@ -1813,6 +1829,7 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
18131829
execute_fat_lto_work_item(
18141830
&cgcx,
18151831
&exported_symbols_for_lto,
1832+
&each_linked_rlib_for_lto,
18161833
needs_fat_lto,
18171834
import_only_modules,
18181835
autodiff,

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
24
use rustc_errors::{DiagCtxtHandle, FatalError};
35
use rustc_middle::dep_graph::WorkProduct;
@@ -25,6 +27,7 @@ pub trait WriteBackendMethods: Clone + 'static {
2527
fn run_and_optimize_fat_lto(
2628
cgcx: &CodegenContext<Self>,
2729
exported_symbols_for_lto: &[String],
30+
each_linked_rlib_for_lto: &[PathBuf],
2831
modules: Vec<FatLtoInput<Self>>,
2932
diff_fncs: Vec<AutoDiffItem>,
3033
) -> Result<ModuleCodegen<Self::Module>, FatalError>;
@@ -34,6 +37,7 @@ pub trait WriteBackendMethods: Clone + 'static {
3437
fn run_thin_lto(
3538
cgcx: &CodegenContext<Self>,
3639
exported_symbols_for_lto: &[String],
40+
each_linked_rlib_for_lto: &[PathBuf],
3741
modules: Vec<(String, Self::ThinBuffer)>,
3842
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
3943
) -> Result<(Vec<ThinModule<Self>>, Vec<WorkProduct>), FatalError>;

0 commit comments

Comments
 (0)