@@ -14,7 +14,7 @@ use llvm;
1414use rustc:: session:: Session ;
1515use rustc:: session:: config:: PrintRequest ;
1616use libc:: c_int;
17- use std:: ffi:: { CStr , CString } ;
17+ use std:: ffi:: CString ;
1818
1919use std:: sync:: atomic:: { AtomicBool , Ordering } ;
2020use std:: sync:: Once ;
@@ -79,57 +79,61 @@ unsafe fn configure_llvm(sess: &Session) {
7979// detection code will walk past the end of the feature array,
8080// leading to crashes.
8181
82- const ARM_WHITELIST : & ' static [ & ' static str ] = & [ "neon\0 " , "v7\0 " , "vfp2\0 " , "vfp3\0 " , "vfp4\0 " ] ;
82+ const ARM_WHITELIST : & ' static [ & ' static str ] = & [ "neon" , "v7" , "vfp2" , "vfp3" , "vfp4" ] ;
8383
84- const AARCH64_WHITELIST : & ' static [ & ' static str ] = & [ "neon\0 " , "v7\0 " ] ;
84+ const AARCH64_WHITELIST : & ' static [ & ' static str ] = & [ "neon" , "v7" ] ;
8585
86- const X86_WHITELIST : & ' static [ & ' static str ] = & [ "avx\0 " , "avx2\0 " , "bmi\0 " , "bmi2\0 " , "sse\0 " ,
87- "sse2\0 " , "sse3\0 " , "sse4.1\0 " , "sse4.2\0 " ,
88- "ssse3\0 " , "tbm\0 " , "lzcnt\0 " , "popcnt\0 " ,
89- "sse4a\0 " , "rdrnd\0 " , "rdseed\0 " , "fma\0 " ,
90- "xsave\0 " , "xsaveopt\0 " , "xsavec\0 " ,
91- "xsaves\0 " , "aes\0 " ,
92- "avx512bw\0 " , "avx512cd\0 " ,
93- "avx512dq\0 " , "avx512er\0 " ,
94- "avx512f\0 " , "avx512ifma\0 " ,
95- "avx512pf\0 " , "avx512vbmi\0 " ,
96- "avx512vl\0 " , "avx512vpopcntdq\0 " ,
97- "mmx\0 " , "fxsr\0 " ] ;
86+ const X86_WHITELIST : & ' static [ & ' static str ] = & [ "avx" , "avx2" , "bmi" , "bmi2" , "sse" ,
87+ "sse2" , "sse3" , "sse4.1" , "sse4.2" ,
88+ "ssse3" , "tbm" , "lzcnt" , "popcnt" ,
89+ "sse4a" , "rdrnd" , "rdseed" , "fma" ,
90+ "xsave" , "xsaveopt" , "xsavec" ,
91+ "xsaves" , "aes" , "pclmulqdq ",
92+ "avx512bw" , "avx512cd" ,
93+ "avx512dq" , "avx512er" ,
94+ "avx512f" , "avx512ifma" ,
95+ "avx512pf" , "avx512vbmi" ,
96+ "avx512vl" , "avx512vpopcntdq" ,
97+ "mmx" , "fxsr" ] ;
9898
99- const HEXAGON_WHITELIST : & ' static [ & ' static str ] = & [ "hvx\0 " , "hvx-double\0 " ] ;
99+ const HEXAGON_WHITELIST : & ' static [ & ' static str ] = & [ "hvx" , "hvx-double" ] ;
100100
101- const POWERPC_WHITELIST : & ' static [ & ' static str ] = & [ "altivec\0 " ,
102- "power8-altivec\0 " , "power9-altivec\0 " ,
103- "power8-vector\0 " , "power9-vector\0 " ,
104- "vsx\0 " ] ;
101+ const POWERPC_WHITELIST : & ' static [ & ' static str ] = & [ "altivec" ,
102+ "power8-altivec" , "power9-altivec" ,
103+ "power8-vector" , "power9-vector" ,
104+ "vsx" ] ;
105105
106- const MIPS_WHITELIST : & ' static [ & ' static str ] = & [ "msa\0 " ] ;
106+ const MIPS_WHITELIST : & ' static [ & ' static str ] = & [ "msa" ] ;
107+
108+ pub fn to_llvm_feature ( s : & str ) -> & str {
109+ match s {
110+ "pclmulqdq" => "pclmul" ,
111+ s => s,
112+ }
113+ }
107114
108115pub fn target_features ( sess : & Session ) -> Vec < Symbol > {
109- let whitelist = target_feature_whitelist ( sess) ;
110116 let target_machine = create_target_machine ( sess) ;
111- let mut features = Vec :: new ( ) ;
112- for feat in whitelist {
113- if unsafe { llvm:: LLVMRustHasFeature ( target_machine, feat. as_ptr ( ) ) } {
114- features. push ( Symbol :: intern ( feat. to_str ( ) . unwrap ( ) ) ) ;
115- }
116- }
117- features
117+ target_feature_whitelist ( sess)
118+ . iter ( )
119+ . filter ( |feature| {
120+ let llvm_feature = to_llvm_feature ( feature) ;
121+ let cstr = CString :: new ( llvm_feature) . unwrap ( ) ;
122+ unsafe { llvm:: LLVMRustHasFeature ( target_machine, cstr. as_ptr ( ) ) }
123+ } )
124+ . map ( |feature| Symbol :: intern ( feature) ) . collect ( )
118125}
119126
120- pub fn target_feature_whitelist ( sess : & Session ) -> Vec < & CStr > {
121- let whitelist = match & * sess. target . target . arch {
127+ pub fn target_feature_whitelist ( sess : & Session ) -> & ' static [ & ' static str ] {
128+ match & * sess. target . target . arch {
122129 "arm" => ARM_WHITELIST ,
123130 "aarch64" => AARCH64_WHITELIST ,
124131 "x86" | "x86_64" => X86_WHITELIST ,
125132 "hexagon" => HEXAGON_WHITELIST ,
126133 "mips" | "mips64" => MIPS_WHITELIST ,
127134 "powerpc" | "powerpc64" => POWERPC_WHITELIST ,
128135 _ => & [ ] ,
129- } ;
130- whitelist. iter ( ) . map ( |m| {
131- CStr :: from_bytes_with_nul ( m. as_bytes ( ) ) . unwrap ( )
132- } ) . collect ( )
136+ }
133137}
134138
135139pub fn print_version ( ) {
0 commit comments