Skip to content

Commit 78c65a5

Browse files
committed
Merge new_metadata into codegen_allocator
1 parent fab7230 commit 78c65a5

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

compiler/rustc_codegen_gcc/src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,12 @@ impl CodegenBackend for GccCodegenBackend {
139139
}
140140

141141
impl ExtraBackendMethods for GccCodegenBackend {
142-
fn new_metadata<'tcx>(&self, _tcx: TyCtxt<'tcx>, _mod_name: &str) -> Self::Module {
143-
GccContext {
142+
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) -> Self::Module {
143+
let mut mods = GccContext {
144144
context: Context::default(),
145-
}
146-
}
147-
148-
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, mods: &mut Self::Module, module_name: &str, kind: AllocatorKind, has_alloc_error_handler: bool) {
149-
unsafe { allocator::codegen(tcx, mods, module_name, kind, has_alloc_error_handler) }
145+
};
146+
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, has_alloc_error_handler); }
147+
mods
150148
}
151149

152150
fn compile_codegen_unit<'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (ModuleCodegen<Self::Module>, u64) {

compiler/rustc_codegen_llvm/src/lib.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,18 @@ impl Drop for TimeTraceProfiler {
104104
}
105105

106106
impl ExtraBackendMethods for LlvmCodegenBackend {
107-
fn new_metadata(&self, tcx: TyCtxt<'_>, mod_name: &str) -> ModuleLlvm {
108-
ModuleLlvm::new_metadata(tcx, mod_name)
109-
}
110-
111107
fn codegen_allocator<'tcx>(
112108
&self,
113109
tcx: TyCtxt<'tcx>,
114-
module_llvm: &mut ModuleLlvm,
115110
module_name: &str,
116111
kind: AllocatorKind,
117112
has_alloc_error_handler: bool,
118-
) {
119-
unsafe { allocator::codegen(tcx, module_llvm, module_name, kind, has_alloc_error_handler) }
113+
) -> ModuleLlvm {
114+
let mut module_llvm = ModuleLlvm::new_metadata(tcx, module_name);
115+
unsafe {
116+
allocator::codegen(tcx, &mut module_llvm, module_name, kind, has_alloc_error_handler);
117+
}
118+
module_llvm
120119
}
121120
fn compile_codegen_unit(
122121
&self,

compiler/rustc_codegen_ssa/src/back/lto.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
6969
) -> Result<ModuleCodegen<B::Module>, FatalError> {
7070
match self {
7171
LtoModuleCodegen::Fat { mut module, .. } => {
72-
{
73-
B::optimize_fat(cgcx, &mut module)?;
74-
}
72+
B::optimize_fat(cgcx, &mut module)?;
7573
Ok(module)
7674
}
7775
LtoModuleCodegen::Thin(thin) => B::optimize_thin(cgcx, thin),

compiler/rustc_codegen_ssa/src/base.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,8 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
575575
} else if let Some(kind) = tcx.allocator_kind(()) {
576576
let llmod_id =
577577
cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string();
578-
let mut module_llvm = backend.new_metadata(tcx, &llmod_id);
579-
tcx.sess.time("write_allocator_module", || {
580-
backend.codegen_allocator(
581-
tcx,
582-
&mut module_llvm,
583-
&llmod_id,
584-
kind,
585-
tcx.lang_items().oom().is_some(),
586-
)
578+
let module_llvm = tcx.sess.time("write_allocator_module", || {
579+
backend.codegen_allocator(tcx, &llmod_id, kind, tcx.lang_items().oom().is_some())
587580
});
588581

589582
Some(ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator })

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,13 @@ pub trait CodegenBackend {
114114
}
115115

116116
pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
117-
fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module;
118117
fn codegen_allocator<'tcx>(
119118
&self,
120119
tcx: TyCtxt<'tcx>,
121-
module_llvm: &mut Self::Module,
122120
module_name: &str,
123121
kind: AllocatorKind,
124122
has_alloc_error_handler: bool,
125-
);
123+
) -> Self::Module;
126124
/// This generates the codegen unit and returns it along with
127125
/// a `u64` giving an estimate of the unit's processing cost.
128126
fn compile_codegen_unit(

0 commit comments

Comments
 (0)