Skip to content

Commit e372e17

Browse files
authored
Unrolled build for rust-lang#139534
Rollup merge of rust-lang#139534 - madhav-madhusoodanan:apx-target-feature-addition, r=workingjubilee Added support for `apxf` target feature
2 parents 669c1ab + c32dc2d commit e372e17

File tree

7 files changed

+55
-17
lines changed

7 files changed

+55
-17
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+32-17
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
use crate::back::write::create_informational_target_machine;
2425
use crate::errors::{
@@ -180,27 +181,27 @@ impl<'a> TargetFeatureFoldStrength<'a> {
180181

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

186187
impl<'a> LLVMFeature<'a> {
187188
fn 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(
192193
llvm_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 {
199200
self.iter().any(|dep| dep == feat)
200201
}
201202

202203
fn 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> {
210211
type IntoIter = impl Iterator<Item = &'a str>;
211212

212213
fn 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
};
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") 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,
@@ -304,6 +307,18 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
304307
("x86", "avx10.1") => Some(LLVMFeature::new("avx10.1-512")),
305308
("x86", "avx10.2") if get_version().0 < 20 => None,
306309
("x86", "avx10.2") if get_version().0 >= 20 => Some(LLVMFeature::new("avx10.2-512")),
310+
("x86", "apxf") => Some(LLVMFeature::with_dependencies(
311+
"egpr",
312+
smallvec![
313+
TargetFeatureFoldStrength::Both("push2pop2"),
314+
TargetFeatureFoldStrength::Both("ppx"),
315+
TargetFeatureFoldStrength::Both("ndd"),
316+
TargetFeatureFoldStrength::Both("ccmp"),
317+
TargetFeatureFoldStrength::Both("cf"),
318+
TargetFeatureFoldStrength::Both("nf"),
319+
TargetFeatureFoldStrength::Both("zu"),
320+
],
321+
)),
307322
(_, s) => Some(LLVMFeature::new(s)),
308323
}
309324
}
@@ -853,7 +868,7 @@ pub(crate) fn global_llvm_features(
853868
"{}{}",
854869
enable_disable, llvm_feature.llvm_feature_name
855870
))
856-
.chain(llvm_feature.dependency.into_iter().filter_map(
871+
.chain(llvm_feature.dependencies.into_iter().filter_map(
857872
move |feat| match (enable, feat) {
858873
(_, TargetFeatureFoldStrength::Both(f))
859874
| (true, TargetFeatureFoldStrength::EnableOnly(f)) => {

compiler/rustc_feature/src/unstable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ declare_features! (
316316
// Unstable `#[target_feature]` directives.
317317
(unstable, aarch64_unstable_target_feature, "1.82.0", Some(44839)),
318318
(unstable, aarch64_ver_target_feature, "1.27.0", Some(44839)),
319+
(unstable, apx_target_feature, "CURRENT_RUSTC_VERSION", Some(139284)),
319320
(unstable, arm_target_feature, "1.27.0", Some(44839)),
320321
(unstable, avx512_target_feature, "1.27.0", Some(44839)),
321322
(unstable, bpf_target_feature, "1.54.0", Some(44839)),

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ symbols! {
459459
anonymous_lifetime_in_impl_trait,
460460
any,
461461
append_const_msg,
462+
apx_target_feature,
462463
arbitrary_enum_discriminant,
463464
arbitrary_self_types,
464465
arbitrary_self_types_pointers,

compiler/rustc_target/src/target_features.rs

+1
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
393393
("amx-tf32", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
394394
("amx-tile", Unstable(sym::x86_amx_intrinsics), &[]),
395395
("amx-transpose", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
396+
("apxf", Unstable(sym::apx_target_feature), &[]),
396397
("avx", Stable, &["sse4.2"]),
397398
(
398399
"avx10.1",

tests/ui/check-cfg/target_feature.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
2727
`amx-tf32`
2828
`amx-tile`
2929
`amx-transpose`
30+
`apxf`
3031
`atomics`
3132
`avx`
3233
`avx10.1`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ only-x86_64
2+
#[target_feature(enable = "apxf")]
3+
//~^ ERROR: currently unstable
4+
unsafe fn foo() {}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: the target feature `apxf` is currently unstable
2+
--> $DIR/feature-gate-apx-target-feature.rs:2:18
3+
|
4+
LL | #[target_feature(enable = "apxf")]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #139284 <https://github.com/rust-lang/rust/issues/139284> for more information
8+
= help: add `#![feature(apx_target_feature)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)