Skip to main content

rustc_codegen_ssa/traits/
write.rs

1use std::path::PathBuf;
2
3use rustc_data_structures::profiling::SelfProfilerRef;
4use rustc_errors::DiagCtxtHandle;
5use rustc_middle::dep_graph::WorkProduct;
6
7use crate::back::lto::{SerializedModule, ThinModule};
8use crate::back::write::{
9    CodegenContext, FatLtoInput, ModuleConfig, SharedEmitter, TargetMachineFactoryFn,
10};
11use crate::{CompiledModule, ModuleCodegen};
12
13pub trait WriteBackendMethods: Clone + 'static {
14    type Module: Send + Sync;
15    type TargetMachine;
16    type ModuleBuffer: ModuleBufferMethods;
17    type ThinData: Send + Sync;
18    type ThinBuffer: ThinBufferMethods;
19
20    /// Performs fat LTO by merging all modules into a single one, running autodiff
21    /// if necessary and running any further optimizations
22    fn run_and_optimize_fat_lto(
23        cgcx: &CodegenContext,
24        prof: &SelfProfilerRef,
25        shared_emitter: &SharedEmitter,
26        tm_factory: TargetMachineFactoryFn<Self>,
27        exported_symbols_for_lto: &[String],
28        each_linked_rlib_for_lto: &[PathBuf],
29        modules: Vec<FatLtoInput<Self>>,
30    ) -> ModuleCodegen<Self::Module>;
31    /// Performs thin LTO by performing necessary global analysis and returning two
32    /// lists, one of the modules that need optimization and another for modules that
33    /// can simply be copied over from the incr. comp. cache.
34    fn run_thin_lto(
35        cgcx: &CodegenContext,
36        prof: &SelfProfilerRef,
37        dcx: DiagCtxtHandle<'_>,
38        exported_symbols_for_lto: &[String],
39        each_linked_rlib_for_lto: &[PathBuf],
40        modules: Vec<(String, Self::ThinBuffer)>,
41        cached_modules: Vec<(SerializedModule<Self::ModuleBuffer>, WorkProduct)>,
42    ) -> (Vec<ThinModule<Self>>, Vec<WorkProduct>);
43    fn print_pass_timings(&self);
44    fn print_statistics(&self);
45    fn optimize(
46        cgcx: &CodegenContext,
47        prof: &SelfProfilerRef,
48        shared_emitter: &SharedEmitter,
49        module: &mut ModuleCodegen<Self::Module>,
50        config: &ModuleConfig,
51    );
52    fn optimize_thin(
53        cgcx: &CodegenContext,
54        prof: &SelfProfilerRef,
55        shared_emitter: &SharedEmitter,
56        tm_factory: TargetMachineFactoryFn<Self>,
57        thin: ThinModule<Self>,
58    ) -> ModuleCodegen<Self::Module>;
59    fn codegen(
60        cgcx: &CodegenContext,
61        prof: &SelfProfilerRef,
62        shared_emitter: &SharedEmitter,
63        module: ModuleCodegen<Self::Module>,
64        config: &ModuleConfig,
65    ) -> CompiledModule;
66    fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer);
67    fn serialize_module(module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer);
68}
69
70pub trait ThinBufferMethods: Send + Sync {
71    fn data(&self) -> &[u8];
72}
73
74pub trait ModuleBufferMethods: Send + Sync {
75    fn data(&self) -> &[u8];
76}