Skip to main content

rustc_target/
target_features.rs

1//! Declares Rust's target feature names for each target.
2//! Note that these are similar to but not always identical to LLVM's feature names,
3//! and Rust adds some features that do not correspond to LLVM features at all.
4//!
5//! The target features listed here can be used in `#[target_feature]` and `#[cfg(target_feature)]`.
6//! They also do not trigger any warnings when used with `-Ctarget-feature`.
7//!
8//! Note that even unstable (and even entirely unlisted) features can be used with `-Ctarget-feature`
9//! on stable. Using a feature not on the list of Rust target features only emits a warning.
10//! Only `cfg(target_feature)` and `#[target_feature]` actually do any stability gating.
11//! `cfg(target_feature)` for unstable features just works on nightly without any feature gate.
12//! `#[target_feature]` requires a feature gate.
13//!
14//! When adding features to the below lists
15//! check whether they're named already elsewhere in rust
16//! e.g. in stdarch and whether the given name matches LLVM's
17//! if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
18//! Additionally, if the feature is not available in older version of LLVM supported by the current
19//! rust, the same function must be updated to filter out these features to avoid triggering
20//! warnings.
21//!
22//! Also note that all target features listed here must be purely additive: for target_feature 1.1 to
23//! be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a
24//! per-function level, since we would then allow safe calls from functions with `+soft-float` to
25//! functions without that feature!
26//!
27//! It is important for soundness to consider the interaction of target features and the function
28//! call ABI. For example, disabling the `x87` feature on x86 changes how scalar floats are passed as
29//! arguments, so letting people toggle that feature would be unsound. To this end, the
30//! [`Target::abi_required_features`] function computes which target features must and must not be
31//! enabled for any given target, and individual features can also be marked as [`Forbidden`]. See
32//! <https://github.com/rust-lang/rust/issues/116344> for some more context.
33//!
34//! The one exception to features that change the ABI is features that enable larger vector
35//! registers. Those are permitted to be listed here. The `*_FOR_CORRECT_VECTOR_ABI` arrays store
36//! information about which target feature is ABI-required for which vector size; this is used to
37//! ensure that vectors can only be passed via `extern "C"` when the right feature is enabled. (For
38//! the "Rust" ABI we generally pass vectors by-ref exactly to avoid these issues.)
39//! Also see <https://github.com/rust-lang/rust/issues/116558>.
40//!
41//! Stabilizing a target feature requires t-lang approval.
42use rustc_data_structures::fx::{FxHashMap, FxHashSet};
43use rustc_macros::StableHash;
44use rustc_span::{Symbol, sym};
45
46use crate::spec::{Arch, FloatAbi, LlvmAbi, RustcAbi, Target};
47
48/// Features that control behaviour of rustc, rather than the codegen.
49/// These exist globally and are not in the target-specific lists below.
50pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
51
52/// Stability information for target features.
53#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Stability {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Stability::Stable =>
                ::core::fmt::Formatter::write_str(f, "Stable"),
            Stability::CfgStableToggleUnstable(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "CfgStableToggleUnstable", &__self_0),
            Stability::Unstable(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Unstable", &__self_0),
            Stability::Forbidden { reason: __self_0, hard_error: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "Forbidden", "reason", __self_0, "hard_error", &__self_1),
        }
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for Stability { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Stability {
    #[inline]
    fn clone(&self) -> Stability {
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        let _: ::core::clone::AssertParamIsClone<&'static str>;
        let _: ::core::clone::AssertParamIsClone<bool>;
        *self
    }
}Clone, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Stability {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    Stability::Stable => {}
                    Stability::CfgStableToggleUnstable(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Stability::Unstable(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Stability::Forbidden {
                        reason: ref __binding_0, hard_error: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
54pub enum Stability {
55    /// This target feature is stable, it can be used in `#[target_feature]` and
56    /// `#[cfg(target_feature)]`.
57    Stable,
58    /// This target feature is cfg-stable. It can be used for `#[cfg(target_feature)]` on stable,
59    /// but using it in `#[target_feature]` requires the given nightly feature.
60    CfgStableToggleUnstable(
61        /// This must be a *language* feature, or else rustc will ICE when reporting a missing
62        /// feature gate!
63        Symbol,
64    ),
65    /// This target feature is unstable. It is only present in `#[cfg(target_feature)]` on
66    /// nightly and using it in `#[target_feature]` requires enabling the given nightly feature.
67    Unstable(
68        /// This must be a *language* feature, or else rustc will ICE when reporting a missing
69        /// feature gate!
70        Symbol,
71    ),
72    /// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be
73    /// set in the target spec. It is never set in `cfg(target_feature)`. Used in particular for
74    /// features are actually ABI configuration flags (such as "soft-float" on many targets).
75    /// However, "forbidden" target features can still sometimes be enabled via `-Ctarget-cpu` or
76    /// target feature implications (on the Rust/LLVM level). To prevent that, ABI-relevant target
77    /// features are ideally pinned down (required or forbidden) in
78    /// [`Target::abi_required_features`].
79    Forbidden {
80        reason: &'static str,
81        /// True if this is always an error, false if this can be reported as a warning when set via
82        /// `-Ctarget-feature`.
83        hard_error: bool,
84    },
85}
86use Stability::*;
87
88impl Stability {
89    /// Returns whether the feature can be used in `cfg(target_feature)` ever.
90    /// (It might still be nightly-only even if this returns `true`, so make sure to also check
91    /// `requires_nightly`.)
92    pub fn in_cfg(&self) -> bool {
93        #[allow(non_exhaustive_omitted_patterns)] match self {
    Stability::Stable | Stability::CfgStableToggleUnstable { .. } |
        Stability::Unstable { .. } => true,
    _ => false,
}matches!(
94            self,
95            Stability::Stable
96                | Stability::CfgStableToggleUnstable { .. }
97                | Stability::Unstable { .. }
98        )
99    }
100
101    /// Returns the nightly feature that is required to toggle this target feature via
102    /// `#[target_feature]`/`-Ctarget-feature` or to test it via `cfg(target_feature)`.
103    /// (For `cfg` we only care whether the feature is nightly or not, we don't require
104    /// the feature gate to actually be enabled when using a nightly compiler.)
105    ///
106    /// Before calling this, ensure the feature is even permitted for this use:
107    /// - for `#[target_feature]`/`-Ctarget-feature`, check `toggle_allowed()`
108    /// - for `cfg(target_feature)`, check `in_cfg()`
109    ///
110    /// The `in_cfg` parameter is used to determine whether it will be used in
111    /// `cfg(target_feature)` (true) or `#[target_feature]`/`-Ctarget-feature` (false)
112    pub fn requires_nightly(&self, in_cfg: bool) -> Option<Symbol> {
113        match *self {
114            Stability::Unstable(nightly_feature) => Some(nightly_feature),
115            Stability::CfgStableToggleUnstable(nightly_feature) => {
116                if in_cfg {
117                    None
118                } else {
119                    Some(nightly_feature)
120                }
121            }
122            Stability::Stable { .. } => None,
123            Stability::Forbidden { .. } => {
    ::core::panicking::panic_fmt(format_args!("forbidden features should not reach this far"));
}panic!("forbidden features should not reach this far"),
124        }
125    }
126
127    /// Returns whether the feature is cfg-stable but still requires a nightly feature gate to
128    /// be used in `#[target_feature]`/`-Ctarget-feature`.
129    pub fn is_cfg_stable_toggle_unstable(&self) -> bool {
130        #[allow(non_exhaustive_omitted_patterns)] match self {
    Stability::CfgStableToggleUnstable { .. } => true,
    _ => false,
}matches!(self, Stability::CfgStableToggleUnstable { .. })
131    }
132
133    /// Returns whether the feature may be toggled via `#[target_feature]` or `-Ctarget-feature`.
134    /// (It might still be nightly-only even if this returns `Ok(())`, so make sure to also check
135    /// `requires_nightly`.)
136    pub fn toggle_allowed(&self) -> Result<(), &'static str> {
137        match self {
138            Stability::Unstable(_)
139            | Stability::CfgStableToggleUnstable(_)
140            | Stability::Stable { .. } => Ok(()),
141            Stability::Forbidden { reason, hard_error: _ } => Err(reason),
142        }
143    }
144}
145
146/// If feature A "implies" feature B, then:
147/// - when A gets enabled (via `-Ctarget-feature` or `#[target_feature]`), we also enable B
148/// - when B gets disabled (via `-Ctarget-feature`), we also disable A
149///
150/// Both of these are also applied transitively.
151type ImpliedFeatures = &'static [&'static str];
152
153static ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
154    // tidy-alphabetical-start
155    ("aclass", Unstable(sym::arm_target_feature), &[]),
156    ("acquire-release", Unstable(sym::arm_target_feature), &[]),
157    ("aes", Unstable(sym::arm_target_feature), &["neon"]),
158    (
159        "atomics-32",
160        Stability::Forbidden {
161            reason: "unsound because it changes the ABI of atomic operations",
162            hard_error: false,
163        },
164        &[],
165    ),
166    ("crc", Unstable(sym::arm_target_feature), &[]),
167    ("d32", Unstable(sym::arm_target_feature), &[]),
168    ("dotprod", Unstable(sym::arm_target_feature), &["neon"]),
169    ("dsp", Unstable(sym::arm_target_feature), &[]),
170    ("fp-armv8", Unstable(sym::arm_target_feature), &["vfp4"]),
171    ("fp16", Unstable(sym::arm_target_feature), &["neon"]),
172    ("fpregs", Unstable(sym::arm_target_feature), &[]),
173    ("i8mm", Unstable(sym::arm_target_feature), &["neon"]),
174    ("mclass", Unstable(sym::arm_target_feature), &[]),
175    ("mve", Unstable(sym::arm_target_feature), &["v8.1m.main", "dsp", "fpregs"]),
176    ("mve.fp", Unstable(sym::arm_target_feature), &["mve"]),
177    ("neon", Unstable(sym::arm_target_feature), &["vfp3"]),
178    ("rclass", Unstable(sym::arm_target_feature), &[]),
179    ("sha2", Unstable(sym::arm_target_feature), &["neon"]),
180    // This can be *disabled* on non-`hf` targets to enable the use
181    // of hardfloats while keeping the softfloat ABI.
182    // FIXME before stabilization: Should we expose this as a `hard-float` target feature instead of
183    // matching the odd negative feature LLVM uses?
184    ("soft-float", Unstable(sym::arm_target_feature), &[]),
185    // This is needed for inline assembly, but shouldn't be stabilized as-is
186    // since it should be enabled per-function using #[instruction_set], not
187    // #[target_feature].
188    ("thumb-mode", Unstable(sym::arm_target_feature), &[]),
189    ("thumb2", Unstable(sym::arm_target_feature), &[]),
190    ("trustzone", Unstable(sym::arm_target_feature), &[]),
191    ("v5te", Unstable(sym::arm_target_feature), &[]),
192    ("v6", Unstable(sym::arm_target_feature), &["v5te"]),
193    ("v6k", Unstable(sym::arm_target_feature), &["v6"]),
194    ("v6m", Unstable(sym::arm_target_feature), &["v6"]),
195    ("v6t2", Unstable(sym::arm_target_feature), &["v6k", "v8m", "thumb2"]),
196    ("v7", Unstable(sym::arm_target_feature), &["v6t2"]),
197    ("v8", Unstable(sym::arm_target_feature), &["v7", "acquire-release"]),
198    ("v8.1m.main", Unstable(sym::arm_target_feature), &["v8m.main"]),
199    ("v8m", Unstable(sym::arm_target_feature), &["v6m"]),
200    ("v8m.main", Unstable(sym::arm_target_feature), &["v7"]),
201    ("vfp2", Unstable(sym::arm_target_feature), &[]),
202    ("vfp3", Unstable(sym::arm_target_feature), &["vfp2", "d32"]),
203    ("vfp4", Unstable(sym::arm_target_feature), &["vfp3"]),
204    ("virtualization", Unstable(sym::arm_target_feature), &[]),
205    // tidy-alphabetical-end
206];
207
208static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
209    // tidy-alphabetical-start
210    // FEAT_AES & FEAT_PMULL
211    ("aes", Stable, &["neon"]),
212    // FEAT_BF16
213    ("bf16", Stable, &[]),
214    // FEAT_BTI
215    ("bti", Stable, &[]),
216    // FEAT_CRC
217    ("crc", Stable, &[]),
218    // FEAT_CSSC
219    ("cssc", Unstable(sym::aarch64_unstable_target_feature), &[]),
220    // FEAT_DIT
221    ("dit", Stable, &[]),
222    // FEAT_DotProd
223    ("dotprod", Stable, &["neon"]),
224    // FEAT_DPB
225    ("dpb", Stable, &[]),
226    // FEAT_DPB2
227    ("dpb2", Stable, &["dpb"]),
228    // FEAT_ECV
229    ("ecv", Unstable(sym::aarch64_unstable_target_feature), &[]),
230    // FEAT_F32MM
231    ("f32mm", Stable, &["sve"]),
232    // FEAT_F64MM
233    ("f64mm", Stable, &["sve"]),
234    // FEAT_FAMINMAX
235    ("faminmax", Unstable(sym::aarch64_unstable_target_feature), &[]),
236    // FEAT_FCMA
237    ("fcma", Stable, &["neon"]),
238    // FEAT_FHM
239    ("fhm", Stable, &["fp16"]),
240    // FEAT_FLAGM
241    ("flagm", Stable, &[]),
242    // FEAT_FLAGM2
243    ("flagm2", Unstable(sym::aarch64_unstable_target_feature), &[]),
244    // We forbid directly toggling just `fp-armv8`; it must be toggled with `neon`.
245    (
246        "fp-armv8",
247        Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`", hard_error: false },
248        &[],
249    ),
250    // FEAT_FP8
251    ("fp8", Unstable(sym::aarch64_unstable_target_feature), &["faminmax", "lut", "bf16"]),
252    // FEAT_FP8DOT2
253    ("fp8dot2", Unstable(sym::aarch64_unstable_target_feature), &["fp8dot4"]),
254    // FEAT_FP8DOT4
255    ("fp8dot4", Unstable(sym::aarch64_unstable_target_feature), &["fp8fma"]),
256    // FEAT_FP8FMA
257    ("fp8fma", Unstable(sym::aarch64_unstable_target_feature), &["fp8"]),
258    // FEAT_FP16
259    // Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
260    ("fp16", Stable, &["neon"]),
261    // FEAT_FRINTTS
262    ("frintts", Stable, &[]),
263    // FEAT_HBC
264    ("hbc", Unstable(sym::aarch64_unstable_target_feature), &[]),
265    // FEAT_I8MM
266    ("i8mm", Stable, &[]),
267    // FEAT_JSCVT
268    // Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
269    ("jsconv", Stable, &["neon"]),
270    // FEAT_LOR
271    ("lor", Stable, &[]),
272    // FEAT_LSE
273    ("lse", Stable, &[]),
274    // FEAT_LSE2
275    ("lse2", Unstable(sym::aarch64_unstable_target_feature), &[]),
276    // FEAT_LSE128
277    ("lse128", Unstable(sym::aarch64_unstable_target_feature), &["lse"]),
278    // FEAT_LUT
279    ("lut", Unstable(sym::aarch64_unstable_target_feature), &[]),
280    // FEAT_MOPS
281    ("mops", Unstable(sym::aarch64_unstable_target_feature), &[]),
282    // FEAT_MTE & FEAT_MTE2
283    ("mte", Stable, &[]),
284    // FEAT_AdvSimd & FEAT_FP
285    ("neon", Stable, &[]),
286    // Backend option to turn atomic operations into an intrinsic call when `lse` is not known to be
287    // available, so the intrinsic can do runtime LSE feature detection rather than unconditionally
288    // using slower non-LSE operations. Unstable since it doesn't need to user-togglable.
289    ("outline-atomics", Unstable(sym::aarch64_unstable_target_feature), &[]),
290    // FEAT_PAUTH (address authentication)
291    ("paca", Stable, &[]),
292    // FEAT_PAUTH (generic authentication)
293    ("pacg", Stable, &[]),
294    // FEAT_PAN
295    ("pan", Stable, &[]),
296    // FEAT_PAuth_LR
297    ("pauth-lr", Unstable(sym::aarch64_unstable_target_feature), &[]),
298    // FEAT_PMUv3
299    ("pmuv3", Stable, &[]),
300    // FEAT_RNG
301    ("rand", Stable, &[]),
302    // FEAT_RAS & FEAT_RASv1p1
303    ("ras", Stable, &[]),
304    // FEAT_LRCPC
305    ("rcpc", Stable, &[]),
306    // FEAT_LRCPC2
307    ("rcpc2", Stable, &["rcpc"]),
308    // FEAT_LRCPC3
309    ("rcpc3", Unstable(sym::aarch64_unstable_target_feature), &["rcpc2"]),
310    // FEAT_RDM
311    ("rdm", Stable, &["neon"]),
312    (
313        "reserve-x18",
314        Forbidden { reason: "use `-Zfixed-x18` compiler flag instead", hard_error: false },
315        &[],
316    ),
317    // FEAT_SB
318    ("sb", Stable, &[]),
319    // FEAT_SHA1 & FEAT_SHA256
320    ("sha2", Stable, &["neon"]),
321    // FEAT_SHA512 & FEAT_SHA3
322    ("sha3", Stable, &["sha2"]),
323    // FEAT_SM3 & FEAT_SM4
324    ("sm4", Stable, &["neon"]),
325    // FEAT_SME
326    ("sme", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]),
327    // FEAT_SME_B16B16
328    ("sme-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16", "sme2", "sve-b16b16"]),
329    // FEAT_SME_F8F16
330    ("sme-f8f16", Unstable(sym::aarch64_unstable_target_feature), &["sme-f8f32"]),
331    // FEAT_SME_F8F32
332    ("sme-f8f32", Unstable(sym::aarch64_unstable_target_feature), &["sme2", "fp8"]),
333    // FEAT_SME_F16F16
334    ("sme-f16f16", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]),
335    // FEAT_SME_F64F64
336    ("sme-f64f64", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
337    // FEAT_SME_FA64
338    ("sme-fa64", Unstable(sym::aarch64_unstable_target_feature), &["sme", "sve2"]),
339    // FEAT_SME_I16I64
340    ("sme-i16i64", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
341    // FEAT_SME_LUTv2
342    ("sme-lutv2", Unstable(sym::aarch64_unstable_target_feature), &[]),
343    // FEAT_SME2
344    ("sme2", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
345    // FEAT_SME2p1
346    ("sme2p1", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]),
347    // FEAT_SPE
348    ("spe", Stable, &[]),
349    // FEAT_SSBS & FEAT_SSBS2
350    ("ssbs", Stable, &[]),
351    // FEAT_SSVE_FP8FDOT2
352    ("ssve-fp8dot2", Unstable(sym::aarch64_unstable_target_feature), &["ssve-fp8dot4"]),
353    // FEAT_SSVE_FP8FDOT4
354    ("ssve-fp8dot4", Unstable(sym::aarch64_unstable_target_feature), &["ssve-fp8fma"]),
355    // FEAT_SSVE_FP8FMA
356    ("ssve-fp8fma", Unstable(sym::aarch64_unstable_target_feature), &["sme2", "fp8"]),
357    // FEAT_SVE
358    // It was decided that SVE requires Neon: https://github.com/rust-lang/rust/pull/91608
359    //
360    // LLVM doesn't enable Neon for SVE. ARM indicates that they're separate, but probably always
361    // exist together: https://developer.arm.com/documentation/102340/0100/New-features-in-SVE2
362    //
363    // "For backwards compatibility, Neon and VFP are required in the latest architectures."
364    ("sve", Stable, &["neon", "fp16"]),
365    // FEAT_SVE_B16B16 (SVE or SME Z-targeting instructions)
366    ("sve-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]),
367    // FEAT_SVE2
368    ("sve2", Stable, &["sve"]),
369    // FEAT_SVE_AES & FEAT_SVE_PMULL128
370    ("sve2-aes", Stable, &["sve2", "aes"]),
371    // FEAT_SVE2_BitPerm
372    ("sve2-bitperm", Stable, &["sve2"]),
373    // FEAT_SVE2_SHA3
374    ("sve2-sha3", Stable, &["sve2", "sha3"]),
375    // FEAT_SVE2_SM4
376    ("sve2-sm4", Stable, &["sve2", "sm4"]),
377    // FEAT_SVE2p1
378    ("sve2p1", Unstable(sym::aarch64_unstable_target_feature), &["sve2"]),
379    // FEAT_TME
380    ("tme", Stable, &[]),
381    (
382        "v8.1a",
383        Unstable(sym::aarch64_ver_target_feature),
384        &["crc", "lse", "rdm", "pan", "lor", "vh"],
385    ),
386    ("v8.2a", Unstable(sym::aarch64_ver_target_feature), &["v8.1a", "ras", "dpb"]),
387    (
388        "v8.3a",
389        Unstable(sym::aarch64_ver_target_feature),
390        &["v8.2a", "rcpc", "paca", "pacg", "jsconv"],
391    ),
392    ("v8.4a", Unstable(sym::aarch64_ver_target_feature), &["v8.3a", "dotprod", "dit", "flagm"]),
393    ("v8.5a", Unstable(sym::aarch64_ver_target_feature), &["v8.4a", "ssbs", "sb", "dpb2", "bti"]),
394    ("v8.6a", Unstable(sym::aarch64_ver_target_feature), &["v8.5a", "bf16", "i8mm"]),
395    ("v8.7a", Unstable(sym::aarch64_ver_target_feature), &["v8.6a", "wfxt"]),
396    ("v8.8a", Unstable(sym::aarch64_ver_target_feature), &["v8.7a", "hbc", "mops"]),
397    ("v8.9a", Unstable(sym::aarch64_ver_target_feature), &["v8.8a", "cssc"]),
398    ("v9.1a", Unstable(sym::aarch64_ver_target_feature), &["v9a", "v8.6a"]),
399    ("v9.2a", Unstable(sym::aarch64_ver_target_feature), &["v9.1a", "v8.7a"]),
400    ("v9.3a", Unstable(sym::aarch64_ver_target_feature), &["v9.2a", "v8.8a"]),
401    ("v9.4a", Unstable(sym::aarch64_ver_target_feature), &["v9.3a", "v8.9a"]),
402    ("v9.5a", Unstable(sym::aarch64_ver_target_feature), &["v9.4a"]),
403    ("v9a", Unstable(sym::aarch64_ver_target_feature), &["v8.5a"]),
404    // FEAT_VHE
405    ("vh", Stable, &[]),
406    // FEAT_WFxT
407    ("wfxt", Unstable(sym::aarch64_unstable_target_feature), &[]),
408    // tidy-alphabetical-end
409];
410
411const AARCH64_TIED_FEATURES: &[&[&str]] = &[
412    &["paca", "pacg"], // Together these represent `pauth` in LLVM
413];
414
415static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
416    // tidy-alphabetical-start
417    ("adx", Stable, &[]),
418    ("aes", Stable, &["sse2"]),
419    ("amx-avx512", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
420    ("amx-bf16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
421    ("amx-complex", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
422    ("amx-fp8", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
423    ("amx-fp16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
424    ("amx-int8", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
425    ("amx-movrs", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
426    ("amx-tile", Unstable(sym::x86_amx_intrinsics), &[]),
427    ("apxf", Unstable(sym::apx_target_feature), &[]),
428    ("avx", Stable, &["sse4.2"]),
429    ("avx2", Stable, &["avx"]),
430    (
431        "avx10.1",
432        Unstable(sym::avx10_target_feature),
433        &[
434            "avx512bf16",
435            "avx512bitalg",
436            "avx512bw",
437            "avx512cd",
438            "avx512dq",
439            "avx512f",
440            "avx512fp16",
441            "avx512ifma",
442            "avx512vbmi",
443            "avx512vbmi2",
444            "avx512vl",
445            "avx512vnni",
446            "avx512vpopcntdq",
447        ],
448    ),
449    (
450        "avx10.2",
451        Unstable(sym::avx10_target_feature),
452        &["avx10.1", "avxvnni", "avxvnniint8", "avxvnniint16"],
453    ),
454    ("avx512bf16", Stable, &["avx512bw"]),
455    ("avx512bitalg", Stable, &["avx512bw"]),
456    ("avx512bw", Stable, &["avx512f"]),
457    ("avx512cd", Stable, &["avx512f"]),
458    ("avx512dq", Stable, &["avx512f"]),
459    ("avx512f", Stable, &["avx2", "fma", "f16c"]),
460    ("avx512fp16", Stable, &["avx512bw"]),
461    ("avx512ifma", Stable, &["avx512f"]),
462    ("avx512vbmi", Stable, &["avx512bw"]),
463    ("avx512vbmi2", Stable, &["avx512bw"]),
464    ("avx512vl", Stable, &["avx512f"]),
465    ("avx512vnni", Stable, &["avx512f"]),
466    ("avx512vp2intersect", Stable, &["avx512f"]),
467    ("avx512vpopcntdq", Stable, &["avx512f"]),
468    ("avxifma", Stable, &["avx2"]),
469    ("avxneconvert", Stable, &["avx2"]),
470    ("avxvnni", Stable, &["avx2"]),
471    ("avxvnniint8", Stable, &["avx2"]),
472    ("avxvnniint16", Stable, &["avx2"]),
473    ("bmi1", Stable, &[]),
474    ("bmi2", Stable, &[]),
475    ("clflushopt", Unstable(sym::clflushopt_target_feature), &[]),
476    ("cmpxchg16b", Stable, &[]),
477    ("ermsb", Unstable(sym::ermsb_target_feature), &[]),
478    ("f16c", Stable, &["avx"]),
479    ("fma", Stable, &["avx"]),
480    ("fma4", Unstable(sym::fma4_target_feature), &["avx", "sse4a"]),
481    ("fxsr", Stable, &[]),
482    ("gfni", Stable, &["sse2"]),
483    ("kl", Stable, &["sse2"]),
484    ("lahfsahf", Unstable(sym::lahfsahf_target_feature), &[]),
485    ("lzcnt", Stable, &[]),
486    ("movbe", Stable, &[]),
487    ("movrs", Unstable(sym::movrs_target_feature), &[]),
488    ("pclmulqdq", Stable, &["sse2"]),
489    ("popcnt", Stable, &[]),
490    ("prfchw", Unstable(sym::prfchw_target_feature), &[]),
491    ("rdrand", Stable, &[]),
492    ("rdseed", Stable, &[]),
493    (
494        "retpoline-external-thunk",
495        Stability::Forbidden {
496            reason: "use `-Zretpoline-external-thunk` compiler flag instead",
497            hard_error: false,
498        },
499        &[],
500    ),
501    (
502        "retpoline-indirect-branches",
503        Stability::Forbidden {
504            reason: "use `-Zretpoline` compiler flag instead",
505            hard_error: false,
506        },
507        &[],
508    ),
509    (
510        "retpoline-indirect-calls",
511        Stability::Forbidden {
512            reason: "use `-Zretpoline` compiler flag instead",
513            hard_error: false,
514        },
515        &[],
516    ),
517    ("rtm", Unstable(sym::rtm_target_feature), &[]),
518    ("sha", Stable, &["sse2"]),
519    ("sha512", Stable, &["avx2"]),
520    ("sm3", Stable, &["avx"]),
521    ("sm4", Stable, &["avx2"]),
522    (
523        "soft-float",
524        Stability::Forbidden { reason: "use a soft-float target instead", hard_error: false },
525        &[],
526    ),
527    ("sse", Stable, &[]),
528    ("sse2", Stable, &["sse"]),
529    ("sse3", Stable, &["sse2"]),
530    ("sse4.1", Stable, &["ssse3"]),
531    ("sse4.2", Stable, &["sse4.1"]),
532    ("sse4a", Stable, &["sse3"]),
533    ("ssse3", Stable, &["sse3"]),
534    ("tbm", Stable, &[]),
535    ("vaes", Stable, &["avx2", "aes"]),
536    ("vpclmulqdq", Stable, &["avx", "pclmulqdq"]),
537    ("widekl", Stable, &["kl"]),
538    ("x87", Unstable(sym::x87_target_feature), &[]),
539    ("xop", Unstable(sym::xop_target_feature), &["fma4", "avx", "sse4a"]),
540    ("xsave", Stable, &[]),
541    ("xsavec", Stable, &["xsave"]),
542    ("xsaveopt", Stable, &["xsave"]),
543    ("xsaves", Stable, &["xsave"]),
544    // tidy-alphabetical-end
545];
546
547const HEXAGON_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
548    // tidy-alphabetical-start
549    ("audio", Unstable(sym::hexagon_target_feature), &[]),
550    ("hvx", Unstable(sym::hexagon_target_feature), &[]),
551    ("hvx-ieee-fp", Unstable(sym::hexagon_target_feature), &["hvx"]),
552    ("hvx-length64b", Unstable(sym::hexagon_target_feature), &["hvx"]),
553    ("hvx-length128b", Unstable(sym::hexagon_target_feature), &["hvx"]),
554    ("hvx-qfloat", Unstable(sym::hexagon_target_feature), &["hvx"]),
555    ("hvxv60", Unstable(sym::hexagon_target_feature), &["hvx"]),
556    ("hvxv62", Unstable(sym::hexagon_target_feature), &["hvxv60"]),
557    ("hvxv65", Unstable(sym::hexagon_target_feature), &["hvxv62"]),
558    ("hvxv66", Unstable(sym::hexagon_target_feature), &["hvxv65", "zreg"]),
559    ("hvxv67", Unstable(sym::hexagon_target_feature), &["hvxv66"]),
560    ("hvxv68", Unstable(sym::hexagon_target_feature), &["hvxv67"]),
561    ("hvxv69", Unstable(sym::hexagon_target_feature), &["hvxv68"]),
562    ("hvxv71", Unstable(sym::hexagon_target_feature), &["hvxv69"]),
563    ("hvxv73", Unstable(sym::hexagon_target_feature), &["hvxv71"]),
564    ("hvxv75", Unstable(sym::hexagon_target_feature), &["hvxv73"]),
565    ("hvxv79", Unstable(sym::hexagon_target_feature), &["hvxv75"]),
566    ("v60", Unstable(sym::hexagon_target_feature), &[]),
567    ("v62", Unstable(sym::hexagon_target_feature), &["v60"]),
568    ("v65", Unstable(sym::hexagon_target_feature), &["v62"]),
569    ("v66", Unstable(sym::hexagon_target_feature), &["v65"]),
570    ("v67", Unstable(sym::hexagon_target_feature), &["v66"]),
571    ("v68", Unstable(sym::hexagon_target_feature), &["v67"]),
572    ("v69", Unstable(sym::hexagon_target_feature), &["v68"]),
573    ("v71", Unstable(sym::hexagon_target_feature), &["v69"]),
574    ("v73", Unstable(sym::hexagon_target_feature), &["v71"]),
575    ("v75", Unstable(sym::hexagon_target_feature), &["v73"]),
576    ("v79", Unstable(sym::hexagon_target_feature), &["v75"]),
577    ("zreg", Unstable(sym::hexagon_target_feature), &[]),
578    // tidy-alphabetical-end
579];
580
581static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
582    // If you are thinking of adding "efpu2" here, please double-check that it really does not
583    // affect the ABI.
584    // tidy-alphabetical-start
585    ("altivec", Unstable(sym::powerpc_target_feature), &[]),
586    (
587        "hard-float",
588        Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false },
589        &[],
590    ),
591    ("msync", Unstable(sym::powerpc_target_feature), &[]),
592    ("partword-atomics", Unstable(sym::powerpc_target_feature), &[]),
593    ("power8-altivec", Unstable(sym::powerpc_target_feature), &["altivec"]),
594    ("power8-crypto", Unstable(sym::powerpc_target_feature), &["power8-altivec"]),
595    ("power8-vector", Unstable(sym::powerpc_target_feature), &["vsx", "power8-altivec"]),
596    ("power9-altivec", Unstable(sym::powerpc_target_feature), &["power8-altivec"]),
597    ("power9-vector", Unstable(sym::powerpc_target_feature), &["power8-vector", "power9-altivec"]),
598    ("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]),
599    ("quadword-atomics", Unstable(sym::powerpc_target_feature), &[]),
600    ("spe", Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, &[]),
601    ("vsx", Unstable(sym::powerpc_target_feature), &["altivec"]),
602    // tidy-alphabetical-end
603];
604
605const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
606    // tidy-alphabetical-start
607    ("fp64", Unstable(sym::mips_target_feature), &[]),
608    ("msa", Unstable(sym::mips_target_feature), &[]),
609    ("virt", Unstable(sym::mips_target_feature), &[]),
610    // tidy-alphabetical-end
611];
612
613const NVPTX_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
614    // tidy-alphabetical-start
615    ("sm_70", Unstable(sym::nvptx_target_feature), &[]),
616    ("sm_72", Unstable(sym::nvptx_target_feature), &["sm_70"]),
617    ("sm_75", Unstable(sym::nvptx_target_feature), &["sm_72"]),
618    ("sm_80", Unstable(sym::nvptx_target_feature), &["sm_75"]),
619    ("sm_86", Unstable(sym::nvptx_target_feature), &["sm_80"]),
620    ("sm_87", Unstable(sym::nvptx_target_feature), &["sm_86"]),
621    ("sm_89", Unstable(sym::nvptx_target_feature), &["sm_87"]),
622    ("sm_90", Unstable(sym::nvptx_target_feature), &["sm_89"]),
623    ("sm_90a", Unstable(sym::nvptx_target_feature), &["sm_90"]),
624    // tidy-alphabetical-end
625    // tidy-alphabetical-start
626    ("sm_100", Unstable(sym::nvptx_target_feature), &["sm_90"]),
627    ("sm_100a", Unstable(sym::nvptx_target_feature), &["sm_100"]),
628    ("sm_101", Unstable(sym::nvptx_target_feature), &["sm_100"]),
629    ("sm_101a", Unstable(sym::nvptx_target_feature), &["sm_101"]),
630    ("sm_120", Unstable(sym::nvptx_target_feature), &["sm_101"]),
631    ("sm_120a", Unstable(sym::nvptx_target_feature), &["sm_120"]),
632    // tidy-alphabetical-end
633    // tidy-alphabetical-start
634    ("ptx70", Unstable(sym::nvptx_target_feature), &[]),
635    ("ptx71", Unstable(sym::nvptx_target_feature), &["ptx70"]),
636    ("ptx72", Unstable(sym::nvptx_target_feature), &["ptx71"]),
637    ("ptx73", Unstable(sym::nvptx_target_feature), &["ptx72"]),
638    ("ptx74", Unstable(sym::nvptx_target_feature), &["ptx73"]),
639    ("ptx75", Unstable(sym::nvptx_target_feature), &["ptx74"]),
640    ("ptx76", Unstable(sym::nvptx_target_feature), &["ptx75"]),
641    ("ptx77", Unstable(sym::nvptx_target_feature), &["ptx76"]),
642    ("ptx78", Unstable(sym::nvptx_target_feature), &["ptx77"]),
643    ("ptx80", Unstable(sym::nvptx_target_feature), &["ptx78"]),
644    ("ptx81", Unstable(sym::nvptx_target_feature), &["ptx80"]),
645    ("ptx82", Unstable(sym::nvptx_target_feature), &["ptx81"]),
646    ("ptx83", Unstable(sym::nvptx_target_feature), &["ptx82"]),
647    ("ptx84", Unstable(sym::nvptx_target_feature), &["ptx83"]),
648    ("ptx85", Unstable(sym::nvptx_target_feature), &["ptx84"]),
649    ("ptx86", Unstable(sym::nvptx_target_feature), &["ptx85"]),
650    ("ptx87", Unstable(sym::nvptx_target_feature), &["ptx86"]),
651    // tidy-alphabetical-end
652];
653
654static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
655    // tidy-alphabetical-start
656    ("a", Stable, &["zaamo", "zalrsc"]),
657    ("b", Stable, &["zba", "zbb", "zbs"]),
658    ("c", Stable, &["zca"]),
659    ("d", CfgStableToggleUnstable(sym::riscv_target_feature), &["f"]),
660    ("e", CfgStableToggleUnstable(sym::riscv_target_feature), &[]),
661    ("f", CfgStableToggleUnstable(sym::riscv_target_feature), &["zicsr"]),
662    (
663        "forced-atomics",
664        Stability::Forbidden {
665            reason: "unsound because it changes the ABI of atomic operations",
666            hard_error: false,
667        },
668        &[],
669    ),
670    ("m", Stable, &[]),
671    ("relax", Unstable(sym::riscv_target_feature), &[]),
672    (
673        "rva23u64",
674        Unstable(sym::riscv_target_feature),
675        &[
676            "m",
677            "a",
678            "f",
679            "d",
680            "c",
681            "b",
682            "v",
683            "zicsr",
684            "zicntr",
685            "zihpm",
686            "ziccif",
687            "ziccrse",
688            "ziccamoa",
689            "zicclsm",
690            "zic64b",
691            "za64rs",
692            "zihintpause",
693            "zba",
694            "zbb",
695            "zbs",
696            "zicbom",
697            "zicbop",
698            "zicboz",
699            "zfhmin",
700            "zkt",
701            "zvfhmin",
702            "zvbb",
703            "zvkt",
704            "zihintntl",
705            "zicond",
706            "zimop",
707            "zcmop",
708            "zcb",
709            "zfa",
710            "zawrs",
711            "supm",
712        ],
713    ),
714    ("supm", Unstable(sym::riscv_target_feature), &[]),
715    ("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
716    ("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
717    ("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
718    ("za64rs", Stable, &["za128rs"]), // Za64rs ⊃ Za128rs
719    ("za128rs", Stable, &[]),
720    ("zaamo", Stable, &[]),
721    ("zabha", Stable, &["zaamo"]),
722    ("zacas", Stable, &["zaamo"]),
723    ("zalrsc", Stable, &[]),
724    ("zama16b", Stable, &[]),
725    ("zawrs", Stable, &[]),
726    ("zba", Stable, &[]),
727    ("zbb", Stable, &[]),
728    ("zbc", Stable, &["zbkc"]), // Zbc ⊃ Zbkc
729    ("zbkb", Stable, &[]),
730    ("zbkc", Stable, &[]),
731    ("zbkx", Stable, &[]),
732    ("zbs", Stable, &[]),
733    ("zca", Stable, &[]),
734    ("zcb", Stable, &["zca"]),
735    ("zcmop", Stable, &["zca"]),
736    ("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
737    ("zfa", Unstable(sym::riscv_target_feature), &["f"]),
738    ("zfbfmin", Unstable(sym::riscv_target_feature), &["f"]), // and a subset of Zfhmin
739    ("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
740    ("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
741    ("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
742    ("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
743    ("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
744    ("zic64b", Stable, &[]),
745    ("zicbom", Stable, &[]),
746    ("zicbop", Stable, &[]),
747    ("zicboz", Stable, &[]),
748    ("ziccamoa", Stable, &[]),
749    ("ziccif", Stable, &[]),
750    ("zicclsm", Stable, &[]),
751    ("ziccrse", Stable, &[]),
752    ("zicntr", Stable, &["zicsr"]),
753    ("zicond", Stable, &[]),
754    ("zicsr", Stable, &[]),
755    ("zifencei", Stable, &[]),
756    ("zihintntl", Stable, &[]),
757    ("zihintpause", Stable, &[]),
758    ("zihpm", Stable, &["zicsr"]),
759    ("zimop", Stable, &[]),
760    ("zk", Stable, &["zkn", "zkr", "zkt"]),
761    ("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
762    ("zknd", Stable, &["zkne_or_zknd"]),
763    ("zkne", Stable, &["zkne_or_zknd"]),
764    ("zkne_or_zknd", Unstable(sym::riscv_target_feature), &[]), // Not an extension
765    ("zknh", Stable, &[]),
766    ("zkr", Stable, &[]),
767    ("zks", Stable, &["zbkb", "zbkc", "zbkx", "zksed", "zksh"]),
768    ("zksed", Stable, &[]),
769    ("zksh", Stable, &[]),
770    ("zkt", Stable, &[]),
771    ("ztso", Stable, &[]),
772    ("zvbb", Unstable(sym::riscv_target_feature), &["zvkb"]), // Zvbb ⊃ Zvkb
773    ("zvbc", Unstable(sym::riscv_target_feature), &["zve64x"]),
774    ("zve32f", Unstable(sym::riscv_target_feature), &["zve32x", "f"]),
775    ("zve32x", Unstable(sym::riscv_target_feature), &["zvl32b", "zicsr"]),
776    ("zve64d", Unstable(sym::riscv_target_feature), &["zve64f", "d"]),
777    ("zve64f", Unstable(sym::riscv_target_feature), &["zve32f", "zve64x"]),
778    ("zve64x", Unstable(sym::riscv_target_feature), &["zve32x", "zvl64b"]),
779    ("zvfbfmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
780    ("zvfbfwma", Unstable(sym::riscv_target_feature), &["zfbfmin", "zvfbfmin"]),
781    ("zvfh", Unstable(sym::riscv_target_feature), &["zvfhmin", "zve32f", "zfhmin"]), // Zvfh ⊃ Zvfhmin
782    ("zvfhmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
783    ("zvkb", Unstable(sym::riscv_target_feature), &["zve32x"]),
784    ("zvkg", Unstable(sym::riscv_target_feature), &["zve32x"]),
785    ("zvkn", Unstable(sym::riscv_target_feature), &["zvkned", "zvknhb", "zvkb", "zvkt"]),
786    ("zvknc", Unstable(sym::riscv_target_feature), &["zvkn", "zvbc"]),
787    ("zvkned", Unstable(sym::riscv_target_feature), &["zve32x"]),
788    ("zvkng", Unstable(sym::riscv_target_feature), &["zvkn", "zvkg"]),
789    ("zvknha", Unstable(sym::riscv_target_feature), &["zve32x"]),
790    ("zvknhb", Unstable(sym::riscv_target_feature), &["zvknha", "zve64x"]), // Zvknhb ⊃ Zvknha
791    ("zvks", Unstable(sym::riscv_target_feature), &["zvksed", "zvksh", "zvkb", "zvkt"]),
792    ("zvksc", Unstable(sym::riscv_target_feature), &["zvks", "zvbc"]),
793    ("zvksed", Unstable(sym::riscv_target_feature), &["zve32x"]),
794    ("zvksg", Unstable(sym::riscv_target_feature), &["zvks", "zvkg"]),
795    ("zvksh", Unstable(sym::riscv_target_feature), &["zve32x"]),
796    ("zvkt", Unstable(sym::riscv_target_feature), &[]),
797    ("zvl32b", Unstable(sym::riscv_target_feature), &[]),
798    ("zvl64b", Unstable(sym::riscv_target_feature), &["zvl32b"]),
799    ("zvl128b", Unstable(sym::riscv_target_feature), &["zvl64b"]),
800    ("zvl256b", Unstable(sym::riscv_target_feature), &["zvl128b"]),
801    ("zvl512b", Unstable(sym::riscv_target_feature), &["zvl256b"]),
802    ("zvl1024b", Unstable(sym::riscv_target_feature), &["zvl512b"]),
803    ("zvl2048b", Unstable(sym::riscv_target_feature), &["zvl1024b"]),
804    ("zvl4096b", Unstable(sym::riscv_target_feature), &["zvl2048b"]),
805    ("zvl8192b", Unstable(sym::riscv_target_feature), &["zvl4096b"]),
806    ("zvl16384b", Unstable(sym::riscv_target_feature), &["zvl8192b"]),
807    ("zvl32768b", Unstable(sym::riscv_target_feature), &["zvl16384b"]),
808    ("zvl65536b", Unstable(sym::riscv_target_feature), &["zvl32768b"]),
809    // tidy-alphabetical-end
810];
811
812static WASM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
813    // tidy-alphabetical-start
814    ("atomics", Unstable(sym::wasm_target_feature), &[]),
815    ("bulk-memory", Stable, &[]),
816    ("exception-handling", Unstable(sym::wasm_target_feature), &[]),
817    ("extended-const", Stable, &[]),
818    ("gc", Unstable(sym::wasm_target_feature), &["reference-types"]),
819    ("multivalue", Stable, &[]),
820    ("mutable-globals", Stable, &[]),
821    ("nontrapping-fptoint", Stable, &[]),
822    ("reference-types", Stable, &[]),
823    ("relaxed-simd", Stable, &["simd128"]),
824    ("sign-ext", Stable, &[]),
825    ("simd128", Stable, &[]),
826    ("tail-call", Stable, &[]),
827    ("wide-arithmetic", Unstable(sym::wasm_target_feature), &[]),
828    // tidy-alphabetical-end
829];
830
831const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
832    ("alu32", Unstable(sym::bpf_target_feature), &[]),
833    ("allows-misaligned-mem-access", Unstable(sym::bpf_target_feature), &[]),
834];
835
836static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
837    // tidy-alphabetical-start
838    ("2e3", Unstable(sym::csky_target_feature), &["e2"]),
839    ("3e3r1", Unstable(sym::csky_target_feature), &[]),
840    ("3e3r2", Unstable(sym::csky_target_feature), &["3e3r1", "doloop"]),
841    ("3e3r3", Unstable(sym::csky_target_feature), &["doloop"]),
842    ("3e7", Unstable(sym::csky_target_feature), &["2e3"]),
843    ("7e10", Unstable(sym::csky_target_feature), &["3e7"]),
844    ("10e60", Unstable(sym::csky_target_feature), &["7e10"]),
845    ("cache", Unstable(sym::csky_target_feature), &[]),
846    ("doloop", Unstable(sym::csky_target_feature), &[]),
847    ("dsp1e2", Unstable(sym::csky_target_feature), &[]),
848    ("dspe60", Unstable(sym::csky_target_feature), &[]),
849    ("e1", Unstable(sym::csky_target_feature), &["elrw"]),
850    ("e2", Unstable(sym::csky_target_feature), &["e2"]),
851    ("edsp", Unstable(sym::csky_target_feature), &[]),
852    ("elrw", Unstable(sym::csky_target_feature), &[]),
853    ("float1e2", Unstable(sym::csky_target_feature), &[]),
854    ("float1e3", Unstable(sym::csky_target_feature), &[]),
855    ("float3e4", Unstable(sym::csky_target_feature), &[]),
856    ("float7e60", Unstable(sym::csky_target_feature), &[]),
857    ("floate1", Unstable(sym::csky_target_feature), &[]),
858    ("hard-tp", Unstable(sym::csky_target_feature), &[]),
859    ("high-registers", Unstable(sym::csky_target_feature), &[]),
860    ("hwdiv", Unstable(sym::csky_target_feature), &[]),
861    ("mp", Unstable(sym::csky_target_feature), &["2e3"]),
862    ("mp1e2", Unstable(sym::csky_target_feature), &["3e7"]),
863    ("nvic", Unstable(sym::csky_target_feature), &[]),
864    ("trust", Unstable(sym::csky_target_feature), &[]),
865    ("vdsp2e60f", Unstable(sym::csky_target_feature), &[]),
866    ("vdspv1", Unstable(sym::csky_target_feature), &[]),
867    ("vdspv2", Unstable(sym::csky_target_feature), &[]),
868    // tidy-alphabetical-end
869    //fpu
870    // tidy-alphabetical-start
871    ("fdivdu", Unstable(sym::csky_target_feature), &[]),
872    ("fpuv2_df", Unstable(sym::csky_target_feature), &[]),
873    ("fpuv2_sf", Unstable(sym::csky_target_feature), &[]),
874    ("fpuv3_df", Unstable(sym::csky_target_feature), &[]),
875    ("fpuv3_hf", Unstable(sym::csky_target_feature), &[]),
876    ("fpuv3_hi", Unstable(sym::csky_target_feature), &[]),
877    ("fpuv3_sf", Unstable(sym::csky_target_feature), &[]),
878    ("hard-float", Unstable(sym::csky_target_feature), &[]),
879    ("hard-float-abi", Unstable(sym::csky_target_feature), &[]),
880    // tidy-alphabetical-end
881];
882
883static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
884    // tidy-alphabetical-start
885    ("32s", Unstable(sym::loongarch_target_feature), &[]),
886    ("d", Stable, &["f"]),
887    ("div32", Stable, &[]),
888    ("f", Stable, &[]),
889    ("frecipe", Stable, &[]),
890    ("lam-bh", Stable, &[]),
891    ("lamcas", Stable, &[]),
892    ("lasx", Stable, &["lsx"]),
893    ("lbt", Stable, &[]),
894    ("ld-seq-sa", Stable, &[]),
895    ("lsx", Stable, &["d"]),
896    ("lvz", Stable, &[]),
897    ("relax", Unstable(sym::loongarch_target_feature), &[]),
898    ("scq", Stable, &[]),
899    ("ual", Unstable(sym::loongarch_target_feature), &[]),
900    // tidy-alphabetical-end
901];
902
903#[rustfmt::skip]
904const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
905    // tidy-alphabetical-start
906    // For "backchain", https://github.com/rust-lang/rust/issues/142412 is a stabilization blocker
907    ("backchain", Unstable(sym::s390x_target_feature), &[]),
908    ("concurrent-functions", Unstable(sym::s390x_target_feature), &[]),
909    ("deflate-conversion", Unstable(sym::s390x_target_feature), &[]),
910    ("enhanced-sort", Unstable(sym::s390x_target_feature), &[]),
911    ("guarded-storage", Unstable(sym::s390x_target_feature), &[]),
912    ("high-word", Unstable(sym::s390x_target_feature), &[]),
913    // LLVM does not define message-security-assist-extension versions 1, 2, 6, 10 and 11.
914    ("message-security-assist-extension3", Unstable(sym::s390x_target_feature), &[]),
915    ("message-security-assist-extension4", Unstable(sym::s390x_target_feature), &[]),
916    ("message-security-assist-extension5", Unstable(sym::s390x_target_feature), &[]),
917    ("message-security-assist-extension8", Unstable(sym::s390x_target_feature), &["message-security-assist-extension3"]),
918    ("message-security-assist-extension9", Unstable(sym::s390x_target_feature), &["message-security-assist-extension3", "message-security-assist-extension4"]),
919    ("message-security-assist-extension12", Unstable(sym::s390x_target_feature), &[]),
920    ("miscellaneous-extensions-2", Stable, &[]),
921    ("miscellaneous-extensions-3", Stable, &[]),
922    ("miscellaneous-extensions-4", Stable, &[]),
923    ("nnp-assist", Stable, &["vector"]),
924    ("soft-float", Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, &[]),
925    ("transactional-execution", Unstable(sym::s390x_target_feature), &[]),
926    ("vector", Stable, &[]),
927    ("vector-enhancements-1", Stable, &["vector"]),
928    ("vector-enhancements-2", Stable, &["vector-enhancements-1"]),
929    ("vector-enhancements-3", Stable, &["vector-enhancements-2"]),
930    ("vector-packed-decimal", Stable, &["vector"]),
931    ("vector-packed-decimal-enhancement", Stable, &["vector-packed-decimal"]),
932    ("vector-packed-decimal-enhancement-2", Stable, &["vector-packed-decimal-enhancement"]),
933    ("vector-packed-decimal-enhancement-3", Stable, &["vector-packed-decimal-enhancement-2"]),
934    // tidy-alphabetical-end
935];
936
937const SPARC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
938    // tidy-alphabetical-start
939    ("leoncasa", Unstable(sym::sparc_target_feature), &[]),
940    ("v8plus", Unstable(sym::sparc_target_feature), &[]),
941    ("v9", Unstable(sym::sparc_target_feature), &[]),
942    // tidy-alphabetical-end
943];
944
945static M68K_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
946    // tidy-alphabetical-start
947    ("isa-68000", Unstable(sym::m68k_target_feature), &[]),
948    ("isa-68010", Unstable(sym::m68k_target_feature), &["isa-68000"]),
949    ("isa-68020", Unstable(sym::m68k_target_feature), &["isa-68010"]),
950    ("isa-68030", Unstable(sym::m68k_target_feature), &["isa-68020"]),
951    ("isa-68040", Unstable(sym::m68k_target_feature), &["isa-68030", "isa-68882"]),
952    ("isa-68060", Unstable(sym::m68k_target_feature), &["isa-68040"]),
953    // FPU
954    ("isa-68881", Unstable(sym::m68k_target_feature), &[]),
955    ("isa-68882", Unstable(sym::m68k_target_feature), &["isa-68881"]),
956    // tidy-alphabetical-end
957];
958
959static AVR_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
960    // tidy-alphabetical-start
961    ("addsubiw", Unstable(sym::avr_target_feature), &[]),
962    ("break", Unstable(sym::avr_target_feature), &[]),
963    ("eijmpcall", Unstable(sym::avr_target_feature), &[]),
964    ("elpm", Unstable(sym::avr_target_feature), &[]),
965    ("elpmx", Unstable(sym::avr_target_feature), &[]),
966    ("ijmpcall", Unstable(sym::avr_target_feature), &[]),
967    ("jmpcall", Unstable(sym::avr_target_feature), &[]),
968    ("lowbytefirst", Unstable(sym::avr_target_feature), &[]),
969    ("lpm", Unstable(sym::avr_target_feature), &[]),
970    ("lpmx", Unstable(sym::avr_target_feature), &[]),
971    ("movw", Unstable(sym::avr_target_feature), &[]),
972    ("mul", Unstable(sym::avr_target_feature), &[]),
973    ("rmw", Unstable(sym::avr_target_feature), &[]),
974    ("spm", Unstable(sym::avr_target_feature), &[]),
975    ("spmx", Unstable(sym::avr_target_feature), &[]),
976    (
977        "sram",
978        Forbidden { reason: "devices that have no SRAM are unsupported", hard_error: false },
979        &[],
980    ),
981    ("tinyencoding", Unstable(sym::avr_target_feature), &[]),
982    // tidy-alphabetical-end
983];
984
985const XTENSA_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
986    ("bool", Unstable(sym::xtensa_target_feature), &[]),
987    ("fp", Unstable(sym::xtensa_target_feature), &["bool", "coprocessor"]),
988    ("coprocessor", Unstable(sym::xtensa_target_feature), &[]),
989    ("highpriinterrupts", Unstable(sym::xtensa_target_feature), &["interrupt"]),
990    ("interrupt", Unstable(sym::xtensa_target_feature), &["exception"]),
991    (
992        "windowed",
993        Forbidden { reason: "windowed changes the Xtensa calling convention", hard_error: false },
994        &["exception"],
995    ),
996    ("loop", Unstable(sym::xtensa_target_feature), &[]),
997    ("sext", Unstable(sym::xtensa_target_feature), &[]),
998    ("nsa", Unstable(sym::xtensa_target_feature), &[]),
999    ("mul32", Unstable(sym::xtensa_target_feature), &[]),
1000    ("mul32high", Unstable(sym::xtensa_target_feature), &["mul32"]),
1001    ("div32", Unstable(sym::xtensa_target_feature), &[]),
1002    ("mac16", Unstable(sym::xtensa_target_feature), &[]),
1003    ("s32c1i", Unstable(sym::xtensa_target_feature), &[]),
1004    ("threadptr", Unstable(sym::xtensa_target_feature), &[]),
1005    ("extendedl32r", Unstable(sym::xtensa_target_feature), &[]),
1006    ("debug", Unstable(sym::xtensa_target_feature), &["exception"]),
1007    ("exception", Unstable(sym::xtensa_target_feature), &[]),
1008    ("rvector", Unstable(sym::xtensa_target_feature), &["exception"]),
1009    ("prid", Unstable(sym::xtensa_target_feature), &[]),
1010    ("regprotect", Unstable(sym::xtensa_target_feature), &[]),
1011    ("miscsr", Unstable(sym::xtensa_target_feature), &[]),
1012];
1013
1014/// When rustdoc is running, provide a list of all known features so that all their respective
1015/// primitives may be documented.
1016///
1017/// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
1018pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
1019    std::iter::empty()
1020        .chain(ARM_FEATURES.iter())
1021        .chain(AARCH64_FEATURES.iter())
1022        .chain(X86_FEATURES.iter())
1023        .chain(HEXAGON_FEATURES.iter())
1024        .chain(POWERPC_FEATURES.iter())
1025        .chain(MIPS_FEATURES.iter())
1026        .chain(NVPTX_FEATURES.iter())
1027        .chain(RISCV_FEATURES.iter())
1028        .chain(WASM_FEATURES.iter())
1029        .chain(BPF_FEATURES.iter())
1030        .chain(XTENSA_FEATURES.iter())
1031        .chain(CSKY_FEATURES)
1032        .chain(LOONGARCH_FEATURES)
1033        .chain(IBMZ_FEATURES)
1034        .chain(SPARC_FEATURES)
1035        .chain(M68K_FEATURES)
1036        .chain(AVR_FEATURES)
1037        .cloned()
1038        .map(|(f, s, _)| (f, s))
1039}
1040
1041/// Find which target architectures a feature belongs to.
1042/// Returns arch display names for all targets where this feature name appears.
1043/// Returns empty vec if feature unknown on any target.
1044pub fn feature_to_arch_names(feature: &str) -> Vec<&'static str> {
1045    let mut arches = Vec::new();
1046    macro_rules! check_arch_feats {
1047        ($arch_name:expr, $feats:expr) => {
1048            if $feats.iter().any(|(f, _, _)| *f == feature) {
1049                arches.push($arch_name);
1050            }
1051        };
1052    }
1053    if ARM_FEATURES.iter().any(|(f, _, _)| *f == feature) { arches.push("arm"); };check_arch_feats!("arm", ARM_FEATURES);
1054    if AARCH64_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("aarch64");
};check_arch_feats!("aarch64", AARCH64_FEATURES);
1055    if X86_FEATURES.iter().any(|(f, _, _)| *f == feature) { arches.push("x86"); };check_arch_feats!("x86", X86_FEATURES);
1056    if HEXAGON_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("hexagon");
};check_arch_feats!("hexagon", HEXAGON_FEATURES);
1057    if MIPS_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("mips");
};check_arch_feats!("mips", MIPS_FEATURES);
1058    if NVPTX_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("nvptx64");
};check_arch_feats!("nvptx64", NVPTX_FEATURES);
1059    if POWERPC_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("powerpc");
};check_arch_feats!("powerpc", POWERPC_FEATURES);
1060    if RISCV_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("riscv");
};check_arch_feats!("riscv", RISCV_FEATURES);
1061    if WASM_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("wasm");
};check_arch_feats!("wasm", WASM_FEATURES);
1062    if BPF_FEATURES.iter().any(|(f, _, _)| *f == feature) { arches.push("bpf"); };check_arch_feats!("bpf", BPF_FEATURES);
1063    if CSKY_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("csky");
};check_arch_feats!("csky", CSKY_FEATURES);
1064    if LOONGARCH_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("loongarch");
};check_arch_feats!("loongarch", LOONGARCH_FEATURES);
1065    if IBMZ_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("s390x");
};check_arch_feats!("s390x", IBMZ_FEATURES);
1066    if SPARC_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("sparc");
};check_arch_feats!("sparc", SPARC_FEATURES);
1067    if M68K_FEATURES.iter().any(|(f, _, _)| *f == feature) {
    arches.push("m68k");
};check_arch_feats!("m68k", M68K_FEATURES);
1068    if AVR_FEATURES.iter().any(|(f, _, _)| *f == feature) { arches.push("avr"); };check_arch_feats!("avr", AVR_FEATURES);
1069    arches.sort();
1070    arches.dedup();
1071    arches
1072}
1073
1074// These arrays represent the least-constraining feature that is required for vector types up to a
1075// certain size to have their "proper" ABI on each architecture.
1076// Note that they must be kept sorted by vector size.
1077const X86_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1078    &[(128, "sse"), (256, "avx"), (512, "avx512f")]; // FIXME: might need changes for AVX10.
1079const AARCH64_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1080    &[(128, "neon")];
1081
1082const ARM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1083    &[(128, "neon"), (128, "mve")];
1084
1085const AMDGPU_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1086    &[(1024, "")];
1087const POWERPC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1088    &[(128, "altivec")];
1089const WASM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1090    &[(128, "simd128")];
1091const S390X_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1092    &[(128, "vector")];
1093const RISCV_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] = &[
1094    (32, "zvl32b"),
1095    (64, "zvl64b"),
1096    (128, "zvl128b"),
1097    (256, "zvl256b"),
1098    (512, "zvl512b"),
1099    (1024, "zvl1024b"),
1100    (2048, "zvl2048b"),
1101    (4096, "zvl4096b"),
1102    (8192, "zvl8192b"),
1103    (16384, "zvl16384b"),
1104    (32768, "zvl32768b"),
1105    (65536, "zvl65536b"),
1106];
1107// Always error on SPARC, as the necessary target features cannot be enabled in Rust at the moment.
1108const SPARC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1109    &[/*(64, "vis")*/];
1110
1111const HEXAGON_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] = &[
1112    (512, "hvx-length64b"),   // HvxVector in 64-byte mode
1113    (1024, "hvx-length128b"), // HvxVector in 128-byte mode, or HvxVectorPair in 64-byte mode
1114    (2048, "hvx-length128b"), // HvxVectorPair in 128-byte mode
1115];
1116const MIPS_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1117    &[(128, "msa")];
1118const CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1119    &[(128, "vdspv1")];
1120const LOONGARCH_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
1121    &[(128, "lsx"), (256, "lasx")];
1122
1123#[derive(#[automatically_derived]
impl ::core::marker::Copy for FeatureConstraints { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FeatureConstraints {
    #[inline]
    fn clone(&self) -> FeatureConstraints {
        let _: ::core::clone::AssertParamIsClone<&'static [&'static str]>;
        let _: ::core::clone::AssertParamIsClone<&'static [&'static str]>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FeatureConstraints {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "FeatureConstraints", "required", &self.required, "incompatible",
            &&self.incompatible)
    }
}Debug)]
1124pub struct FeatureConstraints {
1125    /// Features that must be enabled.
1126    pub required: &'static [&'static str],
1127    /// Features that must be disabled.
1128    pub incompatible: &'static [&'static str],
1129}
1130
1131impl Target {
1132    pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
1133        match &self.arch {
1134            Arch::Arm => ARM_FEATURES,
1135            Arch::AArch64 | Arch::Arm64EC => AARCH64_FEATURES,
1136            Arch::X86 | Arch::X86_64 => X86_FEATURES,
1137            Arch::Hexagon => HEXAGON_FEATURES,
1138            Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => MIPS_FEATURES,
1139            Arch::Nvptx64 => NVPTX_FEATURES,
1140            Arch::PowerPC | Arch::PowerPC64 => POWERPC_FEATURES,
1141            Arch::RiscV32 | Arch::RiscV64 => RISCV_FEATURES,
1142            Arch::Wasm32 | Arch::Wasm64 => WASM_FEATURES,
1143            Arch::Bpf => BPF_FEATURES,
1144            Arch::CSky => CSKY_FEATURES,
1145            Arch::LoongArch32 | Arch::LoongArch64 => LOONGARCH_FEATURES,
1146            Arch::S390x => IBMZ_FEATURES,
1147            Arch::Sparc | Arch::Sparc64 => SPARC_FEATURES,
1148            Arch::M68k => M68K_FEATURES,
1149            Arch::Avr => AVR_FEATURES,
1150            Arch::Xtensa => XTENSA_FEATURES,
1151            Arch::AmdGpu | Arch::Msp430 | Arch::SpirV | Arch::Other(_) => &[],
1152        }
1153    }
1154
1155    pub fn features_for_correct_fixed_length_vector_abi(&self) -> &'static [(u64, &'static str)] {
1156        match &self.arch {
1157            Arch::X86 | Arch::X86_64 => X86_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1158            Arch::AArch64 | Arch::Arm64EC => AARCH64_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1159            Arch::Arm => ARM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1160            Arch::PowerPC | Arch::PowerPC64 => POWERPC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1161            Arch::LoongArch32 | Arch::LoongArch64 => {
1162                LOONGARCH_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI
1163            }
1164            Arch::RiscV32 | Arch::RiscV64 => RISCV_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1165            Arch::Wasm32 | Arch::Wasm64 => WASM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1166            Arch::S390x => S390X_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1167            Arch::Sparc | Arch::Sparc64 => SPARC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1168            Arch::Hexagon => HEXAGON_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1169            Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => {
1170                MIPS_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI
1171            }
1172            Arch::AmdGpu => AMDGPU_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1173            Arch::Nvptx64 | Arch::Bpf | Arch::M68k | Arch::Avr => &[], // no vector ABI
1174            Arch::CSky => CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
1175            // FIXME: for some tier3 targets, we are overly cautious and always give warnings
1176            // when passing args in vector registers.
1177            Arch::Msp430 | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
1178        }
1179    }
1180
1181    pub fn features_for_correct_scalable_vector_abi(&self) -> Option<&'static str> {
1182        match &self.arch {
1183            Arch::AArch64 | Arch::Arm64EC => Some("sve"),
1184            // Other targets have no scalable vectors or they are unimplemented.
1185            _ => None,
1186        }
1187    }
1188
1189    pub fn tied_target_features(&self) -> &'static [&'static [&'static str]] {
1190        match &self.arch {
1191            Arch::AArch64 | Arch::Arm64EC => AARCH64_TIED_FEATURES,
1192            _ => &[],
1193        }
1194    }
1195
1196    // Note: the returned set includes `base_feature`.
1197    pub fn implied_target_features<'a>(&self, base_feature: &'a str) -> FxHashSet<&'a str> {
1198        let implied_features =
1199            self.rust_target_features().iter().map(|(f, _, i)| (f, i)).collect::<FxHashMap<_, _>>();
1200
1201        // Implied target features have their own implied target features, so we traverse the
1202        // map until there are no more features to add.
1203        let mut features = FxHashSet::default();
1204        let mut new_features = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [base_feature]))vec![base_feature];
1205        while let Some(new_feature) = new_features.pop() {
1206            if features.insert(new_feature) {
1207                if let Some(implied_features) = implied_features.get(&new_feature) {
1208                    new_features.extend(implied_features.iter().copied())
1209                }
1210            }
1211        }
1212        features
1213    }
1214
1215    /// Returns two lists of features:
1216    /// the first list contains target features that must be enabled for ABI reasons,
1217    /// and the second list contains target feature that must be disabled for ABI reasons.
1218    ///
1219    /// These features are checked against the target features reported by LLVM based on
1220    /// `-Ctarget-cpu` and `-Ctarget-features`. Constraint violations result in a warning.
1221    ///
1222    /// We also check features enabled via `#[target_feature(..)]` (and here, constraint violations
1223    /// emit a hard error), including features enabled indirectly via implications -- but if LLVM
1224    /// considers more features to be implied than we do, that could bypass this check!
1225    pub fn abi_required_features(&self) -> FeatureConstraints {
1226        const NOTHING: FeatureConstraints = FeatureConstraints { required: &[], incompatible: &[] };
1227        // Some architectures don't have a clean explicit ABI designation; instead, the ABI is
1228        // defined by target features. When that is the case, those target features must be
1229        // "forbidden" in the list above to ensure that there is a consistent answer to the
1230        // questions "which ABI is used".
1231        match &self.arch {
1232            Arch::X86 => {
1233                // We use our own ABI indicator here; LLVM does not have anything native.
1234                // Every case should require or forbid `soft-float`!
1235                match self.rustc_abi {
1236                    None => {
1237                        // Default hardfloat ABI.
1238                        // x87 must be enabled, soft-float must be disabled.
1239                        FeatureConstraints { required: &["x87"], incompatible: &["soft-float"] }
1240                    }
1241                    Some(RustcAbi::X86Sse2) => {
1242                        // Extended hardfloat ABI. x87 and SSE2 must be enabled, soft-float must be disabled.
1243                        FeatureConstraints {
1244                            required: &["x87", "sse2"],
1245                            incompatible: &["soft-float"],
1246                        }
1247                    }
1248                    Some(RustcAbi::Softfloat) => {
1249                        // Softfloat ABI, requires corresponding target feature. That feature trumps
1250                        // `x87` and all other FPU features so those do not matter.
1251                        // Note that this one requirement is the entire implementation of the ABI!
1252                        // LLVM handles the rest.
1253                        FeatureConstraints { required: &["soft-float"], incompatible: &[] }
1254                    }
1255                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1256                }
1257            }
1258            Arch::X86_64 => {
1259                // We use our own ABI indicator here; LLVM does not have anything native.
1260                // Every case should require or forbid `soft-float`!
1261                match self.rustc_abi {
1262                    None => {
1263                        // Default hardfloat ABI. On x86-64, this always includes SSE2.
1264                        FeatureConstraints {
1265                            required: &["x87", "sse2"],
1266                            incompatible: &["soft-float"],
1267                        }
1268                    }
1269                    Some(RustcAbi::Softfloat) => {
1270                        // Softfloat ABI, requires corresponding target feature. That feature trumps
1271                        // `x87` and all other FPU features so those do not matter.
1272                        // Note that this one requirement is the entire implementation of the ABI!
1273                        // LLVM handles the rest.
1274                        FeatureConstraints { required: &["soft-float"], incompatible: &[] }
1275                    }
1276                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1277                }
1278            }
1279            Arch::Arm => {
1280                // On ARM, ABI handling is reasonably sane; we use `llvm_floatabi` to indicate
1281                // to LLVM which ABI we are going for.
1282                match self.llvm_floatabi.unwrap() {
1283                    FloatAbi::Soft => {
1284                        // Nothing special required, will use soft-float ABI throughout.
1285                        // We can even allow `-soft-float` here; in fact that is useful as it lets
1286                        // people use FPU instructions with a softfloat ABI (corresponds to
1287                        // `-mfloat-abi=softfp` in GCC/clang).
1288                        NOTHING
1289                    }
1290                    FloatAbi::Hard => {
1291                        // Must have `fpregs` and must not have `soft-float`.
1292                        FeatureConstraints { required: &["fpregs"], incompatible: &["soft-float"] }
1293                    }
1294                }
1295            }
1296            Arch::AArch64 | Arch::Arm64EC => {
1297                // Aarch64 has no sane ABI specifier, and LLVM doesn't even have a way to force
1298                // the use of soft-float, so all we can do here is some crude hacks.
1299                match self.rustc_abi {
1300                    Some(RustcAbi::Softfloat) => {
1301                        // LLVM will use float registers when `fp-armv8` is available, e.g. for
1302                        // calls to built-ins. The only way to ensure a consistent softfloat ABI
1303                        // on aarch64 is to never enable `fp-armv8`, so we enforce that.
1304                        // In Rust we tie `neon` and `fp-armv8` together, therefore `neon` is the
1305                        // feature we have to mark as incompatible.
1306                        FeatureConstraints { required: &[], incompatible: &["neon"] }
1307                    }
1308                    None => {
1309                        // Everything else is assumed to use a hardfloat ABI. neon and fp-armv8 must be enabled.
1310                        // `FeatureConstraints` uses Rust feature names, hence only "neon" shows up.
1311                        FeatureConstraints { required: &["neon"], incompatible: &[] }
1312                    }
1313                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1314                }
1315            }
1316            Arch::RiscV32 | Arch::RiscV64 => {
1317                // RISC-V handles ABI in a very sane way, being fully explicit via `llvm_abiname`
1318                // about what the intended ABI is.
1319                match &self.llvm_abiname {
1320                    LlvmAbi::Ilp32d | LlvmAbi::Lp64d => {
1321                        // Requires d (which implies f), incompatible with e and zfinx.
1322                        FeatureConstraints { required: &["d"], incompatible: &["e", "zfinx"] }
1323                    }
1324                    LlvmAbi::Ilp32f | LlvmAbi::Lp64f => {
1325                        // Requires f, incompatible with e and zfinx.
1326                        FeatureConstraints { required: &["f"], incompatible: &["e", "zfinx"] }
1327                    }
1328                    LlvmAbi::Ilp32 | LlvmAbi::Lp64 => {
1329                        // Requires nothing, incompatible with e.
1330                        FeatureConstraints { required: &[], incompatible: &["e"] }
1331                    }
1332                    LlvmAbi::Ilp32e => {
1333                        // ilp32e is documented to be incompatible with features that need aligned
1334                        // load/stores > 32 bits, like `d`. (One could also just generate more
1335                        // complicated code to align the stack when needed, but the RISCV
1336                        // architecture manual just explicitly rules out this combination so we
1337                        // might as well.)
1338                        // Note that the `e` feature is not required: the ABI treats the extra
1339                        // registers as caller-save, so it is safe to use them only in some parts of
1340                        // a program while the rest doesn't know they even exist.
1341                        FeatureConstraints { required: &[], incompatible: &["d"] }
1342                    }
1343                    LlvmAbi::Lp64e => {
1344                        // As above, `e` is not required.
1345                        NOTHING
1346                    }
1347                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1348                }
1349            }
1350            Arch::LoongArch32 | Arch::LoongArch64 => {
1351                // LoongArch handles ABI in a very sane way, being fully explicit via `llvm_abiname`
1352                // about what the intended ABI is.
1353                match &self.llvm_abiname {
1354                    LlvmAbi::Ilp32d | LlvmAbi::Lp64d => {
1355                        // Requires d (which implies f), incompatible with nothing.
1356                        FeatureConstraints { required: &["d"], incompatible: &[] }
1357                    }
1358                    LlvmAbi::Ilp32f | LlvmAbi::Lp64f => {
1359                        // Requires f, incompatible with nothing.
1360                        FeatureConstraints { required: &["f"], incompatible: &[] }
1361                    }
1362                    LlvmAbi::Ilp32s | LlvmAbi::Lp64s => {
1363                        // The soft-float ABI does not require any features and is also not
1364                        // incompatible with any features. Rust targets explicitly specify the
1365                        // LLVM ABI names, which allows for enabling hard-float support even on
1366                        // soft-float targets, and ensures that the ABI behavior is as expected.
1367                        NOTHING
1368                    }
1369                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1370                }
1371            }
1372            Arch::S390x => {
1373                // Same as x86, We use our own ABI indicator here;
1374                // LLVM does not have anything native and will switch ABI based
1375                // on the soft-float target feature.
1376                // Every case should require or forbid `soft-float`!
1377                // The "vector" target feature may only be used without soft-float
1378                // because the float and vector registers overlap and the
1379                // standard s390x C ABI may pass vectors via these registers.
1380                match self.rustc_abi {
1381                    None => {
1382                        // Default hardfloat ABI.
1383                        FeatureConstraints { required: &[], incompatible: &["soft-float"] }
1384                    }
1385                    Some(RustcAbi::Softfloat) => {
1386                        // Softfloat ABI, requires corresponding target feature.
1387                        // llvm will switch to soft-float ABI just based on this feature.
1388                        FeatureConstraints { required: &["soft-float"], incompatible: &["vector"] }
1389                    }
1390                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1391                }
1392            }
1393            Arch::PowerPC => {
1394                // The main ABI-relevant target features are "hard-float" and "spe". We use our own
1395                // ABI indicator here.
1396                match self.rustc_abi {
1397                    None => {
1398                        // Default hardfloat ABI.
1399                        FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] }
1400                    }
1401                    Some(RustcAbi::PowerPcSpe) => {
1402                        // "efpu2" (which disables some register use in LLVM) *should* be okay
1403                        // because SPE uses soft-float ABI's parameter passing rules and passes
1404                        // floats via GPRs.
1405                        // <https://github.com/rust-lang/rust/pull/157085#discussion_r3349260222>
1406                        FeatureConstraints { required: &["hard-float", "spe"], incompatible: &[] }
1407                    }
1408                    _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
1409                }
1410            }
1411            Arch::PowerPC64 => {
1412                // There's no SPE for PowerPC64, and we currently don't support any soft-float
1413                // targets. (If we ever add one, we need to match on `RustcAbi::Softfloat` similar
1414                // to other targets above.)
1415                FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] }
1416            }
1417            Arch::Avr => {
1418                // We only support one ABI on AVR at the moment.
1419                // SRAM is minimum requirement for C/C++ in both avr-gcc and Clang,
1420                // and backends of them only support assembly for devices have no SRAM.
1421                // See the discussion in https://github.com/rust-lang/rust/pull/146900 for more.
1422                FeatureConstraints { required: &["sram"], incompatible: &[] }
1423            }
1424            Arch::Wasm32 | Arch::Wasm64 => {
1425                // We only support one ABI on wasm at the moment.
1426                // No ABI-relevant target features have been identified thus far.
1427                NOTHING
1428            }
1429            _ => NOTHING,
1430        }
1431    }
1432}