Skip to content

Commit e1e4357

Browse files
committed
Remove opts field from CodegenContext
1 parent 15506ca commit e1e4357

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub(crate) fn run_thin(
290290
let dcx = cgcx.create_dcx();
291291
let dcx = dcx.handle();
292292
let lto_data = prepare_lto(cgcx, each_linked_rlib_for_lto, dcx);
293-
if cgcx.opts.cg.linker_plugin_lto.enabled() {
293+
if cgcx.use_linker_plugin_lto {
294294
unreachable!(
295295
"We should never reach this case if the LTO step \
296296
is deferred to the linker"

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub(crate) fn run_thin(
179179
prepare_lto(cgcx, exported_symbols_for_lto, each_linked_rlib_for_lto, dcx);
180180
let symbols_below_threshold =
181181
symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
182-
if cgcx.opts.cg.linker_plugin_lto.enabled() {
182+
if cgcx.use_linker_plugin_lto {
183183
unreachable!(
184184
"We should never reach this case if the LTO step \
185185
is deferred to the linker"

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'a> DiagnosticHandlers<'a> {
398398
})
399399
.and_then(|dir| dir.to_str().and_then(|p| CString::new(p).ok()));
400400

401-
let pgo_available = cgcx.opts.cg.profile_use.is_some();
401+
let pgo_available = cgcx.module_config.pgo_use.is_some();
402402
let data = Box::into_raw(Box::new((cgcx, dcx)));
403403
unsafe {
404404
let old_handler = llvm::LLVMRustContextGetDiagnosticHandler(llcx);
@@ -738,7 +738,7 @@ pub(crate) unsafe fn llvm_optimize(
738738
&*module.module_llvm.tm.raw(),
739739
to_pass_builder_opt_level(opt_level),
740740
opt_stage,
741-
cgcx.opts.cg.linker_plugin_lto.enabled(),
741+
cgcx.use_linker_plugin_lto,
742742
config.no_prepopulate_passes,
743743
config.verify_llvm_ir,
744744
config.lint_llvm_ir,
@@ -801,7 +801,7 @@ pub(crate) fn optimize(
801801
let opt_stage = match cgcx.lto {
802802
Lto::Fat => llvm::OptStage::PreLinkFatLTO,
803803
Lto::Thin | Lto::ThinLocal => llvm::OptStage::PreLinkThinLTO,
804-
_ if cgcx.opts.cg.linker_plugin_lto.enabled() => llvm::OptStage::PreLinkThinLTO,
804+
_ if cgcx.use_linker_plugin_lto => llvm::OptStage::PreLinkThinLTO,
805805
_ => llvm::OptStage::PreLinkNoLTO,
806806
};
807807

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ pub(super) fn check_lto_allowed<B: WriteBackendMethods>(cgcx: &CodegenContext<B>
137137
if !crate_type_allows_lto(*crate_type) {
138138
dcx.handle().emit_fatal(LtoDisallowed);
139139
} else if *crate_type == CrateType::Dylib {
140-
if !cgcx.opts.unstable_opts.dylib_lto {
140+
if !cgcx.dylib_lto {
141141
dcx.handle().emit_fatal(LtoDylib);
142142
}
143-
} else if *crate_type == CrateType::ProcMacro && !cgcx.opts.unstable_opts.dylib_lto {
143+
} else if *crate_type == CrateType::ProcMacro && !cgcx.dylib_lto {
144144
dcx.handle().emit_fatal(LtoProcMacro);
145145
}
146146
}
147147

148-
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
148+
if cgcx.prefer_dynamic && !cgcx.dylib_lto {
149149
dcx.handle().emit_fatal(DynamicLinkingWithLTO);
150150
}
151151
}

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,12 @@ pub struct CodegenContext<B: WriteBackendMethods> {
326326
// Resources needed when running LTO
327327
pub prof: SelfProfilerRef,
328328
pub lto: Lto,
329+
pub use_linker_plugin_lto: bool,
330+
pub dylib_lto: bool,
331+
pub prefer_dynamic: bool,
329332
pub save_temps: bool,
330333
pub fewer_names: bool,
331334
pub time_trace: bool,
332-
pub opts: Arc<config::Options>,
333335
pub crate_types: Vec<CrateType>,
334336
pub output_filenames: Arc<OutputFilenames>,
335337
pub invocation_temp: Option<String>,
@@ -796,13 +798,12 @@ pub(crate) enum ComputedLtoType {
796798

797799
pub(crate) fn compute_per_cgu_lto_type(
798800
sess_lto: &Lto,
799-
opts: &config::Options,
801+
linker_does_lto: bool,
800802
sess_crate_types: &[CrateType],
801803
) -> ComputedLtoType {
802804
// If the linker does LTO, we don't have to do it. Note that we
803805
// keep doing full LTO, if it is requested, as not to break the
804806
// assumption that the output will be a single module.
805-
let linker_does_lto = opts.cg.linker_plugin_lto.enabled();
806807

807808
// We ignore a request for full crate graph LTO if the crate type
808809
// is only an rlib, as there is no full crate graph to process,
@@ -838,7 +839,8 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
838839
// back to the coordinator thread for further LTO processing (which
839840
// has to wait for all the initial modules to be optimized).
840841

841-
let lto_type = compute_per_cgu_lto_type(&cgcx.lto, &cgcx.opts, &cgcx.crate_types);
842+
let lto_type =
843+
compute_per_cgu_lto_type(&cgcx.lto, cgcx.use_linker_plugin_lto, &cgcx.crate_types);
842844

843845
// If we're doing some form of incremental LTO then we need to be sure to
844846
// save our module to disk first.
@@ -1279,10 +1281,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
12791281
let cgcx = CodegenContext::<B> {
12801282
crate_types: tcx.crate_types().to_vec(),
12811283
lto: sess.lto(),
1284+
use_linker_plugin_lto: sess.opts.cg.linker_plugin_lto.enabled(),
1285+
dylib_lto: sess.opts.unstable_opts.dylib_lto,
1286+
prefer_dynamic: sess.opts.cg.prefer_dynamic,
12821287
fewer_names: sess.fewer_names(),
12831288
save_temps: sess.opts.cg.save_temps,
12841289
time_trace: sess.opts.unstable_opts.llvm_time_trace,
1285-
opts: Arc::new(sess.opts.clone()),
12861290
prof: sess.prof.clone(),
12871291
remark: sess.opts.cg.remark.clone(),
12881292
remark_dir,

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,11 @@ pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) ->
11301130
// We can re-use either the pre- or the post-thinlto state. If no LTO is
11311131
// being performed then we can use post-LTO artifacts, otherwise we must
11321132
// reuse pre-LTO artifacts
1133-
match compute_per_cgu_lto_type(&tcx.sess.lto(), &tcx.sess.opts, tcx.crate_types()) {
1133+
match compute_per_cgu_lto_type(
1134+
&tcx.sess.lto(),
1135+
tcx.sess.opts.cg.linker_plugin_lto.enabled(),
1136+
tcx.crate_types(),
1137+
) {
11341138
ComputedLtoType::No => CguReuse::PostLto,
11351139
_ => CguReuse::PreLto,
11361140
}

0 commit comments

Comments
 (0)