Skip to content

Commit 5297ef0

Browse files
committed
Special case allocator module submission to avoid special casing it elsewhere
A lot of places had special handling just in case they would get an allocator module even though most of these places could never get one or would have a trivial implementation for the allocator module. Moving all handling of the allocator module to a single place simplifies things a fair bit.
1 parent 5b0b516 commit 5297ef0

File tree

6 files changed

+75
-140
lines changed

6 files changed

+75
-140
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use cranelift_object::{ObjectBuilder, ObjectModule};
1212
use rustc_codegen_ssa::assert_module_sources::CguReuse;
1313
use rustc_codegen_ssa::back::link::ensure_removed;
1414
use rustc_codegen_ssa::base::determine_cgu_reuse;
15-
use rustc_codegen_ssa::{
16-
CodegenResults, CompiledModule, CrateInfo, ModuleKind, errors as ssa_errors,
17-
};
15+
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, errors as ssa_errors};
1816
use rustc_data_structures::profiling::SelfProfilerRef;
1917
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2018
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
@@ -363,7 +361,6 @@ fn emit_cgu(
363361
invocation_temp,
364362
prof,
365363
product.object,
366-
ModuleKind::Regular,
367364
name.clone(),
368365
producer,
369366
)?;
@@ -372,7 +369,6 @@ fn emit_cgu(
372369
module_regular,
373370
module_global_asm: global_asm_object_file.map(|global_asm_object_file| CompiledModule {
374371
name: format!("{name}.asm"),
375-
kind: ModuleKind::Regular,
376372
object: Some(global_asm_object_file),
377373
dwarf_object: None,
378374
bytecode: None,
@@ -389,7 +385,6 @@ fn emit_module(
389385
invocation_temp: Option<&str>,
390386
prof: &SelfProfilerRef,
391387
mut object: cranelift_object::object::write::Object<'_>,
392-
kind: ModuleKind,
393388
name: String,
394389
producer_str: &str,
395390
) -> Result<CompiledModule, String> {
@@ -430,7 +425,6 @@ fn emit_module(
430425

431426
Ok(CompiledModule {
432427
name,
433-
kind,
434428
object: Some(tmp_file),
435429
dwarf_object: None,
436430
bytecode: None,
@@ -485,7 +479,6 @@ fn reuse_workproduct_for_cgu(
485479
Ok(ModuleCodegenResult {
486480
module_regular: CompiledModule {
487481
name: cgu.name().to_string(),
488-
kind: ModuleKind::Regular,
489482
object: Some(obj_out_regular),
490483
dwarf_object: None,
491484
bytecode: None,
@@ -495,7 +488,6 @@ fn reuse_workproduct_for_cgu(
495488
},
496489
module_global_asm: source_file_global_asm.map(|source_file| CompiledModule {
497490
name: cgu.name().to_string(),
498-
kind: ModuleKind::Regular,
499491
object: Some(obj_out_global_asm),
500492
dwarf_object: None,
501493
bytecode: None,
@@ -651,7 +643,6 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
651643
tcx.sess.invocation_temp.as_deref(),
652644
&tcx.sess.prof,
653645
product.object,
654-
ModuleKind::Allocator,
655646
"allocator_shim".to_owned(),
656647
&crate::debuginfo::producer(tcx.sess),
657648
) {

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn fat_lto(
204204
let path = tmp_path.path().to_path_buf().join(&module.name);
205205
let path = path.to_str().expect("path");
206206
let context = &module.module_llvm.context;
207-
let config = cgcx.config(module.kind);
207+
let config = &cgcx.module_config;
208208
// NOTE: we need to set the optimization level here in order for LTO to do its job.
209209
context.set_optimization_level(to_gcc_opt_level(config.opt_level));
210210
context.add_command_line_option("-flto=auto");

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use object::{Object, ObjectSection};
1111
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
1212
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
1313
use rustc_codegen_ssa::traits::*;
14-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind, looks_like_rust_object_file};
14+
use rustc_codegen_ssa::{ModuleCodegen, looks_like_rust_object_file};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_data_structures::memmap::Mmap;
1717
use rustc_errors::DiagCtxtHandle;
@@ -195,15 +195,9 @@ fn fat_lto(
195195
// All the other modules will be serialized and reparsed into the new
196196
// context, so this hopefully avoids serializing and parsing the largest
197197
// codegen unit.
198-
//
199-
// Additionally use a regular module as the base here to ensure that various
200-
// file copy operations in the backend work correctly. The only other kind
201-
// of module here should be an allocator one, and if your crate is smaller
202-
// than the allocator module then the size doesn't really matter anyway.
203198
let costliest_module = in_memory
204199
.iter()
205200
.enumerate()
206-
.filter(|&(_, module)| module.kind == ModuleKind::Regular)
207201
.map(|(i, module)| {
208202
let cost = unsafe { llvm::LLVMRustModuleCost(module.module_llvm.llmod()) };
209203
(cost, i)
@@ -551,7 +545,7 @@ pub(crate) fn run_pass_manager(
551545
thin: bool,
552546
) {
553547
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
554-
let config = cgcx.config(module.kind);
548+
let config = &cgcx.module_config;
555549

556550
// Now we have one massive module inside of llmod. Time to run the
557551
// LTO-specific optimization passes that LLVM provides.
@@ -713,7 +707,7 @@ pub(crate) fn optimize_thin_module(
713707
let module_llvm = ModuleLlvm::parse(cgcx, module_name, thin_module.data(), dcx);
714708
let mut module = ModuleCodegen::new_regular(thin_module.name(), module_llvm);
715709
// Given that the newly created module lacks a thinlto buffer for embedding, we need to re-add it here.
716-
if cgcx.config(ModuleKind::Regular).embed_bitcode() {
710+
if cgcx.module_config.embed_bitcode() {
717711
module.thin_lto_buffer = Some(thin_module.data().to_vec());
718712
}
719713
{

0 commit comments

Comments
 (0)