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