Skip to main content

rustc_codegen_ssa/traits/
write.rs

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