]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/target_features.rs
Rename fptoint to frintts
[rust.git] / compiler / rustc_codegen_ssa / src / target_features.rs
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;
6
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
12 const 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)),
29     ("fp-armv8", 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
32     // #[target_feature].
33     ("thumb-mode", Some(sym::arm_target_feature)),
34 ];
35
36 // Commented features are not available in LLVM 10.0, or have since been renamed
37 const AARCH64_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
38     // FEAT_AdvSimd
39     ("neon", Some(sym::aarch64_target_feature)),
40     // FEAT_FP
41     ("fp", Some(sym::aarch64_target_feature)),
42     // FEAT_FP16
43     ("fp16", Some(sym::aarch64_target_feature)),
44     // FEAT_SVE
45     ("sve", Some(sym::aarch64_target_feature)),
46     // FEAT_CRC
47     ("crc", Some(sym::aarch64_target_feature)),
48     // Cryptographic extension
49     ("crypto", Some(sym::aarch64_target_feature)),
50     // FEAT_RAS
51     ("ras", Some(sym::aarch64_target_feature)),
52     // FEAT_LSE
53     ("lse", Some(sym::aarch64_target_feature)),
54     // FEAT_RDM
55     ("rdm", Some(sym::aarch64_target_feature)),
56     // FEAT_RCPC
57     ("rcpc", Some(sym::aarch64_target_feature)),
58     // FEAT_RCPC2
59     ("rcpc2", Some(sym::aarch64_target_feature)),
60     // FEAT_DotProd
61     ("dotprod", Some(sym::aarch64_target_feature)),
62     // FEAT_TME
63     ("tme", Some(sym::aarch64_target_feature)),
64     // FEAT_FHM
65     ("fhm", Some(sym::aarch64_target_feature)),
66     // FEAT_DIT
67     ("dit", Some(sym::aarch64_target_feature)),
68     // FEAT_FLAGM
69     // ("flagm", Some(sym::aarch64_target_feature)),
70     // FEAT_SSBS
71     ("ssbs", Some(sym::aarch64_target_feature)),
72     // FEAT_SB
73     ("sb", Some(sym::aarch64_target_feature)),
74     // FEAT_PAUTH
75     // ("pauth", Some(sym::aarch64_target_feature)),
76     // FEAT_DPB
77     ("dpb", Some(sym::aarch64_target_feature)),
78     // FEAT_DPB2
79     ("dpb2", Some(sym::aarch64_target_feature)),
80     // FEAT_SVE2
81     ("sve2", Some(sym::aarch64_target_feature)),
82     // FEAT_SVE2_AES
83     ("sve2-aes", Some(sym::aarch64_target_feature)),
84     // FEAT_SVE2_SM4
85     ("sve2-sm4", Some(sym::aarch64_target_feature)),
86     // FEAT_SVE2_SHA3
87     ("sve2-sha3", Some(sym::aarch64_target_feature)),
88     // FEAT_SVE2_BitPerm
89     ("sve2-bitperm", Some(sym::aarch64_target_feature)),
90     // FEAT_FRINTTS
91     ("frintts", Some(sym::aarch64_target_feature)),
92     // FEAT_I8MM
93     // ("i8mm", Some(sym::aarch64_target_feature)),
94     // FEAT_F32MM
95     // ("f32mm", Some(sym::aarch64_target_feature)),
96     // FEAT_F64MM
97     // ("f64mm", Some(sym::aarch64_target_feature)),
98     // FEAT_BF16
99     // ("bf16", Some(sym::aarch64_target_feature)),
100     // FEAT_RAND
101     ("rand", Some(sym::aarch64_target_feature)),
102     // FEAT_BTI
103     ("bti", Some(sym::aarch64_target_feature)),
104     // FEAT_MTE
105     ("mte", Some(sym::aarch64_target_feature)),
106     // FEAT_JSCVT
107     ("jsconv", Some(sym::aarch64_target_feature)),
108     // FEAT_FCMA
109     ("fcma", Some(sym::aarch64_target_feature)),
110     // FEAT_SHA1 & FEAT_SHA256
111     ("sha2", Some(sym::aarch64_target_feature)),
112     // FEAT_SHA512 & FEAT_SHA3
113     ("sha3", Some(sym::aarch64_target_feature)),
114     // FEAT_SM3 & FEAT_SM4
115     ("sm4", Some(sym::aarch64_target_feature)),
116     ("v8.1a", Some(sym::aarch64_target_feature)),
117     ("v8.2a", Some(sym::aarch64_target_feature)),
118     ("v8.3a", Some(sym::aarch64_target_feature)),
119     ("v8.4a", Some(sym::aarch64_target_feature)),
120     ("v8.5a", Some(sym::aarch64_target_feature)),
121     // ("v8.6a", Some(sym::aarch64_target_feature)),
122     // ("v8.7a", Some(sym::aarch64_target_feature)),
123 ];
124
125 const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
126     ("adx", Some(sym::adx_target_feature)),
127     ("aes", None),
128     ("avx", None),
129     ("avx2", None),
130     ("avx512bf16", Some(sym::avx512_target_feature)),
131     ("avx512bitalg", Some(sym::avx512_target_feature)),
132     ("avx512bw", Some(sym::avx512_target_feature)),
133     ("avx512cd", Some(sym::avx512_target_feature)),
134     ("avx512dq", Some(sym::avx512_target_feature)),
135     ("avx512er", Some(sym::avx512_target_feature)),
136     ("avx512f", Some(sym::avx512_target_feature)),
137     ("avx512gfni", Some(sym::avx512_target_feature)),
138     ("avx512ifma", Some(sym::avx512_target_feature)),
139     ("avx512pf", Some(sym::avx512_target_feature)),
140     ("avx512vaes", Some(sym::avx512_target_feature)),
141     ("avx512vbmi", Some(sym::avx512_target_feature)),
142     ("avx512vbmi2", Some(sym::avx512_target_feature)),
143     ("avx512vl", Some(sym::avx512_target_feature)),
144     ("avx512vnni", Some(sym::avx512_target_feature)),
145     ("avx512vp2intersect", Some(sym::avx512_target_feature)),
146     ("avx512vpclmulqdq", Some(sym::avx512_target_feature)),
147     ("avx512vpopcntdq", Some(sym::avx512_target_feature)),
148     ("bmi1", None),
149     ("bmi2", None),
150     ("cmpxchg16b", Some(sym::cmpxchg16b_target_feature)),
151     ("ermsb", Some(sym::ermsb_target_feature)),
152     ("f16c", Some(sym::f16c_target_feature)),
153     ("fma", None),
154     ("fxsr", None),
155     ("lzcnt", None),
156     ("movbe", Some(sym::movbe_target_feature)),
157     ("pclmulqdq", None),
158     ("popcnt", None),
159     ("rdrand", None),
160     ("rdseed", None),
161     ("rtm", Some(sym::rtm_target_feature)),
162     ("sha", None),
163     ("sse", None),
164     ("sse2", None),
165     ("sse3", None),
166     ("sse4.1", None),
167     ("sse4.2", None),
168     ("sse4a", Some(sym::sse4a_target_feature)),
169     ("ssse3", None),
170     ("tbm", Some(sym::tbm_target_feature)),
171     ("xsave", None),
172     ("xsavec", None),
173     ("xsaveopt", None),
174     ("xsaves", None),
175 ];
176
177 const HEXAGON_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
178     ("hvx", Some(sym::hexagon_target_feature)),
179     ("hvx-length128b", Some(sym::hexagon_target_feature)),
180 ];
181
182 const POWERPC_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
183     ("altivec", Some(sym::powerpc_target_feature)),
184     ("power8-altivec", Some(sym::powerpc_target_feature)),
185     ("power9-altivec", Some(sym::powerpc_target_feature)),
186     ("power8-vector", Some(sym::powerpc_target_feature)),
187     ("power9-vector", Some(sym::powerpc_target_feature)),
188     ("vsx", Some(sym::powerpc_target_feature)),
189 ];
190
191 const MIPS_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] =
192     &[("fp64", Some(sym::mips_target_feature)), ("msa", Some(sym::mips_target_feature))];
193
194 const RISCV_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
195     ("m", Some(sym::riscv_target_feature)),
196     ("a", Some(sym::riscv_target_feature)),
197     ("c", Some(sym::riscv_target_feature)),
198     ("f", Some(sym::riscv_target_feature)),
199     ("d", Some(sym::riscv_target_feature)),
200     ("e", Some(sym::riscv_target_feature)),
201 ];
202
203 const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
204     ("simd128", Some(sym::wasm_target_feature)),
205     ("atomics", Some(sym::wasm_target_feature)),
206     ("nontrapping-fptoint", Some(sym::wasm_target_feature)),
207 ];
208
209 /// When rustdoc is running, provide a list of all known features so that all their respective
210 /// primitives may be documented.
211 ///
212 /// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
213 pub fn all_known_features() -> impl Iterator<Item = (&'static str, Option<Symbol>)> {
214     std::iter::empty()
215         .chain(ARM_ALLOWED_FEATURES.iter())
216         .chain(AARCH64_ALLOWED_FEATURES.iter())
217         .chain(X86_ALLOWED_FEATURES.iter())
218         .chain(HEXAGON_ALLOWED_FEATURES.iter())
219         .chain(POWERPC_ALLOWED_FEATURES.iter())
220         .chain(MIPS_ALLOWED_FEATURES.iter())
221         .chain(RISCV_ALLOWED_FEATURES.iter())
222         .chain(WASM_ALLOWED_FEATURES.iter())
223         .cloned()
224 }
225
226 pub fn supported_target_features(sess: &Session) -> &'static [(&'static str, Option<Symbol>)] {
227     match &*sess.target.arch {
228         "arm" => ARM_ALLOWED_FEATURES,
229         "aarch64" => AARCH64_ALLOWED_FEATURES,
230         "x86" | "x86_64" => X86_ALLOWED_FEATURES,
231         "hexagon" => HEXAGON_ALLOWED_FEATURES,
232         "mips" | "mips64" => MIPS_ALLOWED_FEATURES,
233         "powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
234         "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
235         "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
236         _ => &[],
237     }
238 }
239
240 pub(crate) fn provide(providers: &mut Providers) {
241     providers.supported_target_features = |tcx, cnum| {
242         assert_eq!(cnum, LOCAL_CRATE);
243         if tcx.sess.opts.actually_rustdoc {
244             // rustdoc needs to be able to document functions that use all the features, so
245             // whitelist them all
246             all_known_features().map(|(a, b)| (a.to_string(), b)).collect()
247         } else {
248             supported_target_features(tcx.sess).iter().map(|&(a, b)| (a.to_string(), b)).collect()
249         }
250     };
251 }