Skip to content

Commit 8681ac5

Browse files
committed
Use &'static str instead of String for target features.
It's a more precise type -- these are static values. Also it avoids unnecessary allocations.
1 parent 0e864be commit 8681ac5

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

crates/nvvm/src/lib.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -393,40 +393,40 @@ impl NvvmArch {
393393
}
394394

395395
/// Get the target feature string (e.g., "compute_35" for Compute35, "compute_90a" for Compute90a)
396-
pub fn target_feature(&self) -> String {
396+
pub fn target_feature(&self) -> &'static str {
397397
match self {
398-
Self::Compute35 => "compute_35".to_string(),
399-
Self::Compute37 => "compute_37".to_string(),
400-
Self::Compute50 => "compute_50".to_string(),
401-
Self::Compute52 => "compute_52".to_string(),
402-
Self::Compute53 => "compute_53".to_string(),
403-
Self::Compute60 => "compute_60".to_string(),
404-
Self::Compute61 => "compute_61".to_string(),
405-
Self::Compute62 => "compute_62".to_string(),
406-
Self::Compute70 => "compute_70".to_string(),
407-
Self::Compute72 => "compute_72".to_string(),
408-
Self::Compute75 => "compute_75".to_string(),
409-
Self::Compute80 => "compute_80".to_string(),
410-
Self::Compute86 => "compute_86".to_string(),
411-
Self::Compute87 => "compute_87".to_string(),
412-
Self::Compute89 => "compute_89".to_string(),
413-
Self::Compute90 => "compute_90".to_string(),
414-
Self::Compute90a => "compute_90a".to_string(),
415-
Self::Compute100 => "compute_100".to_string(),
416-
Self::Compute100f => "compute_100f".to_string(),
417-
Self::Compute100a => "compute_100a".to_string(),
418-
Self::Compute101 => "compute_101".to_string(),
419-
Self::Compute101f => "compute_101f".to_string(),
420-
Self::Compute101a => "compute_101a".to_string(),
421-
Self::Compute103 => "compute_103".to_string(),
422-
Self::Compute103f => "compute_103f".to_string(),
423-
Self::Compute103a => "compute_103a".to_string(),
424-
Self::Compute120 => "compute_120".to_string(),
425-
Self::Compute120f => "compute_120f".to_string(),
426-
Self::Compute120a => "compute_120a".to_string(),
427-
Self::Compute121 => "compute_121".to_string(),
428-
Self::Compute121f => "compute_121f".to_string(),
429-
Self::Compute121a => "compute_121a".to_string(),
398+
Self::Compute35 => "compute_35",
399+
Self::Compute37 => "compute_37",
400+
Self::Compute50 => "compute_50",
401+
Self::Compute52 => "compute_52",
402+
Self::Compute53 => "compute_53",
403+
Self::Compute60 => "compute_60",
404+
Self::Compute61 => "compute_61",
405+
Self::Compute62 => "compute_62",
406+
Self::Compute70 => "compute_70",
407+
Self::Compute72 => "compute_72",
408+
Self::Compute75 => "compute_75",
409+
Self::Compute80 => "compute_80",
410+
Self::Compute86 => "compute_86",
411+
Self::Compute87 => "compute_87",
412+
Self::Compute89 => "compute_89",
413+
Self::Compute90 => "compute_90",
414+
Self::Compute90a => "compute_90a",
415+
Self::Compute100 => "compute_100",
416+
Self::Compute100f => "compute_100f",
417+
Self::Compute100a => "compute_100a",
418+
Self::Compute101 => "compute_101",
419+
Self::Compute101f => "compute_101f",
420+
Self::Compute101a => "compute_101a",
421+
Self::Compute103 => "compute_103",
422+
Self::Compute103f => "compute_103f",
423+
Self::Compute103a => "compute_103a",
424+
Self::Compute120 => "compute_120",
425+
Self::Compute120f => "compute_120f",
426+
Self::Compute120a => "compute_120a",
427+
Self::Compute121 => "compute_121",
428+
Self::Compute121f => "compute_121f",
429+
Self::Compute121a => "compute_121a",
430430
}
431431
}
432432

@@ -448,18 +448,18 @@ impl NvvmArch {
448448
///
449449
/// For more details on family and architecture-specific features, see:
450450
/// <https://developer.nvidia.com/blog/nvidia-blackwell-and-nvidia-cuda-12-9-introduce-family-specific-architecture-features/>
451-
pub fn all_target_features(&self) -> Vec<String> {
452-
let mut features: Vec<String> = if self.is_architecture_variant() {
451+
pub fn all_target_features(&self) -> Vec<&'static str> {
452+
let mut features: Vec<_> = if self.is_architecture_variant() {
453453
// 'a' variants: include all available instructions for the architecture
454454
// This means: all base variants up to same version, all 'f' variants with same major and <= minor, plus itself
455-
let base_features: Vec<String> = NvvmArch::iter()
455+
let base_features: Vec<_> = NvvmArch::iter()
456456
.filter(|arch| {
457457
arch.is_base_variant() && arch.capability_value() <= self.capability_value()
458458
})
459459
.map(|arch| arch.target_feature())
460460
.collect();
461461

462-
let family_features: Vec<String> = NvvmArch::iter()
462+
let family_features: Vec<_> = NvvmArch::iter()
463463
.filter(|arch| {
464464
arch.is_family_variant()
465465
&& arch.major_version() == self.major_version()

crates/rustc_codegen_nvvm/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ impl CodegenBackend for NvvmCodegenBackend {
146146
for opt in &args.nvvm_options {
147147
if let ::nvvm::NvvmOption::Arch(arch) = opt {
148148
// Add all features up to and including the current architecture
149-
features.extend(arch.all_target_features());
149+
features.extend(
150+
arch.all_target_features()
151+
.into_iter()
152+
.map(|s| s.to_string()),
153+
);
150154
break;
151155
}
152156
}

0 commit comments

Comments
 (0)