use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_macros::StableHash;
use crate::rustc_span::{Symbol, sym};
use crate::rustc_target::spec::{Arch, FloatAbi, LlvmAbi, RustcAbi, Target};
pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
#[derive(Debug, Copy, Clone, StableHash)]
pub enum Stability {
Stable,
CfgStableToggleUnstable(
Symbol,
),
Unstable(
Symbol,
),
InternalOnly {
reason: &'static str,
hard_error: bool,
},
}
use Stability::*;
impl Stability {
pub fn in_cfg(&self) -> bool {
matches!(
self,
Stability::Stable
| Stability::CfgStableToggleUnstable { .. }
| Stability::Unstable { .. }
)
}
pub fn requires_nightly(&self, in_cfg: bool) -> Option<Symbol> {
match *self {
Stability::Unstable(nightly_feature) => Some(nightly_feature),
Stability::CfgStableToggleUnstable(nightly_feature) => {
if in_cfg {
None
} else {
Some(nightly_feature)
}
}
Stability::Stable { .. } => None,
Stability::InternalOnly { .. } => {
panic!("internal-only features should not reach this far")
}
}
}
pub fn is_cfg_stable_toggle_unstable(&self) -> bool {
matches!(self, Stability::CfgStableToggleUnstable { .. })
}
pub fn toggle_allowed(&self) -> Result<(), &'static str> {
match self {
Stability::Unstable(_)
| Stability::CfgStableToggleUnstable(_)
| Stability::Stable { .. } => Ok(()),
Stability::InternalOnly { reason, hard_error: _ } => Err(reason),
}
}
}
type ImpliedFeatures = &'static [&'static str];
static ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("aclass", Unstable(sym::arm_target_feature), &[]),
("acquire-release", Unstable(sym::arm_target_feature), &[]),
("aes", Unstable(sym::arm_target_feature), &["neon"]),
(
"atomics-32",
Stability::InternalOnly {
reason: "unsound because it changes the ABI of atomic operations",
hard_error: false,
},
&[],
),
("crc", Unstable(sym::arm_target_feature), &[]),
("d32", Unstable(sym::arm_target_feature), &[]),
("dotprod", Unstable(sym::arm_target_feature), &["neon"]),
("dsp", Unstable(sym::arm_target_feature), &[]),
("fp-armv8", Unstable(sym::arm_target_feature), &["vfp4"]),
("fp16", Unstable(sym::arm_target_feature), &["neon"]),
("fp64", Unstable(sym::arm_target_feature), &[]),
("fpregs", Unstable(sym::arm_target_feature), &[]),
("i8mm", Unstable(sym::arm_target_feature), &["neon"]),
("mclass", Unstable(sym::arm_target_feature), &[]),
("mve", Unstable(sym::arm_target_feature), &["v8.1m.main", "dsp", "fpregs"]),
("mve.fp", Unstable(sym::arm_target_feature), &["mve"]),
("neon", Unstable(sym::arm_target_feature), &["vfp3"]),
("rclass", Unstable(sym::arm_target_feature), &[]),
("sha2", Unstable(sym::arm_target_feature), &["neon"]),
("soft-float", Unstable(sym::arm_target_feature), &[]),
("thumb-mode", Unstable(sym::arm_target_feature), &[]),
("thumb2", Unstable(sym::arm_target_feature), &[]),
("trustzone", Unstable(sym::arm_target_feature), &[]),
("v5te", Unstable(sym::arm_target_feature), &[]),
("v6", Unstable(sym::arm_target_feature), &["v5te"]),
("v6k", Unstable(sym::arm_target_feature), &["v6"]),
("v6m", Unstable(sym::arm_target_feature), &["v6"]),
("v6t2", Unstable(sym::arm_target_feature), &["v6k", "v8m", "thumb2"]),
("v7", Unstable(sym::arm_target_feature), &["v6t2"]),
("v8", Unstable(sym::arm_target_feature), &["v7", "acquire-release"]),
("v8.1m.main", Unstable(sym::arm_target_feature), &["v8m.main"]),
("v8m", Unstable(sym::arm_target_feature), &["v6m"]),
("v8m.main", Unstable(sym::arm_target_feature), &["v7"]),
("vfp2", Unstable(sym::arm_target_feature), &["vfp2sp", "fp64"]),
("vfp2sp", Unstable(sym::arm_target_feature), &["fpregs"]),
("vfp3", Unstable(sym::arm_target_feature), &["vfp2", "d32"]),
("vfp4", Unstable(sym::arm_target_feature), &["vfp3"]),
("virtualization", Unstable(sym::arm_target_feature), &[]),
];
static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("aes", Stable, &["neon"]),
("bf16", Stable, &[]),
("bti", Stable, &[]),
("crc", Stable, &[]),
("cssc", Unstable(sym::aarch64_unstable_target_feature), &[]),
("dit", Stable, &[]),
("dotprod", Stable, &["neon"]),
("dpb", Stable, &[]),
("dpb2", Stable, &["dpb"]),
("ecv", Unstable(sym::aarch64_unstable_target_feature), &[]),
("f32mm", Stable, &["sve"]),
("f64mm", Stable, &["sve"]),
("faminmax", Unstable(sym::aarch64_unstable_target_feature), &[]),
("fcma", Stable, &["neon"]),
("fhm", Stable, &["fp16"]),
("flagm", Stable, &[]),
("flagm2", Unstable(sym::aarch64_unstable_target_feature), &[]),
(
"fp-armv8",
Stability::InternalOnly { reason: "Rust ties `fp-armv8` to `neon`", hard_error: false },
&[],
),
("fp8", Unstable(sym::aarch64_unstable_target_feature), &["faminmax", "lut", "bf16"]),
("fp8dot2", Unstable(sym::aarch64_unstable_target_feature), &["fp8dot4"]),
("fp8dot4", Unstable(sym::aarch64_unstable_target_feature), &["fp8fma"]),
("fp8fma", Unstable(sym::aarch64_unstable_target_feature), &["fp8"]),
("fp16", Stable, &["neon"]),
("frintts", Stable, &[]),
("hbc", Unstable(sym::aarch64_unstable_target_feature), &[]),
("i8mm", Stable, &[]),
("jsconv", Stable, &["neon"]),
("lor", Stable, &[]),
("lse", Stable, &[]),
("lse2", Unstable(sym::aarch64_unstable_target_feature), &[]),
("lse128", Unstable(sym::aarch64_unstable_target_feature), &["lse"]),
("lut", Unstable(sym::aarch64_unstable_target_feature), &[]),
("mops", Unstable(sym::aarch64_unstable_target_feature), &[]),
("mte", Stable, &[]),
("neon", Stable, &[]),
("outline-atomics", Unstable(sym::aarch64_unstable_target_feature), &[]),
("paca", Stable, &[]),
("pacg", Stable, &[]),
("pan", Stable, &[]),
("pauth-lr", Unstable(sym::aarch64_unstable_target_feature), &[]),
("pmuv3", Stable, &[]),
("rand", Stable, &[]),
("ras", Stable, &[]),
("rcpc", Stable, &[]),
("rcpc2", Stable, &["rcpc"]),
("rcpc3", Unstable(sym::aarch64_unstable_target_feature), &["rcpc2"]),
("rdm", Stable, &["neon"]),
(
"reserve-x18",
InternalOnly { reason: "use `-Zfixed-x18` compiler flag instead", hard_error: false },
&[],
),
("sb", Stable, &[]),
("sha2", Stable, &["neon"]),
("sha3", Stable, &["sha2"]),
("sm4", Stable, &["neon"]),
("sme", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]),
("sme-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16", "sme2", "sve-b16b16"]),
("sme-f8f16", Unstable(sym::aarch64_unstable_target_feature), &["sme-f8f32"]),
("sme-f8f32", Unstable(sym::aarch64_unstable_target_feature), &["sme2", "fp8"]),
("sme-f16f16", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]),
("sme-f64f64", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
("sme-fa64", Unstable(sym::aarch64_unstable_target_feature), &["sme", "sve2"]),
("sme-i16i64", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
("sme-lutv2", Unstable(sym::aarch64_unstable_target_feature), &[]),
("sme2", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
("sme2p1", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]),
("spe", Stable, &[]),
("ssbs", Stable, &[]),
("ssve-fp8dot2", Unstable(sym::aarch64_unstable_target_feature), &["ssve-fp8dot4"]),
("ssve-fp8dot4", Unstable(sym::aarch64_unstable_target_feature), &["ssve-fp8fma"]),
("ssve-fp8fma", Unstable(sym::aarch64_unstable_target_feature), &["sme2", "fp8"]),
("sve", Stable, &["neon", "fp16"]),
("sve-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]),
("sve2", Stable, &["sve"]),
("sve2-aes", Stable, &["sve2", "aes"]),
("sve2-bitperm", Stable, &["sve2"]),
("sve2-sha3", Stable, &["sve2", "sha3"]),
("sve2-sm4", Stable, &["sve2", "sm4"]),
("sve2p1", Unstable(sym::aarch64_unstable_target_feature), &["sve2"]),
("tme", Stable, &[]),
(
"v8.1a",
Unstable(sym::aarch64_ver_target_feature),
&["crc", "lse", "rdm", "pan", "lor", "vh"],
),
("v8.2a", Unstable(sym::aarch64_ver_target_feature), &["v8.1a", "ras", "dpb"]),
(
"v8.3a",
Unstable(sym::aarch64_ver_target_feature),
&["v8.2a", "rcpc", "paca", "pacg", "jsconv"],
),
("v8.4a", Unstable(sym::aarch64_ver_target_feature), &["v8.3a", "dotprod", "dit", "flagm"]),
("v8.5a", Unstable(sym::aarch64_ver_target_feature), &["v8.4a", "ssbs", "sb", "dpb2", "bti"]),
("v8.6a", Unstable(sym::aarch64_ver_target_feature), &["v8.5a", "bf16", "i8mm"]),
("v8.7a", Unstable(sym::aarch64_ver_target_feature), &["v8.6a", "wfxt"]),
("v8.8a", Unstable(sym::aarch64_ver_target_feature), &["v8.7a", "hbc", "mops"]),
("v8.9a", Unstable(sym::aarch64_ver_target_feature), &["v8.8a", "cssc"]),
("v9.1a", Unstable(sym::aarch64_ver_target_feature), &["v9a", "v8.6a"]),
("v9.2a", Unstable(sym::aarch64_ver_target_feature), &["v9.1a", "v8.7a"]),
("v9.3a", Unstable(sym::aarch64_ver_target_feature), &["v9.2a", "v8.8a"]),
("v9.4a", Unstable(sym::aarch64_ver_target_feature), &["v9.3a", "v8.9a"]),
("v9.5a", Unstable(sym::aarch64_ver_target_feature), &["v9.4a"]),
("v9a", Unstable(sym::aarch64_ver_target_feature), &["v8.5a"]),
("vh", Stable, &[]),
("wfxt", Unstable(sym::aarch64_unstable_target_feature), &[]),
];
const AARCH64_TIED_FEATURES: &[&[&str]] = &[
&["paca", "pacg"], ];
static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("adx", Stable, &[]),
("aes", Stable, &["sse2"]),
("amx-avx512", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-bf16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-complex", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-fp8", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-fp16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-int8", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-movrs", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-tile", Unstable(sym::x86_amx_intrinsics), &[]),
("apxf", Unstable(sym::apx_target_feature), &[]),
("avx", Stable, &["sse4.2"]),
("avx2", Stable, &["avx"]),
(
"avx10.1",
Unstable(sym::avx10_target_feature),
&[
"avx512bf16",
"avx512bitalg",
"avx512bw",
"avx512cd",
"avx512dq",
"avx512f",
"avx512fp16",
"avx512ifma",
"avx512vbmi",
"avx512vbmi2",
"avx512vl",
"avx512vnni",
"avx512vpopcntdq",
],
),
(
"avx10.2",
Unstable(sym::avx10_target_feature),
&["avx10.1", "avxvnni", "avxvnniint8", "avxvnniint16"],
),
("avx512bf16", Stable, &["avx512bw"]),
("avx512bitalg", Stable, &["avx512bw"]),
("avx512bw", Stable, &["avx512f"]),
("avx512cd", Stable, &["avx512f"]),
("avx512dq", Stable, &["avx512f"]),
("avx512f", Stable, &["avx2", "fma", "f16c"]),
("avx512fp16", Stable, &["avx512bw"]),
("avx512ifma", Stable, &["avx512f"]),
("avx512vbmi", Stable, &["avx512bw"]),
("avx512vbmi2", Stable, &["avx512bw"]),
("avx512vl", Stable, &["avx512f"]),
("avx512vnni", Stable, &["avx512f"]),
("avx512vp2intersect", Stable, &["avx512f"]),
("avx512vpopcntdq", Stable, &["avx512f"]),
("avxifma", Stable, &["avx2"]),
("avxneconvert", Stable, &["avx2"]),
("avxvnni", Stable, &["avx2"]),
("avxvnniint8", Stable, &["avx2"]),
("avxvnniint16", Stable, &["avx2"]),
("bmi1", Stable, &[]),
("bmi2", Stable, &[]),
("clflushopt", Unstable(sym::clflushopt_target_feature), &[]),
("cmpxchg16b", Stable, &[]),
("ermsb", Unstable(sym::ermsb_target_feature), &[]),
("f16c", Stable, &["avx"]),
("fma", Stable, &["avx"]),
("fma4", Unstable(sym::fma4_target_feature), &["avx", "sse4a"]),
("fxsr", Stable, &[]),
("gfni", Stable, &["sse2"]),
("kl", Stable, &["sse2"]),
("lahfsahf", Unstable(sym::lahfsahf_target_feature), &[]),
("lzcnt", Stable, &[]),
("movbe", Stable, &[]),
("movrs", Unstable(sym::movrs_target_feature), &[]),
("pclmulqdq", Stable, &["sse2"]),
("popcnt", Stable, &[]),
("prfchw", Unstable(sym::prfchw_target_feature), &[]),
("rdrand", Stable, &[]),
("rdseed", Stable, &[]),
(
"retpoline-external-thunk",
Stability::InternalOnly {
reason: "use `-Zretpoline-external-thunk` compiler flag instead",
hard_error: false,
},
&[],
),
(
"retpoline-indirect-branches",
Stability::InternalOnly {
reason: "use `-Zretpoline` compiler flag instead",
hard_error: false,
},
&[],
),
(
"retpoline-indirect-calls",
Stability::InternalOnly {
reason: "use `-Zretpoline` compiler flag instead",
hard_error: false,
},
&[],
),
("rtm", Unstable(sym::rtm_target_feature), &[]),
("sha", Stable, &["sse2"]),
("sha512", Stable, &["avx2"]),
("sm3", Stable, &["avx"]),
("sm4", Stable, &["avx2"]),
(
"soft-float",
Stability::InternalOnly { reason: "use a soft-float target instead", hard_error: false },
&[],
),
("sse", Stable, &[]),
("sse2", Stable, &["sse"]),
("sse3", Stable, &["sse2"]),
("sse4.1", Stable, &["ssse3"]),
("sse4.2", Stable, &["sse4.1"]),
("sse4a", Stable, &["sse3"]),
("ssse3", Stable, &["sse3"]),
("tbm", Stable, &[]),
("vaes", Stable, &["avx2", "aes"]),
("vpclmulqdq", Stable, &["avx", "pclmulqdq"]),
("widekl", Stable, &["kl"]),
("x87", Unstable(sym::x87_target_feature), &[]),
("xop", Unstable(sym::xop_target_feature), &["fma4", "avx", "sse4a"]),
("xsave", Stable, &[]),
("xsavec", Stable, &["xsave"]),
("xsaveopt", Stable, &["xsave"]),
("xsaves", Stable, &["xsave"]),
];
const HEXAGON_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("audio", Unstable(sym::hexagon_target_feature), &[]),
("hvx", Unstable(sym::hexagon_target_feature), &[]),
("hvx-ieee-fp", Unstable(sym::hexagon_target_feature), &["hvx"]),
("hvx-length64b", Unstable(sym::hexagon_target_feature), &["hvx"]),
("hvx-length128b", Unstable(sym::hexagon_target_feature), &["hvx"]),
("hvx-qfloat", Unstable(sym::hexagon_target_feature), &["hvx"]),
("hvxv60", Unstable(sym::hexagon_target_feature), &["hvx"]),
("hvxv62", Unstable(sym::hexagon_target_feature), &["hvxv60"]),
("hvxv65", Unstable(sym::hexagon_target_feature), &["hvxv62"]),
("hvxv66", Unstable(sym::hexagon_target_feature), &["hvxv65", "zreg"]),
("hvxv67", Unstable(sym::hexagon_target_feature), &["hvxv66"]),
("hvxv68", Unstable(sym::hexagon_target_feature), &["hvxv67"]),
("hvxv69", Unstable(sym::hexagon_target_feature), &["hvxv68"]),
("hvxv71", Unstable(sym::hexagon_target_feature), &["hvxv69"]),
("hvxv73", Unstable(sym::hexagon_target_feature), &["hvxv71"]),
("hvxv75", Unstable(sym::hexagon_target_feature), &["hvxv73"]),
("hvxv79", Unstable(sym::hexagon_target_feature), &["hvxv75"]),
("v60", Unstable(sym::hexagon_target_feature), &[]),
("v62", Unstable(sym::hexagon_target_feature), &["v60"]),
("v65", Unstable(sym::hexagon_target_feature), &["v62"]),
("v66", Unstable(sym::hexagon_target_feature), &["v65"]),
("v67", Unstable(sym::hexagon_target_feature), &["v66"]),
("v68", Unstable(sym::hexagon_target_feature), &["v67"]),
("v69", Unstable(sym::hexagon_target_feature), &["v68"]),
("v71", Unstable(sym::hexagon_target_feature), &["v69"]),
("v73", Unstable(sym::hexagon_target_feature), &["v71"]),
("v75", Unstable(sym::hexagon_target_feature), &["v73"]),
("v79", Unstable(sym::hexagon_target_feature), &["v75"]),
("zreg", Unstable(sym::hexagon_target_feature), &[]),
];
static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("altivec", Unstable(sym::powerpc_target_feature), &[]),
(
"hard-float",
InternalOnly { reason: "unsupported ABI-configuration feature", hard_error: false },
&[],
),
("msync", Unstable(sym::powerpc_target_feature), &[]),
("partword-atomics", Unstable(sym::powerpc_target_feature), &[]),
("power8-altivec", Unstable(sym::powerpc_target_feature), &["altivec"]),
("power8-crypto", Unstable(sym::powerpc_target_feature), &["power8-altivec"]),
("power8-vector", Unstable(sym::powerpc_target_feature), &["vsx", "power8-altivec"]),
("power9-altivec", Unstable(sym::powerpc_target_feature), &["power8-altivec"]),
("power9-vector", Unstable(sym::powerpc_target_feature), &["power8-vector", "power9-altivec"]),
("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]),
("quadword-atomics", Unstable(sym::powerpc_target_feature), &[]),
(
"spe",
InternalOnly { reason: "unsupported ABI-configuration feature", hard_error: false },
&[],
),
("vsx", Unstable(sym::powerpc_target_feature), &["altivec"]),
];
const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("fp64", Unstable(sym::mips_target_feature), &[]),
("msa", Unstable(sym::mips_target_feature), &[]),
("virt", Unstable(sym::mips_target_feature), &[]),
];
const NVPTX_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("sm_70", Unstable(sym::nvptx_target_feature), &[]),
("sm_72", Unstable(sym::nvptx_target_feature), &["sm_70"]),
("sm_75", Unstable(sym::nvptx_target_feature), &["sm_72"]),
("sm_80", Unstable(sym::nvptx_target_feature), &["sm_75"]),
("sm_86", Unstable(sym::nvptx_target_feature), &["sm_80"]),
("sm_87", Unstable(sym::nvptx_target_feature), &["sm_86"]),
("sm_89", Unstable(sym::nvptx_target_feature), &["sm_87"]),
("sm_90", Unstable(sym::nvptx_target_feature), &["sm_89"]),
("sm_90a", Unstable(sym::nvptx_target_feature), &["sm_90"]),
("sm_100", Unstable(sym::nvptx_target_feature), &["sm_90"]),
("sm_100a", Unstable(sym::nvptx_target_feature), &["sm_100"]),
("sm_101", Unstable(sym::nvptx_target_feature), &["sm_100"]),
("sm_101a", Unstable(sym::nvptx_target_feature), &["sm_101"]),
("sm_120", Unstable(sym::nvptx_target_feature), &["sm_101"]),
("sm_120a", Unstable(sym::nvptx_target_feature), &["sm_120"]),
("ptx70", Unstable(sym::nvptx_target_feature), &[]),
("ptx71", Unstable(sym::nvptx_target_feature), &["ptx70"]),
("ptx72", Unstable(sym::nvptx_target_feature), &["ptx71"]),
("ptx73", Unstable(sym::nvptx_target_feature), &["ptx72"]),
("ptx74", Unstable(sym::nvptx_target_feature), &["ptx73"]),
("ptx75", Unstable(sym::nvptx_target_feature), &["ptx74"]),
("ptx76", Unstable(sym::nvptx_target_feature), &["ptx75"]),
("ptx77", Unstable(sym::nvptx_target_feature), &["ptx76"]),
("ptx78", Unstable(sym::nvptx_target_feature), &["ptx77"]),
("ptx80", Unstable(sym::nvptx_target_feature), &["ptx78"]),
("ptx81", Unstable(sym::nvptx_target_feature), &["ptx80"]),
("ptx82", Unstable(sym::nvptx_target_feature), &["ptx81"]),
("ptx83", Unstable(sym::nvptx_target_feature), &["ptx82"]),
("ptx84", Unstable(sym::nvptx_target_feature), &["ptx83"]),
("ptx85", Unstable(sym::nvptx_target_feature), &["ptx84"]),
("ptx86", Unstable(sym::nvptx_target_feature), &["ptx85"]),
("ptx87", Unstable(sym::nvptx_target_feature), &["ptx86"]),
];
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("a", Stable, &["zaamo", "zalrsc"]),
("b", Stable, &["zba", "zbb", "zbs"]),
("c", Stable, &["zca"]),
("d", Unstable(sym::riscv_target_feature), &["f"]),
("e", Unstable(sym::riscv_target_feature), &[]),
("f", Unstable(sym::riscv_target_feature), &["zicsr"]),
(
"forced-atomics",
Stability::InternalOnly {
reason: "unsound because it changes the ABI of atomic operations",
hard_error: false,
},
&[],
),
("m", Stable, &[]),
("relax", Unstable(sym::riscv_target_feature), &[]),
(
"rva23u64",
Unstable(sym::riscv_target_feature),
&[
"m",
"a",
"f",
"d",
"c",
"b",
"v",
"zicsr",
"zicntr",
"zihpm",
"ziccif",
"ziccrse",
"ziccamoa",
"zicclsm",
"zic64b",
"za64rs",
"zihintpause",
"zba",
"zbb",
"zbs",
"zicbom",
"zicbop",
"zicboz",
"zfhmin",
"zkt",
"zvfhmin",
"zvbb",
"zvkt",
"zihintntl",
"zicond",
"zimop",
"zcmop",
"zcb",
"zfa",
"zawrs",
"supm",
],
),
("supm", Unstable(sym::riscv_target_feature), &[]),
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
("za64rs", Stable, &["za128rs"]), ("za128rs", Stable, &[]),
("zaamo", Stable, &[]),
("zabha", Stable, &["zaamo"]),
("zacas", Stable, &["zaamo"]),
("zalrsc", Stable, &[]),
("zama16b", Stable, &[]),
("zawrs", Stable, &[]),
("zba", Stable, &[]),
("zbb", Stable, &[]),
("zbc", Stable, &["zbkc"]), ("zbkb", Stable, &[]),
("zbkc", Stable, &[]),
("zbkx", Stable, &[]),
("zbs", Stable, &[]),
("zca", Stable, &[]),
("zcb", Stable, &["zca"]),
("zcmop", Stable, &["zca"]),
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
("zfbfmin", Unstable(sym::riscv_target_feature), &["f"]), ("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
("zic64b", Stable, &[]),
("zicbom", Stable, &[]),
("zicbop", Stable, &[]),
("zicboz", Stable, &[]),
("ziccamoa", Stable, &[]),
("ziccif", Stable, &[]),
("zicclsm", Stable, &[]),
("ziccrse", Stable, &[]),
("zicntr", Stable, &["zicsr"]),
("zicond", Stable, &[]),
("zicsr", Stable, &[]),
("zifencei", Stable, &[]),
("zihintntl", Stable, &[]),
("zihintpause", Stable, &[]),
("zihpm", Stable, &["zicsr"]),
("zimop", Stable, &[]),
("zk", Stable, &["zkn", "zkr", "zkt"]),
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
("zknd", Stable, &["zkne_or_zknd"]),
("zkne", Stable, &["zkne_or_zknd"]),
("zkne_or_zknd", Unstable(sym::riscv_target_feature), &[]), ("zknh", Stable, &[]),
("zkr", Stable, &[]),
("zks", Stable, &["zbkb", "zbkc", "zbkx", "zksed", "zksh"]),
("zksed", Stable, &[]),
("zksh", Stable, &[]),
("zkt", Stable, &[]),
("ztso", Stable, &[]),
("zvbb", Unstable(sym::riscv_target_feature), &["zvkb"]), ("zvbc", Unstable(sym::riscv_target_feature), &["zve64x"]),
("zve32f", Unstable(sym::riscv_target_feature), &["zve32x", "f"]),
("zve32x", Unstable(sym::riscv_target_feature), &["zvl32b", "zicsr"]),
("zve64d", Unstable(sym::riscv_target_feature), &["zve64f", "d"]),
("zve64f", Unstable(sym::riscv_target_feature), &["zve32f", "zve64x"]),
("zve64x", Unstable(sym::riscv_target_feature), &["zve32x", "zvl64b"]),
("zvfbfmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
("zvfbfwma", Unstable(sym::riscv_target_feature), &["zfbfmin", "zvfbfmin"]),
("zvfh", Unstable(sym::riscv_target_feature), &["zvfhmin", "zve32f", "zfhmin"]), ("zvfhmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
("zvkb", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvkg", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvkn", Unstable(sym::riscv_target_feature), &["zvkned", "zvknhb", "zvkb", "zvkt"]),
("zvknc", Unstable(sym::riscv_target_feature), &["zvkn", "zvbc"]),
("zvkned", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvkng", Unstable(sym::riscv_target_feature), &["zvkn", "zvkg"]),
("zvknha", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvknhb", Unstable(sym::riscv_target_feature), &["zvknha", "zve64x"]), ("zvks", Unstable(sym::riscv_target_feature), &["zvksed", "zvksh", "zvkb", "zvkt"]),
("zvksc", Unstable(sym::riscv_target_feature), &["zvks", "zvbc"]),
("zvksed", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvksg", Unstable(sym::riscv_target_feature), &["zvks", "zvkg"]),
("zvksh", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvkt", Unstable(sym::riscv_target_feature), &[]),
("zvl32b", Unstable(sym::riscv_target_feature), &[]),
("zvl64b", Unstable(sym::riscv_target_feature), &["zvl32b"]),
("zvl128b", Unstable(sym::riscv_target_feature), &["zvl64b"]),
("zvl256b", Unstable(sym::riscv_target_feature), &["zvl128b"]),
("zvl512b", Unstable(sym::riscv_target_feature), &["zvl256b"]),
("zvl1024b", Unstable(sym::riscv_target_feature), &["zvl512b"]),
("zvl2048b", Unstable(sym::riscv_target_feature), &["zvl1024b"]),
("zvl4096b", Unstable(sym::riscv_target_feature), &["zvl2048b"]),
("zvl8192b", Unstable(sym::riscv_target_feature), &["zvl4096b"]),
("zvl16384b", Unstable(sym::riscv_target_feature), &["zvl8192b"]),
("zvl32768b", Unstable(sym::riscv_target_feature), &["zvl16384b"]),
("zvl65536b", Unstable(sym::riscv_target_feature), &["zvl32768b"]),
];
static WASM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("atomics", Unstable(sym::wasm_target_feature), &[]),
("bulk-memory", Stable, &[]),
("exception-handling", Unstable(sym::wasm_target_feature), &[]),
("extended-const", Stable, &[]),
("gc", Unstable(sym::wasm_target_feature), &["reference-types"]),
("multivalue", Stable, &[]),
("mutable-globals", Stable, &[]),
("nontrapping-fptoint", Stable, &[]),
("reference-types", Stable, &[]),
("relaxed-simd", Stable, &["simd128"]),
("sign-ext", Stable, &[]),
("simd128", Stable, &[]),
("tail-call", Stable, &[]),
("wide-arithmetic", Unstable(sym::wasm_target_feature), &[]),
];
const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("alu32", Unstable(sym::bpf_target_feature), &[]),
("allows-misaligned-mem-access", Unstable(sym::bpf_target_feature), &[]),
];
static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("2e3", Unstable(sym::csky_target_feature), &["e2"]),
("3e3r1", Unstable(sym::csky_target_feature), &[]),
("3e3r2", Unstable(sym::csky_target_feature), &["3e3r1", "doloop"]),
("3e3r3", Unstable(sym::csky_target_feature), &["doloop"]),
("3e7", Unstable(sym::csky_target_feature), &["2e3"]),
("7e10", Unstable(sym::csky_target_feature), &["3e7"]),
("10e60", Unstable(sym::csky_target_feature), &["7e10"]),
("cache", Unstable(sym::csky_target_feature), &[]),
("doloop", Unstable(sym::csky_target_feature), &[]),
("dsp1e2", Unstable(sym::csky_target_feature), &[]),
("dspe60", Unstable(sym::csky_target_feature), &[]),
("e1", Unstable(sym::csky_target_feature), &["elrw"]),
("e2", Unstable(sym::csky_target_feature), &["e2"]),
("edsp", Unstable(sym::csky_target_feature), &[]),
("elrw", Unstable(sym::csky_target_feature), &[]),
("float1e2", Unstable(sym::csky_target_feature), &[]),
("float1e3", Unstable(sym::csky_target_feature), &[]),
("float3e4", Unstable(sym::csky_target_feature), &[]),
("float7e60", Unstable(sym::csky_target_feature), &[]),
("floate1", Unstable(sym::csky_target_feature), &[]),
("hard-tp", Unstable(sym::csky_target_feature), &[]),
("high-registers", Unstable(sym::csky_target_feature), &[]),
("hwdiv", Unstable(sym::csky_target_feature), &[]),
("mp", Unstable(sym::csky_target_feature), &["2e3"]),
("mp1e2", Unstable(sym::csky_target_feature), &["3e7"]),
("nvic", Unstable(sym::csky_target_feature), &[]),
("trust", Unstable(sym::csky_target_feature), &[]),
("vdsp2e60f", Unstable(sym::csky_target_feature), &[]),
("vdspv1", Unstable(sym::csky_target_feature), &[]),
("vdspv2", Unstable(sym::csky_target_feature), &[]),
("fdivdu", Unstable(sym::csky_target_feature), &[]),
("fpuv2_df", Unstable(sym::csky_target_feature), &[]),
("fpuv2_sf", Unstable(sym::csky_target_feature), &[]),
("fpuv3_df", Unstable(sym::csky_target_feature), &[]),
("fpuv3_hf", Unstable(sym::csky_target_feature), &[]),
("fpuv3_hi", Unstable(sym::csky_target_feature), &[]),
("fpuv3_sf", Unstable(sym::csky_target_feature), &[]),
("hard-float", Unstable(sym::csky_target_feature), &[]),
("hard-float-abi", Unstable(sym::csky_target_feature), &[]),
];
static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("32s", Unstable(sym::loongarch_target_feature), &[]),
("d", Stable, &["f"]),
("div32", Stable, &[]),
("f", Stable, &[]),
("frecipe", Stable, &[]),
("lam-bh", Stable, &[]),
("lamcas", Stable, &[]),
("lasx", Stable, &["lsx"]),
("lbt", Stable, &[]),
("ld-seq-sa", Stable, &[]),
("lsx", Stable, &["d"]),
("lvz", Stable, &[]),
("relax", Unstable(sym::loongarch_target_feature), &[]),
("scq", Stable, &[]),
("ual", Unstable(sym::loongarch_target_feature), &[]),
];
#[rustfmt::skip]
const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("backchain", Unstable(sym::s390x_target_feature), &[]),
("concurrent-functions", Unstable(sym::s390x_target_feature), &[]),
("deflate-conversion", Unstable(sym::s390x_target_feature), &[]),
("enhanced-sort", Unstable(sym::s390x_target_feature), &[]),
("guarded-storage", Unstable(sym::s390x_target_feature), &[]),
("high-word", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension3", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension4", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension5", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension8", Unstable(sym::s390x_target_feature), &["message-security-assist-extension3"]),
("message-security-assist-extension9", Unstable(sym::s390x_target_feature), &["message-security-assist-extension3", "message-security-assist-extension4"]),
("message-security-assist-extension12", Unstable(sym::s390x_target_feature), &[]),
("miscellaneous-extensions-2", Stable, &[]),
("miscellaneous-extensions-3", Stable, &[]),
("miscellaneous-extensions-4", Stable, &[]),
("nnp-assist", Stable, &["vector"]),
("soft-float", InternalOnly { reason: "unsupported ABI-configuration feature", hard_error: false }, &[]),
("transactional-execution", Unstable(sym::s390x_target_feature), &[]),
("vector", Stable, &[]),
("vector-enhancements-1", Stable, &["vector"]),
("vector-enhancements-2", Stable, &["vector-enhancements-1"]),
("vector-enhancements-3", Stable, &["vector-enhancements-2"]),
("vector-packed-decimal", Stable, &["vector"]),
("vector-packed-decimal-enhancement", Stable, &["vector-packed-decimal"]),
("vector-packed-decimal-enhancement-2", Stable, &["vector-packed-decimal-enhancement"]),
("vector-packed-decimal-enhancement-3", Stable, &["vector-packed-decimal-enhancement-2"]),
];
const SPARC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("leoncasa", Unstable(sym::sparc_target_feature), &[]),
(
"soft-float",
InternalOnly { reason: "unsupported ABI-configuration feature", hard_error: false },
&[],
),
("v8plus", Unstable(sym::sparc_target_feature), &[]),
("v9", Unstable(sym::sparc_target_feature), &[]),
];
static M68K_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("isa-68000", Unstable(sym::m68k_target_feature), &[]),
("isa-68010", Unstable(sym::m68k_target_feature), &["isa-68000"]),
("isa-68020", Unstable(sym::m68k_target_feature), &["isa-68010"]),
("isa-68030", Unstable(sym::m68k_target_feature), &["isa-68020"]),
("isa-68040", Unstable(sym::m68k_target_feature), &["isa-68030", "isa-68882"]),
("isa-68060", Unstable(sym::m68k_target_feature), &["isa-68040"]),
("isa-68881", Unstable(sym::m68k_target_feature), &[]),
("isa-68882", Unstable(sym::m68k_target_feature), &["isa-68881"]),
];
static AVR_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("addsubiw", Unstable(sym::avr_target_feature), &[]),
("break", Unstable(sym::avr_target_feature), &[]),
("eijmpcall", Unstable(sym::avr_target_feature), &[]),
("elpm", Unstable(sym::avr_target_feature), &[]),
("elpmx", Unstable(sym::avr_target_feature), &[]),
("ijmpcall", Unstable(sym::avr_target_feature), &[]),
("jmpcall", Unstable(sym::avr_target_feature), &[]),
("lowbytefirst", Unstable(sym::avr_target_feature), &[]),
("lpm", Unstable(sym::avr_target_feature), &[]),
("lpmx", Unstable(sym::avr_target_feature), &[]),
("movw", Unstable(sym::avr_target_feature), &[]),
("mul", Unstable(sym::avr_target_feature), &[]),
("rmw", Unstable(sym::avr_target_feature), &[]),
("spm", Unstable(sym::avr_target_feature), &[]),
("spmx", Unstable(sym::avr_target_feature), &[]),
(
"sram",
InternalOnly { reason: "devices that have no SRAM are unsupported", hard_error: false },
&[],
),
("tinyencoding", Unstable(sym::avr_target_feature), &[]),
];
const XTENSA_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("bool", Unstable(sym::xtensa_target_feature), &[]),
("fp", Unstable(sym::xtensa_target_feature), &["bool", "coprocessor"]),
("coprocessor", Unstable(sym::xtensa_target_feature), &[]),
("highpriinterrupts", Unstable(sym::xtensa_target_feature), &["interrupt"]),
("interrupt", Unstable(sym::xtensa_target_feature), &["exception"]),
(
"windowed",
InternalOnly {
reason: "windowed changes the Xtensa calling convention",
hard_error: false,
},
&["exception"],
),
("loop", Unstable(sym::xtensa_target_feature), &[]),
("sext", Unstable(sym::xtensa_target_feature), &[]),
("nsa", Unstable(sym::xtensa_target_feature), &[]),
("mul32", Unstable(sym::xtensa_target_feature), &[]),
("mul32high", Unstable(sym::xtensa_target_feature), &["mul32"]),
("div32", Unstable(sym::xtensa_target_feature), &[]),
("mac16", Unstable(sym::xtensa_target_feature), &[]),
("s32c1i", Unstable(sym::xtensa_target_feature), &[]),
("threadptr", Unstable(sym::xtensa_target_feature), &[]),
("extendedl32r", Unstable(sym::xtensa_target_feature), &[]),
("debug", Unstable(sym::xtensa_target_feature), &["exception"]),
("exception", Unstable(sym::xtensa_target_feature), &[]),
("rvector", Unstable(sym::xtensa_target_feature), &["exception"]),
("prid", Unstable(sym::xtensa_target_feature), &[]),
("regprotect", Unstable(sym::xtensa_target_feature), &[]),
("miscsr", Unstable(sym::xtensa_target_feature), &[]),
];
pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
core::iter::empty()
.chain(ARM_FEATURES)
.chain(AARCH64_FEATURES)
.chain(X86_FEATURES)
.chain(HEXAGON_FEATURES)
.chain(POWERPC_FEATURES)
.chain(MIPS_FEATURES)
.chain(NVPTX_FEATURES)
.chain(RISCV_FEATURES)
.chain(WASM_FEATURES)
.chain(BPF_FEATURES)
.chain(XTENSA_FEATURES)
.chain(CSKY_FEATURES)
.chain(LOONGARCH_FEATURES)
.chain(IBMZ_FEATURES)
.chain(SPARC_FEATURES)
.chain(M68K_FEATURES)
.chain(AVR_FEATURES)
.cloned()
.map(|(f, s, _)| (f, s))
}
pub fn feature_to_arch_names(feature: &str) -> Vec<&'static str> {
let mut arches = Vec::new();
macro_rules! check_arch_feats {
($arch_name:expr, $feats:expr) => {
if $feats.iter().any(|(f, _, _)| *f == feature) {
arches.push($arch_name);
}
};
}
check_arch_feats!("arm", ARM_FEATURES);
check_arch_feats!("aarch64", AARCH64_FEATURES);
check_arch_feats!("x86", X86_FEATURES);
check_arch_feats!("hexagon", HEXAGON_FEATURES);
check_arch_feats!("mips", MIPS_FEATURES);
check_arch_feats!("nvptx64", NVPTX_FEATURES);
check_arch_feats!("powerpc", POWERPC_FEATURES);
check_arch_feats!("riscv", RISCV_FEATURES);
check_arch_feats!("wasm", WASM_FEATURES);
check_arch_feats!("bpf", BPF_FEATURES);
check_arch_feats!("csky", CSKY_FEATURES);
check_arch_feats!("loongarch", LOONGARCH_FEATURES);
check_arch_feats!("s390x", IBMZ_FEATURES);
check_arch_feats!("sparc", SPARC_FEATURES);
check_arch_feats!("m68k", M68K_FEATURES);
check_arch_feats!("avr", AVR_FEATURES);
arches.sort();
arches.dedup();
arches
}
const X86_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "sse"), (256, "avx"), (512, "avx512f")]; const AARCH64_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "neon")];
const ARM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "neon"), (128, "mve")];
const AMDGPU_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(1024, "")];
const POWERPC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "altivec")];
const WASM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "simd128")];
const S390X_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "vector")];
const RISCV_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] = &[
(32, "zvl32b"),
(64, "zvl64b"),
(128, "zvl128b"),
(256, "zvl256b"),
(512, "zvl512b"),
(1024, "zvl1024b"),
(2048, "zvl2048b"),
(4096, "zvl4096b"),
(8192, "zvl8192b"),
(16384, "zvl16384b"),
(32768, "zvl32768b"),
(65536, "zvl65536b"),
];
const SPARC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[];
const HEXAGON_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] = &[
(512, "hvx-length64b"), (1024, "hvx-length128b"), (2048, "hvx-length128b"), ];
const MIPS_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "msa")];
const CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "vdspv1")];
const LOONGARCH_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI: &'static [(u64, &'static str)] =
&[(128, "lsx"), (256, "lasx")];
#[derive(Copy, Clone, Debug)]
pub struct FeatureConstraints {
pub required: &'static [&'static str],
pub incompatible: &'static [&'static str],
}
impl Target {
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
match &self.arch {
Arch::Arm => ARM_FEATURES,
Arch::AArch64 | Arch::Arm64EC => AARCH64_FEATURES,
Arch::X86 | Arch::X86_64 => X86_FEATURES,
Arch::Hexagon => HEXAGON_FEATURES,
Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => MIPS_FEATURES,
Arch::Nvptx64 => NVPTX_FEATURES,
Arch::PowerPC | Arch::PowerPC64 => POWERPC_FEATURES,
Arch::RiscV32 | Arch::RiscV64 => RISCV_FEATURES,
Arch::Wasm32 | Arch::Wasm64 => WASM_FEATURES,
Arch::Bpf => BPF_FEATURES,
Arch::CSky => CSKY_FEATURES,
Arch::LoongArch32 | Arch::LoongArch64 => LOONGARCH_FEATURES,
Arch::S390x => IBMZ_FEATURES,
Arch::Sparc | Arch::Sparc64 => SPARC_FEATURES,
Arch::M68k => M68K_FEATURES,
Arch::Avr => AVR_FEATURES,
Arch::Xtensa => XTENSA_FEATURES,
Arch::AmdGpu | Arch::Msp430 | Arch::SpirV | Arch::Other(_) => &[],
}
}
pub fn rust_target_features_map(
&self,
) -> FxHashMap<&'static str, (Stability, ImpliedFeatures)> {
self.rust_target_features()
.iter()
.map(|&(f, s, i)| (f, (s, i)))
.collect::<FxHashMap<_, _>>()
}
pub fn features_for_correct_fixed_length_vector_abi(&self) -> &'static [(u64, &'static str)] {
match &self.arch {
Arch::X86 | Arch::X86_64 => X86_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::AArch64 | Arch::Arm64EC => AARCH64_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Arm => ARM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::PowerPC | Arch::PowerPC64 => POWERPC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::LoongArch32 | Arch::LoongArch64 => {
LOONGARCH_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI
}
Arch::RiscV32 | Arch::RiscV64 => RISCV_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Wasm32 | Arch::Wasm64 => WASM_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::S390x => S390X_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Sparc | Arch::Sparc64 => SPARC_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Hexagon => HEXAGON_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => {
MIPS_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI
}
Arch::AmdGpu => AMDGPU_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Nvptx64 | Arch::Bpf | Arch::M68k | Arch::Avr => &[], Arch::CSky => CSKY_FEATURES_FOR_CORRECT_FIXED_LENGTH_VECTOR_ABI,
Arch::Msp430 | Arch::SpirV | Arch::Xtensa | Arch::Other(_) => &[],
}
}
pub fn features_for_correct_scalable_vector_abi(&self) -> Option<&'static str> {
match &self.arch {
Arch::AArch64 | Arch::Arm64EC => Some("sve"),
_ => None,
}
}
pub fn tied_target_features(&self) -> &'static [&'static [&'static str]] {
match &self.arch {
Arch::AArch64 | Arch::Arm64EC => AARCH64_TIED_FEATURES,
_ => &[],
}
}
#[track_caller]
pub fn implied_target_features<'a>(
&self,
base_feature: &'a str,
target_features_map: &FxHashMap<&'static str, (Stability, ImpliedFeatures)>,
) -> FxHashSet<&'a str> {
let mut features = FxHashSet::default();
let mut new_features = vec![base_feature];
while let Some(new_feature) = new_features.pop() {
if features.insert(new_feature) {
let (_, implied_features) = target_features_map
.get(&new_feature)
.unwrap_or_else(|| panic!("encountered non-Rust target feature {new_feature}"));
new_features.extend(implied_features.iter().copied());
}
}
features
}
pub fn abi_required_features(&self) -> FeatureConstraints {
const NOTHING: FeatureConstraints = FeatureConstraints { required: &[], incompatible: &[] };
match &self.arch {
Arch::X86 => {
match self.rustc_abi {
None => {
FeatureConstraints { required: &["x87"], incompatible: &["soft-float"] }
}
Some(RustcAbi::X86Sse2) => {
FeatureConstraints {
required: &["x87", "sse2"],
incompatible: &["soft-float"],
}
}
Some(RustcAbi::Softfloat) => {
FeatureConstraints { required: &["soft-float"], incompatible: &["sse"] }
}
_ => unreachable!(),
}
}
Arch::X86_64 => {
match self.rustc_abi {
None => {
FeatureConstraints {
required: &["x87", "sse2"],
incompatible: &["soft-float"],
}
}
Some(RustcAbi::Softfloat) => {
FeatureConstraints { required: &["soft-float"], incompatible: &["sse"] }
}
_ => unreachable!(),
}
}
Arch::Arm => {
match self.llvm_floatabi.unwrap() {
FloatAbi::Soft => {
NOTHING
}
FloatAbi::Hard => {
FeatureConstraints { required: &["fpregs"], incompatible: &["soft-float"] }
}
}
}
Arch::AArch64 | Arch::Arm64EC => {
match self.rustc_abi {
Some(RustcAbi::Softfloat) => {
FeatureConstraints { required: &[], incompatible: &["neon", "fp-armv8"] }
}
None => {
FeatureConstraints { required: &["neon"], incompatible: &[] }
}
_ => unreachable!(),
}
}
Arch::RiscV32 | Arch::RiscV64 => {
match &self.llvm_abiname {
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => {
FeatureConstraints { required: &["d"], incompatible: &["e", "zfinx"] }
}
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => {
FeatureConstraints { required: &["f"], incompatible: &["e", "zfinx"] }
}
LlvmAbi::Ilp32 | LlvmAbi::Lp64 => {
FeatureConstraints { required: &[], incompatible: &["e"] }
}
LlvmAbi::Ilp32e => {
FeatureConstraints { required: &[], incompatible: &["d"] }
}
LlvmAbi::Lp64e => {
NOTHING
}
_ => unreachable!(),
}
}
Arch::LoongArch32 | Arch::LoongArch64 => {
match &self.llvm_abiname {
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => {
FeatureConstraints { required: &["d"], incompatible: &[] }
}
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => {
FeatureConstraints { required: &["f"], incompatible: &[] }
}
LlvmAbi::Ilp32s | LlvmAbi::Lp64s => {
NOTHING
}
_ => unreachable!(),
}
}
Arch::S390x => {
match self.rustc_abi {
None => {
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
}
Some(RustcAbi::Softfloat) => {
FeatureConstraints { required: &["soft-float"], incompatible: &["vector"] }
}
_ => unreachable!(),
}
}
Arch::PowerPC => {
match self.rustc_abi {
None => {
FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] }
}
Some(RustcAbi::PowerPcSpe) => {
FeatureConstraints { required: &["hard-float", "spe"], incompatible: &[] }
}
_ => unreachable!(),
}
}
Arch::PowerPC64 => {
FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] }
}
Arch::Sparc => {
match self.rustc_abi {
None => FeatureConstraints {
required: &[],
incompatible: &["soft-float", "v8plus"],
},
Some(RustcAbi::SparcV8Plus) => {
FeatureConstraints { required: &["v8plus"], incompatible: &["soft-float"] }
}
_ => unreachable!(),
}
}
Arch::Sparc64 => {
FeatureConstraints { required: &[], incompatible: &["soft-float", "v8plus"] }
}
Arch::Avr => {
FeatureConstraints { required: &["sram"], incompatible: &[] }
}
Arch::Wasm32 | Arch::Wasm64 => {
NOTHING
}
Arch::Xtensa => {
FeatureConstraints { required: &["windowed", "exception"], incompatible: &[] }
}
_ => NOTHING,
}
}
}