Skip to content

Commit 336c5f9

Browse files
feat: Added capability to add multiple dependencies for an LLVMFeature
1 parent e5fefc3 commit 336c5f9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -179,27 +179,27 @@ impl<'a> TargetFeatureFoldStrength<'a> {
179179

180180
pub(crate) struct LLVMFeature<'a> {
181181
llvm_feature_name: &'a str,
182-
dependency: Option<TargetFeatureFoldStrength<'a>>,
182+
dependencies: Vec<TargetFeatureFoldStrength<'a>>,
183183
}
184184

185185
impl<'a> LLVMFeature<'a> {
186186
fn new(llvm_feature_name: &'a str) -> Self {
187-
Self { llvm_feature_name, dependency: None }
187+
Self { llvm_feature_name, dependencies: Vec::new() }
188188
}
189189

190-
fn with_dependency(
190+
fn with_dependencies(
191191
llvm_feature_name: &'a str,
192-
dependency: TargetFeatureFoldStrength<'a>,
192+
dependencies: Vec<TargetFeatureFoldStrength<'a>>,
193193
) -> Self {
194-
Self { llvm_feature_name, dependency: Some(dependency) }
194+
Self { llvm_feature_name, dependencies: dependencies }
195195
}
196196

197197
fn contains(&self, feat: &str) -> bool {
198198
self.iter().any(|dep| dep == feat)
199199
}
200200

201201
fn iter(&'a self) -> impl Iterator<Item = &'a str> {
202-
let dependencies = self.dependency.iter().map(|feat| feat.as_str());
202+
let dependencies = self.dependencies.iter().map(|feat| feat.as_str());
203203
std::iter::once(self.llvm_feature_name).chain(dependencies)
204204
}
205205
}
@@ -209,7 +209,7 @@ impl<'a> IntoIterator for LLVMFeature<'a> {
209209
type IntoIter = impl Iterator<Item = &'a str>;
210210

211211
fn into_iter(self) -> Self::IntoIter {
212-
let dependencies = self.dependency.into_iter().map(|feat| feat.as_str());
212+
let dependencies = self.dependencies.into_iter().map(|feat| feat.as_str());
213213
std::iter::once(self.llvm_feature_name).chain(dependencies)
214214
}
215215
}
@@ -239,9 +239,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
239239
&*sess.target.arch
240240
};
241241
match (arch, s) {
242-
("x86", "sse4.2") => Some(LLVMFeature::with_dependency(
242+
("x86", "sse4.2") => Some(LLVMFeature::with_dependencies(
243243
"sse4.2",
244-
TargetFeatureFoldStrength::EnableOnly("crc32"),
244+
vec![TargetFeatureFoldStrength::EnableOnly("crc32")],
245245
)),
246246
("x86", "pclmulqdq") => Some(LLVMFeature::new("pclmul")),
247247
("x86", "rdrand") => Some(LLVMFeature::new("rdrnd")),
@@ -262,7 +262,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
262262
("aarch64", "flagm2") => Some(LLVMFeature::new("altnzcv")),
263263
// Rust ties fp and neon together.
264264
("aarch64", "neon") => {
265-
Some(LLVMFeature::with_dependency("neon", TargetFeatureFoldStrength::Both("fp-armv8")))
265+
Some(LLVMFeature::with_dependencies("neon", vec![TargetFeatureFoldStrength::Both("fp-armv8")]))
266266
}
267267
// In LLVM neon implicitly enables fp, but we manually enable
268268
// neon when a feature only implicitly enables fp
@@ -275,7 +275,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
275275
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
276276
// Enable the evex512 target feature if an avx512 target feature is enabled.
277277
("x86", s) if s.starts_with("avx512") => {
278-
Some(LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512")))
278+
Some(LLVMFeature::with_dependencies(s, vec![TargetFeatureFoldStrength::EnableOnly("evex512")]))
279279
}
280280
// Support for `wide-arithmetic` will first land in LLVM 20 as part of
281281
// llvm/llvm-project#111598
@@ -765,7 +765,7 @@ pub(crate) fn global_llvm_features(
765765
"{}{}",
766766
enable_disable, llvm_feature.llvm_feature_name
767767
))
768-
.chain(llvm_feature.dependency.into_iter().filter_map(
768+
.chain(llvm_feature.dependencies.into_iter().filter_map(
769769
move |feat| match (enable, feat) {
770770
(_, TargetFeatureFoldStrength::Both(f))
771771
| (true, TargetFeatureFoldStrength::EnableOnly(f)) => {

0 commit comments

Comments
 (0)