Skip to content

Commit e4272d1

Browse files
feat: Added capability to add multiple dependencies for an LLVMFeature
1 parent 62c5f58 commit e4272d1

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

‎compiler/rustc_codegen_llvm/src/llvm_util.rs‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_session::config::{PrintKind, PrintRequest};
1919
use rustc_span::Symbol;
2020
use rustc_target::spec::{MergeFunctions,PanicStrategy,SmallDataThresholdSupport};
2121
use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES,RUSTC_SPECIFIC_FEATURES};
22+
use smallvec::{SmallVec, smallvec};
2223

2324
usecrate::back::write::create_informational_target_machine;
2425
usecrate::errors::{
@@ -180,27 +181,27 @@ impl<'a> TargetFeatureFoldStrength<'a> {
180181

181182
pub(crate)structLLVMFeature<'a>{
182183
llvm_feature_name:&'astr,
183-
dependency:Option<TargetFeatureFoldStrength<'a>>,
184+
dependencies:SmallVec<[TargetFeatureFoldStrength<'a>;1]>,
184185
}
185186

186187
impl<'a>LLVMFeature<'a>{
187188
fnnew(llvm_feature_name:&'astr) -> Self{
188-
Self{ llvm_feature_name,dependency:None}
189+
Self{ llvm_feature_name,dependencies:SmallVec::new()}
189190
}
190191

191-
fnwith_dependency(
192+
fnwith_dependencies(
192193
llvm_feature_name:&'astr,
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-
fncontains(&self,feat:&str) -> bool{
199+
fncontains(&'aself,feat:&str) -> bool{
199200
self.iter().any(|dep| dep == feat)
200201
}
201202

202203
fniter(&'aself) -> implIterator<Item = &'astr>{
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> {
210211
typeIntoIter = implIterator<Item = &'astr>;
211212

212213
fninto_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
};
242243
match(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")ifget_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")ifget_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")ifget_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(
857860
move |feat| match(enable, feat){
858861
(_,TargetFeatureFoldStrength::Both(f))
859862
| (true,TargetFeatureFoldStrength::EnableOnly(f)) => {

0 commit comments

Comments
 (0)