]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_ssa/src/target_features.rs
New upstream version 1.64.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
5e7ed085
FG
7/// Features that control behaviour of rustc, rather than the codegen.
8pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
9
fc512014
XL
10// When adding features to the below lists
11// check whether they're named already elsewhere in rust
12// e.g. in stdarch and whether the given name matches LLVM's
13// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted
14
29967ef6
XL
15const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
16 ("aclass", Some(sym::arm_target_feature)),
17 ("mclass", Some(sym::arm_target_feature)),
18 ("rclass", Some(sym::arm_target_feature)),
19 ("dsp", Some(sym::arm_target_feature)),
20 ("neon", Some(sym::arm_target_feature)),
21 ("crc", Some(sym::arm_target_feature)),
22 ("crypto", Some(sym::arm_target_feature)),
17df50a5
XL
23 ("aes", Some(sym::arm_target_feature)),
24 ("sha2", Some(sym::arm_target_feature)),
3c0e092e
XL
25 ("i8mm", Some(sym::arm_target_feature)),
26 ("dotprod", Some(sym::arm_target_feature)),
29967ef6
XL
27 ("v5te", Some(sym::arm_target_feature)),
28 ("v6", Some(sym::arm_target_feature)),
29 ("v6k", Some(sym::arm_target_feature)),
30 ("v6t2", Some(sym::arm_target_feature)),
31 ("v7", Some(sym::arm_target_feature)),
32 ("v8", Some(sym::arm_target_feature)),
33 ("vfp2", Some(sym::arm_target_feature)),
34 ("vfp3", Some(sym::arm_target_feature)),
35 ("vfp4", Some(sym::arm_target_feature)),
cdc7bbd5 36 ("fp-armv8", Some(sym::arm_target_feature)),
29967ef6
XL
37 // This is needed for inline assembly, but shouldn't be stabilized as-is
38 // since it should be enabled per-function using #[instruction_set], not
39 // #[target_feature].
40 ("thumb-mode", Some(sym::arm_target_feature)),
a2a8927a 41 ("thumb2", Some(sym::arm_target_feature)),
5e7ed085 42 ("d32", Some(sym::arm_target_feature)),
29967ef6
XL
43];
44
45const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
5e7ed085
FG
46 // FEAT_AdvSimd & FEAT_FP
47 ("neon", None),
17df50a5 48 // FEAT_FP16
5e7ed085 49 ("fp16", None),
17df50a5 50 // FEAT_SVE
5e7ed085 51 ("sve", None),
17df50a5 52 // FEAT_CRC
5e7ed085 53 ("crc", None),
17df50a5 54 // FEAT_RAS
5e7ed085 55 ("ras", None),
17df50a5 56 // FEAT_LSE
5e7ed085 57 ("lse", None),
17df50a5 58 // FEAT_RDM
5e7ed085 59 ("rdm", None),
17df50a5 60 // FEAT_RCPC
5e7ed085 61 ("rcpc", None),
17df50a5 62 // FEAT_RCPC2
5e7ed085 63 ("rcpc2", None),
17df50a5 64 // FEAT_DotProd
5e7ed085 65 ("dotprod", None),
17df50a5 66 // FEAT_TME
5e7ed085 67 ("tme", None),
17df50a5 68 // FEAT_FHM
5e7ed085 69 ("fhm", None),
17df50a5 70 // FEAT_DIT
5e7ed085 71 ("dit", None),
17df50a5 72 // FEAT_FLAGM
5e7ed085 73 ("flagm", None),
17df50a5 74 // FEAT_SSBS
5e7ed085 75 ("ssbs", None),
17df50a5 76 // FEAT_SB
5e7ed085 77 ("sb", None),
5099ac24 78 // FEAT_PAUTH (address authentication)
5e7ed085 79 ("paca", None),
5099ac24 80 // FEAT_PAUTH (generic authentication)
5e7ed085 81 ("pacg", None),
17df50a5 82 // FEAT_DPB
5e7ed085 83 ("dpb", None),
17df50a5 84 // FEAT_DPB2
5e7ed085 85 ("dpb2", None),
17df50a5 86 // FEAT_SVE2
5e7ed085 87 ("sve2", None),
17df50a5 88 // FEAT_SVE2_AES
5e7ed085 89 ("sve2-aes", None),
17df50a5 90 // FEAT_SVE2_SM4
5e7ed085 91 ("sve2-sm4", None),
17df50a5 92 // FEAT_SVE2_SHA3
5e7ed085 93 ("sve2-sha3", None),
17df50a5 94 // FEAT_SVE2_BitPerm
5e7ed085 95 ("sve2-bitperm", None),
17df50a5 96 // FEAT_FRINTTS
5e7ed085 97 ("frintts", None),
17df50a5 98 // FEAT_I8MM
5e7ed085 99 ("i8mm", None),
17df50a5 100 // FEAT_F32MM
5e7ed085 101 ("f32mm", None),
17df50a5 102 // FEAT_F64MM
5e7ed085 103 ("f64mm", None),
17df50a5 104 // FEAT_BF16
5e7ed085 105 ("bf16", None),
17df50a5 106 // FEAT_RAND
5e7ed085 107 ("rand", None),
17df50a5 108 // FEAT_BTI
5e7ed085 109 ("bti", None),
17df50a5 110 // FEAT_MTE
5e7ed085 111 ("mte", None),
17df50a5 112 // FEAT_JSCVT
5e7ed085 113 ("jsconv", None),
17df50a5 114 // FEAT_FCMA
5e7ed085 115 ("fcma", None),
17df50a5 116 // FEAT_AES
5e7ed085 117 ("aes", None),
17df50a5 118 // FEAT_SHA1 & FEAT_SHA256
5e7ed085 119 ("sha2", None),
17df50a5 120 // FEAT_SHA512 & FEAT_SHA3
5e7ed085 121 ("sha3", None),
17df50a5 122 // FEAT_SM3 & FEAT_SM4
5e7ed085 123 ("sm4", None),
3c0e092e 124 // FEAT_PAN
5e7ed085 125 ("pan", None),
3c0e092e 126 // FEAT_LOR
5e7ed085 127 ("lor", None),
3c0e092e 128 // FEAT_VHE
5e7ed085 129 ("vh", None),
3c0e092e 130 // FEAT_PMUv3
5e7ed085 131 ("pmuv3", None),
3c0e092e 132 // FEAT_SPE
5e7ed085
FG
133 ("spe", None),
134 ("v8.1a", Some(sym::aarch64_ver_target_feature)),
135 ("v8.2a", Some(sym::aarch64_ver_target_feature)),
136 ("v8.3a", Some(sym::aarch64_ver_target_feature)),
137 ("v8.4a", Some(sym::aarch64_ver_target_feature)),
138 ("v8.5a", Some(sym::aarch64_ver_target_feature)),
139 ("v8.6a", Some(sym::aarch64_ver_target_feature)),
140 ("v8.7a", Some(sym::aarch64_ver_target_feature)),
29967ef6
XL
141];
142
5e7ed085
FG
143const AARCH64_TIED_FEATURES: &[&[&str]] = &[
144 &["paca", "pacg"], // Together these represent `pauth` in LLVM
145];
5099ac24 146
29967ef6 147const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
5e7ed085 148 ("adx", None),
29967ef6
XL
149 ("aes", None),
150 ("avx", None),
151 ("avx2", None),
fc512014
XL
152 ("avx512bf16", Some(sym::avx512_target_feature)),
153 ("avx512bitalg", Some(sym::avx512_target_feature)),
29967ef6
XL
154 ("avx512bw", Some(sym::avx512_target_feature)),
155 ("avx512cd", Some(sym::avx512_target_feature)),
156 ("avx512dq", Some(sym::avx512_target_feature)),
157 ("avx512er", Some(sym::avx512_target_feature)),
158 ("avx512f", Some(sym::avx512_target_feature)),
fc512014 159 ("avx512gfni", Some(sym::avx512_target_feature)),
29967ef6
XL
160 ("avx512ifma", Some(sym::avx512_target_feature)),
161 ("avx512pf", Some(sym::avx512_target_feature)),
fc512014 162 ("avx512vaes", Some(sym::avx512_target_feature)),
29967ef6 163 ("avx512vbmi", Some(sym::avx512_target_feature)),
fc512014 164 ("avx512vbmi2", Some(sym::avx512_target_feature)),
29967ef6 165 ("avx512vl", Some(sym::avx512_target_feature)),
fc512014
XL
166 ("avx512vnni", Some(sym::avx512_target_feature)),
167 ("avx512vp2intersect", Some(sym::avx512_target_feature)),
168 ("avx512vpclmulqdq", Some(sym::avx512_target_feature)),
29967ef6
XL
169 ("avx512vpopcntdq", Some(sym::avx512_target_feature)),
170 ("bmi1", None),
171 ("bmi2", None),
172 ("cmpxchg16b", Some(sym::cmpxchg16b_target_feature)),
173 ("ermsb", Some(sym::ermsb_target_feature)),
174 ("f16c", Some(sym::f16c_target_feature)),
175 ("fma", None),
176 ("fxsr", None),
177 ("lzcnt", None),
178 ("movbe", Some(sym::movbe_target_feature)),
179 ("pclmulqdq", None),
180 ("popcnt", None),
181 ("rdrand", None),
182 ("rdseed", None),
183 ("rtm", Some(sym::rtm_target_feature)),
184 ("sha", None),
185 ("sse", None),
186 ("sse2", None),
187 ("sse3", None),
188 ("sse4.1", None),
189 ("sse4.2", None),
190 ("sse4a", Some(sym::sse4a_target_feature)),
191 ("ssse3", None),
192 ("tbm", Some(sym::tbm_target_feature)),
193 ("xsave", None),
194 ("xsavec", None),
195 ("xsaveopt", None),
196 ("xsaves", None),
197];
198
199const HEXAGON_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
200 ("hvx", Some(sym::hexagon_target_feature)),
201 ("hvx-length128b", Some(sym::hexagon_target_feature)),
202];
203
204const POWERPC_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
205 ("altivec", Some(sym::powerpc_target_feature)),
206 ("power8-altivec", Some(sym::powerpc_target_feature)),
207 ("power9-altivec", Some(sym::powerpc_target_feature)),
208 ("power8-vector", Some(sym::powerpc_target_feature)),
209 ("power9-vector", Some(sym::powerpc_target_feature)),
210 ("vsx", Some(sym::powerpc_target_feature)),
211];
212
213const MIPS_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] =
214 &[("fp64", Some(sym::mips_target_feature)), ("msa", Some(sym::mips_target_feature))];
215
216const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
217 ("m", Some(sym::riscv_target_feature)),
218 ("a", Some(sym::riscv_target_feature)),
219 ("c", Some(sym::riscv_target_feature)),
220 ("f", Some(sym::riscv_target_feature)),
221 ("d", Some(sym::riscv_target_feature)),
222 ("e", Some(sym::riscv_target_feature)),
5e7ed085
FG
223 ("v", Some(sym::riscv_target_feature)),
224 ("zfinx", Some(sym::riscv_target_feature)),
225 ("zdinx", Some(sym::riscv_target_feature)),
226 ("zhinx", Some(sym::riscv_target_feature)),
227 ("zhinxmin", Some(sym::riscv_target_feature)),
228 ("zfh", Some(sym::riscv_target_feature)),
229 ("zfhmin", Some(sym::riscv_target_feature)),
230 ("zbkb", Some(sym::riscv_target_feature)),
231 ("zbkc", Some(sym::riscv_target_feature)),
232 ("zbkx", Some(sym::riscv_target_feature)),
233 ("zknd", Some(sym::riscv_target_feature)),
234 ("zkne", Some(sym::riscv_target_feature)),
235 ("zknh", Some(sym::riscv_target_feature)),
236 ("zksed", Some(sym::riscv_target_feature)),
237 ("zksh", Some(sym::riscv_target_feature)),
238 ("zkr", Some(sym::riscv_target_feature)),
239 ("zkn", Some(sym::riscv_target_feature)),
240 ("zks", Some(sym::riscv_target_feature)),
241 ("zk", Some(sym::riscv_target_feature)),
242 ("zkt", Some(sym::riscv_target_feature)),
29967ef6
XL
243];
244
245const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
17df50a5 246 ("simd128", None),
29967ef6
XL
247 ("atomics", Some(sym::wasm_target_feature)),
248 ("nontrapping-fptoint", Some(sym::wasm_target_feature)),
923072b8
FG
249 ("bulk-memory", Some(sym::wasm_target_feature)),
250 ("mutable-globals", Some(sym::wasm_target_feature)),
251 ("reference-types", Some(sym::wasm_target_feature)),
064997fb 252 ("sign-ext", Some(sym::wasm_target_feature)),
29967ef6
XL
253];
254
17df50a5
XL
255const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
256
29967ef6
XL
257/// When rustdoc is running, provide a list of all known features so that all their respective
258/// primitives may be documented.
259///
260/// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
261pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol>)> {
262 std::iter::empty()
263 .chain(ARM_ALLOWED_FEATURES.iter())
264 .chain(AARCH64_ALLOWED_FEATURES.iter())
265 .chain(X86_ALLOWED_FEATURES.iter())
266 .chain(HEXAGON_ALLOWED_FEATURES.iter())
267 .chain(POWERPC_ALLOWED_FEATURES.iter())
268 .chain(MIPS_ALLOWED_FEATURES.iter())
269 .chain(RISCV_ALLOWED_FEATURES.iter())
270 .chain(WASM_ALLOWED_FEATURES.iter())
17df50a5 271 .chain(BPF_ALLOWED_FEATURES.iter())
29967ef6
XL
272 .cloned()
273}
274
275pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Option<Symbol>)] {
276 match &*sess.target.arch {
277 "arm" => ARM_ALLOWED_FEATURES,
278 "aarch64" => AARCH64_ALLOWED_FEATURES,
279 "x86" | "x86_64" => X86_ALLOWED_FEATURES,
280 "hexagon" => HEXAGON_ALLOWED_FEATURES,
281 "mips" | "mips64" => MIPS_ALLOWED_FEATURES,
282 "powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
283 "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
cdc7bbd5 284 "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
17df50a5 285 "bpf" => BPF_ALLOWED_FEATURES,
29967ef6
XL
286 _ => &[],
287 }
288}
289
5099ac24
FG
290pub fn tied_target_features(sess: &Session) -> &'static [&'static [&'static str]] {
291 match &*sess.target.arch {
292 "aarch64" => AARCH64_TIED_FEATURES,
293 _ => &[],
294 }
295}
296
29967ef6
XL
297pub(crate) fn provide(providers: &mut Providers) {
298 providers.supported_target_features = |tcx, cnum| {
299 assert_eq!(cnum, LOCAL_CRATE);
300 if tcx.sess.opts.actually_rustdoc {
301 // rustdoc needs to be able to document functions that use all the features, so
302 // whitelist them all
303 all_known_features().map(|(a, b)| (a.to_string(), b)).collect()
304 } else {
305 supported_target_features(tcx.sess).iter().map(|&(a, b)| (a.to_string(), b)).collect()
306 }
307 };
308}