Skip to content

Commit 00c6bb7

Browse files
committed
add nvptx_target_feature
1 parent 9f274ba commit 00c6bb7

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+7
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
272272
// Filter out features that are not supported by the current LLVM version
273273
("aarch64", "fpmr") if get_version().0 != 18 => None,
274274
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
275+
// NVPTX targets added in LLVM 20
276+
("nvptx32" | "nvptx64", "sm_100") if get_version().0 < 20 => None,
277+
("nvptx32" | "nvptx64", "sm_100a") if get_version().0 < 20 => None,
278+
("nvptx32" | "nvptx64", "sm_101") if get_version().0 < 20 => None,
279+
("nvptx32" | "nvptx64", "sm_101a") if get_version().0 < 20 => None,
280+
("nvptx32" | "nvptx64", "sm_120") if get_version().0 < 20 => None,
281+
("nvptx32" | "nvptx64", "sm_120a") if get_version().0 < 20 => None,
275282
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single
276283
// feature called `fast-unaligned-access`. In LLVM 19, it was split back out.
277284
("riscv32" | "riscv64", "unaligned-scalar-mem") if get_version().0 == 18 => {

compiler/rustc_feature/src/unstable.rs

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ declare_features! (
324324
(unstable, loongarch_target_feature, "1.73.0", Some(44839)),
325325
(unstable, m68k_target_feature, "1.85.0", Some(134328)),
326326
(unstable, mips_target_feature, "1.27.0", Some(44839)),
327+
(unstable, nvptx_target_feature, "CURRENT_RUSTC_VERSION", Some(44839)),
327328
(unstable, powerpc_target_feature, "1.27.0", Some(44839)),
328329
(unstable, prfchw_target_feature, "1.78.0", Some(44839)),
329330
(unstable, riscv_target_feature, "1.45.0", Some(44839)),

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,7 @@ symbols! {
14471447
not,
14481448
notable_trait,
14491449
note,
1450+
nvptx_target_feature,
14501451
object_safe_for_dispatch,
14511452
of,
14521453
off,

compiler/rustc_target/src/target_features.rs

+67
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,70 @@ const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
482482
// tidy-alphabetical-end
483483
];
484484

485+
const NVPTX_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
486+
// tidy-alphabetical-start
487+
("sm_20", Unstable(sym::nvptx_target_feature), &[]),
488+
("sm_21", Unstable(sym::nvptx_target_feature), &["sm_20"]),
489+
("sm_30", Unstable(sym::nvptx_target_feature), &["sm_21"]),
490+
("sm_32", Unstable(sym::nvptx_target_feature), &["sm_30"]),
491+
("sm_35", Unstable(sym::nvptx_target_feature), &["sm_32"]),
492+
("sm_37", Unstable(sym::nvptx_target_feature), &["sm_35"]),
493+
("sm_50", Unstable(sym::nvptx_target_feature), &["sm_37"]),
494+
("sm_52", Unstable(sym::nvptx_target_feature), &["sm_50"]),
495+
("sm_53", Unstable(sym::nvptx_target_feature), &["sm_52"]),
496+
("sm_60", Unstable(sym::nvptx_target_feature), &["sm_53"]),
497+
("sm_61", Unstable(sym::nvptx_target_feature), &["sm_60"]),
498+
("sm_62", Unstable(sym::nvptx_target_feature), &["sm_61"]),
499+
("sm_70", Unstable(sym::nvptx_target_feature), &["sm_62"]),
500+
("sm_72", Unstable(sym::nvptx_target_feature), &["sm_70"]),
501+
("sm_75", Unstable(sym::nvptx_target_feature), &["sm_72"]),
502+
("sm_80", Unstable(sym::nvptx_target_feature), &["sm_75"]),
503+
("sm_86", Unstable(sym::nvptx_target_feature), &["sm_80"]),
504+
("sm_87", Unstable(sym::nvptx_target_feature), &["sm_86"]),
505+
("sm_90", Unstable(sym::nvptx_target_feature), &["sm_87"]),
506+
("sm_90a", Unstable(sym::nvptx_target_feature), &["sm_90"]),
507+
// tidy-alphabetical-end
508+
// tidy-alphabetical-start
509+
("sm_100", Unstable(sym::nvptx_target_feature), &["sm_90"]),
510+
("sm_100a", Unstable(sym::nvptx_target_feature), &["sm_100"]),
511+
("sm_101", Unstable(sym::nvptx_target_feature), &["sm_100"]),
512+
("sm_101a", Unstable(sym::nvptx_target_feature), &["sm_101"]),
513+
("sm_120", Unstable(sym::nvptx_target_feature), &["sm_101"]),
514+
("sm_120a", Unstable(sym::nvptx_target_feature), &["sm_120"]),
515+
// tidy-alphabetical-end
516+
// tidy-alphabetical-start
517+
("ptx32", Unstable(sym::nvptx_target_feature), &[]),
518+
("ptx40", Unstable(sym::nvptx_target_feature), &["ptx32"]),
519+
("ptx41", Unstable(sym::nvptx_target_feature), &["ptx40"]),
520+
("ptx42", Unstable(sym::nvptx_target_feature), &["ptx41"]),
521+
("ptx43", Unstable(sym::nvptx_target_feature), &["ptx42"]),
522+
("ptx50", Unstable(sym::nvptx_target_feature), &["ptx43"]),
523+
("ptx60", Unstable(sym::nvptx_target_feature), &["ptx50"]),
524+
("ptx61", Unstable(sym::nvptx_target_feature), &["ptx60"]),
525+
("ptx62", Unstable(sym::nvptx_target_feature), &["ptx61"]),
526+
("ptx63", Unstable(sym::nvptx_target_feature), &["ptx62"]),
527+
("ptx64", Unstable(sym::nvptx_target_feature), &["ptx63"]),
528+
("ptx65", Unstable(sym::nvptx_target_feature), &["ptx64"]),
529+
("ptx70", Unstable(sym::nvptx_target_feature), &["ptx65"]),
530+
("ptx71", Unstable(sym::nvptx_target_feature), &["ptx70"]),
531+
("ptx72", Unstable(sym::nvptx_target_feature), &["ptx71"]),
532+
("ptx73", Unstable(sym::nvptx_target_feature), &["ptx72"]),
533+
("ptx74", Unstable(sym::nvptx_target_feature), &["ptx73"]),
534+
("ptx75", Unstable(sym::nvptx_target_feature), &["ptx74"]),
535+
("ptx76", Unstable(sym::nvptx_target_feature), &["ptx75"]),
536+
("ptx77", Unstable(sym::nvptx_target_feature), &["ptx76"]),
537+
("ptx78", Unstable(sym::nvptx_target_feature), &["ptx77"]),
538+
("ptx80", Unstable(sym::nvptx_target_feature), &["ptx78"]),
539+
("ptx81", Unstable(sym::nvptx_target_feature), &["ptx80"]),
540+
("ptx82", Unstable(sym::nvptx_target_feature), &["ptx81"]),
541+
("ptx83", Unstable(sym::nvptx_target_feature), &["ptx82"]),
542+
("ptx84", Unstable(sym::nvptx_target_feature), &["ptx83"]),
543+
("ptx85", Unstable(sym::nvptx_target_feature), &["ptx84"]),
544+
("ptx86", Unstable(sym::nvptx_target_feature), &["ptx85"]),
545+
("ptx87", Unstable(sym::nvptx_target_feature), &["ptx86"]),
546+
// tidy-alphabetical-end
547+
];
548+
485549
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
486550
// tidy-alphabetical-start
487551
("a", Stable, &["zaamo", "zalrsc"]),
@@ -679,6 +743,7 @@ pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
679743
.chain(HEXAGON_FEATURES.iter())
680744
.chain(POWERPC_FEATURES.iter())
681745
.chain(MIPS_FEATURES.iter())
746+
.chain(NVPTX_FEATURES.iter())
682747
.chain(RISCV_FEATURES.iter())
683748
.chain(WASM_FEATURES.iter())
684749
.chain(BPF_FEATURES.iter())
@@ -732,6 +797,7 @@ impl Target {
732797
"x86" | "x86_64" => X86_FEATURES,
733798
"hexagon" => HEXAGON_FEATURES,
734799
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_FEATURES,
800+
"nvptx32" | "nvptx64" => NVPTX_FEATURES,
735801
"powerpc" | "powerpc64" => POWERPC_FEATURES,
736802
"riscv32" | "riscv64" => RISCV_FEATURES,
737803
"wasm32" | "wasm64" => WASM_FEATURES,
@@ -758,6 +824,7 @@ impl Target {
758824
"sparc" | "sparc64" => SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI,
759825
"hexagon" => HEXAGON_FEATURES_FOR_CORRECT_VECTOR_ABI,
760826
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_FEATURES_FOR_CORRECT_VECTOR_ABI,
827+
"nvptx" => &[], // no vector ABI
761828
"bpf" | "m68k" => &[], // no vector ABI
762829
"csky" => CSKY_FEATURES_FOR_CORRECT_VECTOR_ABI,
763830
// FIXME: for some tier3 targets, we are overly cautious and always give warnings

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
//
203203
// Target features:
204204
// tidy-alphabetical-start
205+
#![cfg_attr(not(bootstrap), feature(nvptx_target_feature))]
205206
#![feature(aarch64_unstable_target_feature)]
206207
#![feature(arm_target_feature)]
207208
#![feature(avx512_target_feature)]

tests/ui/target-feature/gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// gate-test-arm_target_feature
88
// gate-test-hexagon_target_feature
99
// gate-test-mips_target_feature
10+
// gate-test-nvptx_target_feature
1011
// gate-test-wasm_target_feature
1112
// gate-test-adx_target_feature
1213
// gate-test-cmpxchg16b_target_feature

0 commit comments

Comments
 (0)