rustc_codegen_ssa/traits/
backend.rs1use std::any::Any;
2use std::hash::Hash;
3
4use rustc_ast::expand::allocator::AllocatorMethod;
5use rustc_data_structures::fx::FxIndexMap;
6use rustc_data_structures::sync::{DynSend, DynSync};
7use rustc_metadata::EncodedMetadata;
8use rustc_metadata::creader::MetadataLoaderDyn;
9use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
10use rustc_middle::ty::TyCtxt;
11use rustc_middle::util::Providers;
12use rustc_session::Session;
13use rustc_session::config::{CrateType, OutputFilenames, PrintRequest};
14use rustc_span::Symbol;
15
16use super::CodegenObject;
17use super::write::WriteBackendMethods;
18use crate::back::archive::ArArchiveBuilderBuilder;
19use crate::back::link::link_binary;
20use crate::{CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
21
22pub trait BackendTypes {
23 type Function: CodegenObject;
24 type BasicBlock: Copy;
25 type Funclet;
26
27 type Value: CodegenObject + PartialEq;
28 type Type: CodegenObject + PartialEq;
29 type FunctionSignature: CodegenObject + PartialEq;
30
31 type DIScope: Copy + Hash + PartialEq + Eq;
34 type DILocation: Copy;
35 type DIVariable: Copy;
36}
37
38pub trait CodegenBackend {
39 fn name(&self) -> &'static str;
40
41 fn init(&self, _sess: &Session) {}
42
43 fn print(&self, _req: &PrintRequest, _out: &mut String, _sess: &Session) {}
44
45 fn target_config(&self, _sess: &Session) -> TargetConfig {
48 TargetConfig {
49 target_features: ::alloc::vec::Vec::new()vec![],
50 unstable_target_features: ::alloc::vec::Vec::new()vec![],
51 has_reliable_f16: true,
54 has_reliable_f16_math: true,
55 has_reliable_f128: true,
56 has_reliable_f128_math: true,
57 }
58 }
59
60 fn supported_crate_types(&self, _sess: &Session) -> Vec<CrateType> {
61 ::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![
62 CrateType::Executable,
63 CrateType::Dylib,
64 CrateType::Rlib,
65 CrateType::StaticLib,
66 CrateType::Cdylib,
67 CrateType::ProcMacro,
68 CrateType::Sdylib,
69 ]
70 }
71
72 fn print_passes(&self) {}
73
74 fn print_version(&self) {}
75
76 fn replaced_intrinsics(&self) -> Vec<Symbol> {
79 ::alloc::vec::Vec::new()vec![]
80 }
81
82 fn thin_lto_supported(&self) -> bool {
84 true
85 }
86
87 fn has_zstd(&self) -> bool {
92 false
93 }
94
95 fn has_mnemonic(&self, _sess: &Session, _mnemonic: &str) -> bool {
100 false
101 }
102
103 fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
108 Box::new(crate::back::metadata::DefaultMetadataLoader)
109 }
110
111 fn provide(&self, _providers: &mut Providers) {}
112
113 fn target_cpu(&self, sess: &Session) -> String;
114
115 fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any>;
116
117 fn join_codegen(
123 &self,
124 ongoing_codegen: Box<dyn Any>,
125 sess: &Session,
126 outputs: &OutputFilenames,
127 crate_info: &CrateInfo,
128 ) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>);
129
130 fn print_pass_timings(&self) {}
131
132 fn print_statistics(&self) {}
133
134 fn print_statistics_json(&self) -> String {
135 String::new()
136 }
137
138 fn link(
140 &self,
141 sess: &Session,
142 compiled_modules: CompiledModules,
143 crate_info: CrateInfo,
144 metadata: EncodedMetadata,
145 outputs: &OutputFilenames,
146 ) {
147 link_binary(
148 sess,
149 &ArArchiveBuilderBuilder,
150 compiled_modules,
151 crate_info,
152 metadata,
153 outputs,
154 self.name(),
155 );
156 }
157}
158
159pub trait ExtraBackendMethods:
160 WriteBackendMethods + Sized + Send + Sync + DynSend + DynSync
161{
162 fn codegen_allocator<'tcx>(
163 &self,
164 tcx: TyCtxt<'tcx>,
165 module_name: &str,
166 methods: &[AllocatorMethod],
167 ) -> Self::Module;
168
169 fn compile_codegen_unit(
172 &self,
173 tcx: TyCtxt<'_>,
174 cgu_name: Symbol,
175 ) -> (ModuleCodegen<Self::Module>, u64);
176
177 fn supports_parallel(&self) -> bool {
181 true
182 }
183}