Skip to content

Commit 9431427

Browse files
committed
Add new_regular and new_allocator to ModuleCodegen
1 parent f32ca1a commit 9431427

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

Diff for: compiler/rustc_codegen_gcc/src/back/lto.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,16 @@ pub unsafe fn optimize_thin_module(
632632
Arc::new(SyncContext::new(context))
633633
}
634634
};
635-
let module = ModuleCodegen {
636-
module_llvm: GccContext {
635+
let module = ModuleCodegen::new_regular(
636+
thin_module.name().to_string(),
637+
GccContext {
637638
context,
638639
should_combine_object_files,
639640
// TODO(antoyo): use the correct relocation model here.
640641
relocation_model: RelocModel::Pic,
641642
temp_dir: None,
642643
},
643-
name: thin_module.name().to_string(),
644-
kind: ModuleKind::Regular,
645-
};
644+
);
646645
/*{
647646
let target = &*module.module_llvm.tm;
648647
let llmod = module.module_llvm.llmod();

Diff for: compiler/rustc_codegen_gcc/src/base.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::sync::Arc;
44
use std::time::Instant;
55

66
use gccjit::{CType, Context, FunctionType, GlobalKind};
7+
use rustc_codegen_ssa::ModuleCodegen;
78
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
89
use rustc_codegen_ssa::mono_item::MonoItemExt;
910
use rustc_codegen_ssa::traits::DebugInfoCodegenMethods;
10-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
1111
use rustc_middle::dep_graph;
1212
use rustc_middle::mir::mono::Linkage;
1313
#[cfg(feature = "master")]
@@ -237,16 +237,15 @@ pub fn compile_codegen_unit(
237237
}
238238
}
239239

240-
ModuleCodegen {
241-
name: cgu_name.to_string(),
242-
module_llvm: GccContext {
240+
ModuleCodegen::new_regular(
241+
cgu_name.to_string(),
242+
GccContext {
243243
context: Arc::new(SyncContext::new(context)),
244244
relocation_model: tcx.sess.relocation_model(),
245245
should_combine_object_files: false,
246246
temp_dir: None,
247247
},
248-
kind: ModuleKind::Regular,
249-
}
248+
)
250249
}
251250

252251
(module, cost)

Diff for: compiler/rustc_codegen_llvm/src/back/lto.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,8 @@ fn fat_lto(
306306
assert!(!serialized_modules.is_empty(), "must have at least one serialized module");
307307
let (buffer, name) = serialized_modules.remove(0);
308308
info!("no in-memory regular modules to choose from, parsing {:?}", name);
309-
ModuleCodegen {
310-
module_llvm: ModuleLlvm::parse(cgcx, &name, buffer.data(), dcx)?,
311-
name: name.into_string().unwrap(),
312-
kind: ModuleKind::Regular,
313-
}
309+
let llvm_module = ModuleLlvm::parse(cgcx, &name, buffer.data(), dcx)?;
310+
ModuleCodegen::new_regular(name.into_string().unwrap(), llvm_module)
314311
}
315312
};
316313
{
@@ -778,11 +775,7 @@ pub(crate) unsafe fn optimize_thin_module(
778775
// crates but for locally codegened modules we may be able to reuse
779776
// that LLVM Context and Module.
780777
let module_llvm = ModuleLlvm::parse(cgcx, module_name, thin_module.data(), dcx)?;
781-
let mut module = ModuleCodegen {
782-
module_llvm,
783-
name: thin_module.name().to_string(),
784-
kind: ModuleKind::Regular,
785-
};
778+
let mut module = ModuleCodegen::new_regular(thin_module.name(), module_llvm);
786779
{
787780
let target = &*module.module_llvm.tm;
788781
let llmod = module.module_llvm.llmod();

Diff for: compiler/rustc_codegen_llvm/src/base.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
1414
use std::time::Instant;
1515

16+
use rustc_codegen_ssa::ModuleCodegen;
1617
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
1718
use rustc_codegen_ssa::mono_item::MonoItemExt;
1819
use rustc_codegen_ssa::traits::*;
19-
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
2020
use rustc_data_structures::small_c_str::SmallCStr;
2121
use rustc_middle::dep_graph;
2222
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@@ -133,11 +133,7 @@ pub(crate) fn compile_codegen_unit(
133133
}
134134
}
135135

136-
ModuleCodegen {
137-
name: cgu_name.to_string(),
138-
module_llvm: llvm_module,
139-
kind: ModuleKind::Regular,
140-
}
136+
ModuleCodegen::new_regular(cgu_name.to_string(), llvm_module)
141137
}
142138

143139
(module, cost)

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
686686
submit_codegened_module_to_llvm(
687687
&backend,
688688
&ongoing_codegen.coordinator.sender,
689-
ModuleCodegen { name: llmod_id, module_llvm, kind: ModuleKind::Allocator },
689+
ModuleCodegen::new_allocator(llmod_id, module_llvm),
690690
cost,
691691
);
692692
}

Diff for: compiler/rustc_codegen_ssa/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ pub struct ModuleCodegen<M> {
7878
}
7979

8080
impl<M> ModuleCodegen<M> {
81+
pub fn new_regular(name: impl Into<String>, module: M) -> Self {
82+
Self { name: name.into(), module_llvm: module, kind: ModuleKind::Regular }
83+
}
84+
85+
pub fn new_allocator(name: impl Into<String>, module: M) -> Self {
86+
Self { name: name.into(), module_llvm: module, kind: ModuleKind::Allocator }
87+
}
88+
8189
pub fn into_compiled_module(
8290
self,
8391
emit_obj: bool,

0 commit comments

Comments
 (0)