Skip to content

Commit 470c4f9

Browse files
Rollup merge of rust-lang#133452 - taiki-e:hexagon-asm-pred, r=Amanieu
Support predicate registers (clobber-only) in Hexagon inline assembly The result of the Hexagon instructions such as comparison, store conditional, etc. is stored in predicate registers (`p[0-3]`), but currently there is no way to mark it as clobbered in `asm!`. This is also needed for `clobber_abi` (although implementing `clobber_abi` will require the addition of support for [several more register classes](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Hexagon/HexagonRegisterInfo.cpp#L71-L90). see also rust-lang#93335 (comment)). Refs: - [Section 6 "Conditional Execution" in Qualcomm Hexagon V73 Programmer’s Reference Manual](https://docs.qualcomm.com/bundle/publicresource/80-N2040-53_REV_AB_Qualcomm_Hexagon_V73_Programmers_Reference_Manual.pdf#page=90) - [Register definition in LLVM](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Hexagon/HexagonRegisterInfo.td#L155) cc `@androm3da` (target maintainer of hexagon-unknown-{[none-elf](https://doc.rust-lang.org/nightly/rustc/platform-support/hexagon-unknown-none-elf.html#target-maintainers),[linux-musl](https://doc.rust-lang.org/nightly/rustc/platform-support/hexagon-unknown-linux-musl.html#target-maintainers)}) r? `@Amanieu` `@rustbot` label +A-inline-assembly (Currently there is no O-hexagon label...)
2 parents 89ae19e + 59f01cd commit 470c4f9

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

compiler/rustc_codegen_gcc/src/asm.rs

+6
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
634634
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
635635
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
636636
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
637+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
638+
unreachable!("clobber-only")
639+
}
637640
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
638641
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
639642
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
@@ -720,6 +723,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
720723
cx.type_vector(cx.type_i64(), 2)
721724
}
722725
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
726+
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
727+
unreachable!("clobber-only")
728+
}
723729
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
724730
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
725731
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_llvm/src/asm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
645645
| Arm(ArmInlineAsmRegClass::qreg_low4) => "x",
646646
Arm(ArmInlineAsmRegClass::dreg) | Arm(ArmInlineAsmRegClass::qreg) => "w",
647647
Hexagon(HexagonInlineAsmRegClass::reg) => "r",
648+
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
648649
LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
649650
LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
650651
Mips(MipsInlineAsmRegClass::reg) => "r",
@@ -813,6 +814,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
813814
| Arm(ArmInlineAsmRegClass::qreg_low8)
814815
| Arm(ArmInlineAsmRegClass::qreg_low4) => cx.type_vector(cx.type_i64(), 2),
815816
Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
817+
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
816818
LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
817819
LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
818820
Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_target/src/asm/hexagon.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
77
def_reg_class! {
88
Hexagon HexagonInlineAsmRegClass {
99
reg,
10+
preg,
1011
}
1112
}
1213

@@ -37,6 +38,7 @@ impl HexagonInlineAsmRegClass {
3738
) -> &'static [(InlineAsmType, Option<Symbol>)] {
3839
match self {
3940
Self::reg => types! { _: I8, I16, I32, F32; },
41+
Self::preg => &[],
4042
}
4143
}
4244
}
@@ -71,6 +73,10 @@ def_regs! {
7173
r26: reg = ["r26"],
7274
r27: reg = ["r27"],
7375
r28: reg = ["r28"],
76+
p0: preg = ["p0"],
77+
p1: preg = ["p1"],
78+
p2: preg = ["p2"],
79+
p3: preg = ["p3"],
7480
#error = ["r19"] =>
7581
"r19 is used internally by LLVM and cannot be used as an operand for inline asm",
7682
#error = ["r29", "sp"] =>

src/doc/unstable-book/src/language-features/asm-experimental-arch.md

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
3030
| NVPTX | `reg32` | None\* | `r` |
3131
| NVPTX | `reg64` | None\* | `l` |
3232
| Hexagon | `reg` | `r[0-28]` | `r` |
33+
| Hexagon | `preg` | `p[0-3]` | Only clobbers |
3334
| PowerPC | `reg` | `r0`, `r[3-12]`, `r[14-28]` | `r` |
3435
| PowerPC | `reg_nonzero` | `r[3-12]`, `r[14-28]` | `b` |
3536
| PowerPC | `freg` | `f[0-31]` | `f` |
@@ -70,6 +71,7 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
7071
| NVPTX | `reg32` | None | `i8`, `i16`, `i32`, `f32` |
7172
| NVPTX | `reg64` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
7273
| Hexagon | `reg` | None | `i8`, `i16`, `i32`, `f32` |
74+
| Hexagon | `preg` | N/A | Only clobbers |
7375
| PowerPC | `reg` | None | `i8`, `i16`, `i32`, `i64` (powerpc64 only) |
7476
| PowerPC | `reg_nonzero` | None | `i8`, `i16`, `i32`, `i64` (powerpc64 only) |
7577
| PowerPC | `freg` | None | `f32`, `f64` |

tests/codegen/asm/hexagon-clobbers.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ revisions: hexagon
2+
//@[hexagon] compile-flags: --target hexagon-unknown-linux-musl
3+
//@[hexagon] needs-llvm-components: hexagon
4+
//@ compile-flags: -Zmerge-functions=disabled
5+
6+
#![crate_type = "rlib"]
7+
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
8+
#![no_core]
9+
10+
#[lang = "sized"]
11+
trait Sized {}
12+
13+
#[rustc_builtin_macro]
14+
macro_rules! asm {
15+
() => {};
16+
}
17+
18+
// CHECK-LABEL: @flags_clobber
19+
// CHECK: call void asm sideeffect "", ""()
20+
#[no_mangle]
21+
pub unsafe fn flags_clobber() {
22+
asm!("", options(nostack, nomem));
23+
}
24+
25+
// CHECK-LABEL: @no_clobber
26+
// CHECK: call void asm sideeffect "", ""()
27+
#[no_mangle]
28+
pub unsafe fn no_clobber() {
29+
asm!("", options(nostack, nomem, preserves_flags));
30+
}
31+
32+
// CHECK-LABEL: @p0_clobber
33+
// CHECK: call void asm sideeffect "", "~{p0}"()
34+
#[no_mangle]
35+
pub unsafe fn p0_clobber() {
36+
asm!("", out("p0") _, options(nostack, nomem, preserves_flags));
37+
}

0 commit comments

Comments
 (0)