1 use rustc_hir::def_id::LOCAL_CRATE;
2 use rustc_middle::ty::query::Providers;
3 use rustc_session::Session;
4 use rustc_span::symbol::sym;
5 use rustc_span::symbol::Symbol;
7 /// Features that control behaviour of rustc, rather than the codegen.
8 pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
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
15 const ARM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
16 // tidy-alphabetical-start
17 ("aclass", Some(sym::arm_target_feature)),
18 ("aes", Some(sym::arm_target_feature)),
19 ("crc", Some(sym::arm_target_feature)),
20 ("crypto", Some(sym::arm_target_feature)),
21 ("d32", Some(sym::arm_target_feature)),
22 ("dotprod", Some(sym::arm_target_feature)),
23 ("dsp", Some(sym::arm_target_feature)),
24 ("fp-armv8", Some(sym::arm_target_feature)),
25 ("i8mm", Some(sym::arm_target_feature)),
26 ("mclass", Some(sym::arm_target_feature)),
27 ("neon", Some(sym::arm_target_feature)),
28 ("rclass", Some(sym::arm_target_feature)),
29 ("sha2", Some(sym::arm_target_feature)),
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
33 ("thumb-mode", Some(sym::arm_target_feature)),
34 ("thumb2", Some(sym::arm_target_feature)),
35 ("v5te", Some(sym::arm_target_feature)),
36 ("v6", Some(sym::arm_target_feature)),
37 ("v6k", Some(sym::arm_target_feature)),
38 ("v6t2", Some(sym::arm_target_feature)),
39 ("v7", Some(sym::arm_target_feature)),
40 ("v8", Some(sym::arm_target_feature)),
41 ("vfp2", Some(sym::arm_target_feature)),
42 ("vfp3", Some(sym::arm_target_feature)),
43 ("vfp4", Some(sym::arm_target_feature)),
44 // tidy-alphabetical-end
47 const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
48 // tidy-alphabetical-start
89 // FEAT_AdvSimd & FEAT_FP
91 // FEAT_PAUTH (address authentication)
93 // FEAT_PAUTH (generic authentication)
111 // FEAT_SHA1 & FEAT_SHA256
113 // FEAT_SHA512 & FEAT_SHA3
115 // FEAT_SM3 & FEAT_SM4
128 ("sve2-bitperm", None),
135 ("v8.1a", Some(sym::aarch64_ver_target_feature)),
136 ("v8.2a", Some(sym::aarch64_ver_target_feature)),
137 ("v8.3a", Some(sym::aarch64_ver_target_feature)),
138 ("v8.4a", Some(sym::aarch64_ver_target_feature)),
139 ("v8.5a", Some(sym::aarch64_ver_target_feature)),
140 ("v8.6a", Some(sym::aarch64_ver_target_feature)),
141 ("v8.7a", Some(sym::aarch64_ver_target_feature)),
144 // tidy-alphabetical-end
147 const AARCH64_TIED_FEATURES: &[&[&str]] = &[
148 &["paca", "pacg"], // Together these represent `pauth` in LLVM
151 const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
152 // tidy-alphabetical-start
157 ("avx512bf16", Some(sym::avx512_target_feature)),
158 ("avx512bitalg", Some(sym::avx512_target_feature)),
159 ("avx512bw", Some(sym::avx512_target_feature)),
160 ("avx512cd", Some(sym::avx512_target_feature)),
161 ("avx512dq", Some(sym::avx512_target_feature)),
162 ("avx512er", Some(sym::avx512_target_feature)),
163 ("avx512f", Some(sym::avx512_target_feature)),
164 ("avx512gfni", Some(sym::avx512_target_feature)),
165 ("avx512ifma", Some(sym::avx512_target_feature)),
166 ("avx512pf", Some(sym::avx512_target_feature)),
167 ("avx512vaes", Some(sym::avx512_target_feature)),
168 ("avx512vbmi", Some(sym::avx512_target_feature)),
169 ("avx512vbmi2", Some(sym::avx512_target_feature)),
170 ("avx512vl", Some(sym::avx512_target_feature)),
171 ("avx512vnni", Some(sym::avx512_target_feature)),
172 ("avx512vp2intersect", Some(sym::avx512_target_feature)),
173 ("avx512vpclmulqdq", Some(sym::avx512_target_feature)),
174 ("avx512vpopcntdq", Some(sym::avx512_target_feature)),
177 ("cmpxchg16b", Some(sym::cmpxchg16b_target_feature)),
178 ("ermsb", Some(sym::ermsb_target_feature)),
179 ("f16c", Some(sym::f16c_target_feature)),
183 ("movbe", Some(sym::movbe_target_feature)),
188 ("rtm", Some(sym::rtm_target_feature)),
195 ("sse4a", Some(sym::sse4a_target_feature)),
197 ("tbm", Some(sym::tbm_target_feature)),
202 // tidy-alphabetical-end
205 const HEXAGON_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
206 // tidy-alphabetical-start
207 ("hvx", Some(sym::hexagon_target_feature)),
208 ("hvx-length128b", Some(sym::hexagon_target_feature)),
209 // tidy-alphabetical-end
212 const POWERPC_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
213 // tidy-alphabetical-start
214 ("altivec", Some(sym::powerpc_target_feature)),
215 ("power8-altivec", Some(sym::powerpc_target_feature)),
216 ("power8-vector", Some(sym::powerpc_target_feature)),
217 ("power9-altivec", Some(sym::powerpc_target_feature)),
218 ("power9-vector", Some(sym::powerpc_target_feature)),
219 ("vsx", Some(sym::powerpc_target_feature)),
220 // tidy-alphabetical-end
223 const MIPS_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
224 // tidy-alphabetical-start
225 ("fp64", Some(sym::mips_target_feature)),
226 ("msa", Some(sym::mips_target_feature)),
227 ("virt", Some(sym::mips_target_feature)),
228 // tidy-alphabetical-end
231 const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
232 // tidy-alphabetical-start
233 ("a", Some(sym::riscv_target_feature)),
234 ("c", Some(sym::riscv_target_feature)),
235 ("d", Some(sym::riscv_target_feature)),
236 ("e", Some(sym::riscv_target_feature)),
237 ("f", Some(sym::riscv_target_feature)),
238 ("m", Some(sym::riscv_target_feature)),
239 ("v", Some(sym::riscv_target_feature)),
240 ("zba", Some(sym::riscv_target_feature)),
241 ("zbb", Some(sym::riscv_target_feature)),
242 ("zbc", Some(sym::riscv_target_feature)),
243 ("zbkb", Some(sym::riscv_target_feature)),
244 ("zbkc", Some(sym::riscv_target_feature)),
245 ("zbkx", Some(sym::riscv_target_feature)),
246 ("zbs", Some(sym::riscv_target_feature)),
247 ("zdinx", Some(sym::riscv_target_feature)),
248 ("zfh", Some(sym::riscv_target_feature)),
249 ("zfhmin", Some(sym::riscv_target_feature)),
250 ("zfinx", Some(sym::riscv_target_feature)),
251 ("zhinx", Some(sym::riscv_target_feature)),
252 ("zhinxmin", Some(sym::riscv_target_feature)),
253 ("zk", Some(sym::riscv_target_feature)),
254 ("zkn", Some(sym::riscv_target_feature)),
255 ("zknd", Some(sym::riscv_target_feature)),
256 ("zkne", Some(sym::riscv_target_feature)),
257 ("zknh", Some(sym::riscv_target_feature)),
258 ("zkr", Some(sym::riscv_target_feature)),
259 ("zks", Some(sym::riscv_target_feature)),
260 ("zksed", Some(sym::riscv_target_feature)),
261 ("zksh", Some(sym::riscv_target_feature)),
262 ("zkt", Some(sym::riscv_target_feature)),
263 // tidy-alphabetical-end
266 const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
267 // tidy-alphabetical-start
268 ("atomics", Some(sym::wasm_target_feature)),
269 ("bulk-memory", Some(sym::wasm_target_feature)),
270 ("multivalue", Some(sym::wasm_target_feature)),
271 ("mutable-globals", Some(sym::wasm_target_feature)),
272 ("nontrapping-fptoint", Some(sym::wasm_target_feature)),
273 ("reference-types", Some(sym::wasm_target_feature)),
274 ("sign-ext", Some(sym::wasm_target_feature)),
276 // tidy-alphabetical-end
279 const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];
281 /// When rustdoc is running, provide a list of all known features so that all their respective
282 /// primitives may be documented.
284 /// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
285 pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol>)> {
287 .chain(ARM_ALLOWED_FEATURES.iter())
288 .chain(AARCH64_ALLOWED_FEATURES.iter())
289 .chain(X86_ALLOWED_FEATURES.iter())
290 .chain(HEXAGON_ALLOWED_FEATURES.iter())
291 .chain(POWERPC_ALLOWED_FEATURES.iter())
292 .chain(MIPS_ALLOWED_FEATURES.iter())
293 .chain(RISCV_ALLOWED_FEATURES.iter())
294 .chain(WASM_ALLOWED_FEATURES.iter())
295 .chain(BPF_ALLOWED_FEATURES.iter())
299 pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Option<Symbol>)] {
300 match &*sess.target.arch {
301 "arm" => ARM_ALLOWED_FEATURES,
302 "aarch64" => AARCH64_ALLOWED_FEATURES,
303 "x86" | "x86_64" => X86_ALLOWED_FEATURES,
304 "hexagon" => HEXAGON_ALLOWED_FEATURES,
305 "mips" | "mips64" => MIPS_ALLOWED_FEATURES,
306 "powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
307 "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
308 "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
309 "bpf" => BPF_ALLOWED_FEATURES,
314 pub fn tied_target_features(sess: &Session) -> &'static [&'static [&'static str]] {
315 match &*sess.target.arch {
316 "aarch64" => AARCH64_TIED_FEATURES,
321 pub(crate) fn provide(providers: &mut Providers) {
322 providers.supported_target_features = |tcx, cnum| {
323 assert_eq!(cnum, LOCAL_CRATE);
324 if tcx.sess.opts.actually_rustdoc {
325 // rustdoc needs to be able to document functions that use all the features, so
326 // whitelist them all
327 all_known_features().map(|(a, b)| (a.to_string(), b)).collect()
329 supported_target_features(tcx.sess).iter().map(|&(a, b)| (a.to_string(), b)).collect()