@@ -19,6 +19,7 @@ use rustc_session::config::{PrintKind, PrintRequest};
1919use rustc_span:: Symbol ;
2020use rustc_target:: spec:: { MergeFunctions , PanicStrategy , SmallDataThresholdSupport } ;
2121use rustc_target:: target_features:: { RUSTC_SPECIAL_FEATURES , RUSTC_SPECIFIC_FEATURES } ;
22+ use smallvec:: { SmallVec , smallvec} ;
2223
2324use crate :: back:: write:: create_informational_target_machine;
2425use crate :: errors:: {
@@ -180,27 +181,27 @@ impl<'a> TargetFeatureFoldStrength<'a> {
180181
181182pub ( crate ) struct LLVMFeature < ' a > {
182183llvm_feature_name : & ' a str ,
183- dependency : Option < TargetFeatureFoldStrength < ' a > > ,
184+ dependencies : SmallVec < [ TargetFeatureFoldStrength < ' a > ; 1 ] > ,
184185}
185186
186187impl < ' a > LLVMFeature < ' a > {
187188fn new ( llvm_feature_name : & ' a str ) -> Self {
188- Self { llvm_feature_name, dependency : None }
189+ Self { llvm_feature_name, dependencies : SmallVec :: new ( ) }
189190}
190191
191- fn with_dependency (
192+ fn with_dependencies (
192193llvm_feature_name : & ' a str ,
193- dependency : TargetFeatureFoldStrength < ' a > ,
194+ dependencies : SmallVec < [ TargetFeatureFoldStrength < ' a > ; 1 ] > ,
194195) -> Self {
195- Self { llvm_feature_name, dependency : Some ( dependency ) }
196+ Self { llvm_feature_name, dependencies }
196197}
197198
198- fn contains ( & self , feat : & str ) -> bool {
199+ fn contains ( & ' a self , feat : & str ) -> bool {
199200self . iter ( ) . any ( |dep| dep == feat)
200201}
201202
202203fn iter ( & ' a self ) -> impl Iterator < Item = & ' a str > {
203- let dependencies = self . dependency . iter ( ) . map ( |feat| feat. as_str ( ) ) ;
204+ let dependencies = self . dependencies . iter ( ) . map ( |feat| feat. as_str ( ) ) ;
204205 std:: iter:: once ( self . llvm_feature_name ) . chain ( dependencies)
205206}
206207}
@@ -210,7 +211,7 @@ impl<'a> IntoIterator for LLVMFeature<'a> {
210211type IntoIter = impl Iterator < Item = & ' a str > ;
211212
212213fn into_iter ( self ) -> Self :: IntoIter {
213- let dependencies = self . dependency . into_iter ( ) . map ( |feat| feat. as_str ( ) ) ;
214+ let dependencies = self . dependencies . into_iter ( ) . map ( |feat| feat. as_str ( ) ) ;
214215 std:: iter:: once ( self . llvm_feature_name ) . chain ( dependencies)
215216}
216217}
@@ -240,9 +241,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
240241& * sess. target . arch
241242} ;
242243match ( arch, s) {
243- ( "x86" , "sse4.2" ) => Some ( LLVMFeature :: with_dependency (
244+ ( "x86" , "sse4.2" ) => Some ( LLVMFeature :: with_dependencies (
244245"sse4.2" ,
245- TargetFeatureFoldStrength :: EnableOnly ( "crc32" ) ,
246+ smallvec ! [ TargetFeatureFoldStrength :: EnableOnly ( "crc32" ) ] ,
246247) ) ,
247248( "x86" , "pclmulqdq" ) => Some ( LLVMFeature :: new ( "pclmul" ) ) ,
248249( "x86" , "rdrand" ) => Some ( LLVMFeature :: new ( "rdrnd" ) ) ,
@@ -262,9 +263,10 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
262263( "aarch64" , "sme-b16b16" ) if get_version ( ) . 0 < 20 => Some ( LLVMFeature :: new ( "b16b16" ) ) ,
263264( "aarch64" , "flagm2" ) => Some ( LLVMFeature :: new ( "altnzcv" ) ) ,
264265// Rust ties fp and neon together.
265- ( "aarch64" , "neon" ) => {
266- Some ( LLVMFeature :: with_dependency ( "neon" , TargetFeatureFoldStrength :: Both ( "fp-armv8" ) ) )
267- }
266+ ( "aarch64" , "neon" ) => Some ( LLVMFeature :: with_dependencies (
267+ "neon" ,
268+ smallvec ! [ TargetFeatureFoldStrength :: Both ( "fp-armv8" ) ] ,
269+ ) ) ,
268270// In LLVM neon implicitly enables fp, but we manually enable
269271// neon when a feature only implicitly enables fp
270272( "aarch64" , "fhm" ) => Some ( LLVMFeature :: new ( "fp16fml" ) ) ,
@@ -281,9 +283,10 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
281283// Filter out features that are not supported by the current LLVM version
282284( "riscv32" | "riscv64" , "zacas" ) if get_version ( ) . 0 < 20 => None ,
283285// Enable the evex512 target feature if an avx512 target feature is enabled.
284- ( "x86" , s) if s. starts_with ( "avx512" ) => {
285- Some ( LLVMFeature :: with_dependency ( s, TargetFeatureFoldStrength :: EnableOnly ( "evex512" ) ) )
286- }
286+ ( "x86" , s) if s. starts_with ( "avx512" ) => Some ( LLVMFeature :: with_dependencies (
287+ s,
288+ smallvec ! [ TargetFeatureFoldStrength :: EnableOnly ( "evex512" ) ] ,
289+ ) ) ,
287290// Support for `wide-arithmetic` will first land in LLVM 20 as part of
288291// llvm/llvm-project#111598
289292( "wasm32" | "wasm64" , "wide-arithmetic" ) if get_version ( ) < ( 20 , 0 , 0 ) => None ,
@@ -853,7 +856,7 @@ pub(crate) fn global_llvm_features(
853856"{}{}" ,
854857 enable_disable, llvm_feature. llvm_feature_name
855858) )
856- . chain ( llvm_feature. dependency . into_iter ( ) . filter_map (
859+ . chain ( llvm_feature. dependencies . into_iter ( ) . filter_map (
857860move |feat| match ( enable, feat) {
858861( _, TargetFeatureFoldStrength :: Both ( f) )
859862 | ( true , TargetFeatureFoldStrength :: EnableOnly ( f) ) => {
0 commit comments