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