Skip to content

Commit 3faef27

Browse files
committed
ABI checks: add support for loongarch
LoongArch psABI[^1] specifies that LSX vector types are passed via general-purpose registers, while LASX vector types are passed indirectly through the stack. This patch addresses the following warnings: ``` warning: this function call uses a SIMD vector type that is not currently supported with the chosen ABI --> .../library/core/src/../../stdarch/crates/core_arch/src/loongarch64/lsx/generated.rs:3695:5 | 3695 | __lsx_vreplgr2vr_b(a) | ^^^^^^^^^^^^^^^^^^^^^ function called here | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #116558 <#116558> = note: `#[warn(abi_unsupported_vector_types)]` on by default ``` [^1]: https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc
1 parent f5d1857 commit 3faef27

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ fn do_check_abi<'tcx>(
3636
target_feature_def: DefId,
3737
mut emit_err: impl FnMut(Option<&'static str>),
3838
) {
39-
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
39+
let Some(feature_def) = tcx.sess.target.features_for_correct_vector_abi() else {
40+
// Target doesn't use vector registers for vectors.
41+
return;
42+
};
4043
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
4144
for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) {
4245
let size = arg_abi.layout.size;

compiler/rustc_target/src/target_features.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -625,24 +625,27 @@ impl super::spec::Target {
625625
}
626626
}
627627

628-
pub fn features_for_correct_vector_abi(&self) -> &'static [(u64, &'static str)] {
628+
// Returns None if the given target does not use vector registers to pass vector-type data.
629+
pub fn features_for_correct_vector_abi(&self) -> Option<&'static [(u64, &'static str)]> {
629630
match &*self.arch {
630-
"x86" | "x86_64" => X86_FEATURES_FOR_CORRECT_VECTOR_ABI,
631-
"aarch64" | "arm64ec" => AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI,
632-
"arm" => ARM_FEATURES_FOR_CORRECT_VECTOR_ABI,
633-
"powerpc" | "powerpc64" => POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI,
634-
"loongarch64" => &[], // on-stack ABI, so we complain about all by-val vectors
635-
"riscv32" | "riscv64" => RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI,
636-
"wasm32" | "wasm64" => WASM_FEATURES_FOR_CORRECT_VECTOR_ABI,
637-
"s390x" => S390X_FEATURES_FOR_CORRECT_VECTOR_ABI,
638-
"sparc" | "sparc64" => SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI,
639-
"hexagon" => HEXAGON_FEATURES_FOR_CORRECT_VECTOR_ABI,
640-
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_FEATURES_FOR_CORRECT_VECTOR_ABI,
641-
"bpf" => &[], // no vector ABI
642-
"csky" => CSKY_FEATURES_FOR_CORRECT_VECTOR_ABI,
631+
"x86" | "x86_64" => Some(X86_FEATURES_FOR_CORRECT_VECTOR_ABI),
632+
"aarch64" | "arm64ec" => Some(AARCH64_FEATURES_FOR_CORRECT_VECTOR_ABI),
633+
"arm" => Some(ARM_FEATURES_FOR_CORRECT_VECTOR_ABI),
634+
"powerpc" | "powerpc64" => Some(POWERPC_FEATURES_FOR_CORRECT_VECTOR_ABI),
635+
"loongarch64" => None, // LoongArch doesn't use vector registers for vectors
636+
"riscv32" | "riscv64" => Some(RISCV_FEATURES_FOR_CORRECT_VECTOR_ABI),
637+
"wasm32" | "wasm64" => Some(WASM_FEATURES_FOR_CORRECT_VECTOR_ABI),
638+
"s390x" => Some(S390X_FEATURES_FOR_CORRECT_VECTOR_ABI),
639+
"sparc" | "sparc64" => Some(SPARC_FEATURES_FOR_CORRECT_VECTOR_ABI),
640+
"hexagon" => Some(HEXAGON_FEATURES_FOR_CORRECT_VECTOR_ABI),
641+
"mips" | "mips32r6" | "mips64" | "mips64r6" => {
642+
Some(MIPS_FEATURES_FOR_CORRECT_VECTOR_ABI)
643+
}
644+
"bpf" => Some(&[]), // no vector ABI
645+
"csky" => Some(CSKY_FEATURES_FOR_CORRECT_VECTOR_ABI),
643646
// FIXME: for some tier3 targets, we are overly cautious and always give warnings
644647
// when passing args in vector registers.
645-
_ => &[],
648+
_ => Some(&[]),
646649
}
647650
}
648651

0 commit comments

Comments
 (0)