Skip to content

Commit 3e412fa

Browse files
authored
Rollup merge of #149994 - Flakebi:amdgpu-vectors, r=jieyouxu
Allow vector types for amdgpu The amdgpu target uses vector types in various places. The vector types can be used on all architectures, there is no associated target feature that needs to be enabled. The largest vector type found in LLVM intrinsics is `v32i32` (`[32 x i32]`) for mfma intrinsics. Note that while this intrinsic is only supported on some architectures, the vector type itself is supported on all architectures. Tracking issue: #135024 (I used an empty string to say “does not need a target feature”. If you prefer an `Option` or something like that, I’ll change it.)
2 parents cebdc1a + a9b1472 commit 3e412fa

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn do_check_simd_vector_abi<'tcx>(
5454
continue;
5555
}
5656
};
57-
if !have_feature(Symbol::intern(feature)) {
57+
if !feature.is_empty() && !have_feature(Symbol::intern(feature)) {
5858
// Emit error.
5959
let (span, _hir_id) = loc();
6060
tcx.dcx().emit_err(errors::AbiErrorDisabledVectorType {

compiler/rustc_target/src/target_features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ const AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] =
918918
// We might want to add "helium" too.
919919
const ARM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "neon")];
920920

921+
const AMDGPU_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(1024, "")];
921922
const POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "altivec")];
922923
const WASM_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "simd128")];
923924
const S390X_FEATURES_FOR_CORRECT_VECTOR_ABI: &'static [(u64, &'static str)] = &[(128, "vector")];
@@ -996,12 +997,12 @@ impl Target {
996997
Arch::Mips | Arch::Mips32r6 | Arch::Mips64 | Arch::Mips64r6 => {
997998
MIPS_FEATURES_FOR_CORRECT_VECTOR_ABI
998999
}
1000+
Arch::AmdGpu => AMDGPU_FEATURES_FOR_CORRECT_VECTOR_ABI,
9991001
Arch::Nvptx64 | Arch::Bpf | Arch::M68k => &[], // no vector ABI
10001002
Arch::CSky => CSKY_FEATURES_FOR_CORRECT_VECTOR_ABI,
10011003
// FIXME: for some tier3 targets, we are overly cautious and always give warnings
10021004
// when passing args in vector registers.
1003-
Arch::AmdGpu
1004-
| Arch::Avr
1005+
Arch::Avr
10051006
| Arch::Msp430
10061007
| Arch::PowerPC64LE
10071008
| Arch::SpirV

tests/run-make/simd-ffi/rmake.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ fn main() {
1717
"arm-unknown-linux-gnueabi".to_owned(),
1818
]);
1919
}
20+
if llvm_components_contain("amdgpu") {
21+
targets.push("amdgcn-amd-amdhsa".to_owned());
22+
}
2023
let mut x86_archs = Vec::new();
2124
if llvm_components_contain("x86") {
2225
x86_archs.append(&mut vec!["i686", "x86_64"]);
@@ -52,21 +55,25 @@ fn main() {
5255
// enabled by-default for i686 and ARM; these features will be invalid
5356
// on some platforms, but LLVM just prints a warning so that's fine for
5457
// now.
58+
let mut cmd = rustc();
59+
cmd.target(&target).emit("llvm-ir,asm").input("simd.rs");
5560
let target_feature = if target.starts_with("i686") || target.starts_with("x86") {
5661
"+sse2"
5762
} else if target.starts_with("arm") || target.starts_with("aarch64") {
5863
"-soft-float,+neon"
5964
} else if target.starts_with("mips") {
6065
"+msa,+fp64"
66+
} else if target.starts_with("amdgcn") {
67+
cmd.arg("-Ctarget-cpu=gfx900");
68+
""
6169
} else {
6270
panic!("missing target_feature case for {target}");
6371
};
64-
rustc()
65-
.target(&target)
66-
.emit("llvm-ir,asm")
67-
.input("simd.rs")
68-
.arg(format!("-Ctarget-feature={target_feature}"))
69-
.arg(&format!("-Cextra-filename=-{target}"))
70-
.run();
72+
73+
if !target_feature.is_empty() {
74+
cmd.arg(format!("-Ctarget-feature={target_feature}"));
75+
}
76+
77+
cmd.arg(&format!("-Cextra-filename=-{target}")).run();
7178
}
7279
}

0 commit comments

Comments
 (0)