@@ -15,6 +15,7 @@ use rustc::session::Session;
15
15
use rustc:: session:: config:: PrintRequest ;
16
16
use libc:: c_int;
17
17
use std:: ffi:: CString ;
18
+ use syntax:: feature_gate:: UnstableFeatures ;
18
19
19
20
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
20
21
use std:: sync:: Once ;
@@ -82,40 +83,95 @@ unsafe fn configure_llvm(sess: &Session) {
82
83
// to LLVM or the feature detection code will walk past the end of the feature
83
84
// array, leading to crashes.
84
85
85
- const ARM_WHITELIST : & ' static [ & ' static str ] = & [ "neon" , "v7" , "vfp2" , "vfp3" , "vfp4" ] ;
86
-
87
- const AARCH64_WHITELIST : & ' static [ & ' static str ] = & [ "fp" , "neon" , "sve" , "crc" , "crypto" ,
88
- "ras" , "lse" , "rdm" , "fp16" , "rcpc" ,
89
- "dotprod" , "v8.1a" , "v8.2a" , "v8.3a" ] ;
90
-
91
- const X86_WHITELIST : & ' static [ & ' static str ] = & [ "aes" , "avx" , "avx2" , "avx512bw" ,
92
- "avx512cd" , "avx512dq" , "avx512er" ,
93
- "avx512f" , "avx512ifma" , "avx512pf" ,
94
- "avx512vbmi" , "avx512vl" , "avx512vpopcntdq" ,
95
- "bmi1" , "bmi2" , "fma" , "fxsr" ,
96
- "lzcnt" , "mmx" , "pclmulqdq" ,
97
- "popcnt" , "rdrand" , "rdseed" ,
98
- "sha" ,
99
- "sse" , "sse2" , "sse3" , "sse4.1" ,
100
- "sse4.2" , "sse4a" , "ssse3" ,
101
- "tbm" , "xsave" , "xsavec" ,
102
- "xsaveopt" , "xsaves" ] ;
103
-
104
- const HEXAGON_WHITELIST : & ' static [ & ' static str ] = & [ "hvx" , "hvx-double" ] ;
105
-
106
- const POWERPC_WHITELIST : & ' static [ & ' static str ] = & [ "altivec" ,
107
- "power8-altivec" , "power9-altivec" ,
108
- "power8-vector" , "power9-vector" ,
109
- "vsx" ] ;
110
-
111
- const MIPS_WHITELIST : & ' static [ & ' static str ] = & [ "fp64" , "msa" ] ;
86
+ const ARM_WHITELIST : & [ ( & str , Option < & str > ) ] = & [
87
+ ( "neon" , Some ( "arm_target_feature" ) ) ,
88
+ ( "v7" , Some ( "arm_target_feature" ) ) ,
89
+ ( "vfp2" , Some ( "arm_target_feature" ) ) ,
90
+ ( "vfp3" , Some ( "arm_target_feature" ) ) ,
91
+ ( "vfp4" , Some ( "arm_target_feature" ) ) ,
92
+ ] ;
93
+
94
+ const AARCH64_WHITELIST : & [ ( & str , Option < & str > ) ] = & [
95
+ ( "fp" , Some ( "aarch64_target_feature" ) ) ,
96
+ ( "neon" , Some ( "aarch64_target_feature" ) ) ,
97
+ ( "sve" , Some ( "aarch64_target_feature" ) ) ,
98
+ ( "crc" , Some ( "aarch64_target_feature" ) ) ,
99
+ ( "crypto" , Some ( "aarch64_target_feature" ) ) ,
100
+ ( "ras" , Some ( "aarch64_target_feature" ) ) ,
101
+ ( "lse" , Some ( "aarch64_target_feature" ) ) ,
102
+ ( "rdm" , Some ( "aarch64_target_feature" ) ) ,
103
+ ( "fp16" , Some ( "aarch64_target_feature" ) ) ,
104
+ ( "rcpc" , Some ( "aarch64_target_feature" ) ) ,
105
+ ( "dotprod" , Some ( "aarch64_target_feature" ) ) ,
106
+ ( "v8.1a" , Some ( "aarch64_target_feature" ) ) ,
107
+ ( "v8.2a" , Some ( "aarch64_target_feature" ) ) ,
108
+ ( "v8.3a" , Some ( "aarch64_target_feature" ) ) ,
109
+ ] ;
110
+
111
+ const X86_WHITELIST : & [ ( & str , Option < & str > ) ] = & [
112
+ ( "aes" , None ) ,
113
+ ( "avx" , None ) ,
114
+ ( "avx2" , None ) ,
115
+ ( "avx512bw" , Some ( "avx512_target_feature" ) ) ,
116
+ ( "avx512cd" , Some ( "avx512_target_feature" ) ) ,
117
+ ( "avx512dq" , Some ( "avx512_target_feature" ) ) ,
118
+ ( "avx512er" , Some ( "avx512_target_feature" ) ) ,
119
+ ( "avx512f" , Some ( "avx512_target_feature" ) ) ,
120
+ ( "avx512ifma" , Some ( "avx512_target_feature" ) ) ,
121
+ ( "avx512pf" , Some ( "avx512_target_feature" ) ) ,
122
+ ( "avx512vbmi" , Some ( "avx512_target_feature" ) ) ,
123
+ ( "avx512vl" , Some ( "avx512_target_feature" ) ) ,
124
+ ( "avx512vpopcntdq" , Some ( "avx512_target_feature" ) ) ,
125
+ ( "bmi1" , None ) ,
126
+ ( "bmi2" , None ) ,
127
+ ( "fma" , None ) ,
128
+ ( "fxsr" , None ) ,
129
+ ( "lzcnt" , None ) ,
130
+ ( "mmx" , Some ( "mmx_target_feature" ) ) ,
131
+ ( "pclmulqdq" , None ) ,
132
+ ( "popcnt" , None ) ,
133
+ ( "rdrand" , None ) ,
134
+ ( "rdseed" , None ) ,
135
+ ( "sha" , None ) ,
136
+ ( "sse" , None ) ,
137
+ ( "sse2" , None ) ,
138
+ ( "sse3" , None ) ,
139
+ ( "sse4.1" , None ) ,
140
+ ( "sse4.2" , None ) ,
141
+ ( "sse4a" , Some ( "sse4a_target_feature" ) ) ,
142
+ ( "ssse3" , None ) ,
143
+ ( "tbm" , Some ( "tbm_target_feature" ) ) ,
144
+ ( "xsave" , None ) ,
145
+ ( "xsavec" , None ) ,
146
+ ( "xsaveopt" , None ) ,
147
+ ( "xsaves" , None ) ,
148
+ ] ;
149
+
150
+ const HEXAGON_WHITELIST : & [ ( & str , Option < & str > ) ] = & [
151
+ ( "hvx" , Some ( "hexagon_target_feature" ) ) ,
152
+ ( "hvx-double" , Some ( "hexagon_target_feature" ) ) ,
153
+ ] ;
154
+
155
+ const POWERPC_WHITELIST : & [ ( & str , Option < & str > ) ] = & [
156
+ ( "altivec" , Some ( "powerpc_target_feature" ) ) ,
157
+ ( "power8-altivec" , Some ( "powerpc_target_feature" ) ) ,
158
+ ( "power9-altivec" , Some ( "powerpc_target_feature" ) ) ,
159
+ ( "power8-vector" , Some ( "powerpc_target_feature" ) ) ,
160
+ ( "power9-vector" , Some ( "powerpc_target_feature" ) ) ,
161
+ ( "vsx" , Some ( "powerpc_target_feature" ) ) ,
162
+ ] ;
163
+
164
+ const MIPS_WHITELIST : & [ ( & str , Option < & str > ) ] = & [
165
+ ( "fp64" , Some ( "mips_target_feature" ) ) ,
166
+ ( "msa" , Some ( "mips_target_feature" ) ) ,
167
+ ] ;
112
168
113
169
/// When rustdoc is running, provide a list of all known features so that all their respective
114
170
/// primtives may be documented.
115
171
///
116
172
/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this
117
173
/// iterator!
118
- pub fn all_known_features ( ) -> impl Iterator < Item =& ' static str > {
174
+ pub fn all_known_features ( ) -> impl Iterator < Item =( & ' static str , Option < & ' static str > ) > {
119
175
ARM_WHITELIST . iter ( ) . cloned ( )
120
176
. chain ( AARCH64_WHITELIST . iter ( ) . cloned ( ) )
121
177
. chain ( X86_WHITELIST . iter ( ) . cloned ( ) )
@@ -144,6 +200,13 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
144
200
let target_machine = create_target_machine ( sess, true ) ;
145
201
target_feature_whitelist ( sess)
146
202
. iter ( )
203
+ . filter_map ( |& ( feature, gate) | {
204
+ if UnstableFeatures :: from_environment ( ) . is_nightly_build ( ) || gate. is_none ( ) {
205
+ Some ( feature)
206
+ } else {
207
+ None
208
+ }
209
+ } )
147
210
. filter ( |feature| {
148
211
let llvm_feature = to_llvm_feature ( sess, feature) ;
149
212
let cstr = CString :: new ( llvm_feature) . unwrap ( ) ;
@@ -152,7 +215,9 @@ pub fn target_features(sess: &Session) -> Vec<Symbol> {
152
215
. map ( |feature| Symbol :: intern ( feature) ) . collect ( )
153
216
}
154
217
155
- pub fn target_feature_whitelist ( sess : & Session ) -> & ' static [ & ' static str ] {
218
+ pub fn target_feature_whitelist ( sess : & Session )
219
+ -> & ' static [ ( & ' static str , Option < & ' static str > ) ]
220
+ {
156
221
match & * sess. target . target . arch {
157
222
"arm" => ARM_WHITELIST ,
158
223
"aarch64" => AARCH64_WHITELIST ,
0 commit comments