mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Remove last remaining ModuleBuffer/ThinBuffer duplication
This commit is contained in:
@@ -86,9 +86,7 @@
|
||||
};
|
||||
use rustc_codegen_ssa::base::codegen_crate;
|
||||
use rustc_codegen_ssa::target_features::cfg_target_feature;
|
||||
use rustc_codegen_ssa::traits::{
|
||||
CodegenBackend, ExtraBackendMethods, ModuleBufferMethods, WriteBackendMethods,
|
||||
};
|
||||
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods};
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
@@ -423,20 +421,11 @@ unsafe impl Send for SyncContext {}
|
||||
// FIXME(antoyo): that shouldn't be Sync. Parallel compilation is currently disabled with "CodegenBackend::supports_parallel()".
|
||||
unsafe impl Sync for SyncContext {}
|
||||
|
||||
pub struct ThinBuffer;
|
||||
|
||||
impl ModuleBufferMethods for ThinBuffer {
|
||||
fn data(&self) -> &[u8] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
||||
impl WriteBackendMethods for GccCodegenBackend {
|
||||
type Module = GccContext;
|
||||
type TargetMachine = ();
|
||||
type ModuleBuffer = ModuleBuffer;
|
||||
type ThinData = ();
|
||||
type ThinBuffer = ThinBuffer;
|
||||
|
||||
fn run_and_optimize_fat_lto(
|
||||
cgcx: &CodegenContext,
|
||||
@@ -458,7 +447,7 @@ fn run_thin_lto(
|
||||
// FIXME(bjorn3): Limit LTO exports to these symbols
|
||||
_exported_symbols_for_lto: &[String],
|
||||
_each_linked_rlib_for_lto: &[PathBuf],
|
||||
_modules: Vec<(String, Self::ThinBuffer)>,
|
||||
_modules: Vec<(String, Self::ModuleBuffer)>,
|
||||
_cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
|
||||
) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>) {
|
||||
unreachable!()
|
||||
@@ -502,11 +491,7 @@ fn codegen(
|
||||
back::write::codegen(cgcx, prof, shared_emitter, module, config)
|
||||
}
|
||||
|
||||
fn prepare_thin(_module: Self::Module) -> Self::ThinBuffer {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn serialize_module(_module: Self::Module) -> Self::ModuleBuffer {
|
||||
fn serialize_module(_module: Self::Module, _is_thin: bool) -> Self::ModuleBuffer {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,6 @@ impl WriteBackendMethods for LlvmCodegenBackend {
|
||||
type ModuleBuffer = back::lto::ModuleBuffer;
|
||||
type TargetMachine = OwnedTargetMachine;
|
||||
type ThinData = back::lto::ThinData;
|
||||
type ThinBuffer = back::lto::ModuleBuffer;
|
||||
fn print_pass_timings(&self) {
|
||||
let timings = llvm::build_string(|s| unsafe { llvm::LLVMRustPrintPassTimings(s) }).unwrap();
|
||||
print!("{timings}");
|
||||
@@ -193,7 +192,7 @@ fn run_thin_lto(
|
||||
dcx: DiagCtxtHandle<'_>,
|
||||
exported_symbols_for_lto: &[String],
|
||||
each_linked_rlib_for_lto: &[PathBuf],
|
||||
modules: Vec<(String, Self::ThinBuffer)>,
|
||||
modules: Vec<(String, Self::ModuleBuffer)>,
|
||||
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
|
||||
) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>) {
|
||||
back::lto::run_thin(
|
||||
@@ -233,11 +232,8 @@ fn codegen(
|
||||
) -> CompiledModule {
|
||||
back::write::codegen(cgcx, prof, shared_emitter, module, config)
|
||||
}
|
||||
fn prepare_thin(module: Self::Module) -> Self::ThinBuffer {
|
||||
back::lto::ModuleBuffer::new(module.llmod(), true)
|
||||
}
|
||||
fn serialize_module(module: Self::Module) -> Self::ModuleBuffer {
|
||||
back::lto::ModuleBuffer::new(module.llmod(), false)
|
||||
fn serialize_module(module: Self::Module, is_thin: bool) -> Self::ModuleBuffer {
|
||||
back::lto::ModuleBuffer::new(module.llmod(), is_thin)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ pub fn data(&self) -> &[u8] {
|
||||
|
||||
pub struct ThinShared<B: WriteBackendMethods> {
|
||||
pub data: B::ThinData,
|
||||
pub thin_buffers: Vec<B::ThinBuffer>,
|
||||
pub thin_buffers: Vec<B::ModuleBuffer>,
|
||||
pub serialized_modules: Vec<SerializedModule<B::ModuleBuffer>>,
|
||||
pub module_names: Vec<CString>,
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ fn generate_thin_lto_work<B: ExtraBackendMethods>(
|
||||
dcx: DiagCtxtHandle<'_>,
|
||||
exported_symbols_for_lto: &[String],
|
||||
each_linked_rlib_for_lto: &[PathBuf],
|
||||
needs_thin_lto: Vec<(String, B::ThinBuffer)>,
|
||||
needs_thin_lto: Vec<(String, B::ModuleBuffer)>,
|
||||
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
|
||||
) -> Vec<(ThinLtoWorkItem<B>, u64)> {
|
||||
let _prof_timer = prof.generic_activity("codegen_thin_generate_lto_work");
|
||||
@@ -416,7 +416,7 @@ enum MaybeLtoModules<B: WriteBackendMethods> {
|
||||
cgcx: CodegenContext,
|
||||
exported_symbols_for_lto: Arc<Vec<String>>,
|
||||
each_linked_rlib_file_for_lto: Vec<PathBuf>,
|
||||
needs_thin_lto: Vec<(String, <B as WriteBackendMethods>::ThinBuffer)>,
|
||||
needs_thin_lto: Vec<(String, <B as WriteBackendMethods>::ModuleBuffer)>,
|
||||
lto_import_only_modules:
|
||||
Vec<(SerializedModule<<B as WriteBackendMethods>::ModuleBuffer>, WorkProduct)>,
|
||||
},
|
||||
@@ -793,7 +793,7 @@ pub(crate) enum WorkItemResult<B: WriteBackendMethods> {
|
||||
|
||||
/// The backend has finished compiling a CGU, which now needs to go through
|
||||
/// thin LTO.
|
||||
NeedsThinLto(String, B::ThinBuffer),
|
||||
NeedsThinLto(String, B::ModuleBuffer),
|
||||
}
|
||||
|
||||
pub enum FatLtoInput<B: WriteBackendMethods> {
|
||||
@@ -868,7 +868,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
|
||||
WorkItemResult::Finished(module)
|
||||
}
|
||||
ComputedLtoType::Thin => {
|
||||
let thin_buffer = B::prepare_thin(module.module_llvm);
|
||||
let thin_buffer = B::serialize_module(module.module_llvm, true);
|
||||
if let Some(path) = bitcode {
|
||||
fs::write(&path, thin_buffer.data()).unwrap_or_else(|e| {
|
||||
panic!("Error writing pre-lto-bitcode file `{}`: {}", path.display(), e);
|
||||
@@ -878,7 +878,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
|
||||
}
|
||||
ComputedLtoType::Fat => match bitcode {
|
||||
Some(path) => {
|
||||
let buffer = B::serialize_module(module.module_llvm);
|
||||
let buffer = B::serialize_module(module.module_llvm, false);
|
||||
fs::write(&path, buffer.data()).unwrap_or_else(|e| {
|
||||
panic!("Error writing pre-lto-bitcode file `{}`: {}", path.display(), e);
|
||||
});
|
||||
@@ -1020,7 +1020,7 @@ fn do_thin_lto<B: ExtraBackendMethods>(
|
||||
tm_factory: TargetMachineFactoryFn<B>,
|
||||
exported_symbols_for_lto: Arc<Vec<String>>,
|
||||
each_linked_rlib_for_lto: Vec<PathBuf>,
|
||||
needs_thin_lto: Vec<(String, <B as WriteBackendMethods>::ThinBuffer)>,
|
||||
needs_thin_lto: Vec<(String, <B as WriteBackendMethods>::ModuleBuffer)>,
|
||||
lto_import_only_modules: Vec<(
|
||||
SerializedModule<<B as WriteBackendMethods>::ModuleBuffer>,
|
||||
WorkProduct,
|
||||
@@ -1804,7 +1804,7 @@ enum CodegenState {
|
||||
));
|
||||
} else {
|
||||
if let Some(allocator_module) = allocator_module.take() {
|
||||
let thin_buffer = B::prepare_thin(allocator_module.module_llvm);
|
||||
let thin_buffer = B::serialize_module(allocator_module.module_llvm, true);
|
||||
needs_thin_lto.push((allocator_module.name, thin_buffer));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ pub trait WriteBackendMethods: Clone + 'static {
|
||||
type TargetMachine;
|
||||
type ModuleBuffer: ModuleBufferMethods;
|
||||
type ThinData: Send + Sync;
|
||||
type ThinBuffer: ModuleBufferMethods;
|
||||
|
||||
/// Performs fat LTO by merging all modules into a single one, running autodiff
|
||||
/// if necessary and running any further optimizations
|
||||
@@ -37,7 +36,7 @@ fn run_thin_lto(
|
||||
dcx: DiagCtxtHandle<'_>,
|
||||
exported_symbols_for_lto: &[String],
|
||||
each_linked_rlib_for_lto: &[PathBuf],
|
||||
modules: Vec<(String, Self::ThinBuffer)>,
|
||||
modules: Vec<(String, Self::ModuleBuffer)>,
|
||||
cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
|
||||
) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>);
|
||||
fn print_pass_timings(&self);
|
||||
@@ -63,8 +62,7 @@ fn codegen(
|
||||
module: ModuleCodegen<Self::Module>,
|
||||
config: &ModuleConfig,
|
||||
) -> CompiledModule;
|
||||
fn prepare_thin(module: Self::Module) -> Self::ThinBuffer;
|
||||
fn serialize_module(module: Self::Module) -> Self::ModuleBuffer;
|
||||
fn serialize_module(module: Self::Module, is_thin: bool) -> Self::ModuleBuffer;
|
||||
}
|
||||
|
||||
pub trait ModuleBufferMethods: Send + Sync {
|
||||
|
||||
Reference in New Issue
Block a user