forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.rs
More file actions
180 lines (151 loc) · 5.55 KB
/
backend.rs
File metadata and controls
180 lines (151 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use std::any::Any;
use std::hash::Hash;
use rustc_ast::expand::allocator::AllocatorMethod;
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_metadata::EncodedMetadata;
use rustc_metadata::creader::MetadataLoaderDyn;
use rustc_middle::dep_graph::WorkProductMap;
use rustc_middle::ty::TyCtxt;
use rustc_middle::util::Providers;
use rustc_session::Session;
use rustc_session::config::{CrateType, OutputFilenames, PrintRequest};
use rustc_span::Symbol;
use super::CodegenObject;
use crate::back::archive::ArArchiveBuilderBuilder;
use crate::back::link::link_binary;
use crate::{CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
pub trait BackendTypes {
type Function: CodegenObject;
type BasicBlock: Copy;
type Funclet;
type Value: CodegenObject + PartialEq;
type Type: CodegenObject + PartialEq;
type FunctionSignature: CodegenObject + PartialEq;
// FIXME(eddyb) find a common convention for all of the debuginfo-related
// names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
type DIScope: Copy + Hash + PartialEq + Eq;
type DILocation: Copy;
type DIVariable: Copy;
}
pub trait CodegenBackend {
fn name(&self) -> &'static str;
fn init(&self, _sess: &Session) {}
fn print(&self, _req: &PrintRequest, _out: &mut String, _sess: &Session) {}
/// Collect target-specific options that should be set in `cfg(...)`, including
/// `target_feature` and support for unstable float types.
fn target_config(&self, _sess: &Session) -> TargetConfig {
TargetConfig {
target_features: vec![],
unstable_target_features: vec![],
// `true` is used as a default so backends need to acknowledge when they do not
// support the float types, rather than accidentally quietly skipping all tests.
has_reliable_f16: true,
has_reliable_f16_math: true,
has_reliable_f128: true,
has_reliable_f128_math: true,
}
}
fn supported_crate_types(&self, _sess: &Session) -> Vec<CrateType> {
vec![
CrateType::Executable,
CrateType::Dylib,
CrateType::Rlib,
CrateType::StaticLib,
CrateType::Cdylib,
CrateType::ProcMacro,
CrateType::Sdylib,
]
}
fn print_passes(&self) {}
fn print_version(&self) {}
/// Returns a list of all intrinsics that this backend definitely
/// replaces, which means their fallback bodies do not need to be monomorphized.
fn replaced_intrinsics(&self) -> Vec<Symbol> {
vec![]
}
/// Returns a list of all intrinsics that this backend definitely
/// does *not* replace, which means their fallback bodies can be MIR-inlined.
fn fallback_intrinsics(&self) -> Vec<Symbol> {
vec![]
}
/// Is ThinLTO supported by this backend?
fn thin_lto_supported(&self) -> bool {
true
}
/// Value printed by `--print=backend-has-zstd`.
///
/// Used by compiletest to determine whether tests involving zstd compression
/// (e.g. `-Zdebuginfo-compression=zstd`) should be executed or skipped.
fn has_zstd(&self) -> bool {
false
}
/// Value printed by `--print=backend-has-mnemonic:...`.
///
/// Used by compiletest to determine whether tests involving `asm!()` should
/// be executed or skipped.
fn has_mnemonic(&self, _sess: &Session, _mnemonic: &str) -> bool {
false
}
/// The metadata loader used to load rlib and dylib metadata.
///
/// Alternative codegen backends may want to use different rlib or dylib formats than the
/// default native static archives and dynamic libraries.
fn metadata_loader(&self) -> Box<MetadataLoaderDyn> {
Box::new(crate::back::metadata::DefaultMetadataLoader)
}
fn provide(&self, _providers: &mut Providers) {}
fn target_cpu(&self, sess: &Session) -> String;
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any>;
/// This is called on the returned `Box<dyn Any>` from [`codegen_crate`](Self::codegen_crate)
///
/// # Panics
///
/// Panics when the passed `Box<dyn Any>` was not returned by [`codegen_crate`](Self::codegen_crate).
fn join_codegen(
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
crate_info: &CrateInfo,
) -> (CompiledModules, WorkProductMap);
fn print_pass_timings(&self) {}
fn print_statistics(&self) {}
fn print_statistics_json(&self) -> String {
String::new()
}
/// This is called on the returned [`CompiledModules`] from [`join_codegen`](Self::join_codegen).
fn link(
&self,
sess: &Session,
compiled_modules: CompiledModules,
crate_info: CrateInfo,
metadata: EncodedMetadata,
outputs: &OutputFilenames,
) {
link_binary(
sess,
&ArArchiveBuilderBuilder,
compiled_modules,
crate_info,
metadata,
outputs,
self.name(),
);
}
}
pub trait ExtraBackendMethods: Send + Sync + DynSend + DynSync {
type Module;
fn codegen_allocator<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
module_name: &str,
methods: &[AllocatorMethod],
) -> Self::Module;
/// This generates the codegen unit and returns it along with
/// a `u64` giving an estimate of the unit's processing cost.
fn compile_codegen_unit(
&self,
tcx: TyCtxt<'_>,
cgu_name: Symbol,
) -> (ModuleCodegen<Self::Module>, u64);
}