@@ -3,6 +3,7 @@ use gccjit::Context;
33use rustc_codegen_ssa:: target_features;
44use rustc_data_structures:: smallvec:: { SmallVec , smallvec} ;
55use rustc_session:: Session ;
6+ use rustc_target:: spec:: Arch ;
67
78fn gcc_features_by_flags ( sess : & Session , features : & mut Vec < String > ) {
89 target_features:: retpoline_features_by_flags ( sess, features) ;
@@ -11,7 +12,7 @@ fn gcc_features_by_flags(sess: &Session, features: &mut Vec<String>) {
1112
1213/// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
1314/// `--target` and similar).
14- pub ( crate ) fn global_gcc_features ( sess : & Session , diagnostics : bool ) -> Vec < String > {
15+ pub ( crate ) fn global_gcc_features ( sess : & Session ) -> Vec < String > {
1516 // Features that come earlier are overridden by conflicting features later in the string.
1617 // Typically we'll want more explicit settings to override the implicit ones, so:
1718 //
@@ -36,27 +37,18 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
3637 features. extend ( sess. target . features . split ( ',' ) . filter ( |v| !v. is_empty ( ) ) . map ( String :: from) ) ;
3738
3839 // -Ctarget-features
39- target_features:: flag_to_backend_features (
40- sess,
41- diagnostics,
42- |feature| to_gcc_features ( sess, feature) ,
43- |feature, enable| {
44- // We run through `to_gcc_features` when
45- // passing requests down to GCC. This means that all in-language
46- // features also work on the command line instead of having two
47- // different names when the GCC name and the Rust name differ.
48- features. extend (
49- to_gcc_features ( sess, feature)
50- . iter ( )
51- . flat_map ( |feat| to_gcc_features ( sess, feat) . into_iter ( ) )
52- . map (
53- |feature| {
54- if !enable { format ! ( "-{}" , feature) } else { feature. to_string ( ) }
55- } ,
56- ) ,
57- ) ;
58- } ,
59- ) ;
40+ target_features:: flag_to_backend_features ( sess, |feature, enable| {
41+ // We run through `to_gcc_features` when
42+ // passing requests down to GCC. This means that all in-language
43+ // features also work on the command line instead of having two
44+ // different names when the GCC name and the Rust name differ.
45+ features. extend (
46+ to_gcc_features ( sess, feature)
47+ . iter ( )
48+ . flat_map ( |feat| to_gcc_features ( sess, feat) . into_iter ( ) )
49+ . map ( |feature| if !enable { format ! ( "-{}" , feature) } else { feature. to_string ( ) } ) ,
50+ ) ;
51+ } ) ;
6052
6153 gcc_features_by_flags ( sess, & mut features) ;
6254
@@ -65,44 +57,47 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
6557
6658// To find a list of GCC's names, check https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
6759pub fn to_gcc_features < ' a > ( sess : & Session , s : & ' a str ) -> SmallVec < [ & ' a str ; 2 ] > {
68- let arch = if sess. target . arch == "x86_64" { "x86" } else { & * sess. target . arch } ;
6960 // cSpell:disable
70- match ( arch, s) {
61+ match ( & sess . target . arch , s) {
7162 // FIXME: seems like x87 does not exist?
72- ( "x86" , "x87" ) => smallvec ! [ ] ,
73- ( "x86" , "sse4.2" ) => smallvec ! [ "sse4.2" , "crc32" ] ,
74- ( "x86" , "pclmulqdq" ) => smallvec ! [ "pclmul" ] ,
75- ( "x86" , "rdrand" ) => smallvec ! [ "rdrnd" ] ,
76- ( "x86" , "bmi1" ) => smallvec ! [ "bmi" ] ,
77- ( "x86" , "cmpxchg16b" ) => smallvec ! [ "cx16" ] ,
78- ( "x86" , "avx512vaes" ) => smallvec ! [ "vaes" ] ,
79- ( "x86" , "avx512gfni" ) => smallvec ! [ "gfni" ] ,
80- ( "x86" , "avx512vpclmulqdq" ) => smallvec ! [ "vpclmulqdq" ] ,
63+ ( & Arch :: X86 | & Arch :: X86_64 , "x87" ) => smallvec ! [ ] ,
64+ ( & Arch :: X86 | & Arch :: X86_64 , "sse4.2" ) => smallvec ! [ "sse4.2" , "crc32" ] ,
65+ ( & Arch :: X86 | & Arch :: X86_64 , "pclmulqdq" ) => smallvec ! [ "pclmul" ] ,
66+ ( & Arch :: X86 | & Arch :: X86_64 , "rdrand" ) => smallvec ! [ "rdrnd" ] ,
67+ ( & Arch :: X86 | & Arch :: X86_64 , "bmi1" ) => smallvec ! [ "bmi" ] ,
68+ ( & Arch :: X86 | & Arch :: X86_64 , "cmpxchg16b" ) => smallvec ! [ "cx16" ] ,
69+ ( & Arch :: X86 | & Arch :: X86_64 , "avx512vaes" ) => smallvec ! [ "vaes" ] ,
70+ ( & Arch :: X86 | & Arch :: X86_64 , "avx512gfni" ) => smallvec ! [ "gfni" ] ,
71+ ( & Arch :: X86 | & Arch :: X86_64 , "avx512vpclmulqdq" ) => smallvec ! [ "vpclmulqdq" ] ,
8172 // NOTE: seems like GCC requires 'avx512bw' for 'avx512vbmi2'.
82- ( "x86" , "avx512vbmi2" ) => smallvec ! [ "avx512vbmi2" , "avx512bw" ] ,
73+ ( & Arch :: X86 | & Arch :: X86_64 , "avx512vbmi2" ) => {
74+ smallvec ! [ "avx512vbmi2" , "avx512bw" ]
75+ }
8376 // NOTE: seems like GCC requires 'avx512bw' for 'avx512bitalg'.
84- ( "x86" , "avx512bitalg" ) => smallvec ! [ "avx512bitalg" , "avx512bw" ] ,
85- ( "aarch64" , "rcpc2" ) => smallvec ! [ "rcpc-immo" ] ,
86- ( "aarch64" , "dpb" ) => smallvec ! [ "ccpp" ] ,
87- ( "aarch64" , "dpb2" ) => smallvec ! [ "ccdp" ] ,
88- ( "aarch64" , "frintts" ) => smallvec ! [ "fptoint" ] ,
89- ( "aarch64" , "fcma" ) => smallvec ! [ "complxnum" ] ,
90- ( "aarch64" , "pmuv3" ) => smallvec ! [ "perfmon" ] ,
91- ( "aarch64" , "paca" ) => smallvec ! [ "pauth" ] ,
92- ( "aarch64" , "pacg" ) => smallvec ! [ "pauth" ] ,
77+ ( & Arch :: X86 | & Arch :: X86_64 , "avx512bitalg" ) => {
78+ smallvec ! [ "avx512bitalg" , "avx512bw" ]
79+ }
80+ ( & Arch :: AArch64 , "rcpc2" ) => smallvec ! [ "rcpc-immo" ] ,
81+ ( & Arch :: AArch64 , "dpb" ) => smallvec ! [ "ccpp" ] ,
82+ ( & Arch :: AArch64 , "dpb2" ) => smallvec ! [ "ccdp" ] ,
83+ ( & Arch :: AArch64 , "frintts" ) => smallvec ! [ "fptoint" ] ,
84+ ( & Arch :: AArch64 , "fcma" ) => smallvec ! [ "complxnum" ] ,
85+ ( & Arch :: AArch64 , "pmuv3" ) => smallvec ! [ "perfmon" ] ,
86+ ( & Arch :: AArch64 , "paca" ) => smallvec ! [ "pauth" ] ,
87+ ( & Arch :: AArch64 , "pacg" ) => smallvec ! [ "pauth" ] ,
9388 // Rust ties fp and neon together. In GCC neon implicitly enables fp,
9489 // but we manually enable neon when a feature only implicitly enables fp
95- ( "aarch64" , "f32mm" ) => smallvec ! [ "f32mm" , "neon" ] ,
96- ( "aarch64" , "f64mm" ) => smallvec ! [ "f64mm" , "neon" ] ,
97- ( "aarch64" , "fhm" ) => smallvec ! [ "fp16fml" , "neon" ] ,
98- ( "aarch64" , "fp16" ) => smallvec ! [ "fullfp16" , "neon" ] ,
99- ( "aarch64" , "jsconv" ) => smallvec ! [ "jsconv" , "neon" ] ,
100- ( "aarch64" , "sve" ) => smallvec ! [ "sve" , "neon" ] ,
101- ( "aarch64" , "sve2" ) => smallvec ! [ "sve2" , "neon" ] ,
102- ( "aarch64" , "sve2-aes" ) => smallvec ! [ "sve2-aes" , "neon" ] ,
103- ( "aarch64" , "sve2-sm4" ) => smallvec ! [ "sve2-sm4" , "neon" ] ,
104- ( "aarch64" , "sve2-sha3" ) => smallvec ! [ "sve2-sha3" , "neon" ] ,
105- ( "aarch64" , "sve2-bitperm" ) => smallvec ! [ "sve2-bitperm" , "neon" ] ,
90+ ( & Arch :: AArch64 , "f32mm" ) => smallvec ! [ "f32mm" , "neon" ] ,
91+ ( & Arch :: AArch64 , "f64mm" ) => smallvec ! [ "f64mm" , "neon" ] ,
92+ ( & Arch :: AArch64 , "fhm" ) => smallvec ! [ "fp16fml" , "neon" ] ,
93+ ( & Arch :: AArch64 , "fp16" ) => smallvec ! [ "fullfp16" , "neon" ] ,
94+ ( & Arch :: AArch64 , "jsconv" ) => smallvec ! [ "jsconv" , "neon" ] ,
95+ ( & Arch :: AArch64 , "sve" ) => smallvec ! [ "sve" , "neon" ] ,
96+ ( & Arch :: AArch64 , "sve2" ) => smallvec ! [ "sve2" , "neon" ] ,
97+ ( & Arch :: AArch64 , "sve2-aes" ) => smallvec ! [ "sve2-aes" , "neon" ] ,
98+ ( & Arch :: AArch64 , "sve2-sm4" ) => smallvec ! [ "sve2-sm4" , "neon" ] ,
99+ ( & Arch :: AArch64 , "sve2-sha3" ) => smallvec ! [ "sve2-sha3" , "neon" ] ,
100+ ( & Arch :: AArch64 , "sve2-bitperm" ) => smallvec ! [ "sve2-bitperm" , "neon" ] ,
106101 ( _, s) => smallvec ! [ s] ,
107102 }
108103 // cSpell:enable
0 commit comments