/src/wasmtime/cranelift/codegen/src/isa/mod.rs
Line | Count | Source |
1 | | //! Instruction Set Architectures. |
2 | | //! |
3 | | //! The `isa` module provides a `TargetIsa` trait which provides the behavior specialization needed |
4 | | //! by the ISA-independent code generator. The sub-modules of this module provide definitions for |
5 | | //! the instruction sets that Cranelift can target. Each sub-module has it's own implementation of |
6 | | //! `TargetIsa`. |
7 | | //! |
8 | | //! # Constructing a `TargetIsa` instance |
9 | | //! |
10 | | //! The target ISA is built from the following information: |
11 | | //! |
12 | | //! - The name of the target ISA as a string. Cranelift is a cross-compiler, so the ISA to target |
13 | | //! can be selected dynamically. Individual ISAs can be left out when Cranelift is compiled, so a |
14 | | //! string is used to identify the proper sub-module. |
15 | | //! - Values for settings that apply to all ISAs. This is represented by a `settings::Flags` |
16 | | //! instance. |
17 | | //! - Values for ISA-specific settings. |
18 | | //! |
19 | | //! The `isa::lookup()` function is the main entry point which returns an `isa::Builder` |
20 | | //! appropriate for the requested ISA: |
21 | | //! |
22 | | //! ``` |
23 | | //! # #[macro_use] extern crate target_lexicon; |
24 | | //! use cranelift_codegen::isa; |
25 | | //! use cranelift_codegen::settings::{self, Configurable}; |
26 | | //! use core::str::FromStr; |
27 | | //! use target_lexicon::Triple; |
28 | | //! |
29 | | //! let shared_builder = settings::builder(); |
30 | | //! let shared_flags = settings::Flags::new(shared_builder); |
31 | | //! |
32 | | //! match isa::lookup(triple!("x86_64")) { |
33 | | //! Err(_) => { |
34 | | //! // The x86_64 target ISA is not available. |
35 | | //! } |
36 | | //! Ok(mut isa_builder) => { |
37 | | //! isa_builder.set("use_popcnt", "on"); |
38 | | //! let isa = isa_builder.finish(shared_flags); |
39 | | //! } |
40 | | //! } |
41 | | //! ``` |
42 | | //! |
43 | | //! The configured target ISA trait object is a `Box<TargetIsa>` which can be used for multiple |
44 | | //! concurrent function compilations. |
45 | | |
46 | | use crate::dominator_tree::DominatorTree; |
47 | | pub use crate::isa::call_conv::CallConv; |
48 | | |
49 | | use crate::CodegenResult; |
50 | | use crate::ir::{self, Function, Type}; |
51 | | #[cfg(feature = "unwind")] |
52 | | use crate::isa::unwind::{UnwindInfoKind, systemv::RegisterMappingError}; |
53 | | use crate::machinst::{CompiledCodeStencil, TextSectionBuilder}; |
54 | | use crate::settings; |
55 | | use crate::settings::Configurable; |
56 | | use crate::settings::SetResult; |
57 | | use crate::{Reg, flowgraph}; |
58 | | use alloc::string::String; |
59 | | use alloc::{boxed::Box, sync::Arc, vec::Vec}; |
60 | | use core::fmt; |
61 | | use core::fmt::{Debug, Formatter}; |
62 | | use cranelift_control::ControlPlane; |
63 | | use target_lexicon::{Architecture, PointerWidth, Triple, triple}; |
64 | | |
65 | | // This module is made public here for benchmarking purposes. No guarantees are |
66 | | // made regarding API stability. |
67 | | #[cfg(feature = "x86")] |
68 | | pub mod x64; |
69 | | |
70 | | #[cfg(feature = "arm64")] |
71 | | pub mod aarch64; |
72 | | |
73 | | #[cfg(feature = "riscv64")] |
74 | | pub mod riscv64; |
75 | | |
76 | | #[cfg(feature = "s390x")] |
77 | | mod s390x; |
78 | | |
79 | | #[cfg(feature = "pulley")] |
80 | | mod pulley32; |
81 | | #[cfg(feature = "pulley")] |
82 | | mod pulley64; |
83 | | #[cfg(feature = "pulley")] |
84 | | mod pulley_shared; |
85 | | |
86 | | pub mod unwind; |
87 | | |
88 | | mod call_conv; |
89 | | mod winch; |
90 | | |
91 | | /// Returns a builder that can create a corresponding `TargetIsa` |
92 | | /// or `Err(LookupError::SupportDisabled)` if not enabled. |
93 | | macro_rules! isa_builder { |
94 | | ($name: ident, $cfg_terms: tt, $triple: ident) => {{ |
95 | | #[cfg $cfg_terms] |
96 | | { |
97 | | Ok($name::isa_builder($triple)) |
98 | | } |
99 | | #[cfg(not $cfg_terms)] |
100 | | { |
101 | | Err(LookupError::SupportDisabled) |
102 | | } |
103 | | }}; |
104 | | } |
105 | | |
106 | | /// Look for an ISA for the given `triple`. |
107 | | /// Return a builder that can create a corresponding `TargetIsa`. |
108 | 144k | pub fn lookup(triple: Triple) -> Result<Builder, LookupError> { |
109 | 144k | match triple.architecture { |
110 | | Architecture::X86_64 => { |
111 | 117k | isa_builder!(x64, (feature = "x86"), triple) |
112 | | } |
113 | 4.16k | Architecture::Aarch64 { .. } => isa_builder!(aarch64, (feature = "arm64"), triple), |
114 | 7.96k | Architecture::S390x { .. } => isa_builder!(s390x, (feature = "s390x"), triple), |
115 | 6.65k | Architecture::Riscv64 { .. } => isa_builder!(riscv64, (feature = "riscv64"), triple), |
116 | | Architecture::Pulley32 | Architecture::Pulley32be => { |
117 | 0 | isa_builder!(pulley32, (feature = "pulley"), triple) |
118 | | } |
119 | | Architecture::Pulley64 | Architecture::Pulley64be => { |
120 | 7.95k | isa_builder!(pulley64, (feature = "pulley"), triple) |
121 | | } |
122 | 0 | _ => Err(LookupError::Unsupported), |
123 | | } |
124 | 144k | } |
125 | | |
126 | | /// The string names of all the supported, but possibly not enabled, architectures. The elements of |
127 | | /// this slice are suitable to be passed to the [lookup_by_name] function to obtain the default |
128 | | /// configuration for that architecture. |
129 | | pub const ALL_ARCHITECTURES: &[&str] = &["x86_64", "aarch64", "s390x", "riscv64"]; |
130 | | |
131 | | /// Look for a supported ISA with the given `name`. |
132 | | /// Return a builder that can create a corresponding `TargetIsa`. |
133 | 9.37k | pub fn lookup_by_name(name: &str) -> Result<Builder, LookupError> { |
134 | 9.37k | lookup(triple!(name)) |
135 | 9.37k | } |
136 | | |
137 | | /// Describes reason for target lookup failure |
138 | | #[derive(PartialEq, Eq, Copy, Clone, Debug)] |
139 | | pub enum LookupError { |
140 | | /// Support for this target was disabled in the current build. |
141 | | SupportDisabled, |
142 | | |
143 | | /// Support for this target has not yet been implemented. |
144 | | Unsupported, |
145 | | } |
146 | | |
147 | | // This is manually implementing Error and Display instead of using thiserror to reduce the amount |
148 | | // of dependencies used by Cranelift. |
149 | | impl core::error::Error for LookupError {} |
150 | | |
151 | | impl fmt::Display for LookupError { |
152 | 0 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
153 | 0 | match self { |
154 | 0 | LookupError::SupportDisabled => write!(f, "Support for this target is disabled"), |
155 | | LookupError::Unsupported => { |
156 | 0 | write!(f, "Support for this target has not been implemented yet") |
157 | | } |
158 | | } |
159 | 0 | } |
160 | | } |
161 | | |
162 | | /// The type of a polymorphic TargetISA object which is 'static. |
163 | | pub type OwnedTargetIsa = Arc<dyn TargetIsa>; |
164 | | |
165 | | /// Type alias of `IsaBuilder` used for building Cranelift's ISAs. |
166 | | pub type Builder = IsaBuilder<CodegenResult<OwnedTargetIsa>>; |
167 | | |
168 | | /// Builder for a `TargetIsa`. |
169 | | /// Modify the ISA-specific settings before creating the `TargetIsa` trait object with `finish`. |
170 | | #[derive(Clone)] |
171 | | pub struct IsaBuilder<T> { |
172 | | triple: Triple, |
173 | | setup: settings::Builder, |
174 | | constructor: fn(Triple, settings::Flags, &settings::Builder) -> T, |
175 | | } |
176 | | |
177 | | impl<T> IsaBuilder<T> { |
178 | | /// Creates a new ISA-builder from its components, namely the `triple` for |
179 | | /// the ISA, the ISA-specific settings builder, and a final constructor |
180 | | /// function to generate the ISA from its components. |
181 | 3.66k | pub fn new( |
182 | 3.66k | triple: Triple, |
183 | 3.66k | setup: settings::Builder, |
184 | 3.66k | constructor: fn(Triple, settings::Flags, &settings::Builder) -> T, |
185 | 3.66k | ) -> Self { |
186 | 3.66k | IsaBuilder { |
187 | 3.66k | triple, |
188 | 3.66k | setup, |
189 | 3.66k | constructor, |
190 | 3.66k | } |
191 | 3.66k | } <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::boxed::Box<dyn winch_codegen::isa::TargetIsa>, wasmtime_internal_core::error::error::Error>>>::new Line | Count | Source | 181 | 3.66k | pub fn new( | 182 | 3.66k | triple: Triple, | 183 | 3.66k | setup: settings::Builder, | 184 | 3.66k | constructor: fn(Triple, settings::Flags, &settings::Builder) -> T, | 185 | 3.66k | ) -> Self { | 186 | 3.66k | IsaBuilder { | 187 | 3.66k | triple, | 188 | 3.66k | setup, | 189 | 3.66k | constructor, | 190 | 3.66k | } | 191 | 3.66k | } |
Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_>>::new |
192 | | |
193 | | /// Creates a new [Builder] from a [TargetIsa], copying all flags in the |
194 | | /// process. |
195 | 33.2k | pub fn from_target_isa(target_isa: &dyn TargetIsa) -> Builder { |
196 | | // We should always be able to find the builder for the TargetISA, since presumably we |
197 | | // also generated the previous TargetISA at some point |
198 | 33.2k | let triple = target_isa.triple().clone(); |
199 | 33.2k | let mut builder = self::lookup(triple).expect("Could not find triple for target ISA"); |
200 | | |
201 | | // Copy ISA Flags |
202 | 550k | for flag in target_isa.isa_flags() { |
203 | 550k | builder.set(&flag.name, &flag.value_string()).unwrap(); |
204 | 550k | } |
205 | | |
206 | 33.2k | builder |
207 | 33.2k | } Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_>>::from_target_isa <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::from_target_isa Line | Count | Source | 195 | 33.2k | pub fn from_target_isa(target_isa: &dyn TargetIsa) -> Builder { | 196 | | // We should always be able to find the builder for the TargetISA, since presumably we | 197 | | // also generated the previous TargetISA at some point | 198 | 33.2k | let triple = target_isa.triple().clone(); | 199 | 33.2k | let mut builder = self::lookup(triple).expect("Could not find triple for target ISA"); | 200 | | | 201 | | // Copy ISA Flags | 202 | 550k | for flag in target_isa.isa_flags() { | 203 | 550k | builder.set(&flag.name, &flag.value_string()).unwrap(); | 204 | 550k | } | 205 | | | 206 | 33.2k | builder | 207 | 33.2k | } |
|
208 | | |
209 | | /// Gets the triple for the builder. |
210 | 30.2k | pub fn triple(&self) -> &Triple { |
211 | 30.2k | &self.triple |
212 | 30.2k | } Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::boxed::Box<dyn winch_codegen::isa::TargetIsa>, wasmtime_internal_core::error::error::Error>>>::triple Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::triple Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_>>::triple <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::triple Line | Count | Source | 210 | 30.2k | pub fn triple(&self) -> &Triple { | 211 | 30.2k | &self.triple | 212 | 30.2k | } |
|
213 | | |
214 | | /// Iterates the available settings in the builder. |
215 | 9.37k | pub fn iter(&self) -> impl Iterator<Item = settings::Setting> + use<T> { |
216 | 9.37k | self.setup.iter() |
217 | 9.37k | } Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::boxed::Box<dyn winch_codegen::isa::TargetIsa>, wasmtime_internal_core::error::error::Error>>>::iter Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::iter Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_>>::iter <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::iter Line | Count | Source | 215 | 9.37k | pub fn iter(&self) -> impl Iterator<Item = settings::Setting> + use<T> { | 216 | 9.37k | self.setup.iter() | 217 | 9.37k | } |
|
218 | | |
219 | | /// Combine the ISA-specific settings with the provided |
220 | | /// ISA-independent settings and allocate a fully configured |
221 | | /// `TargetIsa` trait object. May return an error if some of the |
222 | | /// flags are inconsistent or incompatible: for example, some |
223 | | /// platform-independent features, like general SIMD support, may |
224 | | /// need certain ISA extensions to be enabled. |
225 | 147k | pub fn finish(&self, shared_flags: settings::Flags) -> T { |
226 | 147k | (self.constructor)(self.triple.clone(), shared_flags, &self.setup) |
227 | 147k | } <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::boxed::Box<dyn winch_codegen::isa::TargetIsa>, wasmtime_internal_core::error::error::Error>>>::finish Line | Count | Source | 225 | 3.66k | pub fn finish(&self, shared_flags: settings::Flags) -> T { | 226 | 3.66k | (self.constructor)(self.triple.clone(), shared_flags, &self.setup) | 227 | 3.66k | } |
<cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::finish Line | Count | Source | 225 | 69.2k | pub fn finish(&self, shared_flags: settings::Flags) -> T { | 226 | 69.2k | (self.constructor)(self.triple.clone(), shared_flags, &self.setup) | 227 | 69.2k | } |
Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_>>::finish <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::finish Line | Count | Source | 225 | 63.4k | pub fn finish(&self, shared_flags: settings::Flags) -> T { | 226 | 63.4k | (self.constructor)(self.triple.clone(), shared_flags, &self.setup) | 227 | 63.4k | } |
Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::finish <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>>>::finish Line | Count | Source | 225 | 11.4k | pub fn finish(&self, shared_flags: settings::Flags) -> T { | 226 | 11.4k | (self.constructor)(self.triple.clone(), shared_flags, &self.setup) | 227 | 11.4k | } |
|
228 | | } |
229 | | |
230 | | impl<T> settings::Configurable for IsaBuilder<T> { |
231 | 826k | fn set(&mut self, name: &str, value: &str) -> SetResult<()> { |
232 | 826k | self.setup.set(name, value) |
233 | 826k | } <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::boxed::Box<dyn winch_codegen::isa::TargetIsa>, wasmtime_internal_core::error::error::Error>> as cranelift_codegen::settings::Configurable>::set Line | Count | Source | 231 | 8.99k | fn set(&mut self, name: &str, value: &str) -> SetResult<()> { | 232 | 8.99k | self.setup.set(name, value) | 233 | 8.99k | } |
<cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>> as cranelift_codegen::settings::Configurable>::set Line | Count | Source | 231 | 817k | fn set(&mut self, name: &str, value: &str) -> SetResult<()> { | 232 | 817k | self.setup.set(name, value) | 233 | 817k | } |
Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_> as cranelift_codegen::settings::Configurable>::set Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>> as cranelift_codegen::settings::Configurable>::set |
234 | | |
235 | 1.13M | fn enable(&mut self, name: &str) -> SetResult<()> { |
236 | 1.13M | self.setup.enable(name) |
237 | 1.13M | } <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::boxed::Box<dyn winch_codegen::isa::TargetIsa>, wasmtime_internal_core::error::error::Error>> as cranelift_codegen::settings::Configurable>::enable Line | Count | Source | 235 | 37.5k | fn enable(&mut self, name: &str) -> SetResult<()> { | 236 | 37.5k | self.setup.enable(name) | 237 | 37.5k | } |
<cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>> as cranelift_codegen::settings::Configurable>::enable Line | Count | Source | 235 | 1.09M | fn enable(&mut self, name: &str) -> SetResult<()> { | 236 | 1.09M | self.setup.enable(name) | 237 | 1.09M | } |
Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<_> as cranelift_codegen::settings::Configurable>::enable Unexecuted instantiation: <cranelift_codegen::isa::IsaBuilder<core::result::Result<alloc::sync::Arc<dyn cranelift_codegen::isa::TargetIsa>, cranelift_codegen::result::CodegenError>> as cranelift_codegen::settings::Configurable>::enable |
238 | | } |
239 | | |
240 | | /// After determining that an instruction doesn't have an encoding, how should we proceed to |
241 | | /// legalize it? |
242 | | /// |
243 | | /// The `Encodings` iterator returns a legalization function to call. |
244 | | pub type Legalize = |
245 | | fn(ir::Inst, &mut ir::Function, &mut flowgraph::ControlFlowGraph, &dyn TargetIsa) -> bool; |
246 | | |
247 | | /// This struct provides information that a frontend may need to know about a target to |
248 | | /// produce Cranelift IR for the target. |
249 | | #[derive(Clone, Copy, Hash)] |
250 | | pub struct TargetFrontendConfig { |
251 | | /// The default calling convention of the target. |
252 | | pub default_call_conv: CallConv, |
253 | | |
254 | | /// The pointer width of the target. |
255 | | pub pointer_width: PointerWidth, |
256 | | |
257 | | /// The log2 of the target's page size and alignment. |
258 | | /// |
259 | | /// Note that this may be an upper-bound that is larger than necessary for |
260 | | /// some platforms since it may depend on runtime configuration. |
261 | | pub page_size_align_log2: u8, |
262 | | } |
263 | | |
264 | | impl TargetFrontendConfig { |
265 | | /// Get the pointer type of this target. |
266 | 0 | pub fn pointer_type(self) -> ir::Type { |
267 | 0 | ir::Type::int(self.pointer_bits() as u16).unwrap() |
268 | 0 | } |
269 | | |
270 | | /// Get the width of pointers on this target, in units of bits. |
271 | 0 | pub fn pointer_bits(self) -> u8 { |
272 | 0 | self.pointer_width.bits() |
273 | 0 | } |
274 | | |
275 | | /// Get the width of pointers on this target, in units of bytes. |
276 | 0 | pub fn pointer_bytes(self) -> u8 { |
277 | 0 | self.pointer_width.bytes() |
278 | 0 | } |
279 | | } |
280 | | |
281 | | /// Methods that are specialized to a target ISA. |
282 | | /// |
283 | | /// Implies a Display trait that shows the shared flags, as well as any ISA-specific flags. |
284 | | pub trait TargetIsa: fmt::Display + Send + Sync { |
285 | | /// Get the name of this ISA. |
286 | | fn name(&self) -> &'static str; |
287 | | |
288 | | /// Get the target triple that was used to make this trait object. |
289 | | fn triple(&self) -> &Triple; |
290 | | |
291 | | /// Get the ISA-independent flags that were used to make this trait object. |
292 | | fn flags(&self) -> &settings::Flags; |
293 | | |
294 | | /// Get the ISA-dependent flag values that were used to make this trait object. |
295 | | fn isa_flags(&self) -> Vec<settings::Value>; |
296 | | |
297 | | /// Get the ISA-dependent flag values as raw bytes for hashing. |
298 | | fn isa_flags_hash_key(&self) -> IsaFlagsHashKey<'_>; |
299 | | |
300 | | /// Get a flag indicating whether branch protection is enabled. |
301 | 82.7k | fn is_branch_protection_enabled(&self) -> bool { |
302 | 82.7k | false |
303 | 82.7k | } Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley32::Pulley32> as cranelift_codegen::isa::TargetIsa>::is_branch_protection_enabled <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley64::Pulley64> as cranelift_codegen::isa::TargetIsa>::is_branch_protection_enabled Line | Count | Source | 301 | 14.5k | fn is_branch_protection_enabled(&self) -> bool { | 302 | 14.5k | false | 303 | 14.5k | } |
<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::is_branch_protection_enabled Line | Count | Source | 301 | 68.2k | fn is_branch_protection_enabled(&self) -> bool { | 302 | 68.2k | false | 303 | 68.2k | } |
Unexecuted instantiation: <cranelift_codegen::isa::s390x::S390xBackend as cranelift_codegen::isa::TargetIsa>::is_branch_protection_enabled Unexecuted instantiation: <cranelift_codegen::isa::riscv64::Riscv64Backend as cranelift_codegen::isa::TargetIsa>::is_branch_protection_enabled |
304 | | |
305 | | /// Get the ISA-dependent maximum vector register size, in bytes. |
306 | | fn dynamic_vector_bytes(&self, dynamic_ty: ir::Type) -> u32; |
307 | | |
308 | | /// Compile the given function. |
309 | | fn compile_function( |
310 | | &self, |
311 | | func: &Function, |
312 | | domtree: &DominatorTree, |
313 | | want_disasm: bool, |
314 | | ctrl_plane: &mut ControlPlane, |
315 | | ) -> CodegenResult<CompiledCodeStencil>; |
316 | | |
317 | | #[cfg(feature = "unwind")] |
318 | | /// Map a regalloc::Reg to its corresponding DWARF register. |
319 | 0 | fn map_regalloc_reg_to_dwarf( |
320 | 0 | &self, |
321 | 0 | _: crate::machinst::Reg, |
322 | 0 | ) -> Result<u16, RegisterMappingError> { |
323 | 0 | Err(RegisterMappingError::UnsupportedArchitecture) |
324 | 0 | } Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley32::Pulley32> as cranelift_codegen::isa::TargetIsa>::map_regalloc_reg_to_dwarf Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley64::Pulley64> as cranelift_codegen::isa::TargetIsa>::map_regalloc_reg_to_dwarf |
325 | | |
326 | | /// Creates unwind information for the function. |
327 | | /// |
328 | | /// Returns `None` if there is no unwind information for the function. |
329 | | #[cfg(feature = "unwind")] |
330 | | fn emit_unwind_info( |
331 | | &self, |
332 | | result: &crate::machinst::CompiledCode, |
333 | | kind: UnwindInfoKind, |
334 | | ) -> CodegenResult<Option<crate::isa::unwind::UnwindInfo>>; |
335 | | |
336 | | /// Creates a new System V Common Information Entry for the ISA. |
337 | | /// |
338 | | /// Returns `None` if the ISA does not support System V unwind information. |
339 | | #[cfg(feature = "unwind")] |
340 | 0 | fn create_systemv_cie(&self) -> Option<gimli::write::CommonInformationEntry> { |
341 | | // By default, an ISA cannot create a System V CIE |
342 | 0 | None |
343 | 0 | } Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley32::Pulley32> as cranelift_codegen::isa::TargetIsa>::create_systemv_cie Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley64::Pulley64> as cranelift_codegen::isa::TargetIsa>::create_systemv_cie |
344 | | |
345 | | /// Returns an object that can be used to build the text section of an |
346 | | /// executable. |
347 | | /// |
348 | | /// This object will internally attempt to handle as many relocations as |
349 | | /// possible using relative calls/jumps/etc between functions. |
350 | | /// |
351 | | /// The `num_labeled_funcs` argument here is the number of functions which |
352 | | /// will be "labeled" or might have calls between them, typically the number |
353 | | /// of defined functions in the object file. |
354 | | fn text_section_builder(&self, num_labeled_funcs: usize) -> Box<dyn TextSectionBuilder>; |
355 | | |
356 | | /// Returns the minimum function alignment and the preferred function |
357 | | /// alignment, for performance, required by this ISA. |
358 | | fn function_alignment(&self) -> FunctionAlignment; |
359 | | |
360 | | /// The log2 of the target's page size and alignment. |
361 | | /// |
362 | | /// Note that this may be an upper-bound that is larger than necessary for |
363 | | /// some platforms since it may depend on runtime configuration. |
364 | | fn page_size_align_log2(&self) -> u8; |
365 | | |
366 | | /// Create a polymorphic TargetIsa from this specific implementation. |
367 | 144k | fn wrapped(self) -> OwnedTargetIsa |
368 | 144k | where |
369 | 144k | Self: Sized + 'static, |
370 | | { |
371 | 144k | Arc::new(self) |
372 | 144k | } Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley32::Pulley32> as cranelift_codegen::isa::TargetIsa>::wrapped <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley64::Pulley64> as cranelift_codegen::isa::TargetIsa>::wrapped Line | Count | Source | 367 | 7.95k | fn wrapped(self) -> OwnedTargetIsa | 368 | 7.95k | where | 369 | 7.95k | Self: Sized + 'static, | 370 | | { | 371 | 7.95k | Arc::new(self) | 372 | 7.95k | } |
<cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::wrapped Line | Count | Source | 367 | 117k | fn wrapped(self) -> OwnedTargetIsa | 368 | 117k | where | 369 | 117k | Self: Sized + 'static, | 370 | | { | 371 | 117k | Arc::new(self) | 372 | 117k | } |
<cranelift_codegen::isa::s390x::S390xBackend as cranelift_codegen::isa::TargetIsa>::wrapped Line | Count | Source | 367 | 7.96k | fn wrapped(self) -> OwnedTargetIsa | 368 | 7.96k | where | 369 | 7.96k | Self: Sized + 'static, | 370 | | { | 371 | 7.96k | Arc::new(self) | 372 | 7.96k | } |
<cranelift_codegen::isa::aarch64::AArch64Backend as cranelift_codegen::isa::TargetIsa>::wrapped Line | Count | Source | 367 | 4.16k | fn wrapped(self) -> OwnedTargetIsa | 368 | 4.16k | where | 369 | 4.16k | Self: Sized + 'static, | 370 | | { | 371 | 4.16k | Arc::new(self) | 372 | 4.16k | } |
<cranelift_codegen::isa::riscv64::Riscv64Backend as cranelift_codegen::isa::TargetIsa>::wrapped Line | Count | Source | 367 | 6.65k | fn wrapped(self) -> OwnedTargetIsa | 368 | 6.65k | where | 369 | 6.65k | Self: Sized + 'static, | 370 | | { | 371 | 6.65k | Arc::new(self) | 372 | 6.65k | } |
|
373 | | |
374 | | /// Generate a `Capstone` context for disassembling bytecode for this architecture. |
375 | | #[cfg(feature = "disas")] |
376 | 0 | fn to_capstone(&self) -> Result<capstone::Capstone, capstone::Error> { |
377 | 0 | Err(capstone::Error::UnsupportedArch) |
378 | 0 | } Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley32::Pulley32> as cranelift_codegen::isa::TargetIsa>::to_capstone Unexecuted instantiation: <cranelift_codegen::isa::pulley_shared::PulleyBackend<cranelift_codegen::isa::pulley64::Pulley64> as cranelift_codegen::isa::TargetIsa>::to_capstone |
379 | | |
380 | | /// Return the string representation of "reg" accessed as "size" bytes. |
381 | | /// The returned string will match the usual disassemly view of "reg". |
382 | | fn pretty_print_reg(&self, reg: Reg, size: u8) -> String; |
383 | | |
384 | | /// Returns whether this ISA has a native fused-multiply-and-add instruction |
385 | | /// for floats. |
386 | | /// |
387 | | /// Currently this only returns false on x86 when some native features are |
388 | | /// not detected. |
389 | | fn has_native_fma(&self) -> bool; |
390 | | |
391 | | /// Returns whether this ISA has instructions for `ceil`, `floor`, etc. |
392 | | fn has_round(&self) -> bool; |
393 | | |
394 | | /// Returns whether the CLIF `blendv` instruction is implemented for |
395 | | /// this ISA for the specified type. |
396 | | fn has_blendv_lowering(&self, ty: Type) -> bool; |
397 | | |
398 | | /// Returns whether the CLIF `x86_pshufb` instruction is implemented for |
399 | | /// this ISA. |
400 | | fn has_x86_pshufb_lowering(&self) -> bool; |
401 | | |
402 | | /// Returns whether the CLIF `x86_pmulhrsw` instruction is implemented for |
403 | | /// this ISA. |
404 | | fn has_x86_pmulhrsw_lowering(&self) -> bool; |
405 | | |
406 | | /// Returns whether the CLIF `x86_pmaddubsw` instruction is implemented for |
407 | | /// this ISA. |
408 | | fn has_x86_pmaddubsw_lowering(&self) -> bool; |
409 | | |
410 | | /// Returns the mode of extension used for integer arguments smaller than |
411 | | /// the pointer width in function signatures. |
412 | | /// |
413 | | /// Some platform ABIs require that smaller-than-pointer-width values are |
414 | | /// either zero or sign-extended to the full register width. This value is |
415 | | /// propagated to the `AbiParam` value created for signatures. Note that not |
416 | | /// all ABIs for all platforms require extension of any form, so this is |
417 | | /// generally only necessary for the `default_call_conv`. |
418 | | fn default_argument_extension(&self) -> ir::ArgumentExtension; |
419 | | } |
420 | | |
421 | | /// A wrapper around the ISA-dependent flags types which only implements `Hash`. |
422 | | #[derive(Hash)] |
423 | | pub struct IsaFlagsHashKey<'a>(&'a [u8]); |
424 | | |
425 | | /// Function alignment specifications as required by an ISA, returned by |
426 | | /// [`TargetIsa::function_alignment`]. |
427 | | #[derive(Copy, Clone)] |
428 | | pub struct FunctionAlignment { |
429 | | /// The minimum alignment required by an ISA, where all functions must be |
430 | | /// aligned to at least this amount. |
431 | | pub minimum: u32, |
432 | | /// A "preferred" alignment which should be used for more |
433 | | /// performance-sensitive situations. This can involve cache-line-aligning |
434 | | /// for example to get more of a small function into fewer cache lines. |
435 | | pub preferred: u32, |
436 | | } |
437 | | |
438 | | /// Methods implemented for free for target ISA! |
439 | | impl<'a> dyn TargetIsa + 'a { |
440 | | /// Get the default calling convention of this target. |
441 | 2.07M | pub fn default_call_conv(&self) -> CallConv { |
442 | 2.07M | CallConv::triple_default(self.triple()) |
443 | 2.07M | } |
444 | | |
445 | | /// Get the endianness of this ISA. |
446 | 0 | pub fn endianness(&self) -> ir::Endianness { |
447 | 0 | match self.triple().endianness().unwrap() { |
448 | 0 | target_lexicon::Endianness::Little => ir::Endianness::Little, |
449 | 0 | target_lexicon::Endianness::Big => ir::Endianness::Big, |
450 | | } |
451 | 0 | } |
452 | | |
453 | | /// Returns the minimum symbol alignment for this ISA. |
454 | 36.3k | pub fn symbol_alignment(&self) -> u64 { |
455 | 36.3k | match self.triple().architecture { |
456 | | // All symbols need to be aligned to at least 2 on s390x. |
457 | 0 | Architecture::S390x => 2, |
458 | 36.3k | _ => 1, |
459 | | } |
460 | 36.3k | } |
461 | | |
462 | | /// Get the pointer type of this ISA. |
463 | 28.9M | pub fn pointer_type(&self) -> ir::Type { |
464 | 28.9M | ir::Type::int(self.pointer_bits() as u16).unwrap() |
465 | 28.9M | } |
466 | | |
467 | | /// Get the width of pointers on this ISA. |
468 | 32.3M | pub(crate) fn pointer_width(&self) -> PointerWidth { |
469 | 32.3M | self.triple().pointer_width().unwrap() |
470 | 32.3M | } |
471 | | |
472 | | /// Get the width of pointers on this ISA, in units of bits. |
473 | 28.9M | pub fn pointer_bits(&self) -> u8 { |
474 | 28.9M | self.pointer_width().bits() |
475 | 28.9M | } |
476 | | |
477 | | /// Get the width of pointers on this ISA, in units of bytes. |
478 | 2.01M | pub fn pointer_bytes(&self) -> u8 { |
479 | 2.01M | self.pointer_width().bytes() |
480 | 2.01M | } |
481 | | |
482 | | /// Get the information needed by frontends producing Cranelift IR. |
483 | 1.31M | pub fn frontend_config(&self) -> TargetFrontendConfig { |
484 | 1.31M | TargetFrontendConfig { |
485 | 1.31M | default_call_conv: self.default_call_conv(), |
486 | 1.31M | pointer_width: self.pointer_width(), |
487 | 1.31M | page_size_align_log2: self.page_size_align_log2(), |
488 | 1.31M | } |
489 | 1.31M | } |
490 | | } |
491 | | |
492 | | impl Debug for &dyn TargetIsa { |
493 | 0 | fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
494 | 0 | write!( |
495 | 0 | f, |
496 | | "TargetIsa {{ triple: {:?}, pointer_width: {:?}}}", |
497 | 0 | self.triple(), |
498 | 0 | self.pointer_width() |
499 | | ) |
500 | 0 | } |
501 | | } |