rustc_codegen_ssa/traits/
backend.rs1use std::any::Any;
2use std::hash::Hash;
3
4use rustc_ast::expand::allocator::AllocatorMethod;
5use rustc_data_structures::sync::{DynSend, DynSync};
6use rustc_metadata::EncodedMetadata;
7use rustc_metadata::creader::MetadataLoaderDyn;
8use rustc_middle::dep_graph::WorkProductMap;
9use rustc_middle::ty::TyCtxt;
10use rustc_middle::util::Providers;
11use rustc_session::config::{CrateType, OutputFilenames, PrintRequest};
12use rustc_session::{IncrCompSession, Session};
13use rustc_span::Symbol;
14
15use super::CodegenObject;
16use crate::back::archive::ArArchiveBuilderBuilder;
17use crate::back::link::link_binary;
18use crate::{CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
19
20pub trait BackendTypes {
21 type Function: CodegenObject;
22 type BasicBlock: Copy;
23 type Funclet;
24
25 type Value: CodegenObject + PartialEq;
26 type Type: CodegenObject + PartialEq;
27 type FunctionSignature: CodegenObject + PartialEq;
28
29 type DIScope: Copy + Hash + PartialEq + Eq;
32 type DILocation: Copy;
33 type DIVariable: Copy;
34}
35
36pub trait CodegenBackend {
37 fn name(&self) -> &'static str;
38
39 fn init(&self, _sess: &Session) {}
40
41 fn print(&self, _req: &PrintRequest, _out: &mut String, _sess: &Session) {}
42
43 fn target_config(&self, _sess: &Session) -> TargetConfig {
46 TargetConfig {
47 internal_target_features: Default::default(),
48 has_reliable_f16: true,
51 has_reliable_f16_math: true,
52 has_reliable_f128: true,
53 has_reliable_f128_math: true,
54 }
55 }
56
57 fn supported_crate_types(&self, _sess: &Session) -> Vec<CrateType> {
58 ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[CrateType::Executable, CrateType::Dylib, CrateType::Rlib,
CrateType::StaticLib, CrateType::Cdylib, CrateType::ProcMacro,
CrateType::Sdylib]))vec![
59 CrateType::Executable,
60 CrateType::Dylib,
61 CrateType::Rlib,
62 CrateType::StaticLib,
63 CrateType::Cdylib,
64 CrateType::ProcMacro,
65 CrateType::Sdylib,
66 ]
67 }
68
69 fn print_passes(&self) {}
70
71 fn print_version(&self) {}
72
73 fn replaced_intrinsics(&self) -> Vec<Symbol> {
76 ::alloc::vec::Vec::new()vec![]
77 }
78
79 fn fallback_intrinsics(&self) -> Vec<Symbol> {
82 ::alloc::vec::Vec::new()vec![]
83 }
84
85 fn thin_lto_supported(&self) -> bool {
87 true
88 }
89
90 fn has_zstd(&self) -> bool {
95 false
96 }
97
98 fn has_mnemonic(&self, _sess: &Session, _mnemonic: &str) -> bool {
103 false
104 }
105
106 fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
111 Box::new(crate::back::metadata::DefaultMetadataLoader)
112 }
113
114 fn provide(&self, _providers: &mut Providers) {}
115
116 fn target_cpu(&self, sess: &Session) -> String;
117
118 fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any>;
119
120 fn join_codegen(
126 &self,
127 ongoing_codegen: Box<dyn Any>,
128 sess: &Session,
129 incr_comp_session: Option<&IncrCompSession>,
130 outputs: &OutputFilenames,
131 crate_info: &CrateInfo,
132 ) -> (CompiledModules, WorkProductMap);
133
134 fn print_pass_timings(&self) {}
135
136 fn print_statistics(&self) {}
137
138 fn print_statistics_json(&self) -> String {
139 String::new()
140 }
141
142 fn link(
144 &self,
145 sess: &Session,
146 compiled_modules: CompiledModules,
147 crate_info: CrateInfo,
148 metadata: EncodedMetadata,
149 outputs: &OutputFilenames,
150 ) {
151 link_binary(
152 sess,
153 &ArArchiveBuilderBuilder,
154 compiled_modules,
155 crate_info,
156 metadata,
157 outputs,
158 self.name(),
159 );
160 }
161}
162
163pub trait ExtraBackendMethods: Send + Sync + DynSend + DynSync {
164 type Module;
165
166 fn codegen_allocator<'tcx>(
167 &self,
168 tcx: TyCtxt<'tcx>,
169 module_name: &str,
170 methods: &[AllocatorMethod],
171 ) -> Self::Module;
172
173 fn compile_codegen_unit(
176 &self,
177 tcx: TyCtxt<'_>,
178 cgu_name: Symbol,
179 ) -> (ModuleCodegen<Self::Module>, u64);
180}