]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_ssa/src/target_features.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / compiler / rustc_codegen_ssa / src / target_features.rs
CommitLineData
29967ef6
XL
1use rustc_hir::def_id::LOCAL_CRATE;
2use rustc_middle::ty::query::Providers;
3use rustc_session::Session;
4use rustc_span::symbol::sym;
5use rustc_span::symbol::Symbol;
6
fc512014
XL
7// When adding features to the below lists
8// check whether they're named already elsewhere in rust
9// e.g. in stdarch and whether the given name matches LLVM's
10// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted
11
29967ef6
XL
12const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
13 ("aclass", Some(sym::arm_target_feature)),
14 ("mclass", Some(sym::arm_target_feature)),
15 ("rclass", Some(sym::arm_target_feature)),
16 ("dsp", Some(sym::arm_target_feature)),
17 ("neon", Some(sym::arm_target_feature)),
18 ("crc", Some(sym::arm_target_feature)),
19 ("crypto", Some(sym::arm_target_feature)),
20 ("v5te", Some(sym::arm_target_feature)),
21 ("v6", Some(sym::arm_target_feature)),
22 ("v6k", Some(sym::arm_target_feature)),
23 ("v6t2", Some(sym::arm_target_feature)),
24 ("v7", Some(sym::arm_target_feature)),
25 ("v8", Some(sym::arm_target_feature)),
26 ("vfp2", Some(sym::arm_target_feature)),
27 ("vfp3", Some(sym::arm_target_feature)),
28 ("vfp4", Some(sym::arm_target_feature)),
cdc7bbd5 29 ("fp-armv8", Some(sym::arm_target_feature)),
29967ef6
XL
30 // This is needed for inline assembly, but shouldn't be stabilized as-is
31 // since it should be enabled per-function using #[instruction_set], not
32 // #[target_feature].
33 ("thumb-mode", Some(sym::arm_target_feature)),
34];
35
36const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
37 ("fp", Some(sym::aarch64_target_feature)),
38 ("neon", Some(sym::aarch64_target_feature)),
39 ("sve", Some(sym::aarch64_target_feature)),
40 ("crc", Some(sym::aarch64_target_feature)),
41 ("crypto", Some(sym::aarch64_target_feature)),
42 ("ras", Some(sym::aarch64_target_feature)),
43 ("lse", Some(sym::aarch64_target_feature)),
44 ("rdm", Some(sym::aarch64_target_feature)),
45 ("fp16", Some(sym::aarch64_target_feature)),
46 ("rcpc", Some(sym::aarch64_target_feature)),
47 ("dotprod", Some(sym::aarch64_target_feature)),
48 ("tme", Some(sym::aarch64_target_feature)),
49 ("v8.1a", Some(sym::aarch64_target_feature)),
50 ("v8.2a", Some(sym::aarch64_target_feature)),
51 ("v8.3a", Some(sym::aarch64_target_feature)),
52];
53
54const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
55 ("adx", Some(sym::adx_target_feature)),
56 ("aes", None),
57 ("avx", None),
58 ("avx2", None),
fc512014
XL
59 ("avx512bf16", Some(sym::avx512_target_feature)),
60 ("avx512bitalg", Some(sym::avx512_target_feature)),
29967ef6
XL
61 ("avx512bw", Some(sym::avx512_target_feature)),
62 ("avx512cd", Some(sym::avx512_target_feature)),
63 ("avx512dq", Some(sym::avx512_target_feature)),
64 ("avx512er", Some(sym::avx512_target_feature)),
65 ("avx512f", Some(sym::avx512_target_feature)),
fc512014 66 ("avx512gfni", Some(sym::avx512_target_feature)),
29967ef6
XL
67 ("avx512ifma", Some(sym::avx512_target_feature)),
68 ("avx512pf", Some(sym::avx512_target_feature)),
fc512014 69 ("avx512vaes", Some(sym::avx512_target_feature)),
29967ef6 70 ("avx512vbmi", Some(sym::avx512_target_feature)),
fc512014 71 ("avx512vbmi2", Some(sym::avx512_target_feature)),
29967ef6 72 ("avx512vl", Some(sym::avx512_target_feature)),
fc512014
XL
73 ("avx512vnni", Some(sym::avx512_target_feature)),
74 ("avx512vp2intersect", Some(sym::avx512_target_feature)),
75 ("avx512vpclmulqdq", Some(sym::avx512_target_feature)),
29967ef6
XL
76 ("avx512vpopcntdq", Some(sym::avx512_target_feature)),
77 ("bmi1", None),
78 ("bmi2", None),
79 ("cmpxchg16b", Some(sym::cmpxchg16b_target_feature)),
80 ("ermsb", Some(sym::ermsb_target_feature)),
81 ("f16c", Some(sym::f16c_target_feature)),
82 ("fma", None),
83 ("fxsr", None),
84 ("lzcnt", None),
85 ("movbe", Some(sym::movbe_target_feature)),
86 ("pclmulqdq", None),
87 ("popcnt", None),
88 ("rdrand", None),
89 ("rdseed", None),
90 ("rtm", Some(sym::rtm_target_feature)),
91 ("sha", None),
92 ("sse", None),
93 ("sse2", None),
94 ("sse3", None),
95 ("sse4.1", None),
96 ("sse4.2", None),
97 ("sse4a", Some(sym::sse4a_target_feature)),
98 ("ssse3", None),
99 ("tbm", Some(sym::tbm_target_feature)),
100 ("xsave", None),
101 ("xsavec", None),
102 ("xsaveopt", None),
103 ("xsaves", None),
104];
105
106const HEXAGON_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
107 ("hvx", Some(sym::hexagon_target_feature)),
108 ("hvx-length128b", Some(sym::hexagon_target_feature)),
109];
110
111const POWERPC_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
112 ("altivec", Some(sym::powerpc_target_feature)),
113 ("power8-altivec", Some(sym::powerpc_target_feature)),
114 ("power9-altivec", Some(sym::powerpc_target_feature)),
115 ("power8-vector", Some(sym::powerpc_target_feature)),
116 ("power9-vector", Some(sym::powerpc_target_feature)),
117 ("vsx", Some(sym::powerpc_target_feature)),
118];
119
120const MIPS_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] =
121 &[("fp64", Some(sym::mips_target_feature)), ("msa", Some(sym::mips_target_feature))];
122
123const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
124 ("m", Some(sym::riscv_target_feature)),
125 ("a", Some(sym::riscv_target_feature)),
126 ("c", Some(sym::riscv_target_feature)),
127 ("f", Some(sym::riscv_target_feature)),
128 ("d", Some(sym::riscv_target_feature)),
129 ("e", Some(sym::riscv_target_feature)),
130];
131
132const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
133 ("simd128", Some(sym::wasm_target_feature)),
134 ("atomics", Some(sym::wasm_target_feature)),
135 ("nontrapping-fptoint", Some(sym::wasm_target_feature)),
136];
137
138/// When rustdoc is running, provide a list of all known features so that all their respective
139/// primitives may be documented.
140///
141/// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
142pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol>)> {
143 std::iter::empty()
144 .chain(ARM_ALLOWED_FEATURES.iter())
145 .chain(AARCH64_ALLOWED_FEATURES.iter())
146 .chain(X86_ALLOWED_FEATURES.iter())
147 .chain(HEXAGON_ALLOWED_FEATURES.iter())
148 .chain(POWERPC_ALLOWED_FEATURES.iter())
149 .chain(MIPS_ALLOWED_FEATURES.iter())
150 .chain(RISCV_ALLOWED_FEATURES.iter())
151 .chain(WASM_ALLOWED_FEATURES.iter())
152 .cloned()
153}
154
155pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Option<Symbol>)] {
156 match &*sess.target.arch {
157 "arm" => ARM_ALLOWED_FEATURES,
158 "aarch64" => AARCH64_ALLOWED_FEATURES,
159 "x86" | "x86_64" => X86_ALLOWED_FEATURES,
160 "hexagon" => HEXAGON_ALLOWED_FEATURES,
161 "mips" | "mips64" => MIPS_ALLOWED_FEATURES,
162 "powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
163 "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
cdc7bbd5 164 "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
29967ef6
XL
165 _ => &[],
166 }
167}
168
169pub(crate) fn provide(providers: &mut Providers) {
170 providers.supported_target_features = |tcx, cnum| {
171 assert_eq!(cnum, LOCAL_CRATE);
172 if tcx.sess.opts.actually_rustdoc {
173 // rustdoc needs to be able to document functions that use all the features, so
174 // whitelist them all
175 all_known_features().map(|(a, b)| (a.to_string(), b)).collect()
176 } else {
177 supported_target_features(tcx.sess).iter().map(|&(a, b)| (a.to_string(), b)).collect()
178 }
179 };
180}