Skip to content

Commit d0b2d84

Browse files
authored
Rollup merge of #152478 - bjorn3:lto_refactors10, r=wesleywiser
Remove tm_factory field from CodegenContext This is necessary to support serializing the `CodegenContext` to a `.rlink` file in the future for moving LTO to the `-Zlink-only` step. Follow up to rust-lang/rust#149209 Part of rust-lang/compiler-team#908
2 parents 4e244c7 + a75ff82 commit d0b2d84

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

src/back/lto.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct LtoData {
5050
}
5151

5252
fn prepare_lto(
53-
cgcx: &CodegenContext<GccCodegenBackend>,
53+
cgcx: &CodegenContext,
5454
each_linked_rlib_for_lto: &[PathBuf],
5555
dcx: DiagCtxtHandle<'_>,
5656
) -> LtoData {
@@ -111,7 +111,7 @@ fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
111111
/// Performs fat LTO by merging all modules into a single one and returning it
112112
/// for further optimization.
113113
pub(crate) fn run_fat(
114-
cgcx: &CodegenContext<GccCodegenBackend>,
114+
cgcx: &CodegenContext,
115115
shared_emitter: &SharedEmitter,
116116
each_linked_rlib_for_lto: &[PathBuf],
117117
modules: Vec<FatLtoInput<GccCodegenBackend>>,
@@ -132,7 +132,7 @@ pub(crate) fn run_fat(
132132
}
133133

134134
fn fat_lto(
135-
cgcx: &CodegenContext<GccCodegenBackend>,
135+
cgcx: &CodegenContext,
136136
_dcx: DiagCtxtHandle<'_>,
137137
modules: Vec<FatLtoInput<GccCodegenBackend>>,
138138
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
@@ -283,7 +283,7 @@ impl ModuleBufferMethods for ModuleBuffer {
283283
/// lists, one of the modules that need optimization and another for modules that
284284
/// can simply be copied over from the incr. comp. cache.
285285
pub(crate) fn run_thin(
286-
cgcx: &CodegenContext<GccCodegenBackend>,
286+
cgcx: &CodegenContext,
287287
dcx: DiagCtxtHandle<'_>,
288288
each_linked_rlib_for_lto: &[PathBuf],
289289
modules: Vec<(String, ThinBuffer)>,
@@ -345,7 +345,7 @@ pub(crate) fn prepare_thin(module: ModuleCodegen<GccContext>) -> (String, ThinBu
345345
/// all of the `LtoModuleCodegen` units returned below and destroyed once
346346
/// they all go out of scope.
347347
fn thin_lto(
348-
cgcx: &CodegenContext<GccCodegenBackend>,
348+
cgcx: &CodegenContext,
349349
_dcx: DiagCtxtHandle<'_>,
350350
modules: Vec<(String, ThinBuffer)>,
351351
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
@@ -520,11 +520,9 @@ fn thin_lto(
520520

521521
pub fn optimize_thin_module(
522522
thin_module: ThinModule<GccCodegenBackend>,
523-
_cgcx: &CodegenContext<GccCodegenBackend>,
523+
_cgcx: &CodegenContext,
524524
) -> ModuleCodegen<GccContext> {
525525
//let module_name = &thin_module.shared.module_names[thin_module.idx];
526-
/*let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
527-
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&dcx, e))?;*/
528526

529527
// Right now the implementation we've got only works over serialized
530528
// modules, so we create a fresh new LLVM context and parse the module

src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use rustc_target::spec::SplitDebuginfo;
1414

1515
use crate::base::add_pic_option;
1616
use crate::errors::CopyBitcode;
17-
use crate::{GccCodegenBackend, GccContext, LtoMode};
17+
use crate::{GccContext, LtoMode};
1818

1919
pub(crate) fn codegen(
20-
cgcx: &CodegenContext<GccCodegenBackend>,
20+
cgcx: &CodegenContext,
2121
shared_emitter: &SharedEmitter,
2222
module: ModuleCodegen<GccContext>,
2323
config: &ModuleConfig,
@@ -227,7 +227,7 @@ pub(crate) fn codegen(
227227
}
228228

229229
pub(crate) fn save_temp_bitcode(
230-
cgcx: &CodegenContext<GccCodegenBackend>,
230+
cgcx: &CodegenContext,
231231
_module: &ModuleCodegen<GccContext>,
232232
_name: &str,
233233
) {

src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
374374
_features: &[String],
375375
) -> TargetMachineFactoryFn<Self> {
376376
// TODO(antoyo): set opt level.
377-
Arc::new(|_| Ok(()))
377+
Arc::new(|_, _| ())
378378
}
379379
}
380380

@@ -421,14 +421,14 @@ unsafe impl Sync for SyncContext {}
421421
impl WriteBackendMethods for GccCodegenBackend {
422422
type Module = GccContext;
423423
type TargetMachine = ();
424-
type TargetMachineError = ();
425424
type ModuleBuffer = ModuleBuffer;
426425
type ThinData = ThinData;
427426
type ThinBuffer = ThinBuffer;
428427

429428
fn run_and_optimize_fat_lto(
430-
cgcx: &CodegenContext<Self>,
429+
cgcx: &CodegenContext,
431430
shared_emitter: &SharedEmitter,
431+
_tm_factory: TargetMachineFactoryFn<Self>,
432432
// FIXME(bjorn3): Limit LTO exports to these symbols
433433
_exported_symbols_for_lto: &[String],
434434
each_linked_rlib_for_lto: &[PathBuf],
@@ -438,7 +438,7 @@ impl WriteBackendMethods for GccCodegenBackend {
438438
}
439439

440440
fn run_thin_lto(
441-
cgcx: &CodegenContext<Self>,
441+
cgcx: &CodegenContext,
442442
dcx: DiagCtxtHandle<'_>,
443443
// FIXME(bjorn3): Limit LTO exports to these symbols
444444
_exported_symbols_for_lto: &[String],
@@ -458,7 +458,7 @@ impl WriteBackendMethods for GccCodegenBackend {
458458
}
459459

460460
fn optimize(
461-
_cgcx: &CodegenContext<Self>,
461+
_cgcx: &CodegenContext,
462462
_shared_emitter: &SharedEmitter,
463463
module: &mut ModuleCodegen<Self::Module>,
464464
config: &ModuleConfig,
@@ -467,15 +467,16 @@ impl WriteBackendMethods for GccCodegenBackend {
467467
}
468468

469469
fn optimize_thin(
470-
cgcx: &CodegenContext<Self>,
470+
cgcx: &CodegenContext,
471471
_shared_emitter: &SharedEmitter,
472+
_tm_factory: TargetMachineFactoryFn<Self>,
472473
thin: ThinModule<Self>,
473474
) -> ModuleCodegen<Self::Module> {
474475
back::lto::optimize_thin_module(thin, cgcx)
475476
}
476477

477478
fn codegen(
478-
cgcx: &CodegenContext<Self>,
479+
cgcx: &CodegenContext,
479480
shared_emitter: &SharedEmitter,
480481
module: ModuleCodegen<Self::Module>,
481482
config: &ModuleConfig,

0 commit comments

Comments
 (0)